diff --git a/.gitignore b/.gitignore index c9d9fdda..ec1016b3 100644 --- a/.gitignore +++ b/.gitignore @@ -22,11 +22,9 @@ yarn-error.log* # Compiled Object files *.o *.obj - # Executables *.bin *.elf - # PROS bin/ .vscode/ @@ -44,4 +42,5 @@ EZ-Template-Example-Project/compile_commands.json EZ-Template-Example-Project/temp.log EZ-Template-Example-Project/temp.errors EZ-Template-Example-Project/*.ini -EZ-Template-Example-Project/.d/ \ No newline at end of file +EZ-Template-Example-Project/.d/ +.d/ diff --git a/EZ-Template-Example-Project/EZ-Template-Example-Project-v3.0.1.zip b/EZ-Template-Example-Project-3.1.0.zip similarity index 60% rename from EZ-Template-Example-Project/EZ-Template-Example-Project-v3.0.1.zip rename to EZ-Template-Example-Project-3.1.0.zip index 327ffed0..1045f9f5 100644 Binary files a/EZ-Template-Example-Project/EZ-Template-Example-Project-v3.0.1.zip and b/EZ-Template-Example-Project-3.1.0.zip differ diff --git a/EZ-Template-Example-Project/.clang-format b/EZ-Template-Example-Project/.clang-format new file mode 100644 index 00000000..7318ad65 --- /dev/null +++ b/EZ-Template-Example-Project/.clang-format @@ -0,0 +1,4 @@ +BasedOnStyle: Google +ColumnLimit: 0 +TabWidth: 2 +IndentWidth: 2 diff --git a/EZ-Template-Example-Project/EZ-Template@3.0.1.zip b/EZ-Template-Example-Project/EZ-Template@3.0.1.zip deleted file mode 100644 index 31e8046b..00000000 Binary files a/EZ-Template-Example-Project/EZ-Template@3.0.1.zip and /dev/null differ diff --git a/EZ-Template-Example-Project/EZ-Template@3.1.0.zip b/EZ-Template-Example-Project/EZ-Template@3.1.0.zip new file mode 100644 index 00000000..8185d1fb Binary files /dev/null and b/EZ-Template-Example-Project/EZ-Template@3.1.0.zip differ diff --git a/EZ-Template-Example-Project/common.mk b/EZ-Template-Example-Project/common.mk index 10ab5d38..33efe871 100644 --- a/EZ-Template-Example-Project/common.mk +++ b/EZ-Template-Example-Project/common.mk @@ -5,11 +5,24 @@ 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 := $() $() COMMA := , +C_STANDARD?=gnu11 +CXX_STANDARD?=gnu++20 + DEPDIR := .d $(shell mkdir -p $(DEPDIR)) DEPFLAGS = -MT $$@ -MMD -MP -MF $(DEPDIR)/$$*.Td @@ -24,8 +37,8 @@ wlprefix=-Wl,$(subst $(SPACE),$(COMMA),$1) LNK_FLAGS=--gc-sections --start-group $(strip $(LIBRARIES)) -lgcc -lstdc++ --end-group -T$(FWDIR)/v5-common.ld ASMFLAGS=$(MFLAGS) $(WARNFLAGS) -CFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=gnu11 -CXXFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=gnu++17 +CFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(C_STANDARD) +CXXFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(CXX_STANDARD) LDFLAGS=$(MFLAGS) $(WARNFLAGS) -nostdlib $(GCCFLAGS) SIZEFLAGS=-d --common NUMFMTFLAGS=--to=iec --format %.2f --suffix=B diff --git a/EZ-Template-Example-Project/firmware/EZ-Template.a b/EZ-Template-Example-Project/firmware/EZ-Template.a index 16e2bf4a..40aa3d77 100644 Binary files a/EZ-Template-Example-Project/firmware/EZ-Template.a and b/EZ-Template-Example-Project/firmware/EZ-Template.a differ diff --git a/EZ-Template-Example-Project/firmware/liblvgl.a b/EZ-Template-Example-Project/firmware/liblvgl.a new file mode 100644 index 00000000..81e5f1a9 Binary files /dev/null and b/EZ-Template-Example-Project/firmware/liblvgl.a differ diff --git a/EZ-Template-Example-Project/firmware/libpros.a b/EZ-Template-Example-Project/firmware/libpros.a index 3dbfc1b7..43f4e941 100644 Binary files a/EZ-Template-Example-Project/firmware/libpros.a and b/EZ-Template-Example-Project/firmware/libpros.a differ diff --git a/EZ-Template-Example-Project/firmware/okapilib.a b/EZ-Template-Example-Project/firmware/okapilib.a index ae1c4df5..d8d44809 100644 Binary files a/EZ-Template-Example-Project/firmware/okapilib.a and b/EZ-Template-Example-Project/firmware/okapilib.a differ diff --git a/EZ-Template-Example-Project/include/EZ-Template/PID.hpp b/EZ-Template-Example-Project/include/EZ-Template/PID.hpp index b0e6e266..29605362 100644 --- a/EZ-Template-Example-Project/include/EZ-Template/PID.hpp +++ b/EZ-Template-Example-Project/include/EZ-Template/PID.hpp @@ -97,10 +97,21 @@ class PID { * Computes PID. * * \param current - * Current sensor library. + * Current sensor value. */ double compute(double current); + /** + * Computes PID, but you set the error yourself. This function ignores target. + * Current is only used here for calculative derivative. + * + * \param err + * Error in PID, you need to calculate this yourself. + * \param current + * Current sensor value. + */ + double compute_error(double err, double current); + /** * Returns target value. */ @@ -126,6 +137,58 @@ class PID { */ exit_condition_ exit; + /** + * Updates a secondary sensor for velocity exiting. Ideal use is IMU during normal drive motions. + * + * \param secondary_sensor + * double for a secondary sensor. + */ + void velocity_sensor_secondary_set(double secondary_sensor); + + /** + * Returns the updated secondary sensor for velocity exiting. + */ + double velocity_sensor_secondary_get(); + + /** + * Boolean for if the secondary sensor will be updated or not. True uses this sensor, false does not. + * + * \param toggle + * True uses this sensor, false does not. + */ + void velocity_sensor_secondary_toggle_set(bool toggle); + + /** + * Returns the boolean for if the secondary sensor will be updated or not. True uses this sensor, false does not. + */ + bool velocity_sensor_secondary_toggle_get(); + + /** + * Sets the threshold that the main sensor will return 0 velocity within + * + * \param zero + * a small double + */ + void velocity_sensor_main_exit_set(double zero); + + /** + * Returns the threshold that the main sensor will return 0 velocity within + */ + double velocity_sensor_main_exit_get(); + + /** + * Sets the threshold that the secondary sensor will return 0 velocity within + * + * \param zero + * a small double + */ + void velocity_sensor_secondary_exit_set(double zero); + + /** + * Returns the threshold that the secondary sensor will return 0 velocity within + */ + double velocity_sensor_secondary_exit_get(); + /** * Iterative exit condition for PID. * @@ -180,26 +243,37 @@ class PID { */ bool i_reset_get(); + /** + * Resets all timers for exit conditions. + */ + void timers_reset(); + /** * PID variables. */ - double output; - double cur; - double error; - double target; - double prev_error; - double integral; - double derivative; - long time; - long prev_time; + double output = 0.0; + double cur = 0.0; + double error = 0.0; + double target = 0.0; + double prev_error = 0.0; + double prev_current = 0.0; + double integral = 0.0; + double derivative = 0.0; + long time = 0; + long prev_time = 0; private: - int i = 0, j = 0, k = 0, l = 0; + double velocity_zero_main = 0.05; + double velocity_zero_secondary = 0.1; + int i = 0, j = 0, k = 0, l = 0, m = 0; bool is_mA = false; - void timers_reset(); + double second_sensor = 0.0; + std::string name; bool name_active = false; void exit_condition_print(ez::exit_output exit_type); bool reset_i_sgn = true; + double raw_compute(); + bool use_second_sensor = false; }; }; // namespace ez \ No newline at end of file diff --git a/EZ-Template-Example-Project/include/EZ-Template/drive/drive.hpp b/EZ-Template-Example-Project/include/EZ-Template/drive/drive.hpp index 0fddb2eb..582792d2 100644 --- a/EZ-Template-Example-Project/include/EZ-Template/drive/drive.hpp +++ b/EZ-Template-Example-Project/include/EZ-Template/drive/drive.hpp @@ -66,12 +66,12 @@ class Drive { /** * Left tracking wheel. */ - pros::ADIEncoder left_tracker; + pros::adi::Encoder left_tracker; /** * Right tracking wheel. */ - pros::ADIEncoder right_tracker; + pros::adi::Encoder right_tracker; /** * Left rotation tracker. @@ -249,7 +249,7 @@ class Drive { * \param ratio * External gear ratio, wheel gear / motor gear. */ - Drive(std::vector left_motor_ports, std::vector right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio); + Drive(std::vector left_motor_ports, std::vector right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio = 1.0); /** * Creates a Drive Controller using encoders plugged into the brain. @@ -641,7 +641,7 @@ class Drive { void drive_sensor_reset(); /** - * Resets the current gyro value. Defaults to 0, recommended to run at the start of your autonomous routine. + * Resets the current imu value. Defaults to 0, recommended to run at the start of your autonomous routine. * * \param new_heading * New heading value. @@ -649,10 +649,28 @@ class Drive { void drive_imu_reset(double new_heading = 0); /** - * Returns the current gyro value. + * Returns the current imu rotation value. */ double drive_imu_get(); + /** + * Returns the current imu accel x + accel y value. + */ + double drive_imu_accel_get(); + + /** + * Sets a new imu scaling factor. This value is multiplied by the imu to change its output. + * + * \param scaler + * Factor to scale the imu by. + */ + void drive_imu_scaler_set(double scaler); + + /** + * Returns the current imu scaling factor. + */ + double drive_imu_scaler_get(); + /** * Calibrates the IMU, recommended to run in initialize(). * @@ -834,12 +852,12 @@ class Drive { void pid_targets_reset(); /** - * Sets heading of gyro and target of PID, okapi angle. + * Sets heading of imo and target of PID, okapi angle. */ void drive_angle_set(okapi::QAngle p_angle); /** - * Sets heading of gyro and target of PID, takes double as an angle. + * Sets heading of imo and target of PID, takes double as an angle. */ void drive_angle_set(double angle); @@ -872,6 +890,19 @@ class Drive { */ void pid_wait_until(double target); + /** + * Lock the code in a while loop until the robot has settled. + * Wrapper for pid_wait_until(target), target is your previously input target + */ + void pid_wait_quick(); + + /** + * Lock the code in a while loop until the robot has settled. + * This also adds distance to target, and then exits with pid_wait_quick + * This will exit the motion while carrying momentum into the next motion. + */ + void pid_wait_quick_chain(); + /** * Autonomous interference detection. Returns true when interfered, and false when nothing happened. */ @@ -885,6 +916,24 @@ class Drive { */ void drive_ratio_set(double ratio); + /** + * @brief Set the cartridge/wheel rpm of the robot + * + * @param rpm + * rpm of the cartridge or wheel + */ + void drive_rpm_set(double rpm); + + /** + * Returns the ratio of the drive. + */ + double drive_ratio_get(); + + /** + * Returns the current cartridge / wheel rpm. + */ + double drive_rpm_get(); + /** * Changes max speed during a drive motion. * @@ -918,6 +967,29 @@ class Drive { */ PID::Constants pid_turn_constants_get(); + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets turning constants. + * + * \param input + * okapi angle unit + */ + void pid_turn_chain_constant_set(okapi::QAngle input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets turning constants. + * + * \param input + * angle in degrees + */ + void pid_turn_chain_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for turning. + */ + double pid_turn_chain_constant_get(); + /** * @brief Set the swing pid constants object * @@ -978,6 +1050,70 @@ class Drive { */ PID::Constants pid_swing_constants_backward_get(); + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets forward and backwards swing constants. + * + * \param input + * okapi angle unit + */ + void pid_swing_chain_constant_set(okapi::QAngle input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets forward swing constants. + * + * \param input + * okapi angle unit + */ + void pid_swing_chain_forward_constant_set(okapi::QAngle input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets backward swing constants. + * + * \param input + * okapi angle unit + */ + void pid_swing_chain_backward_constant_set(okapi::QAngle input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets forward and backwards swing constants. + * + * \param input + * angle in degrees + */ + void pid_swing_chain_constant_set(double input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets forward constants. + * + * \param input + * angle in degrees + */ + void pid_swing_chain_forward_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for swinging forward. + */ + double pid_swing_chain_forward_constant_get(); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets backwards swing constants. + * + * \param input + * angle in degrees + */ + void pid_swing_chain_backward_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for swinging backward. + */ + double pid_swing_chain_backward_constant_get(); + /** * @brief Set the heading pid constants object * @@ -1058,6 +1194,70 @@ class Drive { */ PID::Constants pid_drive_constants_backward_get(); + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets forward and backwards driving constants. + * + * \param input + * okapi length unit + */ + void pid_drive_chain_constant_set(okapi::QLength input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets forward driving constants. + * + * \param input + * okapi length unit + */ + void pid_drive_chain_forward_constant_set(okapi::QLength input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets backward driving constants. + * + * \param input + * okapi length unit + */ + void pid_drive_chain_backward_constant_set(okapi::QLength input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets forward and backwards driving constants. + * + * \param input + * distance in inches + */ + void pid_drive_chain_constant_set(double input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets forward driving constants. + * + * \param input + * distance in inches + */ + void pid_drive_chain_forward_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for driving forward. + */ + double pid_drive_chain_forward_constant_get(); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets backward driving constants. + * + * \param input + * distance in inches + */ + void pid_drive_chain_backward_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for driving backward. + */ + double pid_drive_chain_backward_constant_get(); + /** * Sets minimum power for swings when kI and startI are enabled. * @@ -1097,8 +1297,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. In okapi units. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. In okapi units. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_drive_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QLength p_small_error, okapi::QTime p_big_exit_time, okapi::QLength p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout); + void pid_drive_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QLength p_small_error, okapi::QTime p_big_exit_time, okapi::QLength p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu = true); /** * Set's constants for turn exit conditions. @@ -1113,8 +1315,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. In okapi units. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. In okapi units. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_turn_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout); + void pid_turn_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu = true); /** * Set's constants for swing exit conditions. @@ -1129,8 +1333,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. In okapi units. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. In okapi units. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_swing_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout); + void pid_swing_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu = true); /** * Set's constants for drive exit conditions. @@ -1145,8 +1351,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_drive_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout); + void pid_drive_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu = true); /** * Set's constants for turn exit conditions. @@ -1161,8 +1369,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_turn_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout); + void pid_turn_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu = true); /** * Set's constants for swing exit conditions. @@ -1177,8 +1387,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_swing_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout); + void pid_swing_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu = true); /** * Returns current tick_per_inch() @@ -1294,6 +1506,18 @@ class Drive { double pid_tuner_increment_start_i_get(); private: // !Auton + double chain_target_start = 0.0; + double chain_sensor_start = 0.0; + double drive_forward_motion_chain_scale = 0.0; + double drive_backward_motion_chain_scale = 0.0; + double swing_forward_motion_chain_scale = 0.0; + double swing_backward_motion_chain_scale = 0.0; + double turn_motion_chain_scale = 0.0; + double used_motion_chain_scale = 0.0; + bool motion_chain_backward = false; + + double IMU_SCALER = 1.0; + bool drive_toggle = true; bool print_toggle = true; int swing_min = 0; diff --git a/EZ-Template-Example-Project/include/EZ-Template/piston.hpp b/EZ-Template-Example-Project/include/EZ-Template/piston.hpp index 0ecb75a7..ec091ea8 100644 --- a/EZ-Template-Example-Project/include/EZ-Template/piston.hpp +++ b/EZ-Template-Example-Project/include/EZ-Template/piston.hpp @@ -14,7 +14,7 @@ class Piston { /** * Piston used throughout. */ - pros::ADIDigitalOut piston; + pros::adi::DigitalOut piston; /** * Piston constructor. This class keeps track of piston state. The starting position of your piston is FALSE. diff --git a/EZ-Template-Example-Project/include/EZ-Template/sdcard.hpp b/EZ-Template-Example-Project/include/EZ-Template/sdcard.hpp index d6c9be8c..ea8d5427 100644 --- a/EZ-Template-Example-Project/include/EZ-Template/sdcard.hpp +++ b/EZ-Template-Example-Project/include/EZ-Template/sdcard.hpp @@ -51,8 +51,8 @@ inline bool auton_selector_running; extern bool turn_off; -extern pros::ADIDigitalIn* limit_switch_left; -extern pros::ADIDigitalIn* limit_switch_right; +extern pros::adi::DigitalIn* limit_switch_left; +extern pros::adi::DigitalIn* limit_switch_right; /** * Initialize two limitswithces to change pages on the lcd * @@ -61,7 +61,7 @@ extern pros::ADIDigitalIn* limit_switch_right; * @param right_limit_port * port for the right limit switch */ -void limit_switch_lcd_initialize(pros::ADIDigitalIn* right_limit, pros::ADIDigitalIn* left_limit = nullptr); +void limit_switch_lcd_initialize(pros::adi::DigitalIn* right_limit, pros::adi::DigitalIn* left_limit = nullptr); /** * pre_auto_task diff --git a/EZ-Template-Example-Project/include/EZ-Template/slew.hpp b/EZ-Template-Example-Project/include/EZ-Template/slew.hpp index 047c34ca..53e1fa21 100644 --- a/EZ-Template-Example-Project/include/EZ-Template/slew.hpp +++ b/EZ-Template-Example-Project/include/EZ-Template/slew.hpp @@ -76,6 +76,19 @@ class slew { */ double output(); + /** + * Sets the max speed the slew can be + * + * \param speed + * maximum speed + */ + void speed_max_set(double speed); + + /** + * Returns the max speed the slew can be + */ + double speed_max_get(); + private: int sign = 0; double error = 0; diff --git a/EZ-Template-Example-Project/include/api.h b/EZ-Template-Example-Project/include/api.h index 6b09de1d..b97e65d6 100644 --- a/EZ-Template-Example-Project/include/api.h +++ b/EZ-Template-Example-Project/include/api.h @@ -39,13 +39,15 @@ #include #endif /* __cplusplus */ -#define PROS_VERSION_MAJOR 3 -#define PROS_VERSION_MINOR 8 -#define PROS_VERSION_PATCH 3 -#define PROS_VERSION_STRING "3.8.3" +#define PROS_VERSION_MAJOR 4 +#define PROS_VERSION_MINOR 1 + +#define PROS_VERSION_PATCH 0 +#define PROS_VERSION_STRING "4.1.0" #include "pros/adi.h" #include "pros/colors.h" +#include "pros/device.h" #include "pros/distance.h" #include "pros/error.h" #include "pros/ext_adi.h" @@ -63,12 +65,15 @@ #ifdef __cplusplus #include "pros/adi.hpp" +#include "pros/colors.hpp" +#include "pros/device.hpp" #include "pros/distance.hpp" #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" #include "pros/optical.hpp" #include "pros/rotation.hpp" diff --git a/EZ-Template-Example-Project/include/autons.hpp b/EZ-Template-Example-Project/include/autons.hpp index 6d96879f..654902d8 100644 --- a/EZ-Template-Example-Project/include/autons.hpp +++ b/EZ-Template-Example-Project/include/autons.hpp @@ -9,6 +9,7 @@ void turn_example(); void drive_and_turn(); void wait_until_change_speed(); void swing_example(); +void motion_chaining(); void combining_movements(); void interfered_example(); diff --git a/EZ-Template-Example-Project/include/display/README.md b/EZ-Template-Example-Project/include/display/README.md deleted file mode 100644 index afdfdeb5..00000000 --- a/EZ-Template-Example-Project/include/display/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# Littlev Graphics Libraray - -![LittlevGL cover](http://www.gl.littlev.hu/home/main_cover_small.png) - -LittlevGL provides everything you need to create a Graphical User Interface (GUI) on embedded systems with easy-to-use graphical elements, beautiful visual effects and low memory footprint. - -Homepage: https://littlevgl.com - -### Table Of Content -* [Key features](#key-features) -* [Porting](#porting) -* [Project set-up](#project-set-up) -* [PC simulator](#pc-simulator) -* [Screenshots](#screenshots) -* [Contributing](#contributing) -* [Donate](#donate) - -## Key features -* Powerful building blocks buttons, charts, lists, sliders, images etc -* Advanced graphics with animations, anti-aliasing, opacity, smooth scrolling -* Various input devices touch pad, mouse, keyboard, encoder, buttons etc -* Multi language support with UTF-8 decoding -* Fully customizable graphical elements -* Hardware independent to use with any microcontroller or display -* Scalable to operate with few memory (50 kB Flash, 10 kB RAM) -* OS, External memory and GPU supported but not required -* Single frame buffer operation even with advances graphical effects -* Written in C for maximal compatibility -* Simulator to develop on PC without embedded hardware -* Tutorials, examples, themes for rapid development -* Documentation and API references online - -## Porting -In the most sime case you need 4 things: -1. Call `lv_tick_inc(1)` in every millisecods in a Timer or Task -2. Register a function which can **copy a pixel array** to an area of the screen -3. Register a function which can **read an input device**. (E.g. touch pad) -4. Call `lv_task_handler()` periodically in every few milliseconds -For more information visit https://littlevgl.com/porting - -## Project set-up -1. **Clone** or [Download](https://littlevgl.com/download) the lvgl repository: `git clone https://github.com/littlevgl/lvgl.git` -2. **Create project** with your preferred IDE and add the *lvgl* folder -3. Copy **lvgl/lv_conf_templ.h** as **lv_conf.h** next to the *lvgl* folder -4. In the lv_conf.h delete the first `#if 0` and its `#endif`. Let the default configurations at first. -5. In your *main.c*: #include "lvgl/lvgl.h" -6. In your *main function*: - * lvgl_init(); - * tick, display and input device initialization (see above) -7. To **test** create a label: `lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);` -8. In the main *while(1)* call `lv_task_handler();` and make a few milliseconds delay (e.g. `my_delay_ms(5);`) -9. Compile the code and load it to your embedded hardware - -## PC Simulator -If you don't have got an embedded hardware you can test the graphics library in a PC simulator. The simulator uses [SDL2](https://www.libsdl.org/) to emulate a display on your monitor and a touch pad with your mouse. - -There is a pre-configured PC project for **Eclipse CDT** in this repository: https://github.com/littlevgl/pc_simulator - -## Screenshots -![TFT material](http://www.gl.littlev.hu/github_res/tft_material.png) -![TFT zen](http://www.gl.littlev.hu/github_res/tft_zen.png) -![TFT alien](http://www.gl.littlev.hu/github_res/tft_alien.png) -![TFT night](http://www.gl.littlev.hu/github_res/tft_night.png) - -## Contributing -See [CONTRIBUTING.md](https://github.com/littlevgl/lvgl/blob/master/docs/CONTRIBUTING.md) - -## Donate -If you are pleased with the graphics library, found it useful or be happy with the support you got, please help its further development: - -[![Donate](https://littlevgl.com/donate_dir/donate_btn.png)](https://littlevgl.com/donate) diff --git a/EZ-Template-Example-Project/include/display/licence.txt b/EZ-Template-Example-Project/include/display/licence.txt deleted file mode 100644 index beaef1d2..00000000 --- a/EZ-Template-Example-Project/include/display/licence.txt +++ /dev/null @@ -1,8 +0,0 @@ -MIT licence -Copyright (c) 2016 Gábor Kiss-Vámosi - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/EZ-Template-Example-Project/include/display/lv_core/lv_core.mk b/EZ-Template-Example-Project/include/display/lv_core/lv_core.mk deleted file mode 100644 index 9992e3fe..00000000 --- a/EZ-Template-Example-Project/include/display/lv_core/lv_core.mk +++ /dev/null @@ -1,12 +0,0 @@ -CSRCS += lv_group.c -CSRCS += lv_indev.c -CSRCS += lv_obj.c -CSRCS += lv_refr.c -CSRCS += lv_style.c -CSRCS += lv_vdb.c -CSRCS += lv_lang.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_core -VPATH += :$(LVGL_DIR)/lvgl/lv_core - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core" diff --git a/EZ-Template-Example-Project/include/display/lv_core/lv_group.h b/EZ-Template-Example-Project/include/display/lv_core/lv_group.h deleted file mode 100644 index 4fb6043b..00000000 --- a/EZ-Template-Example-Project/include/display/lv_core/lv_group.h +++ /dev/null @@ -1,247 +0,0 @@ -/** - * @file lv_group.h - * - */ - -#ifndef LV_GROUP_H -#define LV_GROUP_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include "lv_obj.h" - -/********************* - * DEFINES - *********************/ -/*Predefined keys to control the focused object via lv_group_send(group, c)*/ -/*For compatibility in signal function define the keys regardless to LV_GROUP*/ -#define LV_GROUP_KEY_UP 17 /*0x11*/ -#define LV_GROUP_KEY_DOWN 18 /*0x12*/ -#define LV_GROUP_KEY_RIGHT 19 /*0x13*/ -#define LV_GROUP_KEY_LEFT 20 /*0x14*/ -#define LV_GROUP_KEY_ESC 27 /*0x1B*/ -#define LV_GROUP_KEY_DEL 127 /*0x7F*/ -#define LV_GROUP_KEY_BACKSPACE 8 /*0x08*/ -#define LV_GROUP_KEY_ENTER 10 /*0x0A, '\n'*/ -#define LV_GROUP_KEY_NEXT 9 /*0x09, '\t'*/ -#define LV_GROUP_KEY_PREV 11 /*0x0B, '*/ - -#if USE_LV_GROUP != 0 -/********************** - * TYPEDEFS - **********************/ -struct _lv_group_t; - -typedef void (*lv_group_style_mod_func_t)(lv_style_t *); -typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *); - -typedef struct _lv_group_t -{ - lv_ll_t obj_ll; /*Linked list to store the objects in the group */ - lv_obj_t ** obj_focus; /*The object in focus*/ - lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/ - lv_group_style_mod_func_t style_mod_edit;/*A function which modifies the style of the focused object*/ - lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/ - lv_style_t style_tmp; /*Stores the modified style of the focused object */ - uint8_t frozen :1; /*1: can't focus to new object*/ - uint8_t editing :1; /*1: Edit mode, 0: Navigate mode*/ - uint8_t click_focus :1; /*1: If an object in a group is clicked by an indev then it will be focused */ - uint8_t refocus_policy :1; /*1: Focus prev if focused on deletion. 0: Focus prev if focused on deletion.*/ - uint8_t wrap :1; /*1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end of list.*/ -} lv_group_t; - -typedef enum _lv_group_refocus_policy_t { - LV_GROUP_REFOCUS_POLICY_NEXT = 0, - LV_GROUP_REFOCUS_POLICY_PREV = 1 -} lv_group_refocus_policy_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a new object group - * @return pointer to the new object group - */ -lv_group_t * lv_group_create(void); - -/** - * Delete a group object - * @param group pointer to a group - */ -void lv_group_del(lv_group_t * group); - -/** - * Add an object to a group - * @param group pointer to a group - * @param obj pointer to an object to add - */ -void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj); - -/** - * Remove an object from its group - * @param obj pointer to an object to remove - */ -void lv_group_remove_obj(lv_obj_t * obj); - -/** - * Focus on an object (defocus the current) - * @param obj pointer to an object to focus on - */ -void lv_group_focus_obj(lv_obj_t * obj); - -/** - * Focus the next object in a group (defocus the current) - * @param group pointer to a group - */ -void lv_group_focus_next(lv_group_t * group); - -/** - * Focus the previous object in a group (defocus the current) - * @param group pointer to a group - */ -void lv_group_focus_prev(lv_group_t * group); - -/** - * Do not let to change the focus from the current object - * @param group pointer to a group - * @param en true: freeze, false: release freezing (normal mode) - */ -void lv_group_focus_freeze(lv_group_t * group, bool en); - -/** - * Send a control character to the focuses object of a group - * @param group pointer to a group - * @param c a character (use LV_GROUP_KEY_.. to navigate) - * @return result of focused object in group. - */ -lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c); - -/** - * Set a function for a group which will modify the object's style if it is in focus - * @param group pointer to a group - * @param style_mod_func the style modifier function pointer - */ -void lv_group_set_style_mod_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func); - -/** - * Set a function for a group which will modify the object's style if it is in focus in edit mode - * @param group pointer to a group - * @param style_mod_func the style modifier function pointer - */ -void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func); - -/** - * Set a function for a group which will be called when a new object is focused - * @param group pointer to a group - * @param focus_cb the call back function or NULL if unused - */ -void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb); - -/** - * Set whether the next or previous item in a group is focused if the currently focussed obj is deleted. - * @param group pointer to a group - * @param new refocus policy enum - */ -void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy); - -/** - * Manually set the current mode (edit or navigate). - * @param group pointer to group - * @param edit: true: edit mode; false: navigate mode - */ -void lv_group_set_editing(lv_group_t * group, bool edit); - -/** - * Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked. - * @param group pointer to group - * @param en: true: enable `click_focus` - */ -void lv_group_set_click_focus(lv_group_t * group, bool en); - -/** - * Set whether focus next/prev will allow wrapping from first->last or last->first object. - * @param group pointer to group - * @param en: true: wrapping enabled; false: wrapping disabled - */ -void lv_group_set_wrap(lv_group_t * group, bool en); - -/** - * Modify a style with the set 'style_mod' function. The input style remains unchanged. - * @param group pointer to group - * @param style pointer to a style to modify - * @return a copy of the input style but modified with the 'style_mod' function - */ -lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style); - -/** - * Get the focused object or NULL if there isn't one - * @param group pointer to a group - * @return pointer to the focused object - */ -lv_obj_t * lv_group_get_focused(const lv_group_t * group); - -/** - * Get a the style modifier function of a group - * @param group pointer to a group - * @return pointer to the style modifier function - */ -lv_group_style_mod_func_t lv_group_get_style_mod_cb(const lv_group_t * group); - -/** - * Get a the style modifier function of a group in edit mode - * @param group pointer to a group - * @return pointer to the style modifier function - */ -lv_group_style_mod_func_t lv_group_get_style_mod_edit_cb(const lv_group_t * group); - -/** - * Get the focus callback function of a group - * @param group pointer to a group - * @return the call back function or NULL if not set - */ -lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group); - -/** - * Get the current mode (edit or navigate). - * @param group pointer to group - * @return true: edit mode; false: navigate mode - */ -bool lv_group_get_editing(const lv_group_t * group); - -/** - * Get the `click_focus` attribute. - * @param group pointer to group - * @return true: `click_focus` is enabled; false: disabled - */ -bool lv_group_get_click_focus(const lv_group_t * group); - -/** - * Get whether focus next/prev will allow wrapping from first->last or last->first object. - * @param group pointer to group - * @param en: true: wrapping enabled; false: wrapping disabled - */ -bool lv_group_get_wrap(lv_group_t * group); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_GROUP != 0*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_GROUP_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_core/lv_indev.h b/EZ-Template-Example-Project/include/display/lv_core/lv_indev.h deleted file mode 100644 index b066246b..00000000 --- a/EZ-Template-Example-Project/include/display/lv_core/lv_indev.h +++ /dev/null @@ -1,157 +0,0 @@ -/** - * @file lv_indev_proc.h - * - */ - -#ifndef LV_INDEV_H -#define LV_INDEV_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_obj.h" -#include "display/lv_hal/lv_hal_indev.h" -#include "display/lv_core/lv_group.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the display input device subsystem - */ -void lv_indev_init(void); - -/** - * Get the currently processed input device. Can be used in action functions too. - * @return pointer to the currently processed input device or NULL if no input device processing right now - */ -lv_indev_t * lv_indev_get_act(void); - - -/** - * Get the type of an input device - * @param indev pointer to an input device - * @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`) - */ -lv_hal_indev_type_t lv_indev_get_type(const lv_indev_t * indev); - -/** - * Reset one or all input devices - * @param indev pointer to an input device to reset or NULL to reset all of them - */ -void lv_indev_reset(lv_indev_t * indev); - -/** - * Reset the long press state of an input device - * @param indev_proc pointer to an input device - */ -void lv_indev_reset_lpr(lv_indev_t * indev); - -/** - * Enable input devices device by type - * @param type Input device type - * @param enable true: enable this type; false: disable this type - */ -void lv_indev_enable(lv_hal_indev_type_t type, bool enable); - -/** - * Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON) - * @param indev pointer to an input device - * @param cur_obj pointer to an object to be used as cursor - */ -void lv_indev_set_cursor(lv_indev_t *indev, lv_obj_t *cur_obj); - -#if USE_LV_GROUP -/** - * Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD) - * @param indev pointer to an input device - * @param group point to a group - */ -void lv_indev_set_group(lv_indev_t *indev, lv_group_t *group); -#endif - -/** - * Set the an array of points for LV_INDEV_TYPE_BUTTON. - * These points will be assigned to the buttons to press a specific point on the screen - * @param indev pointer to an input device - * @param group point to a group - */ -void lv_indev_set_button_points(lv_indev_t *indev, const lv_point_t *points); - -/** - * Set feedback callback for indev. - * @param indev pointer to an input device - * @param feedback feedback callback - */ -void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback); - -/** - * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) - * @param indev pointer to an input device - * @param point pointer to a point to store the result - */ -void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point); - -/** - * Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD) - * @param indev pointer to an input device - * @return the last pressed key (0 on error) - */ -uint32_t lv_indev_get_key(const lv_indev_t * indev); - -/** - * Check if there is dragging with an input device or not (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) - * @param indev pointer to an input device - * @return true: drag is in progress - */ -bool lv_indev_is_dragging(const lv_indev_t * indev); - -/** - * Get the vector of dragging of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) - * @param indev pointer to an input device - * @param point pointer to a point to store the vector - */ -void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point); -/** - * Get elapsed time since last press - * @param indev pointer to an input device (NULL to get the overall smallest inactivity) - * @return Elapsed ticks (milliseconds) since last press - */ -uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev); - -/** - * Get feedback callback for indev. - * @param indev pointer to an input device - * @return feedback callback - */ -lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev); - -/** - * Do nothing until the next release - * @param indev pointer to an input device - */ -void lv_indev_wait_release(lv_indev_t * indev); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_INDEV_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_core/lv_lang.h b/EZ-Template-Example-Project/include/display/lv_core/lv_lang.h deleted file mode 100644 index efbdd0a8..00000000 --- a/EZ-Template-Example-Project/include/display/lv_core/lv_lang.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @file lv_lang.h - * - */ - -#ifndef LV_LANG_H -#define LV_LANG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_MULTI_LANG - -#include - -/********************* - * DEFINES - *********************/ -#define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Change the language - * @param lang_id the id of the - */ -void lv_lang_set(uint8_t lang_id); - -/** - * Set a function to get the texts of the set languages from a `txt_id` - * @param fp a function pointer to get the texts - */ -void lv_lang_set_text_func(const void * (*fp)(uint16_t)); - -/** - * Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language - * @param txt_id an ID of the text to get - * @return the `txt_id` txt on the set language - */ -const void * lv_lang_get_text(uint16_t txt_id); - -/** - * Return with ID of the currently selected language - * @return pointer to the active screen object (loaded by 'lv_scr_load()') - */ -uint8_t lv_lang_act(void); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_MULTI_LANG*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LANG_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_core/lv_obj.h b/EZ-Template-Example-Project/include/display/lv_core/lv_obj.h deleted file mode 100644 index 02378a51..00000000 --- a/EZ-Template-Example-Project/include/display/lv_core/lv_obj.h +++ /dev/null @@ -1,841 +0,0 @@ -/** - * @file lv_obj.h - * - */ - -#ifndef LV_OBJ_H -#define LV_OBJ_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include "lv_style.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_misc/lv_mem.h" -#include "display/lv_misc/lv_ll.h" -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_log.h" - -/********************* - * DEFINES - *********************/ - -/*Error check of lv_conf.h*/ -#if LV_HOR_RES == 0 || LV_VER_RES == 0 -#error "LittlevGL: LV_HOR_RES and LV_VER_RES must be greater than 0" -#endif - -#if LV_ANTIALIAS > 1 -#error "LittlevGL: LV_ANTIALIAS can be only 0 or 1" -#endif - -#if LV_VDB_SIZE == 0 && LV_ANTIALIAS != 0 -#error "LittlevGL: If LV_VDB_SIZE == 0 the anti-aliasing must be disabled" -#endif - -#if LV_VDB_SIZE > 0 && LV_VDB_SIZE < LV_HOR_RES -#error "LittlevGL: Small Virtual Display Buffer (lv_conf.h: LV_VDB_SIZE >= LV_HOR_RES)" -#endif - -#if LV_VDB_SIZE == 0 && USE_LV_REAL_DRAW == 0 -#error "LittlevGL: If LV_VDB_SIZE = 0 Real drawing function are required (lv_conf.h: USE_LV_REAL_DRAW 1)" -#endif - - -#define LV_ANIM_IN 0x00 /*Animation to show an object. 'OR' it with lv_anim_builtin_t*/ -#define LV_ANIM_OUT 0x80 /*Animation to hide an object. 'OR' it with lv_anim_builtin_t*/ -#define LV_ANIM_DIR_MASK 0x80 /*ANIM_IN/ANIM_OUT mask*/ - -#define LV_MAX_ANCESTOR_NUM 8 - -/********************** - * TYPEDEFS - **********************/ - -struct _lv_obj_t; - -enum -{ - LV_DESIGN_DRAW_MAIN, - LV_DESIGN_DRAW_POST, - LV_DESIGN_COVER_CHK, -}; -typedef uint8_t lv_design_mode_t; - -typedef bool (* lv_design_func_t) (struct _lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode); - -enum -{ - LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action function or an operation was failed*/ - LV_RES_OK, /*The object is valid (no deleted) after the action*/ -}; -typedef uint8_t lv_res_t; - -enum -{ - /*General signals*/ - LV_SIGNAL_CLEANUP, - LV_SIGNAL_CHILD_CHG, - LV_SIGNAL_CORD_CHG, - LV_SIGNAL_STYLE_CHG, - LV_SIGNAL_REFR_EXT_SIZE, - LV_SIGNAL_LANG_CHG, - LV_SIGNAL_GET_TYPE, - - _LV_SIGNAL_FEEDBACK_SECTION_START, - /*Input device related*/ - LV_SIGNAL_PRESSED, - LV_SIGNAL_PRESSING, - LV_SIGNAL_PRESS_LOST, - LV_SIGNAL_RELEASED, - LV_SIGNAL_LONG_PRESS, - LV_SIGNAL_LONG_PRESS_REP, - LV_SIGNAL_DRAG_BEGIN, - LV_SIGNAL_DRAG_END, - - /*Group related*/ - LV_SIGNAL_FOCUS, - LV_SIGNAL_DEFOCUS, - LV_SIGNAL_CONTROLL, - _LV_SIGNAL_FEEDBACK_SECTION_END, - LV_SIGNAL_GET_EDITABLE, -}; -typedef uint8_t lv_signal_t; - -typedef lv_res_t (* lv_signal_func_t) (struct _lv_obj_t * obj, lv_signal_t sign, void * param); - -enum -{ - LV_ALIGN_CENTER = 0, - LV_ALIGN_IN_TOP_LEFT, - LV_ALIGN_IN_TOP_MID, - LV_ALIGN_IN_TOP_RIGHT, - LV_ALIGN_IN_BOTTOM_LEFT, - LV_ALIGN_IN_BOTTOM_MID, - LV_ALIGN_IN_BOTTOM_RIGHT, - LV_ALIGN_IN_LEFT_MID, - LV_ALIGN_IN_RIGHT_MID, - LV_ALIGN_OUT_TOP_LEFT, - LV_ALIGN_OUT_TOP_MID, - LV_ALIGN_OUT_TOP_RIGHT, - LV_ALIGN_OUT_BOTTOM_LEFT, - LV_ALIGN_OUT_BOTTOM_MID, - LV_ALIGN_OUT_BOTTOM_RIGHT, - LV_ALIGN_OUT_LEFT_TOP, - LV_ALIGN_OUT_LEFT_MID, - LV_ALIGN_OUT_LEFT_BOTTOM, - LV_ALIGN_OUT_RIGHT_TOP, - LV_ALIGN_OUT_RIGHT_MID, - LV_ALIGN_OUT_RIGHT_BOTTOM, -}; -typedef uint8_t lv_align_t; - -#if LV_OBJ_REALIGN -typedef struct { - const struct _lv_obj_t * base; - lv_coord_t xofs; - lv_coord_t yofs; - lv_align_t align; - uint8_t auto_realign :1; - uint8_t origo_align :1; /*1: the oigo (center of the object) was aligned with `lv_obj_align_origo`*/ -}lv_reailgn_t; -#endif - - -typedef struct _lv_obj_t -{ - struct _lv_obj_t * par; /*Pointer to the parent object*/ - lv_ll_t child_ll; /*Linked list to store the children objects*/ - - lv_area_t coords; /*Coordinates of the object (x1, y1, x2, y2)*/ - - lv_signal_func_t signal_func; /*Object type specific signal function*/ - lv_design_func_t design_func; /*Object type specific design function*/ - - void * ext_attr; /*Object type specific extended data*/ - lv_style_t * style_p; /*Pointer to the object's style*/ - -#if LV_OBJ_FREE_PTR != 0 - void * free_ptr; /*Application specific pointer (set it freely)*/ -#endif - -#if USE_LV_GROUP != 0 - void * group_p; /*Pointer to the group of the object*/ -#endif - /*Attributes and states*/ - uint8_t click :1; /*1: Can be pressed by an input device*/ - uint8_t drag :1; /*1: Enable the dragging*/ - uint8_t drag_throw :1; /*1: Enable throwing with drag*/ - uint8_t drag_parent :1; /*1: Parent will be dragged instead*/ - uint8_t hidden :1; /*1: Object is hidden*/ - uint8_t top :1; /*1: If the object or its children is clicked it goes to the foreground*/ - uint8_t opa_scale_en :1; /*1: opa_scale is set*/ - uint8_t protect; /*Automatically happening actions can be prevented. 'OR'ed values from `lv_protect_t`*/ - lv_opa_t opa_scale; /*Scale down the opacity by this factor. Effects all children as well*/ - - lv_coord_t ext_size; /*EXTtend the size of the object in every direction. E.g. for shadow drawing*/ -#if LV_OBJ_REALIGN - lv_reailgn_t realign; -#endif - -#ifdef LV_OBJ_FREE_NUM_TYPE - LV_OBJ_FREE_NUM_TYPE free_num; /*Application specific identifier (set it freely)*/ -#endif -} lv_obj_t; - -typedef lv_res_t (*lv_action_t) (struct _lv_obj_t * obj); - -/*Protect some attributes (max. 8 bit)*/ -enum -{ - LV_PROTECT_NONE = 0x00, - LV_PROTECT_CHILD_CHG = 0x01, /*Disable the child change signal. Used by the library*/ - LV_PROTECT_PARENT = 0x02, /*Prevent automatic parent change (e.g. in lv_page)*/ - LV_PROTECT_POS = 0x04, /*Prevent automatic positioning (e.g. in lv_cont layout)*/ - LV_PROTECT_FOLLOW = 0x08, /*Prevent the object be followed in automatic ordering (e.g. in lv_cont PRETTY layout)*/ - LV_PROTECT_PRESS_LOST= 0x10, /*If the `indev` was pressing this object but swiped out while pressing do not search other object.*/ - LV_PROTECT_CLICK_FOCUS= 0x20,/*Prevent focusing the object by clicking on it*/ -}; -typedef uint8_t lv_protect_t; - - -/*Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/ -typedef struct { - const char * type[LV_MAX_ANCESTOR_NUM]; /*[0]: the actual type, [1]: ancestor, [2] #1's ancestor ... [x]: "lv_obj" */ -} lv_obj_type_t; - -enum -{ - LV_ANIM_NONE = 0, - LV_ANIM_FLOAT_TOP, /*Float from/to the top*/ - LV_ANIM_FLOAT_LEFT, /*Float from/to the left*/ - LV_ANIM_FLOAT_BOTTOM, /*Float from/to the bottom*/ - LV_ANIM_FLOAT_RIGHT, /*Float from/to the right*/ - LV_ANIM_GROW_H, /*Grow/shrink horizontally*/ - LV_ANIM_GROW_V, /*Grow/shrink vertically*/ -}; -typedef uint8_t lv_anim_builtin_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init. the 'lv' library. - */ -void lv_init(void); - -/*-------------------- - * Create and delete - *-------------------*/ - -/** - * Create a basic object - * @param parent pointer to a parent object. - * If NULL then a screen will be created - * @param copy pointer to a base object, if not NULL then the new object will be copied from it - * @return pointer to the new object - */ -lv_obj_t * lv_obj_create(lv_obj_t * parent,const lv_obj_t * copy); - -/** - * Delete 'obj' and all of its children - * @param obj pointer to an object to delete - * @return LV_RES_INV because the object is deleted - */ -lv_res_t lv_obj_del(lv_obj_t * obj); - -/** - * Delete all children of an object - * @param obj pointer to an object - */ -void lv_obj_clean(lv_obj_t *obj); - -/** - * Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task' - * @param obj pointer to an object - */ -void lv_obj_invalidate(const lv_obj_t * obj); - -/*===================== - * Setter functions - *====================*/ - -/*-------------- - * Screen set - *--------------*/ - -/** - * Load a new screen - * @param scr pointer to a screen - */ -void lv_scr_load(lv_obj_t * scr); - -/*-------------------- - * Parent/children set - *--------------------*/ - -/** - * Set a new parent for an object. Its relative position will be the same. - * @param obj pointer to an object. Can't be a screen. - * @param parent pointer to the new parent object. (Can't be NULL) - */ -void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent); - -/*-------------------- - * Coordinate set - * ------------------*/ - -/** - * Set relative the position of an object (relative to the parent) - * @param obj pointer to an object - * @param x new distance from the left side of the parent - * @param y new distance from the top of the parent - */ -void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y); - -/** - * Set the x coordinate of a object - * @param obj pointer to an object - * @param x new distance from the left side from the parent - */ -void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x); - -/** - * Set the y coordinate of a object - * @param obj pointer to an object - * @param y new distance from the top of the parent - */ -void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y); - -/** - * Set the size of an object - * @param obj pointer to an object - * @param w new width - * @param h new height - */ -void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); - -/** - * Set the width of an object - * @param obj pointer to an object - * @param w new width - */ -void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w); - -/** - * Set the height of an object - * @param obj pointer to an object - * @param h new height - */ -void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h); - -/** - * Align an object to an other object. - * @param obj pointer to an object to align - * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. - * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment - */ -void lv_obj_align(lv_obj_t * obj,const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod); - -/** - * Align an object to an other object. - * @param obj pointer to an object to align - * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. - * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment - */ -void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod); - -/** - * Realign the object based on the last `lv_obj_align` parameters. - * @param obj pointer to an object - */ -void lv_obj_realign(lv_obj_t * obj); - -/** - * Enable the automatic realign of the object when its size has changed based on the last `lv_obj_align` parameters. - * @param obj pointer to an object - * @param en true: enable auto realign; false: disable auto realign - */ -void lv_obj_set_auto_realign(lv_obj_t * obj, bool en); - -/*--------------------- - * Appearance set - *--------------------*/ - -/** - * Set a new style for an object - * @param obj pointer to an object - * @param style_p pointer to the new style - */ -void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style); - -/** - * Notify an object about its style is modified - * @param obj pointer to an object - */ -void lv_obj_refresh_style(lv_obj_t * obj); - -/** - * Notify all object if a style is modified - * @param style pointer to a style. Only the objects with this style will be notified - * (NULL to notify all objects) - */ -void lv_obj_report_style_mod(lv_style_t * style); - -/*----------------- - * Attribute set - *----------------*/ - -/** - * Hide an object. It won't be visible and clickable. - * @param obj pointer to an object - * @param en true: hide the object - */ -void lv_obj_set_hidden(lv_obj_t * obj, bool en); - -/** - * Enable or disable the clicking of an object - * @param obj pointer to an object - * @param en true: make the object clickable - */ -void lv_obj_set_click(lv_obj_t * obj, bool en); - -/** - * Enable to bring this object to the foreground if it - * or any of its children is clicked - * @param obj pointer to an object - * @param en true: enable the auto top feature - */ -void lv_obj_set_top(lv_obj_t * obj, bool en); - -/** - * Enable the dragging of an object - * @param obj pointer to an object - * @param en true: make the object dragable - */ -void lv_obj_set_drag(lv_obj_t * obj, bool en); - -/** - * Enable the throwing of an object after is is dragged - * @param obj pointer to an object - * @param en true: enable the drag throw - */ -void lv_obj_set_drag_throw(lv_obj_t * obj, bool en); - -/** - * Enable to use parent for drag related operations. - * If trying to drag the object the parent will be moved instead - * @param obj pointer to an object - * @param en true: enable the 'drag parent' for the object - */ -void lv_obj_set_drag_parent(lv_obj_t * obj, bool en); - -/** - * Set editable parameter Used by groups and keyboard/encoder control. - * Editable object has something inside to choose (the elements of a list) - * @param obj pointer to an object - * @param en true: enable editing - */ -//void lv_obj_set_editable(lv_obj_t * obj, bool en); - -/** - * Set the opa scale enable parameter (required to set opa_scale with `lv_obj_set_opa_scale()`) - * @param obj pointer to an object - * @param en true: opa scaling is enabled for this object and all children; false: no opa scaling - */ -void lv_obj_set_opa_scale_enable(lv_obj_t * obj, bool en); - -/** - * Set the opa scale of an object - * @param obj pointer to an object - * @param opa_scale a factor to scale down opacity [0..255] - */ -void lv_obj_set_opa_scale(lv_obj_t * obj, lv_opa_t opa_scale); - -/** - * Set a bit or bits in the protect filed - * @param obj pointer to an object - * @param prot 'OR'-ed values from `lv_protect_t` - */ -void lv_obj_set_protect(lv_obj_t * obj, uint8_t prot); - -/** - * Clear a bit or bits in the protect filed - * @param obj pointer to an object - * @param prot 'OR'-ed values from `lv_protect_t` - */ -void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot); - -/** - * Set the signal function of an object. - * Always call the previous signal function in the new. - * @param obj pointer to an object - * @param fp the new signal function - */ -void lv_obj_set_signal_func(lv_obj_t * obj, lv_signal_func_t fp); - -/** - * Set a new design function for an object - * @param obj pointer to an object - * @param fp the new design function - */ -void lv_obj_set_design_func(lv_obj_t * obj, lv_design_func_t fp); - -/*---------------- - * Other set - *--------------*/ - -/** - * Allocate a new ext. data for an object - * @param obj pointer to an object - * @param ext_size the size of the new ext. data - * @return pointer to the allocated ext - */ -void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size); - -/** - * Send a 'LV_SIGNAL_REFR_EXT_SIZE' signal to the object - * @param obj pointer to an object - */ -void lv_obj_refresh_ext_size(lv_obj_t * obj); - -#ifdef LV_OBJ_FREE_NUM_TYPE -/** - * Set an application specific number for an object. - * It can help to identify objects in the application. - * @param obj pointer to an object - * @param free_num the new free number - */ -void lv_obj_set_free_num(lv_obj_t * obj, LV_OBJ_FREE_NUM_TYPE free_num); -#endif - -#if LV_OBJ_FREE_PTR != 0 -/** - * Set an application specific pointer for an object. - * It can help to identify objects in the application. - * @param obj pointer to an object - * @param free_p the new free pinter - */ -void lv_obj_set_free_ptr(lv_obj_t * obj, void * free_p); -#endif - -#if USE_LV_ANIMATION -/** - * Animate an object - * @param obj pointer to an object to animate - * @param type type of animation from 'lv_anim_builtin_t'. 'OR' it with ANIM_IN or ANIM_OUT - * @param time time of animation in milliseconds - * @param delay delay before the animation in milliseconds - * @param cb a function to call when the animation is ready - */ -void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint16_t delay, void (*cb) (lv_obj_t *)); -#endif - -/*======================= - * Getter functions - *======================*/ - -/*------------------ - * Screen get - *-----------------*/ - -/** - * Return with a pointer to the active screen - * @return pointer to the active screen object (loaded by 'lv_scr_load()') - */ -lv_obj_t * lv_scr_act(void); - -/** - * Return with the top layer. (Same on every screen and it is above the normal screen layer) - * @return pointer to the top layer object (transparent screen sized lv_obj) - */ -lv_obj_t * lv_layer_top(void); - -/** - * Return with the system layer. (Same on every screen and it is above the all other layers) - * It is used for example by the cursor - * @return pointer to the system layer object (transparent screen sized lv_obj) - */ -lv_obj_t * lv_layer_sys(void); - -/** - * Return with the screen of an object - * @param obj pointer to an object - * @return pointer to a screen - */ -lv_obj_t * lv_obj_get_screen(const lv_obj_t * obj); - -/*--------------------- - * Parent/children get - *--------------------*/ - -/** - * Returns with the parent of an object - * @param obj pointer to an object - * @return pointer to the parent of 'obj' - */ -lv_obj_t * lv_obj_get_parent(const lv_obj_t * obj); - -/** - * Iterate through the children of an object (start from the "youngest, lastly created") - * @param obj pointer to an object - * @param child NULL at first call to get the next children - * and the previous return value later - * @return the child after 'act_child' or NULL if no more child - */ -lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child); - -/** - * Iterate through the children of an object (start from the "oldest", firstly created) - * @param obj pointer to an object - * @param child NULL at first call to get the next children - * and the previous return value later - * @return the child after 'act_child' or NULL if no more child - */ -lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child); - -/** - * Count the children of an object (only children directly on 'obj') - * @param obj pointer to an object - * @return children number of 'obj' - */ -uint16_t lv_obj_count_children(const lv_obj_t * obj); - -/*--------------------- - * Coordinate get - *--------------------*/ - -/** - * Copy the coordinates of an object to an area - * @param obj pointer to an object - * @param cords_p pointer to an area to store the coordinates - */ -void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p); - -/** - * Get the x coordinate of object - * @param obj pointer to an object - * @return distance of 'obj' from the left side of its parent - */ -lv_coord_t lv_obj_get_x(const lv_obj_t * obj); - -/** - * Get the y coordinate of object - * @param obj pointer to an object - * @return distance of 'obj' from the top of its parent - */ -lv_coord_t lv_obj_get_y(const lv_obj_t * obj); - -/** - * Get the width of an object - * @param obj pointer to an object - * @return the width - */ -lv_coord_t lv_obj_get_width(const lv_obj_t * obj); - -/** - * Get the height of an object - * @param obj pointer to an object - * @return the height - */ -lv_coord_t lv_obj_get_height(const lv_obj_t * obj); - -/** - * Get the extended size attribute of an object - * @param obj pointer to an object - * @return the extended size attribute - */ -lv_coord_t lv_obj_get_ext_size(const lv_obj_t * obj); - -/** - * Get the automatic realign property of the object. - * @param obj pointer to an object - * @return true: auto realign is enabled; false: auto realign is disabled - */ -bool lv_obj_get_auto_realign(lv_obj_t * obj); - -/*----------------- - * Appearance get - *---------------*/ - -/** - * Get the style pointer of an object (if NULL get style of the parent) - * @param obj pointer to an object - * @return pointer to a style - */ -lv_style_t * lv_obj_get_style(const lv_obj_t * obj); - -/*----------------- - * Attribute get - *----------------*/ - -/** - * Get the hidden attribute of an object - * @param obj pointer to an object - * @return true: the object is hidden - */ -bool lv_obj_get_hidden(const lv_obj_t * obj); - -/** - * Get the click enable attribute of an object - * @param obj pointer to an object - * @return true: the object is clickable - */ -bool lv_obj_get_click(const lv_obj_t * obj); - -/** - * Get the top enable attribute of an object - * @param obj pointer to an object - * @return true: the auto top feature is enabled - */ -bool lv_obj_get_top(const lv_obj_t * obj); - -/** - * Get the drag enable attribute of an object - * @param obj pointer to an object - * @return true: the object is dragable - */ -bool lv_obj_get_drag(const lv_obj_t * obj); - -/** - * Get the drag throw enable attribute of an object - * @param obj pointer to an object - * @return true: drag throw is enabled - */ -bool lv_obj_get_drag_throw(const lv_obj_t * obj); - -/** - * Get the drag parent attribute of an object - * @param obj pointer to an object - * @return true: drag parent is enabled - */ -bool lv_obj_get_drag_parent(const lv_obj_t * obj); - - -/** - * Get the opa scale enable parameter - * @param obj pointer to an object - * @return true: opa scaling is enabled for this object and all children; false: no opa scaling - */ -lv_opa_t lv_obj_get_opa_scale_enable(const lv_obj_t * obj); - -/** - * Get the opa scale parameter of an object - * @param obj pointer to an object - * @return opa scale [0..255] - */ -lv_opa_t lv_obj_get_opa_scale(const lv_obj_t * obj); - -/** - * Get the protect field of an object - * @param obj pointer to an object - * @return protect field ('OR'ed values of `lv_protect_t`) - */ -uint8_t lv_obj_get_protect(const lv_obj_t * obj); - -/** - * Check at least one bit of a given protect bitfield is set - * @param obj pointer to an object - * @param prot protect bits to test ('OR'ed values of `lv_protect_t`) - * @return false: none of the given bits are set, true: at least one bit is set - */ -bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot); - -/** - * Get the signal function of an object - * @param obj pointer to an object - * @return the signal function - */ -lv_signal_func_t lv_obj_get_signal_func(const lv_obj_t * obj); - -/** - * Get the design function of an object - * @param obj pointer to an object - * @return the design function - */ -lv_design_func_t lv_obj_get_design_func(const lv_obj_t * obj); - -/*------------------ - * Other get - *-----------------*/ - -/** - * Get the ext pointer - * @param obj pointer to an object - * @return the ext pointer but not the dynamic version - * Use it as ext->data1, and NOT da(ext)->data1 - */ -void * lv_obj_get_ext_attr(const lv_obj_t * obj); - -/** - * Get object's and its ancestors type. Put their name in `type_buf` starting with the current type. - * E.g. buf.type[0]="lv_btn", buf.type[1]="lv_cont", buf.type[2]="lv_obj" - * @param obj pointer to an object which type should be get - * @param buf pointer to an `lv_obj_type_t` buffer to store the types - */ -void lv_obj_get_type(lv_obj_t * obj, lv_obj_type_t * buf); - -#ifdef LV_OBJ_FREE_NUM_TYPE -/** - * Get the free number - * @param obj pointer to an object - * @return the free number - */ -LV_OBJ_FREE_NUM_TYPE lv_obj_get_free_num(const lv_obj_t * obj); -#endif - -#if LV_OBJ_FREE_PTR != 0 -/** - * Get the free pointer - * @param obj pointer to an object - * @return the free pointer - */ -void * lv_obj_get_free_ptr(const lv_obj_t * obj); -#endif - -#if USE_LV_GROUP -/** - * Get the group of the object - * @param obj pointer to an object - * @return the pointer to group of the object - */ -void * lv_obj_get_group(const lv_obj_t * obj); - - -/** - * Tell whether the object is the focused object of a group or not. - * @param obj pointer to an object - * @return true: the object is focused, false: the object is not focused or not in a group - */ -bool lv_obj_is_focused(const lv_obj_t * obj); - -#endif - - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_OBJ_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_core/lv_refr.h b/EZ-Template-Example-Project/include/display/lv_core/lv_refr.h deleted file mode 100644 index 75b22d01..00000000 --- a/EZ-Template-Example-Project/include/display/lv_core/lv_refr.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - * @file lv_refr.h - * - */ - -#ifndef LV_REFR_H -#define LV_REFR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_obj.h" -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the screen refresh subsystem - */ -void lv_refr_init(void); - -/** - * Redraw the invalidated areas now. - * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can - * prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar) - * this function can be called when the screen should be updated. - */ -void lv_refr_now(void); - -/** - * Invalidate an area - * @param area_p pointer to area which should be invalidated - */ -void lv_inv_area(const lv_area_t * area_p); - -/** - * Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels - * @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num)) - */ -void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)); - -/** - * Called when an area is invalidated to modify the coordinates of the area. - * Special display controllers may require special coordinate rounding - * @param cb pointer to the a function which will modify the area - */ -void lv_refr_set_round_cb(void(*cb)(lv_area_t*)); - -/** - * Get the number of areas in the buffer - * @return number of invalid areas - */ -uint16_t lv_refr_get_buf_size(void); - -/** - * Pop (delete) the last 'num' invalidated areas from the buffer - * @param num number of areas to delete - */ -void lv_refr_pop_from_buf(uint16_t num); -/********************** - * STATIC FUNCTIONS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_REFR_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_core/lv_style.h b/EZ-Template-Example-Project/include/display/lv_core/lv_style.h deleted file mode 100644 index 4206ada3..00000000 --- a/EZ-Template-Example-Project/include/display/lv_core/lv_style.h +++ /dev/null @@ -1,199 +0,0 @@ -/** - * @file lv_style.h - * - */ - -#ifndef LV_STYLE_H -#define LV_STYLE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_misc/lv_font.h" -#include "display/lv_misc/lv_anim.h" - -/********************* - * DEFINES - *********************/ -#define LV_RADIUS_CIRCLE (LV_COORD_MAX) /*A very big radius to always draw as circle*/ - -/********************** - * TYPEDEFS - **********************/ - -/*Border types (Use 'OR'ed values)*/ -enum -{ - LV_BORDER_NONE = 0x00, - LV_BORDER_BOTTOM = 0x01, - LV_BORDER_TOP = 0x02, - LV_BORDER_LEFT = 0x04, - LV_BORDER_RIGHT = 0x08, - LV_BORDER_FULL = 0x0F, - LV_BORDER_INTERNAL = 0x10, /*FOR matrix-like objects (e.g. Button matrix)*/ -}; -typedef uint8_t lv_border_part_t; - -/*Shadow types*/ -enum -{ - LV_SHADOW_BOTTOM = 0, - LV_SHADOW_FULL, -}; -typedef uint8_t lv_shadow_type_t; - -typedef struct -{ - uint8_t glass :1; /*1: Do not inherit this style*/ - - struct { - lv_color_t main_color; - lv_color_t grad_color; /*`grad_color` will be removed in v6.0, use `aux_color` instead*/ - lv_coord_t radius; - lv_opa_t opa; - - struct { - lv_color_t color; - lv_coord_t width; - lv_border_part_t part; - lv_opa_t opa; - } border; - - struct { - lv_color_t color; - lv_coord_t width; - lv_shadow_type_t type; - } shadow; - - struct { - lv_coord_t ver; - lv_coord_t hor; - lv_coord_t inner; - } padding; - - uint8_t empty :1; /*Transparent background (border still drawn)*/ - } body; - - - struct { - lv_color_t color; - const lv_font_t * font; - lv_coord_t letter_space; - lv_coord_t line_space; - lv_opa_t opa; - } text; - - struct { - lv_color_t color; - lv_opa_t intense; - lv_opa_t opa; - } image; - - struct { - lv_color_t color; - lv_coord_t width; - lv_opa_t opa; - uint8_t rounded :1; /*1: rounded line endings*/ - } line; -} lv_style_t; - -#if USE_LV_ANIMATION -typedef struct { - const lv_style_t * style_start; /*Pointer to the starting style*/ - const lv_style_t * style_end; /*Pointer to the destination style*/ - lv_style_t * style_anim; /*Pointer to a style to animate*/ - lv_anim_cb_t end_cb; /*Call it when the animation is ready (NULL if unused)*/ - int16_t time; /*Animation time in ms*/ - int16_t act_time; /*Current time in animation. Set to negative to make delay.*/ - uint16_t playback_pause; /*Wait before play back*/ - uint16_t repeat_pause; /*Wait before repeat*/ - uint8_t playback :1; /*When the animation is ready play it back*/ - uint8_t repeat :1; /*Repeat the animation infinitely*/ -} lv_style_anim_t; - -/* Example initialization -lv_style_anim_t a; -a.style_anim = &style_to_anim; -a.style_start = &style_1; -a.style_end = &style_2; -a.act_time = 0; -a.time = 1000; -a.playback = 0; -a.playback_pause = 0; -a.repeat = 0; -a.repeat_pause = 0; -a.end_cb = NULL; -lv_style_anim_create(&a); - */ -#endif - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init the basic styles - */ -void lv_style_init (void); - -/** - * Copy a style to an other - * @param dest pointer to the destination style - * @param src pointer to the source style - */ -void lv_style_copy(lv_style_t * dest, const lv_style_t * src); - - -/** - * Mix two styles according to a given ratio - * @param start start style - * @param end end style - * @param res store the result style here - * @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style - */ -void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio); - -#if USE_LV_ANIMATION - -/** - * Create an animation from a pre-configured 'lv_style_anim_t' variable - * @param anim pointer to a pre-configured 'lv_style_anim_t' variable (will be copied) - * @return pointer to a descriptor. Really this variable will be animated. (Can be used in `lv_anim_del(dsc, NULL)`) - */ -void * lv_style_anim_create(lv_style_anim_t * anim); -#endif - -/************************* - * GLOBAL VARIABLES - *************************/ -extern lv_style_t lv_style_scr; -extern lv_style_t lv_style_transp; -extern lv_style_t lv_style_transp_fit; -extern lv_style_t lv_style_transp_tight; -extern lv_style_t lv_style_plain; -extern lv_style_t lv_style_plain_color; -extern lv_style_t lv_style_pretty; -extern lv_style_t lv_style_pretty_color; -extern lv_style_t lv_style_btn_rel; -extern lv_style_t lv_style_btn_pr; -extern lv_style_t lv_style_btn_tgl_rel; -extern lv_style_t lv_style_btn_tgl_pr; -extern lv_style_t lv_style_btn_ina; - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_STYLE_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_core/lv_vdb.h b/EZ-Template-Example-Project/include/display/lv_core/lv_vdb.h deleted file mode 100644 index 32aac5df..00000000 --- a/EZ-Template-Example-Project/include/display/lv_core/lv_vdb.h +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @file lv_vdb.h - * - */ - -#ifndef LV_VDB_H -#define LV_VDB_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if LV_VDB_SIZE != 0 - -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" - -/********************* - * DEFINES - *********************/ -/*Can be used in `lv_conf.h` the set an invalid address for the VDB. It should be replaced later by a valid address using `lv_vdb_set_adr()`*/ -#define LV_VDB_ADR_INV 8 /*8 is still too small to be valid but it's aligned on 64 bit machines as well*/ - -#ifndef LV_VDB_PX_BPP -#define LV_VDB_PX_BPP LV_COLOR_SIZE /* Default is LV_COLOR_SIZE */ -#endif - - -#if LV_VDB_TRUE_DOUBLE_BUFFERED && (LV_VDB_SIZE != LV_HOR_RES * LV_VER_RES || LV_VDB_DOUBLE == 0) -#error "With LV_VDB_TRUE_DOUBLE_BUFFERED: (LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES and LV_VDB_DOUBLE = 1 is required" -#endif - - -/* The size of VDB in bytes. - * (LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3): just divide by 8 to convert bits to bytes - * (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0): add an extra byte to round up. - * E.g. if LV_VDB_SIZE = 10 and LV_VDB_PX_BPP = 1 -> 10 bits -> 2 bytes*/ -#define LV_VDB_SIZE_IN_BYTES ((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0) - -/********************** - * TYPEDEFS - **********************/ - -typedef struct -{ - lv_area_t area; - lv_color_t *buf; -} lv_vdb_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode - * @return pointer to a 'vdb' variable - */ -lv_vdb_t * lv_vdb_get(void); - -/** - * Flush the content of the vdb - */ -void lv_vdb_flush(void); - -/** - * Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`. - * It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES` - * @param buf1 address of the VDB. - * @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0` - */ -void lv_vdb_set_adr(void * buf1, void * buf2); - -/** - * Call in the display driver's 'disp_flush' function when the flushing is finished - */ -void lv_flush_ready(void); - -/** - * Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1` - * @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB - */ -lv_vdb_t * lv_vdb_get_active(void); - -/** - * Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1` - * @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB - */ -lv_vdb_t * lv_vdb_get_inactive(void); - -/** - * Whether the flushing is in progress or not - * @return true: flushing is in progress; false: flushing ready - */ -bool lv_vdb_is_flushing(void); - -/********************** - * MACROS - **********************/ - -#else /*LV_VDB_SIZE != 0*/ - -/*Just for compatibility*/ -void lv_flush_ready(void); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_VDB_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw.h b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw.h deleted file mode 100644 index 55038836..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw.h +++ /dev/null @@ -1,115 +0,0 @@ -/** - * @file lv_draw.h - * - */ - -#ifndef LV_DRAW_H -#define LV_DRAW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include "display/lv_core/lv_style.h" -#include "display/lv_misc/lv_txt.h" - -/********************* - * DEFINES - *********************/ -/*If image pixels contains alpha we need to know how much byte is a pixel*/ -#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8 -# define LV_IMG_PX_SIZE_ALPHA_BYTE 2 -#elif LV_COLOR_DEPTH == 16 -# define LV_IMG_PX_SIZE_ALPHA_BYTE 3 -#elif LV_COLOR_DEPTH == 32 -# define LV_IMG_PX_SIZE_ALPHA_BYTE 4 -#endif - -/********************** - * TYPEDEFS - **********************/ - -enum { - LV_IMG_SRC_VARIABLE, - LV_IMG_SRC_FILE, - LV_IMG_SRC_SYMBOL, - LV_IMG_SRC_UNKNOWN, -}; -typedef uint8_t lv_img_src_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -#if LV_ANTIALIAS != 0 - -/** - * Get the opacity of a pixel based it's position in a line segment - * @param seg segment length - * @param px_id position of of a pixel which opacity should be get [0..seg-1] - * @param base_opa the base opacity - * @return the opacity of the given pixel - */ -lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa); - -/** - * Add a vertical anti-aliasing segment (pixels with decreasing opacity) - * @param x start point x coordinate - * @param y start point y coordinate - * @param length length of segment (negative value to start from 0 opacity) - * @param mask draw only in this area - * @param color color of pixels - * @param opa maximum opacity - */ -void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); - -/** - * Add a horizontal anti-aliasing segment (pixels with decreasing opacity) - * @param x start point x coordinate - * @param y start point y coordinate - * @param length length of segment (negative value to start from 0 opacity) - * @param mask draw only in this area - * @param color color of pixels - * @param opa maximum opacity - */ -void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); -#endif - -/********************** - * GLOBAL VARIABLES - **********************/ -extern void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); -extern void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); -extern void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa); -extern void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p, - const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, - lv_color_t recolor, lv_opa_t recolor_opa); - -/********************** - * MACROS - **********************/ - -/********************** - * POST INCLUDES - *********************/ -#include "lv_draw_rect.h" -#include "lv_draw_label.h" -#include "lv_draw_img.h" -#include "lv_draw_line.h" -#include "lv_draw_triangle.h" - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw.mk b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw.mk deleted file mode 100644 index a384eefe..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw.mk +++ /dev/null @@ -1,14 +0,0 @@ -CSRCS += lv_draw_vbasic.c -CSRCS += lv_draw_rbasic.c -CSRCS += lv_draw.c -CSRCS += lv_draw_rect.c -CSRCS += lv_draw_label.c -CSRCS += lv_draw_line.c -CSRCS += lv_draw_img.c -CSRCS += lv_draw_arc.c -CSRCS += lv_draw_triangle.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_draw -VPATH += :$(LVGL_DIR)/lvgl/lv_draw - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw" diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_arc.h b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_arc.h deleted file mode 100644 index 203eabe6..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_arc.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file lv_draw_arc.h - * - */ - -#ifndef LV_DRAW_ARC_H -#define LV_DRAW_ARC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Draw an arc. (Can draw pie too with great thickness.) - * @param center_x the x coordinate of the center of the arc - * @param center_y the y coordinate of the center of the arc - * @param radius the radius of the arc - * @param mask the arc will be drawn only in this mask - * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) - * @param end_angle the end angle of the arc - * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) - * @param opa_scale scale down all opacities by the factor - */ -void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask, - uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_ARC*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_img.h b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_img.h deleted file mode 100644 index ff779580..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_img.h +++ /dev/null @@ -1,167 +0,0 @@ -/** - * @file lv_draw_img.h - * - */ - -#ifndef LV_DRAW_IMG_H -#define LV_DRAW_IMG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ -#define LV_IMG_DECODER_OPEN_FAIL ((void*)(-1)) - -/********************** - * TYPEDEFS - **********************/ -struct _lv_img_t; - -typedef struct { - - /* The first 8 bit is very important to distinguish the different source types. - * For more info see `lv_img_get_src_type()` in lv_img.c */ - uint32_t cf :5; /* Color format: See `lv_img_color_format_t`*/ - uint32_t always_zero :3; /*It the upper bits of the first byte. Always zero to look like a non-printable character*/ - - uint32_t reserved :2; /*Reserved to be used later*/ - - uint32_t w:11; /*Width of the image map*/ - uint32_t h:11; /*Height of the image map*/ -} lv_img_header_t; - -/*Image color format*/ -enum { - LV_IMG_CF_UNKOWN = 0, - - LV_IMG_CF_RAW, /*Contains the file as it is. Needs custom decoder function*/ - LV_IMG_CF_RAW_ALPHA, /*Contains the file as it is. The image has alpha. Needs custom decoder function*/ - LV_IMG_CF_RAW_CHROMA_KEYED, /*Contains the file as it is. The image is chroma keyed. Needs custom decoder function*/ - - LV_IMG_CF_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/ - LV_IMG_CF_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/ - LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/ - - LV_IMG_CF_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/ - LV_IMG_CF_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/ - LV_IMG_CF_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/ - LV_IMG_CF_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/ - - LV_IMG_CF_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/ - LV_IMG_CF_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/ - LV_IMG_CF_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/ - LV_IMG_CF_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/ -}; -typedef uint8_t lv_img_cf_t; - -/* Image header it is compatible with - * the result image converter utility*/ -typedef struct -{ - lv_img_header_t header; - uint32_t data_size; - const uint8_t * data; -} lv_img_dsc_t; - -/* Decoder function definitions */ - - -/** - * Get info from an image and store in the `header` - * @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type) - * @param header store the info here - * @return LV_RES_OK: info written correctly; LV_RES_INV: failed - */ -typedef lv_res_t (*lv_img_decoder_info_f_t)(const void * src, lv_img_header_t * header); - -/** - * Open an image for decoding. Prepare it as it is required to read it later - * @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type) - * @param style the style of image (maybe it will be required to determine a color or something) - * @return there are 3 possible return values: - * 1) buffer with the decoded image - * 2) if can decode the whole image NULL. decoder_read_line will be called to read the image line-by-line - * 3) LV_IMG_DECODER_OPEN_FAIL if the image format is unknown to the decoder or an error occurred - */ -typedef const uint8_t * (*lv_img_decoder_open_f_t)(const void * src, const lv_style_t * style); - -/** - * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`. - * Required only if the "open" function can't return with the whole decoded pixel array. - * @param x start x coordinate - * @param y startt y coordinate - * @param len number of pixels to decode - * @param buf a buffer to store the decoded pixels - * @return LV_RES_OK: ok; LV_RES_INV: failed - */ -typedef lv_res_t (*lv_img_decoder_read_line_f_t)(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); - -/** - * Close the pending decoding. Free resources etc. - */ -typedef void (*lv_img_decoder_close_f_t)(void); - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Draw an image - * @param coords the coordinates of the image - * @param mask the image will be drawn only in this area - * @param src pointer to a lv_color_t array which contains the pixels of the image - * @param style style of the image - * @param opa_scale scale down all opacities by the factor - */ -void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask, - const void * src, const lv_style_t * style, lv_opa_t opa_scale); - - -/** - * Get the type of an image source - * @param src pointer to an image source: - * - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code) - * - a path to a file (e.g. "S:/folder/image.bin") - * - or a symbol (e.g. SYMBOL_CLOSE) - * @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN - */ -lv_img_src_t lv_img_src_get_type(const void * src); - -/** - * Set custom decoder functions. See the typdefs of the function typed above for more info about them - * @param info_fp info get function - * @param open_fp open function - * @param read_fp read line function - * @param close_fp clode function - */ -void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp, - lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp); - -lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header); - -uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf); - -bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf); - -bool lv_img_color_format_has_alpha(lv_img_cf_t cf); - - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TEMPL_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_label.h b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_label.h deleted file mode 100644 index 8798573d..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_label.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file lv_draw_label.h - * - */ - -#ifndef LV_DRAW_LABEL_H -#define LV_DRAW_LABEL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Write a text - * @param coords coordinates of the label - * @param mask the label will be drawn only in this area - * @param style pointer to a style - * @param opa_scale scale down all opacities by the factor - * @param txt 0 terminated text to write - * @param flag settings for the text from 'txt_flag_t' enum - * @param offset text offset in x and y direction (NULL if unused) - * - */ -void lv_draw_label(const lv_area_t * coords,const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale, - const char * txt, lv_txt_flag_t flag, lv_point_t * offset); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_LABEL_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_line.h b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_line.h deleted file mode 100644 index 4269475e..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_line.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file lv_draw_line.h - * - */ - -#ifndef LV_DRAW_LINE_H -#define LV_DRAW_LINE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Draw a line - * @param point1 first point of the line - * @param point2 second point of the line - * @param mask the line will be drawn only on this area - * @param style pointer to a line's style - * @param opa_scale scale down all opacities by the factor - */ -void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, - const lv_style_t * style, lv_opa_t opa_scale); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_LINE_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_rbasic.h b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_rbasic.h deleted file mode 100644 index 403cb806..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_rbasic.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * @file lv_draw_rbasic..h - * - */ - -#ifndef LV_DRAW_RBASIC_H -#define LV_DRAW_RBASIC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_REAL_DRAW != 0 - -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_misc/lv_font.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); - -/** - * Fill an area on the display - * @param cords_p coordinates of the area to fill - * @param mask_p fill only o this mask - * @param color fill color - * @param opa opacity (ignored, only for compatibility with lv_vfill) - */ -void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p, - lv_color_t color, lv_opa_t opa); - -/** - * Draw a letter to the display - * @param pos_p left-top coordinate of the latter - * @param mask_p the letter will be drawn only on this area - * @param font_p pointer to font - * @param letter a letter to draw - * @param color color of letter - * @param opa opacity of letter (ignored, only for compatibility with lv_vletter) - */ -void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p, - const lv_font_t * font_p, uint32_t letter, - lv_color_t color, lv_opa_t opa); - -/** - * When the letter is ant-aliased it needs to know the background color - * @param bg_color the background color of the currently drawn letter - */ -void lv_rletter_set_background(lv_color_t color); - - -/** - * Draw a color map to the display (image) - * @param cords_p coordinates the color map - * @param mask_p the map will drawn only on this area - * @param map_p pointer to a lv_color_t array - * @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap') - * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels - * @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it) - * @param recolor mix the pixels with this color - * @param recolor_opa the intense of recoloring - */ -void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p, - const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, - lv_color_t recolor, lv_opa_t recolor_opa); -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_REAL_DRAW*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_RBASIC_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_rect.h b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_rect.h deleted file mode 100644 index 933590ca..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_rect.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @file lv_draw_rect.h - * - */ - -#ifndef LV_DRAW_RECT_H -#define LV_DRAW_RECT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Draw a rectangle - * @param coords the coordinates of the rectangle - * @param mask the rectangle will be drawn only in this mask - * @param style pointer to a style - * @param opa_scale scale down all opacities by the factor - */ -void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_RECT_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_vbasic.h b/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_vbasic.h deleted file mode 100644 index 82d4b7a1..00000000 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_vbasic.h +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @file lv_draw_vbasic.h - * - */ - -#ifndef LV_DRAW_VBASIC_H -#define LV_DRAW_VBASIC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if LV_VDB_SIZE != 0 - -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_misc/lv_font.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); -/** - * Fill an area in the Virtual Display Buffer - * @param cords_p coordinates of the area to fill - * @param mask_p fill only o this mask - * @param color fill color - * @param opa opacity of the area (0..255) - */ -void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p, - lv_color_t color, lv_opa_t opa); - -/** - * Draw a letter in the Virtual Display Buffer - * @param pos_p left-top coordinate of the latter - * @param mask_p the letter will be drawn only on this area - * @param font_p pointer to font - * @param letter a letter to draw - * @param color color of letter - * @param opa opacity of letter (0..255) - */ -void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p, - const lv_font_t * font_p, uint32_t letter, - lv_color_t color, lv_opa_t opa); - -/** - * Draw a color map to the display (image) - * @param cords_p coordinates the color map - * @param mask_p the map will drawn only on this area (truncated to VDB area) - * @param map_p pointer to a lv_color_t array - * @param opa opacity of the map - * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels - * @param alpha_byte true: extra alpha byte is inserted for every pixel - * @param recolor mix the pixels with this color - * @param recolor_opa the intense of recoloring - */ -void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p, - const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, - lv_color_t recolor, lv_opa_t recolor_opa); - -/********************** - * MACROS - **********************/ - -#endif /*LV_VDB_SIZE != 0*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_RBASIC_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_fonts/lv_font_builtin.h b/EZ-Template-Example-Project/include/display/lv_fonts/lv_font_builtin.h deleted file mode 100644 index 5687fa1f..00000000 --- a/EZ-Template-Example-Project/include/display/lv_fonts/lv_font_builtin.h +++ /dev/null @@ -1,150 +0,0 @@ -/** - * @file lv_font_builtin.h - * - */ - -#ifndef LV_FONT_BUILTIN_H -#define LV_FONT_BUILTIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include "display/lv_misc/lv_font.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the built-in fonts - */ -void lv_font_builtin_init(void); - -/********************** - * MACROS - **********************/ - -/********************** - * FONT DECLARATIONS - **********************/ - -/*10 px */ -#if USE_LV_FONT_DEJAVU_10 -LV_FONT_DECLARE(lv_font_dejavu_10); -#endif - -#if USE_LV_FONT_DEJAVU_10_LATIN_SUP -LV_FONT_DECLARE(lv_font_dejavu_10_latin_sup); -#endif - -#if USE_LV_FONT_DEJAVU_10_CYRILLIC -LV_FONT_DECLARE(lv_font_dejavu_10_cyrillic); -#endif - -#if USE_LV_FONT_SYMBOL_10 -LV_FONT_DECLARE(lv_font_symbol_10); -#endif - -/*20 px */ -#if USE_LV_FONT_DEJAVU_20 -LV_FONT_DECLARE(lv_font_dejavu_20); -#endif - -#if USE_LV_FONT_DEJAVU_20_LATIN_SUP -LV_FONT_DECLARE(lv_font_dejavu_20_latin_sup); -#endif - -#if USE_LV_FONT_DEJAVU_20_CYRILLIC -LV_FONT_DECLARE(lv_font_dejavu_20_cyrillic); -#endif - -#if USE_LV_FONT_SYMBOL_20 -LV_FONT_DECLARE(lv_font_symbol_20); -#endif - -/*30 px */ -#if USE_LV_FONT_DEJAVU_30 -LV_FONT_DECLARE(lv_font_dejavu_30); -#endif - -#if USE_LV_FONT_DEJAVU_30_LATIN_SUP -LV_FONT_DECLARE(lv_font_dejavu_30_latin_sup); -#endif - -#if USE_LV_FONT_DEJAVU_30_CYRILLIC -LV_FONT_DECLARE(lv_font_dejavu_30_cyrillic); -#endif - -#if USE_LV_FONT_SYMBOL_30 -LV_FONT_DECLARE(lv_font_symbol_30); -#endif - -/*40 px */ -#if USE_LV_FONT_DEJAVU_40 -LV_FONT_DECLARE(lv_font_dejavu_40); -#endif - -#if USE_LV_FONT_DEJAVU_40_LATIN_SUP -LV_FONT_DECLARE(lv_font_dejavu_40_latin_sup); -#endif - -#if USE_LV_FONT_DEJAVU_40_CYRILLIC -LV_FONT_DECLARE(lv_font_dejavu_40_cyrillic); -#endif - -#if USE_LV_FONT_SYMBOL_40 -LV_FONT_DECLARE(lv_font_symbol_40); -#endif - -#if USE_LV_FONT_MONOSPACE_8 -LV_FONT_DECLARE(lv_font_monospace_8); -#endif - -#if USE_PROS_FONT_DEJAVU_MONO_10 -LV_FONT_DECLARE(pros_font_dejavu_mono_10); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_10_LATIN_SUP -LV_FONT_DECLARE(pros_font_dejavu_mono_10_latin_sup); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_20 -LV_FONT_DECLARE(pros_font_dejavu_mono_20); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_20_LATIN_SUP -LV_FONT_DECLARE(pros_font_dejavu_mono_20_latin_sup); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_30 -LV_FONT_DECLARE(pros_font_dejavu_mono_30); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_30_LATIN_SUP -LV_FONT_DECLARE(pros_font_dejavu_mono_30_latin_sup); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_40 -LV_FONT_DECLARE(pros_font_dejavu_mono_40); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_40_LATIN_SUP -LV_FONT_DECLARE(pros_font_dejavu_mono_40_latin_sup); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_FONT_BUILTIN_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_fonts/lv_fonts.mk b/EZ-Template-Example-Project/include/display/lv_fonts/lv_fonts.mk deleted file mode 100644 index f124b559..00000000 --- a/EZ-Template-Example-Project/include/display/lv_fonts/lv_fonts.mk +++ /dev/null @@ -1,23 +0,0 @@ -CSRCS += lv_font_builtin.c -CSRCS += lv_font_dejavu_10.c -CSRCS += lv_font_dejavu_20.c -CSRCS += lv_font_dejavu_30.c -CSRCS += lv_font_dejavu_40.c -CSRCS += lv_font_dejavu_10_cyrillic.c -CSRCS += lv_font_dejavu_20_cyrillic.c -CSRCS += lv_font_dejavu_30_cyrillic.c -CSRCS += lv_font_dejavu_40_cyrillic.c -CSRCS += lv_font_dejavu_10_latin_sup.c -CSRCS += lv_font_dejavu_20_latin_sup.c -CSRCS += lv_font_dejavu_30_latin_sup.c -CSRCS += lv_font_dejavu_40_latin_sup.c -CSRCS += lv_font_symbol_10.c -CSRCS += lv_font_symbol_20.c -CSRCS += lv_font_symbol_30.c -CSRCS += lv_font_symbol_40.c -CSRCS += lv_font_monospace_8.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_fonts -VPATH += :$(LVGL_DIR)/lvgl/lv_fonts - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_fonts" diff --git a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal.mk b/EZ-Template-Example-Project/include/display/lv_hal/lv_hal.mk deleted file mode 100644 index 83f4bf17..00000000 --- a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal.mk +++ /dev/null @@ -1,8 +0,0 @@ -CSRCS += lv_hal_disp.c -CSRCS += lv_hal_indev.c -CSRCS += lv_hal_tick.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_hal -VPATH += :$(LVGL_DIR)/lvgl/lv_hal - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal" diff --git a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal_disp.h b/EZ-Template-Example-Project/include/display/lv_hal/lv_hal_disp.h deleted file mode 100644 index 273f3314..00000000 --- a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal_disp.h +++ /dev/null @@ -1,174 +0,0 @@ -/** - * @file hal_disp.h - * - * @description Display Driver HAL interface header file - * - */ - -#ifndef HAL_DISP_H -#define HAL_DISP_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include -#include -#include "lv_hal.h" -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/** - * Display Driver structure to be registered by HAL - */ -typedef struct _disp_drv_t { - /*Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has to be called when finished*/ - void (*disp_flush)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); - - /*Fill an area with a color on the display*/ - void (*disp_fill)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); - - /*Write pixel map (e.g. image) to the display*/ - void (*disp_map)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); - - /*Optional interface functions to use GPU*/ -#if USE_LV_GPU - /*Blend two memories using opacity (GPU only)*/ - void (*mem_blend)(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa); - - /*Fill a memory with a color (GPU only)*/ - void (*mem_fill)(lv_color_t * dest, uint32_t length, lv_color_t color); -#endif - -#if LV_VDB_SIZE - /*Optional: Set a pixel in a buffer according to the requirements of the display*/ - void (*vdb_wr)(uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa); -#endif -} lv_disp_drv_t; - -typedef struct _disp_t { - lv_disp_drv_t driver; - struct _disp_t *next; -} lv_disp_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize a display driver with default values. - * It is used to surly have known values in the fields ant not memory junk. - * After it you can set the fields. - * @param driver pointer to driver variable to initialize - */ -void lv_disp_drv_init(lv_disp_drv_t *driver); - -/** - * Register an initialized display driver. - * Automatically set the first display as active. - * @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable) - * @return pointer to the new display or NULL on error - */ -lv_disp_t * lv_disp_drv_register(lv_disp_drv_t *driver); - -/** - * Set the active display - * @param disp pointer to a display (return value of 'lv_disp_register') - */ -void lv_disp_set_active(lv_disp_t * disp); - -/** - * Get a pointer to the active display - * @return pointer to the active display - */ -lv_disp_t * lv_disp_get_active(void); - -/** - * Get the next display. - * @param disp pointer to the current display. NULL to initialize. - * @return the next display or NULL if no more. Give the first display when the parameter is NULL - */ -lv_disp_t * lv_disp_next(lv_disp_t * disp); - -/** - * Fill a rectangular area with a color on the active display - * @param x1 left coordinate of the rectangle - * @param x2 right coordinate of the rectangle - * @param y1 top coordinate of the rectangle - * @param y2 bottom coordinate of the rectangle - * @param color_p pointer to an array of colors - */ -void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p); - -/** - * Fill a rectangular area with a color on the active display - * @param x1 left coordinate of the rectangle - * @param x2 right coordinate of the rectangle - * @param y1 top coordinate of the rectangle - * @param y2 bottom coordinate of the rectangle - * @param color fill color - */ -void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); - -/** - * Put a color map to a rectangular area on the active display - * @param x1 left coordinate of the rectangle - * @param x2 right coordinate of the rectangle - * @param y1 top coordinate of the rectangle - * @param y2 bottom coordinate of the rectangle - * @param color_map pointer to an array of colors - */ -void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map); - -#if USE_LV_GPU -/** - * Blend pixels to a destination memory from a source memory - * In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available) - * @param dest a memory address. Blend 'src' here. - * @param src pointer to pixel map. Blend it to 'dest'. - * @param length number of pixels in 'src' - * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) - */ -void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa); - -/** - * Fill a memory with a color (GPUs may support it) - * In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available) - * @param dest a memory address. Copy 'src' here. - * @param src pointer to pixel map. Copy it to 'dest'. - * @param length number of pixels in 'src' - * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) - */ -void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color); -/** - * Shows if memory blending (by GPU) is supported or not - * @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver - */ -bool lv_disp_is_mem_blend_supported(void); - -/** - * Shows if memory fill (by GPU) is supported or not - * @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver - */ -bool lv_disp_is_mem_fill_supported(void); -#endif -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal_indev.h b/EZ-Template-Example-Project/include/display/lv_hal/lv_hal_indev.h deleted file mode 100644 index 0252dc47..00000000 --- a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal_indev.h +++ /dev/null @@ -1,166 +0,0 @@ -/** - * @file hal_indev.h - * - * @description Input Device HAL interface layer header file - * - */ - -#ifndef HAL_INDEV_H -#define HAL_INDEV_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include -#include -#include "lv_hal.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Possible input device types*/ -enum { - LV_INDEV_TYPE_NONE, /*Show uninitialized state*/ - LV_INDEV_TYPE_POINTER, /*Touch pad, mouse, external button*/ - LV_INDEV_TYPE_KEYPAD, /*Keypad or keyboard*/ - LV_INDEV_TYPE_BUTTON, /*External (hardware button) which is assinged to a specific point of the screen*/ - LV_INDEV_TYPE_ENCODER, /*Encoder with only Left, Right turn and a Button*/ -}; -typedef uint8_t lv_hal_indev_type_t; - -/*States for input devices*/ -enum { - LV_INDEV_STATE_REL = 0, - LV_INDEV_STATE_PR -}; -typedef uint8_t lv_indev_state_t; - -/*Data type when an input device is read */ -typedef struct { - union { - lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/ - uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ - uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/ - int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/ - }; - void *user_data; /*'lv_indev_drv_t.priv' for this driver*/ - lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ -} lv_indev_data_t; - -/*Initialized by the user and registered by 'lv_indev_add()'*/ -typedef struct { - lv_hal_indev_type_t type; /*Input device type*/ - bool (*read)(lv_indev_data_t *data); /*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/ - void *user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/ -} lv_indev_drv_t; - -struct _lv_obj_t; - -/*Run time data of input devices*/ -typedef struct _lv_indev_proc_t { - lv_indev_state_t state; - union { - struct { /*Pointer and button data*/ - lv_point_t act_point; - lv_point_t last_point; - lv_point_t vect; - lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DRAG_LIMIT*/ - struct _lv_obj_t * act_obj; - struct _lv_obj_t * last_obj; - - /*Flags*/ - uint8_t drag_range_out :1; - uint8_t drag_in_prog :1; - uint8_t wait_unil_release :1; - }; - struct { /*Keypad data*/ - lv_indev_state_t last_state; - uint32_t last_key; - }; - }; - - uint32_t pr_timestamp; /*Pressed time stamp*/ - uint32_t longpr_rep_timestamp; /*Long press repeat time stamp*/ - - /*Flags*/ - uint8_t long_pr_sent :1; - uint8_t reset_query :1; - uint8_t disabled :1; -} lv_indev_proc_t; - -struct _lv_indev_t; - -typedef void (*lv_indev_feedback_t)(struct _lv_indev_t *, lv_signal_t); - -struct _lv_obj_t; -struct _lv_group_t; - -/*The main input device descriptor with driver, runtime data ('proc') and some additional information*/ -typedef struct _lv_indev_t { - lv_indev_drv_t driver; - lv_indev_proc_t proc; - lv_indev_feedback_t feedback; - uint32_t last_activity_time; - union { - struct _lv_obj_t *cursor; /*Cursor for LV_INPUT_TYPE_POINTER*/ - struct _lv_group_t *group; /*Keypad destination group*/ - const lv_point_t * btn_points; /*Array points assigned to the button ()screen will be pressed here by the buttons*/ - - }; - struct _lv_indev_t *next; -} lv_indev_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize an input device driver with default values. - * It is used to surly have known values in the fields ant not memory junk. - * After it you can set the fields. - * @param driver pointer to driver variable to initialize - */ -void lv_indev_drv_init(lv_indev_drv_t *driver); - -/** - * Register an initialized input device driver. - * @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable) - * @return pointer to the new input device or NULL on error - */ -lv_indev_t * lv_indev_drv_register(lv_indev_drv_t *driver); - -/** - * Get the next input device. - * @param indev pointer to the current input device. NULL to initialize. - * @return the next input devise or NULL if no more. Gives the first input device when the parameter is NULL - */ -lv_indev_t * lv_indev_next(lv_indev_t * indev); - -/** - * Read data from an input device. - * @param indev pointer to an input device - * @param data input device will write its data here - * @return false: no more data; true: there more data to read (buffered) - */ -bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t *data); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_anim.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_anim.h deleted file mode 100644 index b3b8553b..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_anim.h +++ /dev/null @@ -1,177 +0,0 @@ -/** - * @file anim.h - * - */ - -#ifndef ANIM_H -#define ANIM_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_ANIMATION - -#include -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -struct _lv_anim_t; - -typedef int32_t(*lv_anim_path_t)(const struct _lv_anim_t*); - -typedef void (*lv_anim_fp_t)(void *, int32_t); -typedef void (*lv_anim_cb_t)(void *); - -typedef struct _lv_anim_t -{ - void * var; /*Variable to animate*/ - lv_anim_fp_t fp; /*Animator function*/ - lv_anim_cb_t end_cb; /*Call it when the animation is ready*/ - lv_anim_path_t path; /*An array with the steps of animations*/ - int32_t start; /*Start value*/ - int32_t end; /*End value*/ - uint16_t time; /*Animation time in ms*/ - int16_t act_time; /*Current time in animation. Set to negative to make delay.*/ - uint16_t playback_pause; /*Wait before play back*/ - uint16_t repeat_pause; /*Wait before repeat*/ - uint8_t playback :1; /*When the animation is ready play it back*/ - uint8_t repeat :1; /*Repeat the animation infinitely*/ - /*Animation system use these - user shouldn't set*/ - uint8_t playback_now :1; /*Play back is in progress*/ - uint32_t has_run :1; /*Indicates the animation has run it this round*/ -} lv_anim_t; - -/*Example initialization -lv_anim_t a; -a.var = obj; -a.start = lv_obj_get_height(obj); -a.end = new_height; -a.fp = (lv_anim_fp_t)lv_obj_set_height; -a.path = lv_anim_path_linear; -a.end_cb = NULL; -a.act_time = 0; -a.time = 200; -a.playback = 0; -a.playback_pause = 0; -a.repeat = 0; -a.repeat_pause = 0; -lv_anim_create(&a); - */ -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init. the animation module - */ -void lv_anim_init(void); - -/** - * Create an animation - * @param anim_p an initialized 'anim_t' variable. Not required after call. - */ -void lv_anim_create(lv_anim_t * anim_p); - -/** - * Delete an animation for a variable with a given animatior function - * @param var pointer to variable - * @param fp a function pointer which is animating 'var', - * or NULL to ignore it and delete all animation with 'var - * @return true: at least 1 animation is deleted, false: no animation is deleted - */ -bool lv_anim_del(void * var, lv_anim_fp_t fp); - -/** - * Get the number of currently running animations - * @return the number of running animations - */ -uint16_t lv_anim_count_running(void); - -/** - * Calculate the time of an animation with a given speed and the start and end values - * @param speed speed of animation in unit/sec - * @param start start value of the animation - * @param end end value of the animation - * @return the required time [ms] for the animation with the given parameters - */ -uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end); - -/** - * Calculate the current value of an animation applying linear characteristic - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_linear(const lv_anim_t *a); - -/** - * Calculate the current value of an animation slowing down the start phase - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_ease_in(const lv_anim_t * a); - -/** - * Calculate the current value of an animation slowing down the end phase - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_ease_out(const lv_anim_t * a); - -/** - * Calculate the current value of an animation applying an "S" characteristic (cosine) - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_ease_in_out(const lv_anim_t *a); - -/** - * Calculate the current value of an animation with overshoot at the end - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_overshoot(const lv_anim_t * a); - -/** - * Calculate the current value of an animation with 3 bounces - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_bounce(const lv_anim_t * a); - -/** - * Calculate the current value of an animation applying step characteristic. - * (Set end value on the end of the animation) - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_step(const lv_anim_t *a); -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_ANIMATION == 0*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_ANIM_H*/ - diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_area.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_area.h deleted file mode 100644 index fc8b7dec..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_area.h +++ /dev/null @@ -1,169 +0,0 @@ -/** - * @file lv_area.h - * - */ - -#ifndef LV_AREA_H -#define LV_AREA_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#include -#include -#include - -/********************* - * DEFINES - *********************/ -#define LV_COORD_MAX (16383) /*To avoid overflow don't let the max [-32,32k] range */ -#define LV_COORD_MIN (-16384) - -/********************** - * TYPEDEFS - **********************/ -typedef int16_t lv_coord_t; - -typedef struct -{ - lv_coord_t x; - lv_coord_t y; -} lv_point_t; - -typedef struct -{ - lv_coord_t x1; - lv_coord_t y1; - lv_coord_t x2; - lv_coord_t y2; -} lv_area_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize an area - * @param area_p pointer to an area - * @param x1 left coordinate of the area - * @param y1 top coordinate of the area - * @param x2 right coordinate of the area - * @param y2 bottom coordinate of the area - */ -void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2); - -/** - * Copy an area - * @param dest pointer to the destination area - * @param src pointer to the source area - */ -inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src) -{ - memcpy(dest, src, sizeof(lv_area_t)); -} - -/** - * Get the width of an area - * @param area_p pointer to an area - * @return the width of the area (if x1 == x2 -> width = 1) - */ -static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p) -{ - return area_p->x2 - area_p->x1 + 1; -} - -/** - * Get the height of an area - * @param area_p pointer to an area - * @return the height of the area (if y1 == y2 -> height = 1) - */ -static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p) -{ - return area_p->y2 - area_p->y1 + 1; -} - -/** - * Set the width of an area - * @param area_p pointer to an area - * @param w the new width of the area (w == 1 makes x1 == x2) - */ -void lv_area_set_width(lv_area_t * area_p, lv_coord_t w); - -/** - * Set the height of an area - * @param area_p pointer to an area - * @param h the new height of the area (h == 1 makes y1 == y2) - */ -void lv_area_set_height(lv_area_t * area_p, lv_coord_t h); - -/** - * Set the position of an area (width and height will be kept) - * @param area_p pointer to an area - * @param x the new x coordinate of the area - * @param y the new y coordinate of the area - */ -void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y); - -/** - * Return with area of an area (x * y) - * @param area_p pointer to an area - * @return size of area - */ -uint32_t lv_area_get_size(const lv_area_t * area_p); - -/** - * Get the common parts of two areas - * @param res_p pointer to an area, the result will be stored her - * @param a1_p pointer to the first area - * @param a2_p pointer to the second area - * @return false: the two area has NO common parts, res_p is invalid - */ -bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); - -/** - * Join two areas into a third which involves the other two - * @param res_p pointer to an area, the result will be stored here - * @param a1_p pointer to the first area - * @param a2_p pointer to the second area - */ -void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); - -/** - * Check if a point is on an area - * @param a_p pointer to an area - * @param p_p pointer to a point - * @return false:the point is out of the area - */ -bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p); - -/** - * Check if two area has common parts - * @param a1_p pointer to an area. - * @param a2_p pointer to an other area - * @return false: a1_p and a2_p has no common parts - */ -bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p); - -/** - * Check if an area is fully on an other - * @param ain_p pointer to an area which could be on aholder_p - * @param aholder pointer to an area which could involve ain_p - * @return - */ -bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_circ.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_circ.h deleted file mode 100644 index f2065f71..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_circ.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @file lv_circ.h - * - */ - -#ifndef LV_CIRC_H -#define LV_CIRC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#include -#include "lv_area.h" - -/********************* - * DEFINES - *********************/ -#define LV_CIRC_OCT1_X(p) (p.x) -#define LV_CIRC_OCT1_Y(p) (p.y) -#define LV_CIRC_OCT2_X(p) (p.y) -#define LV_CIRC_OCT2_Y(p) (p.x) -#define LV_CIRC_OCT3_X(p) (-p.y) -#define LV_CIRC_OCT3_Y(p) (p.x) -#define LV_CIRC_OCT4_X(p) (-p.x) -#define LV_CIRC_OCT4_Y(p) (p.y) -#define LV_CIRC_OCT5_X(p) (-p.x) -#define LV_CIRC_OCT5_Y(p) (-p.y) -#define LV_CIRC_OCT6_X(p) (-p.y) -#define LV_CIRC_OCT6_Y(p) (-p.x) -#define LV_CIRC_OCT7_X(p) (p.y) -#define LV_CIRC_OCT7_Y(p) (-p.x) -#define LV_CIRC_OCT8_X(p) (p.x) -#define LV_CIRC_OCT8_Y(p) (-p.y) - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the circle drawing - * @param c pointer to a point. The coordinates will be calculated here - * @param tmp point to a variable. It will store temporary data - * @param radius radius of the circle - */ -void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius); - -/** - * Test the circle drawing is ready or not - * @param c same as in circ_init - * @return true if the circle is not ready yet - */ -bool lv_circ_cont(lv_point_t * c); - -/** - * Get the next point from the circle - * @param c same as in circ_init. The next point stored here. - * @param tmp same as in circ_init. - */ -void lv_circ_next(lv_point_t * c, lv_coord_t * tmp); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_color.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_color.h deleted file mode 100644 index e2da8133..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_color.h +++ /dev/null @@ -1,445 +0,0 @@ -/** - * @file lv_color.h - * - */ - -#ifndef LV_COLOR_H -#define LV_COLOR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -/*Error checking*/ -#if LV_COLOR_DEPTH == 24 -#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)" -#endif - -#if LV_COLOR_DEPTH != 32 && LV_COLOR_SCREEN_TRANSP != 0 -#error "LV_COLOR_SCREEN_TRANSP requires LV_COLOR_DEPTH == 32. Set it in lv_conf.h" -#endif - -#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0 -#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h" -#endif - - -#include - -/********************* - * DEFINES - *********************/ -#define LV_COLOR_WHITE LV_COLOR_MAKE(0xFF,0xFF,0xFF) -#define LV_COLOR_SILVER LV_COLOR_MAKE(0xC0,0xC0,0xC0) -#define LV_COLOR_GRAY LV_COLOR_MAKE(0x80,0x80,0x80) -#define LV_COLOR_BLACK LV_COLOR_MAKE(0x00,0x00,0x00) -#define LV_COLOR_RED LV_COLOR_MAKE(0xFF,0x00,0x00) -#define LV_COLOR_MAROON LV_COLOR_MAKE(0x80,0x00,0x00) -#define LV_COLOR_YELLOW LV_COLOR_MAKE(0xFF,0xFF,0x00) -#define LV_COLOR_OLIVE LV_COLOR_MAKE(0x80,0x80,0x00) -#define LV_COLOR_LIME LV_COLOR_MAKE(0x00,0xFF,0x00) -#define LV_COLOR_GREEN LV_COLOR_MAKE(0x00,0x80,0x00) -#define LV_COLOR_CYAN LV_COLOR_MAKE(0x00,0xFF,0xFF) -#define LV_COLOR_AQUA LV_COLOR_CYAN -#define LV_COLOR_TEAL LV_COLOR_MAKE(0x00,0x80,0x80) -#define LV_COLOR_BLUE LV_COLOR_MAKE(0x00,0x00,0xFF) -#define LV_COLOR_NAVY LV_COLOR_MAKE(0x00,0x00,0x80) -#define LV_COLOR_MAGENTA LV_COLOR_MAKE(0xFF,0x00,0xFF) -#define LV_COLOR_PURPLE LV_COLOR_MAKE(0x80,0x00,0x80) -#define LV_COLOR_ORANGE LV_COLOR_MAKE(0xFF,0xA5,0x00) - -enum { - LV_OPA_TRANSP = 0, - LV_OPA_0 = 0, - LV_OPA_10 = 25, - LV_OPA_20 = 51, - LV_OPA_30 = 76, - LV_OPA_40 = 102, - LV_OPA_50 = 127, - LV_OPA_60 = 153, - LV_OPA_70 = 178, - LV_OPA_80 = 204, - LV_OPA_90 = 229, - LV_OPA_100 = 255, - LV_OPA_COVER = 255, -}; - -#define LV_OPA_MIN 16 /*Opacities below this will be transparent*/ -#define LV_OPA_MAX 251 /*Opacities above this will fully cover*/ - -#if LV_COLOR_DEPTH == 1 -#define LV_COLOR_SIZE 8 -#elif LV_COLOR_DEPTH == 8 -#define LV_COLOR_SIZE 8 -#elif LV_COLOR_DEPTH == 16 -#define LV_COLOR_SIZE 16 -#elif LV_COLOR_DEPTH == 32 -#define LV_COLOR_SIZE 32 -#else -#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!" -#endif - -/********************** - * TYPEDEFS - **********************/ - -typedef union -{ - uint8_t blue :1; - uint8_t green :1; - uint8_t red :1; - uint8_t full :1; -} lv_color1_t; - -typedef union -{ - struct - { - uint8_t blue :2; - uint8_t green :3; - uint8_t red :3; - }; - uint8_t full; -} lv_color8_t; - -typedef union -{ - struct - { -#if LV_COLOR_16_SWAP == 0 - uint16_t blue :5; - uint16_t green :6; - uint16_t red :5; -#else - uint16_t green_h :3; - uint16_t red :5; - uint16_t blue :5; - uint16_t green_l :3; -#endif - }; - uint16_t full; -} lv_color16_t; - -typedef union -{ - struct - { - uint8_t blue; - uint8_t green; - uint8_t red; - uint8_t alpha; - }; - uint32_t full; -} lv_color32_t; - -#if LV_COLOR_DEPTH == 1 -typedef uint8_t lv_color_int_t; -typedef lv_color1_t lv_color_t; -#elif LV_COLOR_DEPTH == 8 -typedef uint8_t lv_color_int_t; -typedef lv_color8_t lv_color_t; -#elif LV_COLOR_DEPTH == 16 -typedef uint16_t lv_color_int_t; -typedef lv_color16_t lv_color_t; -#elif LV_COLOR_DEPTH == 32 -typedef uint32_t lv_color_int_t; -typedef lv_color32_t lv_color_t; -#else -#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!" -#endif - -typedef uint8_t lv_opa_t; - -typedef struct -{ - uint16_t h; - uint8_t s; - uint8_t v; -} lv_color_hsv_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/*In color conversations: - * - When converting to bigger color type the LSB weight of 1 LSB is calculated - * E.g. 16 bit Red has 5 bits - * 8 bit Red has 2 bits - * ---------------------- - * 8 bit red LSB = (2^5 - 1) / (2^2 - 1) = 31 / 3 = 10 - * - * - When calculating to smaller color type simply shift out the LSBs - * E.g. 8 bit Red has 2 bits - * 16 bit Red has 5 bits - * ---------------------- - * Shift right with 5 - 3 = 2 - */ - -static inline uint8_t lv_color_to1(lv_color_t color) -{ -#if LV_COLOR_DEPTH == 1 - return color.full; -#elif LV_COLOR_DEPTH == 8 - if((color.red & 0x4) || - (color.green & 0x4) || - (color.blue & 0x2)) { - return 1; - } else { - return 0; - } -#elif LV_COLOR_DEPTH == 16 -# if LV_COLOR_16_SWAP == 0 - if((color.red & 0x10) || - (color.green & 0x20) || - (color.blue & 0x10)) { - return 1; -# else - if((color.red & 0x10) || - (color.green_h & 0x20) || - (color.blue & 0x10)) { - return 1; -# endif - } else { - return 0; - } -#elif LV_COLOR_DEPTH == 32 - if((color.red & 0x80) || - (color.green & 0x80) || - (color.blue & 0x80)) { - return 1; - } else { - return 0; - } -#endif -} - -static inline uint8_t lv_color_to8(lv_color_t color) -{ -#if LV_COLOR_DEPTH == 1 - if(color.full == 0) return 0; - else return 0xFF; -#elif LV_COLOR_DEPTH == 8 - return color.full; -#elif LV_COLOR_DEPTH == 16 - -# if LV_COLOR_16_SWAP == 0 - lv_color8_t ret; - ret.red = color.red >> 2; /* 5 - 3 = 2*/ - ret.green = color.green >> 3; /* 6 - 3 = 3*/ - ret.blue = color.blue >> 3; /* 5 - 2 = 3*/ - return ret.full; -# else - lv_color8_t ret; - ret.red = color.red >> 2; /* 5 - 3 = 2*/ - ret.green = color.green_h; /* 6 - 3 = 3*/ - ret.blue = color.blue >> 3; /* 5 - 2 = 3*/ - return ret.full; -# endif -#elif LV_COLOR_DEPTH == 32 - lv_color8_t ret; - ret.red = color.red >> 5; /* 8 - 3 = 5*/ - ret.green = color.green >> 5; /* 8 - 3 = 5*/ - ret.blue = color.blue >> 6; /* 8 - 2 = 6*/ - return ret.full; -#endif -} - -static inline uint16_t lv_color_to16(lv_color_t color) -{ -#if LV_COLOR_DEPTH == 1 - if(color.full == 0) return 0; - else return 0xFFFF; -#elif LV_COLOR_DEPTH == 8 - lv_color16_t ret; -# if LV_COLOR_16_SWAP == 0 - ret.red = color.red * 4; /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/ - ret.green = color.green * 9; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/ - ret.blue = color.blue * 10; /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/ -# else - ret.red = color.red * 4; - uint8_t g_tmp = color.green * 9; - ret.green_h = (g_tmp & 0x1F) >> 3; - ret.green_l = g_tmp & 0x07; - ret.blue = color.blue * 10; -# endif - return ret.full; -#elif LV_COLOR_DEPTH == 16 - return color.full; -#elif LV_COLOR_DEPTH == 32 - lv_color16_t ret; -# if LV_COLOR_16_SWAP == 0 - ret.red = color.red >> 3; /* 8 - 5 = 3*/ - ret.green = color.green >> 2; /* 8 - 6 = 2*/ - ret.blue = color.blue >> 3; /* 8 - 5 = 3*/ -# else - ret.red = color.red >> 3; - ret.green_h = (color.green & 0xE0) >> 5; - ret.green_l = (color.green & 0x1C) >> 2; - ret.blue = color.blue >> 3; -# endif - return ret.full; -#endif -} - -static inline uint32_t lv_color_to32(lv_color_t color) -{ -#if LV_COLOR_DEPTH == 1 - if(color.full == 0) return 0; - else return 0xFFFFFFFF; -#elif LV_COLOR_DEPTH == 8 - lv_color32_t ret; - ret.red = color.red * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ - ret.green = color.green * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ - ret.blue = color.blue * 85; /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/ - ret.alpha = 0xFF; - return ret.full; -#elif LV_COLOR_DEPTH == 16 -# if LV_COLOR_16_SWAP == 0 - lv_color32_t ret; - ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ - ret.green = color.green * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/ - ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ - ret.alpha = 0xFF; - return ret.full; -# else - lv_color32_t ret; - ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ - ret.green = ((color.green_h << 3) + color.green_l) * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/ - ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ - ret.alpha = 0xFF; - return ret.full; -# endif -#elif LV_COLOR_DEPTH == 32 - return color.full; -#endif -} - -static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix) -{ - lv_color_t ret; -#if LV_COLOR_DEPTH != 1 - /*LV_COLOR_DEPTH == 8, 16 or 32*/ - ret.red = (uint16_t)((uint16_t) c1.red * mix + (c2.red * (255 - mix))) >> 8; -# if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP - /*If swapped Green is in 2 parts*/ - uint16_t g_1 = (c1.green_h << 3) + c1.green_l; - uint16_t g_2 = (c2.green_h << 3) + c2.green_l; - uint16_t g_out = (uint16_t)((uint16_t) g_1 * mix + (g_2 * (255 - mix))) >> 8; - ret.green_h = g_out >> 3; - ret.green_l = g_out & 0x7; -# else - ret.green = (uint16_t)((uint16_t) c1.green * mix + (c2.green * (255 - mix))) >> 8; -# endif - ret.blue = (uint16_t)((uint16_t) c1.blue * mix + (c2.blue * (255 - mix))) >> 8; -# if LV_COLOR_DEPTH == 32 - ret.alpha = 0xFF; -# endif -#else - /*LV_COLOR_DEPTH == 1*/ - ret.full = mix > LV_OPA_50 ? c1.full : c2.full; -#endif - - return ret; -} - -/** - * Get the brightness of a color - * @param color a color - * @return the brightness [0..255] - */ -static inline uint8_t lv_color_brightness(lv_color_t color) -{ - lv_color32_t c32; - c32.full = lv_color_to32(color); - uint16_t bright = 3 * c32.red + c32.blue + 4 * c32.green; - return (uint16_t) bright >> 3; -} - -/* The most simple macro to create a color from R,G and B values - * The order of bit field is different on Big-endian and Little-endian machines*/ -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#if LV_COLOR_DEPTH == 1 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(b8 >> 7 | g8 >> 7 | r8 >> 7)}) -#elif LV_COLOR_DEPTH == 8 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 6, g8 >> 5, r8 >> 5}}) -#elif LV_COLOR_DEPTH == 16 -# if LV_COLOR_16_SWAP == 0 -# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 3, g8 >> 2, r8 >> 3}}) -# else -# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{g8 >> 5, r8 >> 3, b8 >> 3, (g8 >> 2) & 0x7}}) -# endif -#elif LV_COLOR_DEPTH == 32 -#ifdef __cplusplus -# define LV_COLOR_MAKE(r8, g8, b8) lv_color_t{b8, g8, r8, 0xff} -#else -# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/ -#endif -#endif -#else -#if LV_COLOR_DEPTH == 1 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(r8 >> 7 | g8 >> 7 | b8 >> 7)}) -#elif LV_COLOR_DEPTH == 8 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 6, g8 >> 5, b8 >> 5}}) -#elif LV_COLOR_DEPTH == 16 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 3, g8 >> 2, b8 >> 3}}) -#elif LV_COLOR_DEPTH == 32 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{0xff, r8, g8, b8}}) /*Fix 0xff alpha*/ -#endif -#endif - - -#define LV_COLOR_HEX(c) LV_COLOR_MAKE((uint8_t) ((uint32_t)((uint32_t)c >> 16) & 0xFF), \ - (uint8_t) ((uint32_t)((uint32_t)c >> 8) & 0xFF), \ - (uint8_t) ((uint32_t) c & 0xFF)) - -/*Usage LV_COLOR_HEX3(0x16C) which means LV_COLOR_HEX(0x1166CC)*/ -#define LV_COLOR_HEX3(c) LV_COLOR_MAKE((uint8_t) (((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), \ - (uint8_t) ((uint32_t)(c & 0xF0) | ((c & 0xF0) >> 4)), \ - (uint8_t) ((uint32_t)(c & 0xF) | ((c & 0xF) << 4))) - -static inline lv_color_t lv_color_hex(uint32_t c){ - return LV_COLOR_HEX(c); -} - -static inline lv_color_t lv_color_hex3(uint32_t c){ - return LV_COLOR_HEX3(c); -} - - -/** - * Convert a HSV color to RGB - * @param h hue [0..359] - * @param s saturation [0..100] - * @param v value [0..100] - * @return the given RGB color in RGB (with LV_COLOR_DEPTH depth) - */ -lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v); - -/** - * Convert an RGB color to HSV - * @param r red - * @param g green - * @param b blue - * @return the given RGB color n HSV - */ -lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r, uint8_t g, uint8_t b); - - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*USE_COLOR*/ diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_font.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_font.h deleted file mode 100644 index 0b1675c5..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_font.h +++ /dev/null @@ -1,192 +0,0 @@ -/** - * @file lv_font.h - * - */ - -#ifndef LV_FONT_H -#define LV_FONT_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include - -#include "lv_symbol_def.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -typedef struct -{ - uint32_t w_px :8; - uint32_t glyph_index :24; -} lv_font_glyph_dsc_t; - -typedef struct -{ - uint32_t unicode :21; - uint32_t glyph_dsc_index :11; -} lv_font_unicode_map_t; - -typedef struct _lv_font_struct -{ - uint32_t unicode_first; - uint32_t unicode_last; - const uint8_t * glyph_bitmap; - const lv_font_glyph_dsc_t * glyph_dsc; - const uint32_t * unicode_list; - const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's bitmap from a font*/ - int16_t (*get_width)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's with with a given font*/ - struct _lv_font_struct * next_page; /*Pointer to a font extension*/ - uint32_t h_px :8; - uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/ - uint32_t monospace :8; /*Fix width (0: normal width)*/ - uint16_t glyph_cnt; /*Number of glyphs (letters) in the font*/ -} lv_font_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the fonts - */ -void lv_font_init(void); - -/** - * Add a font to an other to extend the character set. - * @param child the font to add - * @param parent this font will be extended. Using it later will contain the characters from `child` - */ -void lv_font_add(lv_font_t *child, lv_font_t *parent); - -/** - * Remove a font from a character set. - * @param child the font to remove - * @param parent remove `child` from here - */ -void lv_font_remove(lv_font_t * child, lv_font_t * parent); - -/** - * Tells if font which contains `letter` is monospace or not - * @param font_p point to font - * @param letter an UNICODE character code - * @return true: the letter is monospace; false not monospace - */ -bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter); - -/** - * Return with the bitmap of a font. - * @param font_p pointer to a font - * @param letter an UNICODE character code - * @return pointer to the bitmap of the letter - */ -const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter); - -/** - * Get the width of a letter in a font. If `monospace` is set then return with it. - * @param font_p pointer to a font - * @param letter an UNICODE character code - * @return the width of a letter - */ -uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter); - - -/** - * Get the width of the letter without overwriting it with the `monospace` attribute - * @param font_p pointer to a font - * @param letter an UNICODE character code - * @return the width of a letter - */ -uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter); - -/** - * Get the height of a font - * @param font_p pointer to a font - * @return the height of a font - */ -static inline uint8_t lv_font_get_height(const lv_font_t * font_p) -{ - return font_p->h_px; -} - -/** - * Get the bit-per-pixel of font - * @param font pointer to font - * @param letter a letter from font (font extensions can have different bpp) - * @return bpp of the font (or font extension) - */ -uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter); - -/** - * Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range - * @param font pointer to font - * @param unicode_letter an unicode letter which bitmap should be get - * @return pointer to the bitmap or NULL if not found - */ -const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter); - -/** - * Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse) - * @param font pointer to font - * @param unicode_letter an unicode letter which bitmap should be get - * @return pointer to the bitmap or NULL if not found - */ -const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter); -/** - * Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range - * @param font pointer to font - * @param unicode_letter an unicode letter which width should be get - * @return width of the gylph or -1 if not found - */ -int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter); - -/** - * Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse) - * @param font pointer to font - * @param unicode_letter an unicode letter which width should be get - * @return width of the glyph or -1 if not found - */ -int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter); - -/********************** - * MACROS - **********************/ - -#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name - - -/********************** - * ADD BUILT IN FONTS - **********************/ -#include "display/lv_fonts/lv_font_builtin.h" - -/*Declare the custom (user defined) fonts*/ -#ifdef LV_FONT_CUSTOM_DECLARE -LV_FONT_CUSTOM_DECLARE -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*USE_FONT*/ - diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_fs.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_fs.h deleted file mode 100644 index 845b4794..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_fs.h +++ /dev/null @@ -1,277 +0,0 @@ -/** - * @file lv_fs.h - * - */ - -#ifndef LV_FS_H -#define LV_FS_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_FILESYSTEM - -#include -#include -#include "lv_mem.h" - -/********************* - * DEFINES - *********************/ -#define LV_FS_MAX_FN_LENGTH 64 - -/********************** - * TYPEDEFS - **********************/ -enum -{ - LV_FS_RES_OK = 0, - LV_FS_RES_HW_ERR, /*Low level hardware error*/ - LV_FS_RES_FS_ERR, /*Error in the file system structure */ - LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/ - LV_FS_RES_FULL, /*Disk full*/ - LV_FS_RES_LOCKED, /*The file is already opened*/ - LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/ - LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/ - LV_FS_RES_TOUT, /*Process time outed*/ - LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/ - LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/ - LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/ - LV_FS_RES_UNKNOWN, /*Other unknown error*/ -}; -typedef uint8_t lv_fs_res_t; - -struct __lv_fs_drv_t; - -typedef struct -{ - void * file_d; - struct __lv_fs_drv_t* drv; -} lv_fs_file_t; - - -typedef struct -{ - void * dir_d; - struct __lv_fs_drv_t * drv; -} lv_fs_dir_t; - -enum -{ - LV_FS_MODE_WR = 0x01, - LV_FS_MODE_RD = 0x02, -}; -typedef uint8_t lv_fs_mode_t; - -typedef struct __lv_fs_drv_t -{ - char letter; - uint16_t file_size; - uint16_t rddir_size; - bool (*ready) (void); - - lv_fs_res_t (*open) (void * file_p, const char * path, lv_fs_mode_t mode); - lv_fs_res_t (*close) (void * file_p); - lv_fs_res_t (*remove) (const char * fn); - lv_fs_res_t (*read) (void * file_p, void * buf, uint32_t btr, uint32_t * br); - lv_fs_res_t (*write) (void * file_p, const void * buf, uint32_t btw, uint32_t * bw); - lv_fs_res_t (*seek) (void * file_p, uint32_t pos); - lv_fs_res_t (*tell) (void * file_p, uint32_t * pos_p); - lv_fs_res_t (*trunc) (void * file_p); - lv_fs_res_t (*size) (void * file_p, uint32_t * size_p); - lv_fs_res_t (*rename) (const char * oldname, const char * newname); - lv_fs_res_t (*free) (uint32_t * total_p, uint32_t * free_p); - - lv_fs_res_t (*dir_open) (void * rddir_p, const char * path); - lv_fs_res_t (*dir_read) (void * rddir_p, char * fn); - lv_fs_res_t (*dir_close) (void * rddir_p); -} lv_fs_drv_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the File system interface - */ -void lv_fs_init(void); - -/** - * Add a new drive - * @param drv_p pointer to an lv_fs_drv_t structure which is inited with the - * corresponding function pointers. The data will be copied so the variable can be local. - */ -void lv_fs_add_drv(lv_fs_drv_t * drv_p); - -/** - * Test if a drive is rady or not. If the `ready` function was not initialized `true` will be returned. - * @param letter letter of the drive - * @return true: drive is ready; false: drive is not ready - */ -bool lv_fs_is_ready(char letter); - -/** - * Open a file - * @param file_p pointer to a lv_fs_file_t variable - * @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt) - * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_open (lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode); - -/** - * Close an already opened file - * @param file_p pointer to a lv_fs_file_t variable - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_close (lv_fs_file_t * file_p); - -/** - * Delete a file - * @param path path of the file to delete - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_remove (const char * path); - -/** - * Read from a file - * @param file_p pointer to a lv_fs_file_t variable - * @param buf pointer to a buffer where the read bytes are stored - * @param btr Bytes To Read - * @param br the number of real read bytes (Bytes Read). NULL if unused. - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_read (lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br); - -/** - * Write into a file - * @param file_p pointer to a lv_fs_file_t variable - * @param buf pointer to a buffer with the bytes to write - * @param btr Bytes To Write - * @param br the number of real written bytes (Bytes Written). NULL if unused. - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_write (lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw); - -/** - * Set the position of the 'cursor' (read write pointer) in a file - * @param file_p pointer to a lv_fs_file_t variable - * @param pos the new position expressed in bytes index (0: start of file) - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_seek (lv_fs_file_t * file_p, uint32_t pos); - -/** - * Give the position of the read write pointer - * @param file_p pointer to a lv_fs_file_t variable - * @param pos_p pointer to store the position of the read write pointer - * @return LV_FS_RES_OK or any error from 'fs_res_t' - */ -lv_fs_res_t lv_fs_tell (lv_fs_file_t * file_p, uint32_t * pos); - -/** - * Truncate the file size to the current position of the read write pointer - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open ) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_trunc (lv_fs_file_t * file_p); - -/** - * Give the size of a file bytes - * @param file_p pointer to a lv_fs_file_t variable - * @param size pointer to a variable to store the size - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_size (lv_fs_file_t * file_p, uint32_t * size); - -/** - * Rename a file - * @param oldname path to the file - * @param newname path with the new name - * @return LV_FS_RES_OK or any error from 'fs_res_t' - */ -lv_fs_res_t lv_fs_rename (const char * oldname, const char * newname); - -/** - * Initialize a 'fs_dir_t' variable for directory reading - * @param rddir_p pointer to a 'fs_read_dir_t' variable - * @param path path to a directory - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path); - -/** - * Read the next filename form a directory. - * The name of the directories will begin with '/' - * @param rddir_p pointer to an initialized 'fs_rdir_t' variable - * @param fn pointer to a buffer to store the filename - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_dir_read (lv_fs_dir_t * rddir_p, char * fn); - -/** - * Close the directory reading - * @param rddir_p pointer to an initialized 'fs_dir_t' variable - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_dir_close (lv_fs_dir_t * rddir_p); - -/** - * Get the free and total size of a driver in kB - * @param letter the driver letter - * @param total_p pointer to store the total size [kB] - * @param free_p pointer to store the free size [kB] - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_free (char letter, uint32_t * total_p, uint32_t * free_p); - -/** - * Fill a buffer with the letters of existing drivers - * @param buf buffer to store the letters ('\0' added after the last letter) - * @return the buffer - */ -char * lv_fs_get_letters(char * buf); - -/** - * Return with the extension of the filename - * @param fn string with a filename - * @return pointer to the beginning extension or empty string if no extension - */ -const char * lv_fs_get_ext(const char * fn); - -/** - * Step up one level - * @param path pointer to a file name - * @return the truncated file name - */ -char * lv_fs_up(char * path); - -/** - * Get the last element of a path (e.g. U:/folder/file -> file) - * @param buf buffer to store the letters ('\0' added after the last letter) - * @return pointer to the beginning of the last element in the path - */ -const char * lv_fs_get_last(const char * path); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_FILESYSTEM*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_FS_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_gc.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_gc.h deleted file mode 100644 index e3d0d8ac..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_gc.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @file lv_gc.h - * - */ - -#ifndef LV_GC_H -#define LV_GC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include "lv_mem.h" -#include "lv_ll.h" - -/********************* - * DEFINES - *********************/ - -#define LV_GC_ROOTS(prefix) \ - prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \ - prefix lv_ll_t _lv_scr_ll; /*Linked list of screens*/ \ - prefix lv_ll_t _lv_drv_ll;\ - prefix lv_ll_t _lv_file_ll;\ - prefix lv_ll_t _lv_anim_ll;\ - prefix void * _lv_def_scr;\ - prefix void * _lv_act_scr;\ - prefix void * _lv_top_layer;\ - prefix void * _lv_sys_layer;\ - prefix void * _lv_task_act;\ - prefix void * _lv_indev_list;\ - prefix void * _lv_disp_list;\ - - -#define LV_NO_PREFIX -#define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX) - -#if LV_ENABLE_GC == 1 -# if LV_MEM_CUSTOM != 1 -# error "GC requires CUSTOM_MEM" -# endif /* LV_MEM_CUSTOM */ -#else /* LV_ENABLE_GC */ -# define LV_GC_ROOT(x) x - LV_GC_ROOTS(extern) -#endif /* LV_ENABLE_GC */ - - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_GC_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_log.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_log.h deleted file mode 100644 index adcb846d..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_log.h +++ /dev/null @@ -1,86 +0,0 @@ -/** - * @file lv_log.h - * - */ - -#ifndef LV_LOG_H -#define LV_LOG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif -#include - -/********************* - * DEFINES - *********************/ - -/*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/ - -#define LV_LOG_LEVEL_TRACE 0 /*A lot of logs to give detailed information*/ -#define LV_LOG_LEVEL_INFO 1 /*Log important events*/ -#define LV_LOG_LEVEL_WARN 2 /*Log if something unwanted happened but didn't caused problem*/ -#define LV_LOG_LEVEL_ERROR 3 /*Only critical issue, when the system may fail*/ -#define _LV_LOG_LEVEL_NUM 4 - -typedef int8_t lv_log_level_t; - -#if USE_LV_LOG -/********************** - * TYPEDEFS - **********************/ - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Register custom print (or anything else) function to call when log is added - * @param f a function pointer: - * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` - */ -void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)); - -/** - * Add a log - * @param level the level of log. (From `lv_log_level_t` enum) - * @param file name of the file when the log added - * @param line line number in the source code where the log added - * @param dsc description of the log - */ -void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc); - -/********************** - * MACROS - **********************/ - -#define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc); -#define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc); -#define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc); -#define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc); - -#else /*USE_LV_LOG*/ - -/*Do nothing if `USE_LV_LOG 0`*/ -#define lv_log_add(level, file, line, dsc) {;} -#define LV_LOG_TRACE(dsc) {;} -#define LV_LOG_INFO(dsc) {;} -#define LV_LOG_WARN(dsc) {;} -#define LV_LOG_ERROR(dsc) {;} -#endif /*USE_LV_LOG*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LOG_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_math.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_math.h deleted file mode 100644 index a0229eb1..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_math.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @file math_base.h - * - */ - -#ifndef LV_MATH_H -#define LV_MATH_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#include - -/********************* - * DEFINES - *********************/ -#define LV_MATH_MIN(a,b) ((a) < (b) ? (a) : (b)) -#define LV_MATH_MAX(a,b) ((a) > (b) ? (a) : (b)) -#define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x))) - -#define LV_TRIGO_SIN_MAX 32767 -#define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/ - -#define LV_BEZIER_VAL_MAX 1024 /*Max time in Bezier functions (not [0..1] to use integers) */ -#define LV_BEZIER_VAL_SHIFT 10 /*log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -/** - * Convert a number to string - * @param num a number - * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) - * @return same as `buf` (just for convenience) - */ -char * lv_math_num_to_str(int32_t num, char * buf); - -/** - * Return with sinus of an angle - * @param angle - * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 - */ -int16_t lv_trigo_sin(int16_t angle); - -/** - * Calculate a value of a Cubic Bezier function. - * @param t time in range of [0..LV_BEZIER_VAL_MAX] - * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] - * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] - * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] - * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] - * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] - */ -int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_mem.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_mem.h deleted file mode 100644 index 77429018..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_mem.h +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @file lv_mem.h - * - */ - -#ifndef LV_MEM_H -#define LV_MEM_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include "lv_log.h" - -/********************* - * DEFINES - *********************/ -// Check windows -#ifdef __WIN64 -# define LV_MEM_ENV64 -#endif - -// Check GCC -#ifdef __GNUC__ -# if defined(__x86_64__) || defined(__ppc64__) -# define LV_MEM_ENV64 -# endif -#endif - -/********************** - * TYPEDEFS - **********************/ - -typedef struct -{ - uint32_t total_size; - uint32_t free_cnt; - uint32_t free_size; - uint32_t free_biggest_size; - uint32_t used_cnt; - uint8_t used_pct; - uint8_t frag_pct; -} lv_mem_monitor_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Initiaize the dyn_mem module (work memory and other variables) - */ -void lv_mem_init(void); - -/** - * Allocate a memory dynamically - * @param size size of the memory to allocate in bytes - * @return pointer to the allocated memory - */ -void * lv_mem_alloc(uint32_t size); - -/** - * Free an allocated data - * @param data pointer to an allocated memory - */ -void lv_mem_free(const void * data); - -/** - * Reallocate a memory with a new size. The old content will be kept. - * @param data pointer to an allocated memory. - * Its content will be copied to the new memory block and freed - * @param new_size the desired new size in byte - * @return pointer to the new memory - */ -void * lv_mem_realloc(void * data_p, uint32_t new_size); - -/** - * Join the adjacent free memory blocks - */ -void lv_mem_defrag(void); - -/** - * Give information about the work memory of dynamic allocation - * @param mon_p pointer to a dm_mon_p variable, - * the result of the analysis will be stored here - */ -void lv_mem_monitor(lv_mem_monitor_t * mon_p); - -/** - * Give the size of an allocated memory - * @param data pointer to an allocated memory - * @return the size of data memory in bytes - */ -uint32_t lv_mem_get_size(const void * data); - - -/********************** - * MACROS - **********************/ - -/** - * Halt on NULL pointer - * p pointer to a memory - */ -#if USE_LV_LOG == 0 -# define lv_mem_assert(p) {if(p == NULL) while(1); } -#else -# define lv_mem_assert(p) {if(p == NULL) {LV_LOG_ERROR("Out of memory!"); while(1); }} -#endif -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_MEM_H*/ - diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_misc.mk b/EZ-Template-Example-Project/include/display/lv_misc/lv_misc.mk deleted file mode 100644 index 470f1230..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_misc.mk +++ /dev/null @@ -1,19 +0,0 @@ -CSRCS += lv_font.c -CSRCS += lv_circ.c -CSRCS += lv_area.c -CSRCS += lv_task.c -CSRCS += lv_fs.c -CSRCS += lv_anim.c -CSRCS += lv_mem.c -CSRCS += lv_ll.c -CSRCS += lv_color.c -CSRCS += lv_txt.c -CSRCS += lv_ufs.c -CSRCS += lv_math.c -CSRCS += lv_log.c -CSRCS += lv_gc.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_misc -VPATH += :$(LVGL_DIR)/lvgl/lv_misc - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc" diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_symbol_def.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_symbol_def.h deleted file mode 100644 index 6ba6241c..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_symbol_def.h +++ /dev/null @@ -1,207 +0,0 @@ -#ifndef LV_SYMBOL_DEF_H -#define LV_SYMBOL_DEF_H - -#ifdef __cplusplus -extern "C" { -#endif -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -/* - * With no UTF-8 support (192- 255) (192..241 is used) - * - * With UTF-8 support (in Supplemental Private Use Area-A): 0xF800 .. 0xF831 - * - Basic symbols: 0xE000..0xE01F - * - File symbols: 0xE020..0xE03F - * - Feedback symbols: 0xE040..0xE05F - * - Reserved: 0xE060..0xE07F - */ - -#if LV_TXT_UTF8 == 0 -#define LV_SYMBOL_GLYPH_FIRST 0xC0 -#define SYMBOL_AUDIO _SYMBOL_VALUE1(C0) -#define SYMBOL_VIDEO _SYMBOL_VALUE1(C1) -#define SYMBOL_LIST _SYMBOL_VALUE1(C2) -#define SYMBOL_OK _SYMBOL_VALUE1(C3) -#define SYMBOL_CLOSE _SYMBOL_VALUE1(C4) -#define SYMBOL_POWER _SYMBOL_VALUE1(C5) -#define SYMBOL_SETTINGS _SYMBOL_VALUE1(C6) -#define SYMBOL_TRASH _SYMBOL_VALUE1(C7) -#define SYMBOL_HOME _SYMBOL_VALUE1(C8) -#define SYMBOL_DOWNLOAD _SYMBOL_VALUE1(C9) -#define SYMBOL_DRIVE _SYMBOL_VALUE1(CA) -#define SYMBOL_REFRESH _SYMBOL_VALUE1(CB) -#define SYMBOL_MUTE _SYMBOL_VALUE1(CC) -#define SYMBOL_VOLUME_MID _SYMBOL_VALUE1(CD) -#define SYMBOL_VOLUME_MAX _SYMBOL_VALUE1(CE) -#define SYMBOL_IMAGE _SYMBOL_VALUE1(CF) -#define SYMBOL_EDIT _SYMBOL_VALUE1(D0) -#define SYMBOL_PREV _SYMBOL_VALUE1(D1) -#define SYMBOL_PLAY _SYMBOL_VALUE1(D2) -#define SYMBOL_PAUSE _SYMBOL_VALUE1(D3) -#define SYMBOL_STOP _SYMBOL_VALUE1(D4) -#define SYMBOL_NEXT _SYMBOL_VALUE1(D5) -#define SYMBOL_EJECT _SYMBOL_VALUE1(D6) -#define SYMBOL_LEFT _SYMBOL_VALUE1(D7) -#define SYMBOL_RIGHT _SYMBOL_VALUE1(D8) -#define SYMBOL_PLUS _SYMBOL_VALUE1(D9) -#define SYMBOL_MINUS _SYMBOL_VALUE1(DA) -#define SYMBOL_WARNING _SYMBOL_VALUE1(DB) -#define SYMBOL_SHUFFLE _SYMBOL_VALUE1(DC) -#define SYMBOL_UP _SYMBOL_VALUE1(DD) -#define SYMBOL_DOWN _SYMBOL_VALUE1(DE) -#define SYMBOL_LOOP _SYMBOL_VALUE1(DF) -#define SYMBOL_DIRECTORY _SYMBOL_VALUE1(E0) -#define SYMBOL_UPLOAD _SYMBOL_VALUE1(E1) -#define SYMBOL_CALL _SYMBOL_VALUE1(E2) -#define SYMBOL_CUT _SYMBOL_VALUE1(E3) -#define SYMBOL_COPY _SYMBOL_VALUE1(E4) -#define SYMBOL_SAVE _SYMBOL_VALUE1(E5) -#define SYMBOL_CHARGE _SYMBOL_VALUE1(E6) -#define SYMBOL_BELL _SYMBOL_VALUE1(E7) -#define SYMBOL_KEYBOARD _SYMBOL_VALUE1(E8) -#define SYMBOL_GPS _SYMBOL_VALUE1(E9) -#define SYMBOL_FILE _SYMBOL_VALUE1(EA) -#define SYMBOL_WIFI _SYMBOL_VALUE1(EB) -#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE1(EC) -#define SYMBOL_BATTERY_3 _SYMBOL_VALUE1(ED) -#define SYMBOL_BATTERY_2 _SYMBOL_VALUE1(EE) -#define SYMBOL_BATTERY_1 _SYMBOL_VALUE1(EF) -#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE1(F0) -#define SYMBOL_BLUETOOTH _SYMBOL_VALUE1(F1) -#define LV_SYMBOL_GLYPH_LAST 0xF1 -#define SYMBOL_DUMMY _SYMBOL_VALUE1(FF) /*Invalid symbol. If written before a string then `lv_img` will show it as a label*/ - -#else -#define LV_SYMBOL_GLYPH_FIRST 0xF800 -#define SYMBOL_AUDIO _SYMBOL_VALUE3(EF,A0,80) -#define SYMBOL_VIDEO _SYMBOL_VALUE3(EF,A0,81) -#define SYMBOL_LIST _SYMBOL_VALUE3(EF,A0,82) -#define SYMBOL_OK _SYMBOL_VALUE3(EF,A0,83) -#define SYMBOL_CLOSE _SYMBOL_VALUE3(EF,A0,84) -#define SYMBOL_POWER _SYMBOL_VALUE3(EF,A0,85) -#define SYMBOL_SETTINGS _SYMBOL_VALUE3(EF,A0,86) -#define SYMBOL_TRASH _SYMBOL_VALUE3(EF,A0,87) -#define SYMBOL_HOME _SYMBOL_VALUE3(EF,A0,88) -#define SYMBOL_DOWNLOAD _SYMBOL_VALUE3(EF,A0,89) -#define SYMBOL_DRIVE _SYMBOL_VALUE3(EF,A0,8A) -#define SYMBOL_REFRESH _SYMBOL_VALUE3(EF,A0,8B) -#define SYMBOL_MUTE _SYMBOL_VALUE3(EF,A0,8C) -#define SYMBOL_VOLUME_MID _SYMBOL_VALUE3(EF,A0,8D) -#define SYMBOL_VOLUME_MAX _SYMBOL_VALUE3(EF,A0,8E) -#define SYMBOL_IMAGE _SYMBOL_VALUE3(EF,A0,8F) -#define SYMBOL_EDIT _SYMBOL_VALUE3(EF,A0,90) -#define SYMBOL_PREV _SYMBOL_VALUE3(EF,A0,91) -#define SYMBOL_PLAY _SYMBOL_VALUE3(EF,A0,92) -#define SYMBOL_PAUSE _SYMBOL_VALUE3(EF,A0,93) -#define SYMBOL_STOP _SYMBOL_VALUE3(EF,A0,94) -#define SYMBOL_NEXT _SYMBOL_VALUE3(EF,A0,95) -#define SYMBOL_EJECT _SYMBOL_VALUE3(EF,A0,96) -#define SYMBOL_LEFT _SYMBOL_VALUE3(EF,A0,97) -#define SYMBOL_RIGHT _SYMBOL_VALUE3(EF,A0,98) -#define SYMBOL_PLUS _SYMBOL_VALUE3(EF,A0,99) -#define SYMBOL_MINUS _SYMBOL_VALUE3(EF,A0,9A) -#define SYMBOL_WARNING _SYMBOL_VALUE3(EF,A0,9B) -#define SYMBOL_SHUFFLE _SYMBOL_VALUE3(EF,A0,9C) -#define SYMBOL_UP _SYMBOL_VALUE3(EF,A0,9D) -#define SYMBOL_DOWN _SYMBOL_VALUE3(EF,A0,9E) -#define SYMBOL_LOOP _SYMBOL_VALUE3(EF,A0,9F) -#define SYMBOL_DIRECTORY _SYMBOL_VALUE3(EF,A0,A0) -#define SYMBOL_UPLOAD _SYMBOL_VALUE3(EF,A0,A1) -#define SYMBOL_CALL _SYMBOL_VALUE3(EF,A0,A2) -#define SYMBOL_CUT _SYMBOL_VALUE3(EF,A0,A3) -#define SYMBOL_COPY _SYMBOL_VALUE3(EF,A0,A4) -#define SYMBOL_SAVE _SYMBOL_VALUE3(EF,A0,A5) -#define SYMBOL_CHARGE _SYMBOL_VALUE3(EF,A0,A6) -#define SYMBOL_BELL _SYMBOL_VALUE3(EF,A0,A7) -#define SYMBOL_KEYBOARD _SYMBOL_VALUE3(EF,A0,A8) -#define SYMBOL_GPS _SYMBOL_VALUE3(EF,A0,A9) -#define SYMBOL_FILE _SYMBOL_VALUE3(EF,A0,AA) -#define SYMBOL_WIFI _SYMBOL_VALUE3(EF,A0,AB) -#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE3(EF,A0,AC) -#define SYMBOL_BATTERY_3 _SYMBOL_VALUE3(EF,A0,AD) -#define SYMBOL_BATTERY_2 _SYMBOL_VALUE3(EF,A0,AE) -#define SYMBOL_BATTERY_1 _SYMBOL_VALUE3(EF,A0,AF) -#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE3(EF,A0,B0) -#define SYMBOL_BLUETOOTH _SYMBOL_VALUE3(EF,A0,B1) -#define LV_SYMBOL_GLYPH_LAST 0xF831 -#define SYMBOL_DUMMY _SYMBOL_VALUE3(EF,A3,BF) /*Invalid symbol at (U+F831). If written before a string then `lv_img` will show it as a label*/ -#endif - -#define _SYMBOL_VALUE1(x) (0x ## x) -#define _SYMBOL_VALUE3(x, y, z) (0x ## z ## y ## x) -#define _SYMBOL_NUMSTR(sym) LV_ ## sym ## _NUMSTR = sym - -enum -{ - _SYMBOL_NUMSTR(SYMBOL_AUDIO), - _SYMBOL_NUMSTR(SYMBOL_VIDEO), - _SYMBOL_NUMSTR(SYMBOL_LIST), - _SYMBOL_NUMSTR(SYMBOL_OK), - _SYMBOL_NUMSTR(SYMBOL_CLOSE), - _SYMBOL_NUMSTR(SYMBOL_POWER), - _SYMBOL_NUMSTR(SYMBOL_SETTINGS), - _SYMBOL_NUMSTR(SYMBOL_TRASH), - _SYMBOL_NUMSTR(SYMBOL_HOME), - _SYMBOL_NUMSTR(SYMBOL_DOWNLOAD), - _SYMBOL_NUMSTR(SYMBOL_DRIVE), - _SYMBOL_NUMSTR(SYMBOL_REFRESH), - _SYMBOL_NUMSTR(SYMBOL_MUTE), - _SYMBOL_NUMSTR(SYMBOL_VOLUME_MID), - _SYMBOL_NUMSTR(SYMBOL_VOLUME_MAX), - _SYMBOL_NUMSTR(SYMBOL_IMAGE), - _SYMBOL_NUMSTR(SYMBOL_EDIT), - _SYMBOL_NUMSTR(SYMBOL_PREV), - _SYMBOL_NUMSTR(SYMBOL_PLAY), - _SYMBOL_NUMSTR(SYMBOL_PAUSE), - _SYMBOL_NUMSTR(SYMBOL_STOP), - _SYMBOL_NUMSTR(SYMBOL_NEXT), - _SYMBOL_NUMSTR(SYMBOL_EJECT), - _SYMBOL_NUMSTR(SYMBOL_LEFT), - _SYMBOL_NUMSTR(SYMBOL_RIGHT), - _SYMBOL_NUMSTR(SYMBOL_PLUS), - _SYMBOL_NUMSTR(SYMBOL_MINUS), - _SYMBOL_NUMSTR(SYMBOL_WARNING), - _SYMBOL_NUMSTR(SYMBOL_SHUFFLE), - _SYMBOL_NUMSTR(SYMBOL_UP), - _SYMBOL_NUMSTR(SYMBOL_DOWN), - _SYMBOL_NUMSTR(SYMBOL_LOOP), - _SYMBOL_NUMSTR(SYMBOL_DIRECTORY), - _SYMBOL_NUMSTR(SYMBOL_UPLOAD), - _SYMBOL_NUMSTR(SYMBOL_CALL), - _SYMBOL_NUMSTR(SYMBOL_CUT), - _SYMBOL_NUMSTR(SYMBOL_COPY), - _SYMBOL_NUMSTR(SYMBOL_SAVE), - _SYMBOL_NUMSTR(SYMBOL_CHARGE), - _SYMBOL_NUMSTR(SYMBOL_BELL), - _SYMBOL_NUMSTR(SYMBOL_KEYBOARD), - _SYMBOL_NUMSTR(SYMBOL_GPS), - _SYMBOL_NUMSTR(SYMBOL_FILE), - _SYMBOL_NUMSTR(SYMBOL_WIFI), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_FULL), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_3), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_2), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_1), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_EMPTY), - _SYMBOL_NUMSTR(SYMBOL_BLUETOOTH), - _SYMBOL_NUMSTR(SYMBOL_DUMMY), -}; - -#undef _SYMBOL_VALUE1 -#undef _SYMBOL_VALUE3 - -#define _SYMBOL_STR_(x) #x -#define _SYMBOL_STR(x) _SYMBOL_STR_(x) -#define _SYMBOL_CHAR(c) \x ## c -#define _SYMBOL_VALUE1(x) _SYMBOL_STR(_SYMBOL_CHAR(x)) -#define _SYMBOL_VALUE3(x, y, z) _SYMBOL_STR(_SYMBOL_CHAR(x)_SYMBOL_CHAR(y)_SYMBOL_CHAR(z)) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /*LV_SYMBOL_DEF_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_task.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_task.h deleted file mode 100644 index 6cac3efd..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_task.h +++ /dev/null @@ -1,149 +0,0 @@ -/** - * @file lv_task.c - * An 'lv_task' is a void (*fp) (void* param) type function which will be called periodically. - * A priority (5 levels + disable) can be assigned to lv_tasks. - */ - -#ifndef LV_TASK_H -#define LV_TASK_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include "lv_mem.h" -#include "lv_ll.h" - -/********************* - * DEFINES - *********************/ -#ifndef LV_ATTRIBUTE_TASK_HANDLER -#define LV_ATTRIBUTE_TASK_HANDLER -#endif -/********************** - * TYPEDEFS - **********************/ -/** - * Possible priorities for lv_tasks - */ -enum -{ - LV_TASK_PRIO_OFF = 0, - LV_TASK_PRIO_LOWEST, - LV_TASK_PRIO_LOW, - LV_TASK_PRIO_MID, - LV_TASK_PRIO_HIGH, - LV_TASK_PRIO_HIGHEST, - LV_TASK_PRIO_NUM, -}; -typedef uint8_t lv_task_prio_t; - -/** - * Descriptor of a lv_task - */ -typedef struct -{ - uint32_t period; - uint32_t last_run; - void (*task) (void*); - void * param; - uint8_t prio:3; - uint8_t once:1; -} lv_task_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init the lv_task module - */ -void lv_task_init(void); - -/** - * Call it periodically to handle lv_tasks. - */ -LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void); - -/** - * Create a new lv_task - * @param task a function which is the task itself - * @param period call period in ms unit - * @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped) - * @param param free parameter - * @return pointer to the new task - */ -lv_task_t* lv_task_create(void (*task) (void *), uint32_t period, lv_task_prio_t prio, void * param); - -/** - * Delete a lv_task - * @param lv_task_p pointer to task created by lv_task_p - */ -void lv_task_del(lv_task_t* lv_task_p); - -/** - * Set new priority for a lv_task - * @param lv_task_p pointer to a lv_task - * @param prio the new priority - */ -void lv_task_set_prio(lv_task_t* lv_task_p, lv_task_prio_t prio); - -/** - * Set new period for a lv_task - * @param lv_task_p pointer to a lv_task - * @param period the new period - */ -void lv_task_set_period(lv_task_t* lv_task_p, uint32_t period); - -/** - * Make a lv_task ready. It will not wait its period. - * @param lv_task_p pointer to a lv_task. - */ -void lv_task_ready(lv_task_t* lv_task_p); - - -/** - * Delete the lv_task after one call - * @param lv_task_p pointer to a lv_task. - */ -void lv_task_once(lv_task_t * lv_task_p); - -/** - * Reset a lv_task. - * It will be called the previously set period milliseconds later. - * @param lv_task_p pointer to a lv_task. - */ -void lv_task_reset(lv_task_t* lv_task_p); - -/** - * Enable or disable the whole lv_task handling - * @param en: true: lv_task handling is running, false: lv_task handling is suspended - */ -void lv_task_enable(bool en); - -/** - * Get idle percentage - * @return the lv_task idle in percentage - */ -uint8_t lv_task_get_idle(void); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_txt.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_txt.h deleted file mode 100644 index 2e98b60e..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_txt.h +++ /dev/null @@ -1,198 +0,0 @@ -/** - * @file lv_text.h - * - */ - -#ifndef LV_TXT_H -#define LV_TXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include "lv_area.h" -#include "lv_font.h" -#include "lv_area.h" - -/********************* - * DEFINES - *********************/ -#define LV_TXT_COLOR_CMD "#" - -/********************** - * TYPEDEFS - **********************/ -enum -{ - LV_TXT_FLAG_NONE = 0x00, - LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/ - LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width to avoid automatic word wrapping*/ - LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/ - LV_TXT_FLAG_RIGHT = 0x08, /*Align the text to the right*/ -}; -typedef uint8_t lv_txt_flag_t; - -enum -{ - LV_TXT_CMD_STATE_WAIT, /*Waiting for command*/ - LV_TXT_CMD_STATE_PAR, /*Processing the parameter*/ - LV_TXT_CMD_STATE_IN, /*Processing the command*/ -}; -typedef uint8_t lv_txt_cmd_state_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Get size of a text - * @param size_res pointer to a 'point_t' variable to store the result - * @param text pointer to a text - * @param font pinter to font of the text - * @param letter_space letter space of the text - * @param line_space line space of the text - * @param flags settings for the text from 'txt_flag_t' enum - * @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks - */ -void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, - lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag); - -/** - * Get the next line of text. Check line length and break chars too. - * @param txt a '\0' terminated string - * @param font pointer to a font - * @param letter_space letter space - * @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks - * @param flags settings for the text from 'txt_flag_type' enum - * @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different) - */ -uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, - lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag); - -/** - * Give the length of a text with a given font - * @param txt a '\0' terminate string - * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8) - * @param font pointer to a font - * @param letter_space letter space - * @param flags settings for the text from 'txt_flag_t' enum - * @return length of a char_num long text - */ -lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, - const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag); - - -/** - * Check next character in a string and decide if te character is part of the command or not - * @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing - * @param c the current character - * @return true: the character is part of a command and should not be written, - * false: the character should be written - */ -bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c); - -/** - * Insert a string into an other - * @param txt_buf the original text (must be big enough for the result text) - * @param pos position to insert (0: before the original text, 1: after the first char etc.) - * @param ins_txt text to insert - */ -void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt); - -/** - * Delete a part of a string - * @param txt string to modify - * @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.) - * @param len number of characters to delete - */ -void lv_txt_cut(char * txt, uint32_t pos, uint32_t len); - -/*************************************************************** - * GLOBAL FUNCTION POINTERS FOR CAHRACTER ENCODING INTERFACE - ***************************************************************/ - -/** - * Give the size of an encoded character - * @param str pointer to a character in a string - * @return length of the encoded character (1,2,3 ...). O in invalid - */ -extern uint8_t (*lv_txt_encoded_size)(const char *); - - -/** - * Convert an Unicode letter to encoded - * @param letter_uni an Unicode letter - * @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü') - */ -extern uint32_t (*lv_txt_unicode_to_encoded)(uint32_t ); - -/** - * Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format. - * @param c a wide character - * @return `c` in the encoded format - */ -extern uint32_t (*lv_txt_encoded_conv_wc) (uint32_t c); - -/** - * Decode the next encoded character from a string. - * @param txt pointer to '\0' terminated string - * @param i start index in 'txt' where to start. - * After the call it will point to the next encoded char in 'txt'. - * NULL to use txt[0] as index - * @return the decoded Unicode character or 0 on invalid data code - */ -extern uint32_t (*lv_txt_encoded_next)(const char *, uint32_t * ); - -/** - * Get the previous encoded character form a string. - * @param txt pointer to '\0' terminated string - * @param i_start index in 'txt' where to start. After the call it will point to the previous encoded char in 'txt'. - * @return the decoded Unicode character or 0 on invalid data - */ -extern uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *); - -/** - * Convert a letter index (in an the encoded text) to byte index. - * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long - * @param txt a '\0' terminated UTF-8 string - * @param enc_id letter index - * @return byte index of the 'enc_id'th letter - */ -extern uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t); - -/** - * Convert a byte index (in an encoded text) to character index. - * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long - * @param txt a '\0' terminated UTF-8 string - * @param byte_id byte index - * @return character index of the letter at 'byte_id'th position - */ -extern uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t); - -/** - * Get the number of characters (and NOT bytes) in a string. - * E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes) - * @param txt a '\0' terminated char string - * @return number of characters - */ -extern uint32_t (*lv_txt_get_encoded_length)(const char *); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*USE_TXT*/ diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_ufs.h b/EZ-Template-Example-Project/include/display/lv_misc/lv_ufs.h deleted file mode 100644 index d30cbe0f..00000000 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_ufs.h +++ /dev/null @@ -1,214 +0,0 @@ -/** - * @file lv_ufs.h - * Implementation of RAM file system which do NOT support directories. - * The API is compatible with the lv_fs_int module. - */ - -#ifndef LV_UFS_H -#define LV_UFS_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_FILESYSTEM - -#include -#include "lv_fs.h" -#include "lv_mem.h" - -/********************* - * DEFINES - *********************/ -#define UFS_LETTER 'U' - -/********************** - * TYPEDEFS - **********************/ -/*Description of a file entry */ -typedef struct -{ - char * fn_d; - void * data_d; - uint32_t size; /*Data length in bytes*/ - uint16_t oc; /*Open Count*/ - uint8_t const_data :1; -} lv_ufs_ent_t; - -/*File descriptor, used to handle opening an entry more times simultaneously - Contains unique informations about the specific opening*/ -typedef struct -{ - lv_ufs_ent_t* ent; /*Pointer to the entry*/ - uint32_t rwp; /*Read Write Pointer*/ - uint8_t ar :1; /*1: Access for read is enabled */ - uint8_t aw :1; /*1: Access for write is enabled */ -} lv_ufs_file_t; - -/* Read directory descriptor. - * It is used to to iterate through the entries in a directory*/ -typedef struct -{ - lv_ufs_ent_t * last_ent; -} lv_ufs_dir_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a driver for ufs and initialize it. - */ -void lv_ufs_init(void); - -/** - * Give the state of the ufs - * @return true if ufs is initialized and can be used else false - */ -bool lv_ufs_ready(void); - -/** - * Open a file in ufs - * @param file_p pointer to a lv_ufs_file_t variable - * @param fn name of the file. There are no directories so e.g. "myfile.txt" - * @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD) - * @return LV_FS_RES_OK: no error, the file is opened - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode); - -/** - * Create a file with a constant data - * @param fn name of the file (directories are not supported) - * @param const_p pointer to a constant data - * @param len length of the data pointed by 'const_p' in bytes - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len); - -/** - * Close an opened file - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_close (void * file_p); - -/** - * Remove a file. The file can not be opened. - * @param fn '\0' terminated string - * @return LV_FS_RES_OK: no error, the file is removed - * LV_FS_RES_DENIED: the file was opened, remove failed - */ -lv_fs_res_t lv_ufs_remove(const char * fn); - -/** - * Read data from an opened file - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @param buf pointer to a memory block where to store the read data - * @param btr number of Bytes To Read - * @param br the real number of read bytes (Byte Read) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br); - -/** - * Write data to an opened file - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open) - * @param buf pointer to a memory block which content will be written - * @param btw the number Bytes To Write - * @param bw The real number of written bytes (Byte Written) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw); - -/** - * Set the read write pointer. Also expand the file size if necessary. - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @param pos the new position of read write pointer - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos); - -/** - * Give the position of the read write pointer - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @param pos_p pointer to to store the result - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p); - -/** - * Truncate the file size to the current position of the read write pointer - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_trunc (void * file_p); - -/** - * Give the size of the file in bytes - * @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @param size_p pointer to store the size - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p); - -/** - * Initialize a lv_ufs_read_dir_t variable to directory reading - * @param rddir_p pointer to a 'ufs_read_dir_t' variable - * @param path uFS doesn't support folders so it has to be "" - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path); - -/** - * Read the next file name - * @param dir_p pointer to an initialized 'ufs_read_dir_t' variable - * @param fn pointer to buffer to sore the file name - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn); - -/** - * Close the directory reading - * @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_dir_close(void * rddir_p); - -/** - * Give the size of a drive - * @param total_p pointer to store the total size [kB] - * @param free_p pointer to store the free site [kB] - * @return LV_FS_RES_OK or any error from 'fs_res_t' - */ -lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_FILESYSTEM*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_arc.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_arc.h deleted file mode 100644 index 4f82e0d8..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_arc.h +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @file lv_arc.h - * - */ - - -#ifndef LV_ARC_H -#define LV_ARC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_ARC != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of arc*/ -typedef struct { - /*New data for this type */ - lv_coord_t angle_start; - lv_coord_t angle_end; -} lv_arc_ext_t; - - -/*Styles*/ -enum { - LV_ARC_STYLE_MAIN, -}; -typedef uint8_t lv_arc_style_t; - - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a arc objects - * @param par pointer to an object, it will be the parent of the new arc - * @param copy pointer to a arc object, if not NULL then the new object will be copied from it - * @return pointer to the created arc - */ -lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc. - * @param arc pointer to an arc object - * @param start the start angle [0..360] - * @param end the end angle [0..360] - */ -void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end); - -/** - * Set a style of a arc. - * @param arc pointer to arc object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_arc_set_style(lv_obj_t * arc, lv_arc_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the start angle of an arc. - * @param arc pointer to an arc object - * @return the start angle [0..360] - */ -uint16_t lv_arc_get_angle_start(lv_obj_t * arc); - -/** - * Get the end angle of an arc. - * @param arc pointer to an arc object - * @return the end angle [0..360] - */ -uint16_t lv_arc_get_angle_end(lv_obj_t * arc); - -/** - * Get style of a arc. - * @param arc pointer to arc object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_arc_get_style(const lv_obj_t * arc, lv_arc_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_ARC*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_ARC_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_bar.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_bar.h deleted file mode 100644 index 3938aa28..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_bar.h +++ /dev/null @@ -1,160 +0,0 @@ -/** - * @file lv_bar.h - * - */ - -#ifndef LV_BAR_H -#define LV_BAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_BAR != 0 - -#include "display/lv_core/lv_obj.h" -#include "lv_cont.h" -#include "lv_btn.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of bar*/ -typedef struct -{ - /*No inherited ext*/ /*Ext. of ancestor*/ - /*New data for this type */ - int16_t cur_value; /*Current value of the bar*/ - int16_t min_value; /*Minimum value of the bar*/ - int16_t max_value; /*Maximum value of the bar*/ - uint8_t sym :1; /*Symmetric: means the center is around zero value*/ - lv_style_t *style_indic; /*Style of the indicator*/ -} lv_bar_ext_t; - -enum { - LV_BAR_STYLE_BG, - LV_BAR_STYLE_INDIC, -}; -typedef uint8_t lv_bar_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a bar objects - * @param par pointer to an object, it will be the parent of the new bar - * @param copy pointer to a bar object, if not NULL then the new object will be copied from it - * @return pointer to the created bar - */ -lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new value on the bar - * @param bar pointer to a bar object - * @param value new value - */ -void lv_bar_set_value(lv_obj_t * bar, int16_t value); - -/** - * Set a new value with animation on the bar - * @param bar pointer to a bar object - * @param value new value - * @param anim_time animation time in milliseconds - */ -void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time); - - -/** - * Set minimum and the maximum values of a bar - * @param bar pointer to the bar object - * @param min minimum value - * @param max maximum value - */ -void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max); - -/** - * Make the bar symmetric to zero. The indicator will grow from zero instead of the minimum position. - * @param bar pointer to a bar object - * @param en true: enable disable symmetric behavior; false: disable - */ -void lv_bar_set_sym(lv_obj_t * bar, bool en); - -/** - * Set a style of a bar - * @param bar pointer to a bar object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_bar_set_style(lv_obj_t *bar, lv_bar_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a bar - * @param bar pointer to a bar object - * @return the value of the bar - */ -int16_t lv_bar_get_value(const lv_obj_t * bar); - -/** - * Get the minimum value of a bar - * @param bar pointer to a bar object - * @return the minimum value of the bar - */ -int16_t lv_bar_get_min_value(const lv_obj_t * bar); - -/** - * Get the maximum value of a bar - * @param bar pointer to a bar object - * @return the maximum value of the bar - */ -int16_t lv_bar_get_max_value(const lv_obj_t * bar); - -/** - * Get whether the bar is symmetric or not. - * @param bar pointer to a bar object - * @return true: symmetric is enabled; false: disable - */ -bool lv_bar_get_sym(lv_obj_t * bar); - -/** - * Get a style of a bar - * @param bar pointer to a bar object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_bar_get_style(const lv_obj_t *bar, lv_bar_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_BAR*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_BAR_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_btn.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_btn.h deleted file mode 100644 index 805b5d78..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_btn.h +++ /dev/null @@ -1,279 +0,0 @@ -/** - * @file lv_btn.h - * - */ - -#ifndef LV_BTN_H -#define LV_BTN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_BTN != 0 - -/*Testing of dependencies*/ -#if USE_LV_CONT == 0 -#error "lv_btn: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " -#endif - -#include "lv_cont.h" -#include "display/lv_core/lv_indev.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/* Button states - * It can be used not only by buttons but other button-like objects too*/ -enum -{ - LV_BTN_STATE_REL, - LV_BTN_STATE_PR, - LV_BTN_STATE_TGL_REL, - LV_BTN_STATE_TGL_PR, - LV_BTN_STATE_INA, - LV_BTN_STATE_NUM, -}; -typedef uint8_t lv_btn_state_t; - -enum -{ - LV_BTN_ACTION_CLICK, - LV_BTN_ACTION_PR, - LV_BTN_ACTION_LONG_PR, - LV_BTN_ACTION_LONG_PR_REPEAT, - LV_BTN_ACTION_NUM, -}; -typedef uint8_t lv_btn_action_t; - - -/*Data of button*/ -typedef struct -{ - lv_cont_ext_t cont; /*Ext. of ancestor*/ - /*New data for this type */ - lv_action_t actions[LV_BTN_ACTION_NUM]; - lv_style_t * styles[LV_BTN_STATE_NUM]; /*Styles in each state*/ - lv_btn_state_t state; /*Current state of the button from 'lv_btn_state_t' enum*/ -#if LV_BTN_INK_EFFECT - uint16_t ink_in_time; /*[ms] Time of ink fill effect (0: disable ink effect)*/ - uint16_t ink_wait_time; /*[ms] Wait before the ink disappears */ - uint16_t ink_out_time; /*[ms] Time of ink disappearing*/ -#endif - uint8_t toggle :1; /*1: Toggle enabled*/ - uint8_t long_pr_action_executed :1; /*1: Long press action executed (Handled by the library)*/ -} lv_btn_ext_t; - -/*Styles*/ -enum { - LV_BTN_STYLE_REL, - LV_BTN_STYLE_PR, - LV_BTN_STYLE_TGL_REL, - LV_BTN_STYLE_TGL_PR, - LV_BTN_STYLE_INA, -}; -typedef uint8_t lv_btn_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a button objects - * @param par pointer to an object, it will be the parent of the new button - * @param copy pointer to a button object, if not NULL then the new object will be copied from it - * @return pointer to the created button - */ -lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Enable the toggled states. On release the button will change from/to toggled state. - * @param btn pointer to a button object - * @param tgl true: enable toggled states, false: disable - */ -void lv_btn_set_toggle(lv_obj_t * btn, bool tgl); - -/** - * Set the state of the button - * @param btn pointer to a button object - * @param state the new state of the button (from lv_btn_state_t enum) - */ -void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); - -/** - * Toggle the state of the button (ON->OFF, OFF->ON) - * @param btn pointer to a button object - */ -void lv_btn_toggle(lv_obj_t * btn); - -/** - * Set a function to call when a button event happens - * @param btn pointer to a button object - * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) - */ -void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action); - -/** - * Set the layout on a button - * @param btn pointer to a button object - * @param layout a layout from 'lv_cont_layout_t' - */ -static inline void lv_btn_set_layout(lv_obj_t * btn, lv_layout_t layout) -{ - lv_cont_set_layout(btn, layout); -} - -/** - * Enable the horizontal or vertical fit. - * The button size will be set to involve the children horizontally or vertically. - * @param btn pointer to a button object - * @param hor_en true: enable the horizontal fit - * @param ver_en true: enable the vertical fit - */ -static inline void lv_btn_set_fit(lv_obj_t * btn, bool hor_en, bool ver_en) -{ - lv_cont_set_fit(btn, hor_en, ver_en); -} - -/** - * Set time of the ink effect (draw a circle on click to animate in the new state) - * @param btn pointer to a button object - * @param time the time of the ink animation - */ -void lv_btn_set_ink_in_time(lv_obj_t * btn, uint16_t time); - -/** - * Set the wait time before the ink disappears - * @param btn pointer to a button object - * @param time the time of the ink animation - */ -void lv_btn_set_ink_wait_time(lv_obj_t * btn, uint16_t time); - -/** - * Set time of the ink out effect (animate to the released state) - * @param btn pointer to a button object - * @param time the time of the ink animation - */ -void lv_btn_set_ink_out_time(lv_obj_t * btn, uint16_t time); - -/** - * Set a style of a button. - * @param btn pointer to button object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_btn_set_style(lv_obj_t * btn, lv_btn_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the current state of the button - * @param btn pointer to a button object - * @return the state of the button (from lv_btn_state_t enum) - */ -lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn); - -/** - * Get the toggle enable attribute of the button - * @param btn pointer to a button object - * @return ture: toggle enabled, false: disabled - */ -bool lv_btn_get_toggle(const lv_obj_t * btn); - -/** - * Get the release action of a button - * @param btn pointer to a button object - * @return pointer to the release action function - */ -lv_action_t lv_btn_get_action(const lv_obj_t * btn, lv_btn_action_t type); - -/** - * Get the layout of a button - * @param btn pointer to button object - * @return the layout from 'lv_cont_layout_t' - */ -static inline lv_layout_t lv_btn_get_layout(const lv_obj_t * btn) -{ - return lv_cont_get_layout(btn); -} - -/** - * Get horizontal fit enable attribute of a button - * @param btn pointer to a button object - * @return true: horizontal fit is enabled; false: disabled - */ -static inline bool lv_btn_get_hor_fit(const lv_obj_t * btn) -{ - return lv_cont_get_hor_fit(btn); -} - -/** - * Get vertical fit enable attribute of a container - * @param btn pointer to a button object - * @return true: vertical fit is enabled; false: disabled - */ -static inline bool lv_btn_get_ver_fit(const lv_obj_t * btn) -{ - return lv_cont_get_ver_fit(btn); -} - -/** - * Get time of the ink in effect (draw a circle on click to animate in the new state) - * @param btn pointer to a button object - * @return the time of the ink animation - */ -uint16_t lv_btn_get_ink_in_time(const lv_obj_t * btn); - -/** - * Get the wait time before the ink disappears - * @param btn pointer to a button object - * @return the time of the ink animation - */ -uint16_t lv_btn_get_ink_wait_time(const lv_obj_t * btn); - -/** - * Get time of the ink out effect (animate to the releases state) - * @param btn pointer to a button object - * @return the time of the ink animation - */ -uint16_t lv_btn_get_ink_out_time(const lv_obj_t * btn); - -/** - * Get style of a button. - * @param btn pointer to button object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_btn_get_style(const lv_obj_t * btn, lv_btn_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_BUTTON*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_BTN_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_btnm.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_btnm.h deleted file mode 100644 index 89c066a4..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_btnm.h +++ /dev/null @@ -1,197 +0,0 @@ -/** - * @file lv_btnm.h - * - */ - - -#ifndef LV_BTNM_H -#define LV_BTNM_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_BTNM != 0 - -#include "display/lv_core/lv_obj.h" -#include "lv_label.h" -#include "lv_btn.h" - -/********************* - * DEFINES - *********************/ - -/*Control byte*/ -#define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/ -#define LV_BTNM_CTRL_MASK 0xC0 -#define LV_BTNM_WIDTH_MASK 0x07 -#define LV_BTNM_HIDE_MASK 0x08 -#define LV_BTNM_REPEAT_DISABLE_MASK 0x10 -#define LV_BTNM_INACTIVE_MASK 0x20 - - -#define LV_BTNM_PR_NONE 0xFFFF -/********************** - * TYPEDEFS - **********************/ - -/* Type of callback function which is called when a button is released or long pressed on the button matrix - * Parameters: button matrix, text of the released button - * return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/ -typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt); - -/*Data of button matrix*/ -typedef struct -{ - /*No inherited ext.*/ /*Ext. of ancestor*/ - /*New data for this type */ - const char ** map_p; /*Pointer to the current map*/ - lv_area_t *button_areas; /*Array of areas of buttons*/ - lv_btnm_action_t action; /*A function to call when a button is releases*/ - lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/ - uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/ - uint16_t btn_id_pr; /*Index of the currently pressed button (in `button_areas`) or LV_BTNM_PR_NONE*/ - uint16_t btn_id_tgl; /*Index of the currently toggled button (in `button_areas`) or LV_BTNM_PR_NONE */ - uint8_t toggle :1; /*Enable toggling*/ - uint8_t recolor :1; /*Enable button recoloring*/ -} lv_btnm_ext_t; - -enum { - LV_BTNM_STYLE_BG, - LV_BTNM_STYLE_BTN_REL, - LV_BTNM_STYLE_BTN_PR, - LV_BTNM_STYLE_BTN_TGL_REL, - LV_BTNM_STYLE_BTN_TGL_PR, - LV_BTNM_STYLE_BTN_INA, -}; -typedef uint8_t lv_btnm_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a button matrix objects - * @param par pointer to an object, it will be the parent of the new button matrix - * @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it - * @return pointer to the created button matrix - */ -lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new map. Buttons will be created/deleted according to the map. - * @param btnm pointer to a button matrix object - * @param map pointer a string array. The last string has to be: "". - * Use "\n" to begin a new line. - * The first byte can be a control data: - * - bit 7: always 1 - * - bit 6: always 0 - * - bit 5: inactive (disabled) - * - bit 4: no repeat (on long press) - * - bit 3: hidden - * - bit 2..0: button relative width - * Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press - */ -void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); - -/** - * Set a new callback function for the buttons (It will be called when a button is released) - * @param btnm: pointer to button matrix object - * @param action pointer to a callback function - */ -void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action); - -/** - * Enable or disable button toggling - * @param btnm pointer to button matrix object - * @param en true: enable toggling; false: disable toggling - * @param id index of the currently toggled button (ignored if 'en' == false) - */ -void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id); - -/** - * Set a style of a button matrix - * @param btnm pointer to a button matrix object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_btnm_set_style(lv_obj_t *btnm, lv_btnm_style_t type, lv_style_t *style); - -/** - * Set whether recoloring is enabled - * @param btnm pointer to button matrix object - * @param en whether recoloring is enabled - */ -void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the current map of a button matrix - * @param btnm pointer to a button matrix object - * @return the current map - */ -const char ** lv_btnm_get_map(const lv_obj_t * btnm); - -/** - * Get a the callback function of the buttons on a button matrix - * @param btnm: pointer to button matrix object - * @return pointer to the callback function - */ -lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm); - -/** - * Get the pressed button - * @param btnm pointer to button matrix object - * @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset) - */ -uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm); - -/** - * Get the toggled button - * @param btnm pointer to button matrix object - * @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset) - */ -uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm); - -/** - * Get a style of a button matrix - * @param btnm pointer to a button matrix object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_btnm_get_style(const lv_obj_t *btnm, lv_btnm_style_t type); - -/** - * Find whether recoloring is enabled - * @param btnm pointer to button matrix object - * @return whether recoloring is enabled - */ -bool lv_btnm_get_recolor(const lv_obj_t * btnm); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_BTNM*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_BTNM_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_calendar.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_calendar.h deleted file mode 100644 index 3ef4b025..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_calendar.h +++ /dev/null @@ -1,246 +0,0 @@ -/** - * @file lv_calendar.h - * - */ - -#ifndef LV_CALENDAR_H -#define LV_CALENDAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CALENDAR != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -typedef struct { - uint16_t year; - int8_t month; - int8_t day; -} lv_calendar_date_t; - -enum -{ - LV_CALENDAR_ACTION_CLICK, - LV_CALENDAR_ACTION_PR, - LV_CALENDAR_ACTION_LONG_PR, - LV_CALENDAR_ACTION_LONG_PR_REPEAT, - LV_CALENDAR_ACTION_NUM, -}; -typedef uint8_t lv_calendar_action_t; - -/*Data of calendar*/ -typedef struct { - /*None*/ /*Ext. of ancestor*/ - /*New data for this type */ - lv_calendar_date_t today; /*Date of today*/ - lv_calendar_date_t showed_date; /*Currently visible month (day is ignored)*/ - lv_calendar_date_t * highlighted_dates; /*Apply different style on these days (pointer to an array defined by the user)*/ - uint8_t highlighted_dates_num; /*Number of elements in `highlighted_days`*/ - int8_t btn_pressing; /*-1: prev month pressing, +1 next month pressing on the header*/ - lv_calendar_date_t pressed_date; - const char ** day_names; /*Pointer to an array with the name of the days (NULL: use default names)*/ - const char ** month_names; /*Pointer to an array with the name of the month (NULL. use default names)*/ - lv_action_t actions[LV_CALENDAR_ACTION_NUM]; - - /*Styles*/ - lv_style_t * style_header; - lv_style_t * style_header_pr; - lv_style_t * style_day_names; - lv_style_t * style_highlighted_days; - lv_style_t * style_inactive_days; - lv_style_t * style_week_box; - lv_style_t * style_today_box; -} lv_calendar_ext_t; - -/*Styles*/ -enum { - LV_CALENDAR_STYLE_BG, /*Also the style of the "normal" date numbers*/ - LV_CALENDAR_STYLE_HEADER, - LV_CALENDAR_STYLE_HEADER_PR, - LV_CALENDAR_STYLE_DAY_NAMES, - LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS, - LV_CALENDAR_STYLE_INACTIVE_DAYS, - LV_CALENDAR_STYLE_WEEK_BOX, - LV_CALENDAR_STYLE_TODAY_BOX, -}; -typedef uint8_t lv_calendar_style_t; - - - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a calendar objects - * @param par pointer to an object, it will be the parent of the new calendar - * @param copy pointer to a calendar object, if not NULL then the new object will be copied from it - * @return pointer to the created calendar - */ -lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - - -/*===================== - * Setter functions - *====================*/ -/** - * Set a function to call when a calendar event happens - * @param calendar pointer to a calendar object - * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) - */ -void lv_calendar_set_action(lv_obj_t * calendar, lv_calendar_action_t type, lv_action_t action); - -/** - * Set the today's date - * @param calendar pointer to a calendar object - * @param today pointer to an `lv_calendar_date_t` variable containing the date of today. The value will be saved it can be local variable too. - */ -void lv_calendar_set_today_date(lv_obj_t * calendar, lv_calendar_date_t * today); - -/** - * Set the currently showed - * @param calendar pointer to a calendar object - * @param showed pointer to an `lv_calendar_date_t` variable containing the date to show. The value will be saved it can be local variable too. - */ -void lv_calendar_set_showed_date(lv_obj_t * calendar, lv_calendar_date_t * showed); - -/** - * Set the the highlighted dates - * @param calendar pointer to a calendar object - * @param highlighted pointer to an `lv_calendar_date_t` array containing the dates. ONLY A POINTER WILL BE SAVED! CAN'T BE LOCAL ARRAY. - * @param date_num number of dates in the array - */ -void lv_calendar_set_highlighted_dates(lv_obj_t * calendar, lv_calendar_date_t * highlighted, uint16_t date_num); - - -/** - * Set the name of the days - * @param calendar pointer to a calendar object - * @param day_names pointer to an array with the names. E.g. `const char * days[7] = {"Sun", "Mon", ...}` - * Only the pointer will be saved so this variable can't be local which will be destroyed later. - */ -void lv_calendar_set_day_names(lv_obj_t * calendar, const char ** day_names); - -/** - * Set the name of the month - * @param calendar pointer to a calendar object - * @param day_names pointer to an array with the names. E.g. `const char * days[12] = {"Jan", "Feb", ...}` - * Only the pointer will be saved so this variable can't be local which will be destroyed later. - */ -void lv_calendar_set_month_names(lv_obj_t * calendar, const char ** day_names); - -/** - * Set a style of a calendar. - * @param calendar pointer to calendar object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_calendar_set_style(lv_obj_t * calendar, lv_calendar_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ -/** - * Get the action of a calendar - * @param calendar pointer to a calendar object - * @return pointer to the action function - */ -lv_action_t lv_calendar_get_action(const lv_obj_t * calendar, lv_calendar_action_t type); - -/** - * Get the today's date - * @param calendar pointer to a calendar object - * @return return pointer to an `lv_calendar_date_t` variable containing the date of today. - */ -lv_calendar_date_t * lv_calendar_get_today_date(const lv_obj_t * calendar); - -/** - * Get the currently showed - * @param calendar pointer to a calendar object - * @return pointer to an `lv_calendar_date_t` variable containing the date is being shown. - */ -lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar); - -/** - * Get the the pressed date. - * @param calendar pointer to a calendar object - * @return pointer to an `lv_calendar_date_t` variable containing the pressed date. - */ -lv_calendar_date_t * lv_calendar_get_pressed_date(const lv_obj_t * calendar); - -/** - * Get the the highlighted dates - * @param calendar pointer to a calendar object - * @return pointer to an `lv_calendar_date_t` array containing the dates. - */ -lv_calendar_date_t * lv_calendar_get_highlighted_dates(const lv_obj_t * calendar); - -/** - * Get the number of the highlighted dates - * @param calendar pointer to a calendar object - * @return number of highlighted days - */ -uint16_t lv_calendar_get_highlighted_dates_num(const lv_obj_t * calendar); - - -/** - * Get the name of the days - * @param calendar pointer to a calendar object - * @return pointer to the array of day names - */ -const char ** lv_calendar_get_day_names(const lv_obj_t * calendar); - -/** - * Get the name of the month - * @param calendar pointer to a calendar object - * @return pointer to the array of month names - */ -const char ** lv_calendar_get_month_names(const lv_obj_t * calendar); - -/** - * Get style of a calendar. - * @param calendar pointer to calendar object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_calendar_get_style(const lv_obj_t * calendar, lv_calendar_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CALENDAR*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CALENDAR_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_canvas.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_canvas.h deleted file mode 100644 index 14d6e87b..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_canvas.h +++ /dev/null @@ -1,229 +0,0 @@ -/** - * @file lv_canvas.h - * - */ - -#ifndef LV_CANVAS_H -#define LV_CANVAS_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CANVAS != 0 - -#include "display/lv_core/lv_obj.h" -#include "display/lv_objx/lv_img.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of canvas*/ -typedef struct { - lv_img_ext_t img; /*Ext. of ancestor*/ - /*New data for this type */ - lv_img_dsc_t dsc; -} lv_canvas_ext_t; - - -/*Styles*/ -enum { - LV_CANVAS_STYLE_MAIN, -}; -typedef uint8_t lv_canvas_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a canvas object - * @param par pointer to an object, it will be the parent of the new canvas - * @param copy pointer to a canvas object, if not NULL then the new object will be copied from it - * @return pointer to the created canvas - */ -lv_obj_t * lv_canvas_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a buffer for the canvas. - * @param buf a buffer where the content of the canvas will be. - * The required size is (lv_img_color_format_get_px_size(cf) * w * h) / 8) - * It can be allocated with `lv_mem_alloc()` or - * it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or - * it can be an address in RAM or external SRAM - * @param canvas pointer to a canvas object - * @param w width of the canvas - * @param h height of the canvas - * @param cf color format. The following formats are supported: - * LV_IMG_CF_TRUE_COLOR, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, LV_IMG_CF_INDEXES_1/2/4/8BIT - */ -void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); - -/** - * Set the color of a pixel on the canvas - * @param canvas - * @param x x coordinate of the point to set - * @param y x coordinate of the point to set - * @param c color of the point - */ -void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c); - -/** - * Set a style of a canvas. - * @param canvas pointer to canvas object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, lv_style_t * style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the color of a pixel on the canvas - * @param canvas - * @param x x coordinate of the point to set - * @param y x coordinate of the point to set - * @return color of the point - */ -lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y); - -/** - * Get style of a canvas. - * @param canvas pointer to canvas object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type); - -/*===================== - * Other functions - *====================*/ - -/** - * Copy a buffer to the canvas - * @param canvas pointer to a canvas object - * @param to_copy buffer to copy. The color format has to match with the canvas's buffer color format - * @param w width of the buffer to copy - * @param h height of the buffer to copy - * @param x left side of the destination position - * @param y top side of the destination position - */ -void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y); - -/** - * Multiply a buffer with the canvas - * @param canvas pointer to a canvas object - * @param to_copy buffer to copy (multiply). LV_IMG_CF_TRUE_COLOR_ALPHA is not supported - * @param w width of the buffer to copy - * @param h height of the buffer to copy - * @param x left side of the destination position - * @param y top side of the destination position - */ -void lv_canvas_mult_buf(lv_obj_t * canvas, void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y); - -/** - * Draw circle function of the canvas - * @param canvas pointer to a canvas object - * @param x0 x coordinate of the circle - * @param y0 y coordinate of the circle - * @param radius radius of the circle - * @param color border color of the circle - */ -void lv_canvas_draw_circle(lv_obj_t * canvas, lv_coord_t x0, lv_coord_t y0, lv_coord_t radius, lv_color_t color); - -/** - * Draw line function of the canvas - * @param canvas pointer to a canvas object - * @param point1 start point of the line - * @param point2 end point of the line - * @param color color of the line - * - * NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c. - */ -void lv_canvas_draw_line(lv_obj_t * canvas, lv_point_t point1, lv_point_t point2, lv_color_t color); - -/** - * Draw triangle function of the canvas - * @param canvas pointer to a canvas object - * @param points edge points of the triangle - * @param color line color of the triangle - */ -void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color); - -/** - * Draw rectangle function of the canvas - * @param canvas pointer to a canvas object - * @param points edge points of the rectangle - * @param color line color of the rectangle - */ -void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color); - -/** - * Draw polygon function of the canvas - * @param canvas pointer to a canvas object - * @param points edge points of the polygon - * @param size edge count of the polygon - * @param color line color of the polygon - */ -void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color); - -/** - * Fill polygon function of the canvas - * @param canvas pointer to a canvas object - * @param points edge points of the polygon - * @param size edge count of the polygon - * @param boundary_color line color of the polygon - * @param fill_color fill color of the polygon - */ -void lv_canvas_fill_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t boundary_color, lv_color_t fill_color); -/** - * Boundary fill function of the canvas - * @param canvas pointer to a canvas object - * @param x x coordinate of the start position (seed) - * @param y y coordinate of the start position (seed) - * @param boundary_color edge/boundary color of the area - * @param fill_color fill color of the area - */ -void lv_canvas_boundary_fill4(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t boundary_color, lv_color_t fill_color); - -/** - * Flood fill function of the canvas - * @param canvas pointer to a canvas object - * @param x x coordinate of the start position (seed) - * @param y y coordinate of the start position (seed) - * @param fill_color fill color of the area - * @param bg_color background color of the area - */ -void lv_canvas_flood_fill(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t fill_color, lv_color_t bg_color); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CANVAS*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CANVAS_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_cb.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_cb.h deleted file mode 100644 index 5c550b6f..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_cb.h +++ /dev/null @@ -1,174 +0,0 @@ -/** - * @file lv_cb.h - * - */ - -#ifndef LV_CB_H -#define LV_CB_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CB != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTN == 0 -#error "lv_cb: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_cb: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_btn.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of check box*/ -typedef struct -{ - lv_btn_ext_t bg_btn; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * bullet; /*Pointer to button*/ - lv_obj_t * label; /*Pointer to label*/ -} lv_cb_ext_t; - -enum { - LV_CB_STYLE_BG, - LV_CB_STYLE_BOX_REL, - LV_CB_STYLE_BOX_PR, - LV_CB_STYLE_BOX_TGL_REL, - LV_CB_STYLE_BOX_TGL_PR, - LV_CB_STYLE_BOX_INA, -}; -typedef uint8_t lv_cb_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a check box objects - * @param par pointer to an object, it will be the parent of the new check box - * @param copy pointer to a check box object, if not NULL then the new object will be copied from it - * @return pointer to the created check box - */ -lv_obj_t * lv_cb_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the text of a check box - * @param cb pointer to a check box - * @param txt the text of the check box - */ -void lv_cb_set_text(lv_obj_t * cb, const char * txt); - -/** - * Set the state of the check box - * @param cb pointer to a check box object - * @param checked true: make the check box checked; false: make it unchecked - */ -static inline void lv_cb_set_checked(lv_obj_t * cb, bool checked) -{ - lv_btn_set_state(cb, checked ? LV_BTN_STATE_TGL_REL : LV_BTN_STATE_REL); -} - -/** - * Make the check box inactive (disabled) - * @param cb pointer to a check box object - */ -static inline void lv_cb_set_inactive(lv_obj_t * cb) -{ - lv_btn_set_state(cb, LV_BTN_STATE_INA); -} - -/** - * Set a function to call when the check box is clicked - * @param cb pointer to a check box object - */ -static inline void lv_cb_set_action(lv_obj_t * cb, lv_action_t action) -{ - lv_btn_set_action(cb, LV_BTN_ACTION_CLICK, action); -} - - -/** - * Set a style of a check box - * @param cb pointer to check box object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_cb_set_style(lv_obj_t * cb, lv_cb_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the text of a check box - * @param cb pointer to check box object - * @return pointer to the text of the check box - */ -const char * lv_cb_get_text(const lv_obj_t * cb); - -/** - * Get the current state of the check box - * @param cb pointer to a check box object - * @return true: checked; false: not checked - */ -static inline bool lv_cb_is_checked(const lv_obj_t * cb) -{ - return lv_btn_get_state(cb) == LV_BTN_STATE_REL ? false : true; -} - -/** - * Get the action of a check box - * @param cb pointer to a button object - * @return pointer to the action function - */ -static inline lv_action_t lv_cb_get_action(const lv_obj_t * cb) -{ - return lv_btn_get_action(cb, LV_BTN_ACTION_CLICK); -} - - -/** - * Get a style of a button - * @param cb pointer to check box object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_cb_get_style(const lv_obj_t * cb, lv_cb_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CB*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CB_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_chart.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_chart.h deleted file mode 100644 index 92637e89..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_chart.h +++ /dev/null @@ -1,262 +0,0 @@ -/** - * @file lv_chart.h - * - */ - -#ifndef LV_CHART_H -#define LV_CHART_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CHART != 0 - -#include "display/lv_core/lv_obj.h" -#include "lv_line.h" - -/********************* - * DEFINES - *********************/ -#define LV_CHART_POINT_DEF (LV_COORD_MIN) - -/********************** - * TYPEDEFS - **********************/ -typedef struct -{ - lv_coord_t * points; - lv_color_t color; - uint16_t start_point; -} lv_chart_series_t; - -/*Data of chart */ -typedef struct -{ - /*No inherited ext*/ /*Ext. of ancestor*/ - /*New data for this type */ - lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/ - lv_coord_t ymin; /*y min value (used to scale the data)*/ - lv_coord_t ymax; /*y max value (used to scale the data)*/ - uint8_t hdiv_cnt; /*Number of horizontal division lines*/ - uint8_t vdiv_cnt; /*Number of vertical division lines*/ - uint16_t point_cnt; /*Point number in a data line*/ - uint8_t type :4; /*Line, column or point chart (from 'lv_chart_type_t')*/ - struct { - lv_coord_t width; /*Line width or point radius*/ - uint8_t num; /*Number of data lines in dl_ll*/ - lv_opa_t opa; /*Opacity of data lines*/ - lv_opa_t dark; /*Dark level of the point/column bottoms*/ - } series; -} lv_chart_ext_t; - -/*Chart types*/ -enum -{ - LV_CHART_TYPE_LINE = 0x01, /*Connect the points with lines*/ - LV_CHART_TYPE_COLUMN = 0x02, /*Draw columns*/ - LV_CHART_TYPE_POINT = 0x04, /*Draw circles on the points*/ - LV_CHART_TYPE_VERTICAL_LINE = 0x08, /*Draw vertical lines on points (useful when chart width == point count)*/ -}; -typedef uint8_t lv_chart_type_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a chart background objects - * @param par pointer to an object, it will be the parent of the new chart background - * @param copy pointer to a chart background object, if not NULL then the new object will be copied from it - * @return pointer to the created chart background - */ -lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Allocate and add a data series to the chart - * @param chart pointer to a chart object - * @param color color of the data series - * @return pointer to the allocated data series - */ -lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color); - -/** - * Clear the point of a serie - * @param chart pointer to a chart object - * @param serie pointer to the chart's serie to clear - */ -void lv_chart_clear_serie(lv_obj_t * chart, lv_chart_series_t * serie); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the number of horizontal and vertical division lines - * @param chart pointer to a graph background object - * @param hdiv number of horizontal division lines - * @param vdiv number of vertical division lines - */ -void lv_chart_set_div_line_count(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv); - -/** - * Set the minimal and maximal y values - * @param chart pointer to a graph background object - * @param ymin y minimum value - * @param ymax y maximum value - */ -void lv_chart_set_range(lv_obj_t * chart, lv_coord_t ymin, lv_coord_t ymax); - -/** - * Set a new type for a chart - * @param chart pointer to a chart object - * @param type new type of the chart (from 'lv_chart_type_t' enum) - */ -void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type); - -/** - * Set the number of points on a data line on a chart - * @param chart pointer r to chart object - * @param point_cnt new number of points on the data lines - */ -void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt); - -/** - * Set the opacity of the data series - * @param chart pointer to a chart object - * @param opa opacity of the data series - */ -void lv_chart_set_series_opa(lv_obj_t * chart, lv_opa_t opa); - -/** - * Set the line width or point radius of the data series - * @param chart pointer to a chart object - * @param width the new width - */ -void lv_chart_set_series_width(lv_obj_t * chart, lv_coord_t width); - -/** - * Set the dark effect on the bottom of the points or columns - * @param chart pointer to a chart object - * @param dark_eff dark effect level (LV_OPA_TRANSP to turn off) - */ -void lv_chart_set_series_darking(lv_obj_t * chart, lv_opa_t dark_eff); - -/** - * Initialize all data points with a value - * @param chart pointer to chart object - * @param ser pointer to a data series on 'chart' - * @param y the new value for all points - */ -void lv_chart_init_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y); - -/** - * Set the value s of points from an array - * @param chart pointer to chart object - * @param ser pointer to a data series on 'chart' - * @param y_array array of 'lv_coord_t' points (with 'points count' elements ) - */ -void lv_chart_set_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t * y_array); - -/** - * Shift all data right and set the most right data on a data line - * @param chart pointer to chart object - * @param ser pointer to a data series on 'chart' - * @param y the new value of the most right data - */ -void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y); - -/** - * Set the style of a chart - * @param chart pointer to a chart object - * @param style pointer to a style - */ -static inline void lv_chart_set_style(lv_obj_t *chart, lv_style_t *style) -{ - lv_obj_set_style(chart, style); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the type of a chart - * @param chart pointer to chart object - * @return type of the chart (from 'lv_chart_t' enum) - */ -lv_chart_type_t lv_chart_get_type(const lv_obj_t * chart); - -/** - * Get the data point number per data line on chart - * @param chart pointer to chart object - * @return point number on each data line - */ -uint16_t lv_chart_get_point_cnt(const lv_obj_t * chart); - -/** - * Get the opacity of the data series - * @param chart pointer to chart object - * @return the opacity of the data series - */ -lv_opa_t lv_chart_get_series_opa(const lv_obj_t * chart); - -/** - * Get the data series width - * @param chart pointer to chart object - * @return the width the data series (lines or points) - */ -lv_coord_t lv_chart_get_series_width(const lv_obj_t * chart); - -/** - * Get the dark effect level on the bottom of the points or columns - * @param chart pointer to chart object - * @return dark effect level (LV_OPA_TRANSP to turn off) - */ -lv_opa_t lv_chart_get_series_darking(const lv_obj_t * chart); - -/** - * Get the style of an chart object - * @param chart pointer to an chart object - * @return pointer to the chart's style - */ -static inline lv_style_t* lv_chart_get_style(const lv_obj_t *chart) -{ - return lv_obj_get_style(chart); -} - -/*===================== - * Other functions - *====================*/ - -/** - * Refresh a chart if its data line has changed - * @param chart pointer to chart object - */ -void lv_chart_refresh(lv_obj_t * chart); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CHART*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CHART_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_cont.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_cont.h deleted file mode 100644 index 3f4923dc..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_cont.h +++ /dev/null @@ -1,163 +0,0 @@ -/** - * @file lv_cont.h - * - */ - -#ifndef LV_CONT_H -#define LV_CONT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CONT != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Layout options*/ -enum -{ - LV_LAYOUT_OFF = 0, - LV_LAYOUT_CENTER, - LV_LAYOUT_COL_L, /*Column left align*/ - LV_LAYOUT_COL_M, /*Column middle align*/ - LV_LAYOUT_COL_R, /*Column right align*/ - LV_LAYOUT_ROW_T, /*Row top align*/ - LV_LAYOUT_ROW_M, /*Row middle align*/ - LV_LAYOUT_ROW_B, /*Row bottom align*/ - LV_LAYOUT_PRETTY, /*Put as many object as possible in row and begin a new row*/ - LV_LAYOUT_GRID, /*Align same-sized object into a grid*/ -}; -typedef uint8_t lv_layout_t; - -typedef struct -{ - /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/ - /*New data for this type */ - uint8_t layout :4; /*A layout from 'lv_cont_layout_t' enum*/ - uint8_t hor_fit :1; /*1: Enable horizontal fit to involve all children*/ - uint8_t ver_fit :1; /*1: Enable horizontal fit to involve all children*/ -} lv_cont_ext_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a container objects - * @param par pointer to an object, it will be the parent of the new container - * @param copy pointer to a container object, if not NULL then the new object will be copied from it - * @return pointer to the created container - */ -lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a layout on a container - * @param cont pointer to a container object - * @param layout a layout from 'lv_cont_layout_t' - */ -void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout); - - -/** - * Enable the horizontal or vertical fit. - * The container size will be set to involve the children horizontally or vertically. - * @param cont pointer to a container object - * @param hor_en true: enable the horizontal fit - * @param ver_en true: enable the vertical fit - */ -void lv_cont_set_fit(lv_obj_t * cont, bool hor_en, bool ver_en); - -/** - * Set the style of a container - * @param cont pointer to a container object - * @param style pointer to the new style - */ -static inline void lv_cont_set_style(lv_obj_t *cont, lv_style_t * style) -{ - lv_obj_set_style(cont, style); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the layout of a container - * @param cont pointer to container object - * @return the layout from 'lv_cont_layout_t' - */ -lv_layout_t lv_cont_get_layout(const lv_obj_t * cont); - -/** - * Get horizontal fit enable attribute of a container - * @param cont pointer to a container object - * @return true: horizontal fit is enabled; false: disabled - */ -bool lv_cont_get_hor_fit(const lv_obj_t * cont); - -/** - * Get vertical fit enable attribute of a container - * @param cont pointer to a container object - * @return true: vertical fit is enabled; false: disabled - */ -bool lv_cont_get_ver_fit(const lv_obj_t * cont); - - -/** - * Get that width reduced by the horizontal padding. Useful if a layout is used. - * @param cont pointer to a container object - * @return the width which still fits into the container - */ -lv_coord_t lv_cont_get_fit_width(lv_obj_t * cont); - -/** - * Get that height reduced by the vertical padding. Useful if a layout is used. - * @param cont pointer to a container object - * @return the height which still fits into the container - */ -lv_coord_t lv_cont_get_fit_height(lv_obj_t * cont); - -/** - * Get the style of a container - * @param cont pointer to a container object - * @return pointer to the container's style - */ -static inline lv_style_t * lv_cont_get_style(const lv_obj_t *cont) -{ - return lv_obj_get_style(cont); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CONT*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CONT_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_ddlist.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_ddlist.h deleted file mode 100644 index cd9de975..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_ddlist.h +++ /dev/null @@ -1,265 +0,0 @@ -/** - * @file lv_ddlist.h - * - */ - -#ifndef LV_DDLIST_H -#define LV_DDLIST_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_DDLIST != 0 - -/*Testing of dependencies*/ -#if USE_LV_PAGE == 0 -#error "lv_ddlist: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_ddlist: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "display/lv_objx/lv_page.h" -#include "display/lv_objx/lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of drop down list*/ -typedef struct -{ - lv_page_ext_t page; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t *label; /*Label for the options*/ - lv_style_t * sel_style; /*Style of the selected option*/ - lv_action_t action; /*Pointer to function to call when an option is selected*/ - uint16_t option_cnt; /*Number of options*/ - uint16_t sel_opt_id; /*Index of the current option*/ - uint16_t sel_opt_id_ori; /*Store the original index on focus*/ - uint16_t anim_time; /*Open/Close animation time [ms]*/ - uint8_t opened :1; /*1: The list is opened (handled by the library)*/ - uint8_t draw_arrow :1; /*1: Draw arrow*/ - - lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/ -} lv_ddlist_ext_t; - -enum { - LV_DDLIST_STYLE_BG, - LV_DDLIST_STYLE_SEL, - LV_DDLIST_STYLE_SB, -}; -typedef uint8_t lv_ddlist_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ -/** - * Create a drop down list objects - * @param par pointer to an object, it will be the parent of the new drop down list - * @param copy pointer to a drop down list object, if not NULL then the new object will be copied from it - * @return pointer to the created drop down list - */ -lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set arrow draw in a drop down list - * @param ddlist pointer to drop down list object - * @param en enable/disable a arrow draw. E.g. "true" for draw. - */ -void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en); - -/** - * Set the options in a drop down list from a string - * @param ddlist pointer to drop down list object - * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" - */ -void lv_ddlist_set_options(lv_obj_t * ddlist, const char * options); - -/** - * Set the selected option - * @param ddlist pointer to drop down list object - * @param sel_opt id of the selected option (0 ... number of option - 1); - */ -void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt); - -/** - * Set a function to call when a new option is chosen - * @param ddlist pointer to a drop down list - * @param action pointer to a call back function - */ -void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t action); - -/** - * Set the fix height for the drop down list - * If 0 then the opened ddlist will be auto. sized else the set height will be applied. - * @param ddlist pointer to a drop down list - * @param h the height when the list is opened (0: auto size) - */ -void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h); - -/** - * Enable or disable the horizontal fit to the content - * @param ddlist pointer to a drop down list - * @param en true: enable auto fit; false: disable auto fit - */ -void lv_ddlist_set_hor_fit(lv_obj_t * ddlist, bool en); - -/** - * Set the scroll bar mode of a drop down list - * @param ddlist pointer to a drop down list object - * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum - */ -static inline void lv_ddlist_set_sb_mode(lv_obj_t * ddlist, lv_sb_mode_t mode) -{ - lv_page_set_sb_mode(ddlist, mode); -} - -/** - * Set the open/close animation time. - * @param ddlist pointer to a drop down list - * @param anim_time: open/close animation time [ms] - */ -void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time); - - -/** - * Set a style of a drop down list - * @param ddlist pointer to a drop down list object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style); - -/** - * Set the alignment of the labels in a drop down list - * @param ddlist pointer to a drop down list object - * @param align alignment of labels - */ -void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get arrow draw in a drop down list - * @param ddlist pointer to drop down list object - */ -bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist); - -/** - * Get the options of a drop down list - * @param ddlist pointer to drop down list object - * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") - */ -const char * lv_ddlist_get_options(const lv_obj_t * ddlist); - -/** - * Get the selected option - * @param ddlist pointer to drop down list object - * @return id of the selected option (0 ... number of option - 1); - */ -uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist); - -/** - * Get the current selected option as a string - * @param ddlist pointer to ddlist object - * @param buf pointer to an array to store the string - */ -void lv_ddlist_get_selected_str(const lv_obj_t * ddlist, char * buf); - -/** - * Get the "option selected" callback function - * @param ddlist pointer to a drop down list - * @return pointer to the call back function - */ -lv_action_t lv_ddlist_get_action(const lv_obj_t * ddlist); - -/** - * Get the fix height value. - * @param ddlist pointer to a drop down list object - * @return the height if the ddlist is opened (0: auto size) - */ -lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist); - -/** - * Get the scroll bar mode of a drop down list - * @param ddlist pointer to a drop down list object - * @return scrollbar mode from 'lv_page_sb_mode_t' enum - */ -static inline lv_sb_mode_t lv_ddlist_get_sb_mode(const lv_obj_t * ddlist) -{ - return lv_page_get_sb_mode(ddlist); -} - -/** - * Get the open/close animation time. - * @param ddlist pointer to a drop down list - * @return open/close animation time [ms] - */ -uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist); - -/** - * Get a style of a drop down list - * @param ddlist pointer to a drop down list object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_ddlist_get_style(const lv_obj_t *ddlist, lv_ddlist_style_t type); - -/** - * Get the alignment of the labels in a drop down list - * @param ddlist pointer to a drop down list object - * @return alignment of labels - */ -lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist); - -/*===================== - * Other functions - *====================*/ - -/** - * Open the drop down list with or without animation - * @param ddlist pointer to drop down list object - * @param anim_en true: use animation; false: not use animations - */ -void lv_ddlist_open(lv_obj_t * ddlist, bool anim_en); - -/** - * Close (Collapse) the drop down list - * @param ddlist pointer to drop down list object - * @param anim_en true: use animation; false: not use animations - */ -void lv_ddlist_close(lv_obj_t * ddlist, bool anim_en); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_DDLIST*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DDLIST_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_gauge.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_gauge.h deleted file mode 100644 index 3f269cd0..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_gauge.h +++ /dev/null @@ -1,222 +0,0 @@ -/** - * @file lv_gauge.h - * - */ - -#ifndef LV_GAUGE_H -#define LV_GAUGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_GAUGE != 0 - -/*Testing of dependencies*/ -#if USE_LV_LMETER == 0 -#error "lv_gauge: lv_lmeter is required. Enable it in lv_conf.h (USE_LV_LMETER 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_lmeter.h" -#include "lv_label.h" -#include "lv_line.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of gauge*/ -typedef struct -{ - lv_lmeter_ext_t lmeter; /*Ext. of ancestor*/ - /*New data for this type */ - int16_t * values; /*Array of the set values (for needles) */ - const lv_color_t * needle_colors; /*Color of the needles (lv_color_t my_colors[needle_num])*/ - uint8_t needle_count; /*Number of needles*/ - uint8_t label_count; /*Number of labels on the scale*/ -} lv_gauge_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a gauge objects - * @param par pointer to an object, it will be the parent of the new gauge - * @param copy pointer to a gauge object, if not NULL then the new object will be copied from it - * @return pointer to the created gauge - */ -lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the number of needles - * @param gauge pointer to gauge object - * @param needle_cnt new count of needles - * @param colors an array of colors for needles (with 'num' elements) - */ -void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t * colors); - -/** - * Set the value of a needle - * @param gauge pointer to a gauge - * @param needle_id the id of the needle - * @param value the new value - */ -void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int16_t value); - -/** - * Set minimum and the maximum values of a gauge - * @param gauge pointer to he gauge object - * @param min minimum value - * @param max maximum value - */ -static inline void lv_gauge_set_range(lv_obj_t *gauge, int16_t min, int16_t max) -{ - lv_lmeter_set_range(gauge, min, max); -} - -/** - * Set a critical value on the scale. After this value 'line.color' scale lines will be drawn - * @param gauge pointer to a gauge object - * @param value the critical value - */ -static inline void lv_gauge_set_critical_value(lv_obj_t * gauge, int16_t value) -{ - lv_lmeter_set_value(gauge, value); -} - -/** - * Set the scale settings of a gauge - * @param gauge pointer to a gauge object - * @param angle angle of the scale (0..360) - * @param line_cnt count of scale lines. - * The get a given "subdivision" lines between label, `line_cnt` = (sub_div + 1) * (label_cnt - 1) + 1 - * @param label_cnt count of scale labels. - */ -void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt); - -/** - * Set the styles of a gauge - * @param gauge pointer to a gauge object - * @param bg set the style of the gauge - * */ -static inline void lv_gauge_set_style(lv_obj_t *gauge, lv_style_t *bg) -{ - lv_obj_set_style(gauge, bg); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a needle - * @param gauge pointer to gauge object - * @param needle the id of the needle - * @return the value of the needle [min,max] - */ -int16_t lv_gauge_get_value(const lv_obj_t * gauge, uint8_t needle); - -/** - * Get the count of needles on a gauge - * @param gauge pointer to gauge - * @return count of needles - */ -uint8_t lv_gauge_get_needle_count(const lv_obj_t * gauge); - -/** - * Get the minimum value of a gauge - * @param gauge pointer to a gauge object - * @return the minimum value of the gauge - */ -static inline int16_t lv_gauge_get_min_value(const lv_obj_t * lmeter) -{ - return lv_lmeter_get_min_value(lmeter); -} - -/** - * Get the maximum value of a gauge - * @param gauge pointer to a gauge object - * @return the maximum value of the gauge - */ -static inline int16_t lv_gauge_get_max_value(const lv_obj_t * lmeter) -{ - return lv_lmeter_get_max_value(lmeter); -} - -/** - * Get a critical value on the scale. - * @param gauge pointer to a gauge object - * @return the critical value - */ -static inline int16_t lv_gauge_get_critical_value(const lv_obj_t * gauge) -{ - return lv_lmeter_get_value(gauge); -} - -/** - * Set the number of labels (and the thicker lines too) - * @param gauge pointer to a gauge object - * @return count of labels - */ -uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge); - -/** - * Get the scale number of a gauge - * @param gauge pointer to a gauge object - * @return number of the scale units - */ -static inline uint8_t lv_gauge_get_line_count(const lv_obj_t * gauge) -{ - return lv_lmeter_get_line_count(gauge); -} - -/** - * Get the scale angle of a gauge - * @param gauge pointer to a gauge object - * @return angle of the scale - */ -static inline uint16_t lv_gauge_get_scale_angle(const lv_obj_t * gauge) -{ - return lv_lmeter_get_scale_angle(gauge); -} - -/** - * Get the style of a gauge - * @param gauge pointer to a gauge object - * @return pointer to the gauge's style - */ -static inline lv_style_t * lv_gauge_get_style(const lv_obj_t *gauge) -{ - return lv_obj_get_style(gauge); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_GAUGE*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_GAUGE_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_img.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_img.h deleted file mode 100644 index 03eca247..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_img.h +++ /dev/null @@ -1,195 +0,0 @@ -/** - * @file lv_img.h - * - */ - -#ifndef LV_IMG_H -#define LV_IMG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_IMG != 0 - -#include "display/lv_core/lv_obj.h" -#include "display/lv_misc/lv_fs.h" -#include "display/lv_misc/lv_symbol_def.h" -#include "lv_label.h" -#include "display/lv_draw/lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of image*/ -typedef struct -{ - /*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/ - /*New data for this type */ - const void * src; /*Image source: Pointer to an array or a file or a symbol*/ - - lv_coord_t w; /*Width of the image (Handled by the library)*/ - lv_coord_t h; /*Height of the image (Handled by the library)*/ -#if USE_LV_MULTI_LANG - uint16_t lang_txt_id; /*The ID of the image to display. */ -#endif - uint8_t src_type :2; /*See: lv_img_src_t*/ - uint8_t auto_size :1; /*1: automatically set the object size to the image size*/ - uint8_t cf :5; /*Color format from `lv_img_color_format_t`*/ -} lv_img_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create an image objects - * @param par pointer to an object, it will be the parent of the new button - * @param copy pointer to a image object, if not NULL then the new object will be copied from it - * @return pointer to the created image - */ -lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the pixel map to display by the image - * @param img pointer to an image object - * @param data the image data - */ -void lv_img_set_src(lv_obj_t * img, const void * src_img); - -#if USE_LV_MULTI_LANG -/** - * Set an ID which means a the same source but on different languages - * @param img pointer to an image object - * @param src_id ID of the source - */ -void lv_img_set_src_id(lv_obj_t * img, uint32_t txt_id); -#endif - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0. - * Use 'lv_img_set_src()' instead. - * @param img - - * @param fn - - */ -static inline void lv_img_set_file(lv_obj_t * img, const char * fn) -{ - (void) img; - (void) fn; -} - -/** - * Enable the auto size feature. - * If enabled the object size will be same as the picture size. - * @param img pointer to an image - * @param en true: auto size enable, false: auto size disable - */ -void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en); - -/** - * Set the style of an image - * @param img pointer to an image object - * @param style pointer to a style - */ -static inline void lv_img_set_style(lv_obj_t *img, lv_style_t *style) -{ - lv_obj_set_style(img, style); -} - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 - * @param img - - * @param upscale - - */ -static inline void lv_img_set_upscale(lv_obj_t * img, bool upcale) -{ - (void) img; - (void) upcale; -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the source of the image - * @param img pointer to an image object - * @return the image source (symbol, file name or C array) - */ -const void * lv_img_get_src(lv_obj_t * img); - -/** - * Get the name of the file set for an image - * @param img pointer to an image - * @return file name - */ -const char * lv_img_get_file_name(const lv_obj_t * img); - -#if USE_LV_MULTI_LANG -/** - * Get the source ID of the image. (Used by the multi-language feature) - * @param img pointer to an image - * @return ID of the source - */ -uint16_t lv_img_get_src_id(lv_obj_t * img); -#endif - -/** - * Get the auto size enable attribute - * @param img pointer to an image - * @return true: auto size is enabled, false: auto size is disabled - */ -bool lv_img_get_auto_size(const lv_obj_t * img); - -/** - * Get the style of an image object - * @param img pointer to an image object - * @return pointer to the image's style - */ -static inline lv_style_t* lv_img_get_style(const lv_obj_t *img) -{ - return lv_obj_get_style(img); -} - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 - * @param img - - * @return false - */ -static inline bool lv_img_get_upscale(const lv_obj_t * img) -{ - (void)img; - return false; -} - -/********************** - * MACROS - **********************/ - -/*Use this macro to declare an image in a c file*/ -#define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name; - -#endif /*USE_LV_IMG*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_IMG_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_imgbtn.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_imgbtn.h deleted file mode 100644 index 295be8f2..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_imgbtn.h +++ /dev/null @@ -1,248 +0,0 @@ -/** - * @file lv_imgbtn.h - * - */ - -#ifndef LV_IMGBTN_H -#define LV_IMGBTN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_IMGBTN != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTN == 0 -#error "lv_imgbtn: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_btn.h" -#include "display/lv_draw/lv_draw_img.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of image button*/ -typedef struct { - lv_btn_ext_t btn; /*Ext. of ancestor*/ - /*New data for this type */ -#if LV_IMGBTN_TILED == 0 - const void * img_src[LV_BTN_STATE_NUM]; /*Store images to each state*/ -#else - const void * img_src_left[LV_BTN_STATE_NUM]; /*Store left side images to each state*/ - const void * img_src_mid[LV_BTN_STATE_NUM]; /*Store center images to each state*/ - const void * img_src_right[LV_BTN_STATE_NUM]; /*Store right side images to each state*/ -#endif - lv_img_cf_t act_cf; /*Color format of the currently active image*/ -} lv_imgbtn_ext_t; - - -/*Styles*/ -enum { - LV_IMGBTN_STYLE_REL, - LV_IMGBTN_STYLE_PR, - LV_IMGBTN_STYLE_TGL_REL, - LV_IMGBTN_STYLE_TGL_PR, - LV_IMGBTN_STYLE_INA, -}; -typedef uint8_t lv_imgbtn_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a image button objects - * @param par pointer to an object, it will be the parent of the new image button - * @param copy pointer to a image button object, if not NULL then the new object will be copied from it - * @return pointer to the created image button - */ -lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - - -/*===================== - * Setter functions - *====================*/ - -#if LV_IMGBTN_TILED == 0 -/** - * Set images for a state of the image button - * @param imgbtn pointer to an image button object - * @param state for which state set the new image (from `lv_btn_state_t`) ` - * @param src pointer to an image source (a C array or path to a file) - */ -void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src); -#else -/** - * Set images for a state of the image button - * @param imgbtn pointer to an image button object - * @param state for which state set the new image (from `lv_btn_state_t`) ` - * @param src_left pointer to an image source for the left side of the button (a C array or path to a file) - * @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C array or path to a file) - * @param src_right pointer to an image source for the right side of the button (a C array or path to a file) - */ -void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid, const void * src_right); - -#endif - -/** - * Enable the toggled states. On release the button will change from/to toggled state. - * @param imgbtn pointer to an image button object - * @param tgl true: enable toggled states, false: disable - */ -static inline void lv_imgbtn_set_toggle(lv_obj_t * imgbtn, bool tgl) -{ - lv_btn_set_toggle(imgbtn, tgl); -} - -/** - * Set the state of the image button - * @param imgbtn pointer to an image button object - * @param state the new state of the button (from lv_btn_state_t enum) - */ -static inline void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_btn_state_t state) -{ - lv_btn_set_state(imgbtn, state); -} - -/** - * Toggle the state of the image button (ON->OFF, OFF->ON) - * @param imgbtn pointer to a image button object - */ -static inline void lv_imgbtn_toggle(lv_obj_t * imgbtn) -{ - lv_btn_toggle(imgbtn); -} - -/** - * Set a function to call when a button event happens - * @param imgbtn pointer to an image button object - * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) - */ -static inline void lv_imgbtn_set_action(lv_obj_t * imgbtn, lv_btn_action_t type, lv_action_t action) -{ - lv_btn_set_action(imgbtn, type, action); -} - -/** - * Set a style of a image button. - * @param imgbtn pointer to image button object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_imgbtn_set_style(lv_obj_t * imgbtn, lv_imgbtn_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - - -#if LV_IMGBTN_TILED == 0 -/** - * Get the images in a given state - * @param imgbtn pointer to an image button object - * @param state the state where to get the image (from `lv_btn_state_t`) ` - * @return pointer to an image source (a C array or path to a file) - */ -const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state); - -#else - -/** - * Get the left image in a given state - * @param imgbtn pointer to an image button object - * @param state the state where to get the image (from `lv_btn_state_t`) ` - * @return pointer to the left image source (a C array or path to a file) - */ -const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_btn_state_t state); - -/** - * Get the middle image in a given state - * @param imgbtn pointer to an image button object - * @param state the state where to get the image (from `lv_btn_state_t`) ` - * @return pointer to the middle image source (a C array or path to a file) - */ -const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_btn_state_t state); - -/** - * Get the right image in a given state - * @param imgbtn pointer to an image button object - * @param state the state where to get the image (from `lv_btn_state_t`) ` - * @return pointer to the left image source (a C array or path to a file) - */ -const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_btn_state_t state); - -#endif -/** - * Get the current state of the image button - * @param imgbtn pointer to a image button object - * @return the state of the button (from lv_btn_state_t enum) - */ -static inline lv_btn_state_t lv_imgbtn_get_state(const lv_obj_t * imgbtn) -{ - return lv_btn_get_state(imgbtn); -} - -/** - * Get the toggle enable attribute of the image button - * @param imgbtn pointer to a image button object - * @return ture: toggle enabled, false: disabled - */ -static inline bool lv_imgbtn_get_toggle(const lv_obj_t * imgbtn) -{ - return lv_btn_get_toggle(imgbtn); -} - -/** - * Get the release action of a image button - * @param imgbtn pointer to a image button object - * @return pointer to the release action function - */ -static inline lv_action_t lv_imgbtn_get_action(const lv_obj_t * imgbtn, lv_btn_action_t type) -{ - return lv_btn_get_action(imgbtn, type); -} - -/** - * Get style of a image button. - * @param imgbtn pointer to image button object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_imgbtn_get_style(const lv_obj_t * imgbtn, lv_imgbtn_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_IMGBTN*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_IMGBTN_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_kb.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_kb.h deleted file mode 100644 index d6ab9795..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_kb.h +++ /dev/null @@ -1,199 +0,0 @@ -/** - * @file lv_kb.h - * - */ - -#ifndef LV_KB_H -#define LV_KB_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_KB != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTNM == 0 -#error "lv_kb: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " -#endif - -#if USE_LV_TA == 0 -#error "lv_kb: lv_ta is required. Enable it in lv_conf.h (USE_LV_TA 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_btnm.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -enum { - LV_KB_MODE_TEXT, - LV_KB_MODE_NUM, -}; -typedef uint8_t lv_kb_mode_t; - -/*Data of keyboard*/ -typedef struct { - lv_btnm_ext_t btnm; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t *ta; /*Pointer to the assigned text area*/ - lv_kb_mode_t mode; /*Key map type*/ - uint8_t cursor_mng :1; /*1: automatically show/hide cursor when a text area is assigned or left*/ - lv_action_t ok_action; /*Called when the "Ok" button is clicked*/ - lv_action_t hide_action; /*Called when the "Hide" button is clicked*/ -} lv_kb_ext_t; - -enum { - LV_KB_STYLE_BG, - LV_KB_STYLE_BTN_REL, - LV_KB_STYLE_BTN_PR, - LV_KB_STYLE_BTN_TGL_REL, - LV_KB_STYLE_BTN_TGL_PR, - LV_KB_STYLE_BTN_INA, -}; -typedef uint8_t lv_kb_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a keyboard objects - * @param par pointer to an object, it will be the parent of the new keyboard - * @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it - * @return pointer to the created keyboard - */ -lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Assign a Text Area to the Keyboard. The pressed characters will be put there. - * @param kb pointer to a Keyboard object - * @param ta pointer to a Text Area object to write there - */ -void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta); - -/** - * Set a new a mode (text or number map) - * @param kb pointer to a Keyboard object - * @param mode the mode from 'lv_kb_mode_t' - */ -void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode); - -/** - * Automatically hide or show the cursor of the current Text Area - * @param kb pointer to a Keyboard object - * @param en true: show cursor on the current text area, false: hide cursor - */ -void lv_kb_set_cursor_manage(lv_obj_t * kb, bool en); - -/** - * Set call back to call when the "Ok" button is pressed - * @param kb pointer to Keyboard object - * @param action a callback with 'lv_action_t' type - */ -void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action); - -/** - * Set call back to call when the "Hide" button is pressed - * @param kb pointer to Keyboard object - * @param action a callback with 'lv_action_t' type - */ -void lv_kb_set_hide_action(lv_obj_t * kb, lv_action_t action); - -/** - * Set a new map for the keyboard - * @param kb pointer to a Keyboard object - * @param map pointer to a string array to describe the map. - * See 'lv_btnm_set_map()' for more info. - */ -static inline void lv_kb_set_map(lv_obj_t *kb, const char ** map) -{ - lv_btnm_set_map(kb, map); -} - -/** - * Set a style of a keyboard - * @param kb pointer to a keyboard object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_kb_set_style(lv_obj_t *kb, lv_kb_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Assign a Text Area to the Keyboard. The pressed characters will be put there. - * @param kb pointer to a Keyboard object - * @return pointer to the assigned Text Area object - */ -lv_obj_t * lv_kb_get_ta(const lv_obj_t * kb); - -/** - * Set a new a mode (text or number map) - * @param kb pointer to a Keyboard object - * @return the current mode from 'lv_kb_mode_t' - */ -lv_kb_mode_t lv_kb_get_mode(const lv_obj_t * kb); - -/** - * Get the current cursor manage mode. - * @param kb pointer to a Keyboard object - * @return true: show cursor on the current text area, false: hide cursor - */ -bool lv_kb_get_cursor_manage(const lv_obj_t * kb); - -/** - * Get the callback to call when the "Ok" button is pressed - * @param kb pointer to Keyboard object - * @return the ok callback - */ -lv_action_t lv_kb_get_ok_action(const lv_obj_t * kb); - -/** - * Get the callback to call when the "Hide" button is pressed - * @param kb pointer to Keyboard object - * @return the close callback - */ -lv_action_t lv_kb_get_hide_action(const lv_obj_t * kb); - -/** - * Get a style of a keyboard - * @param kb pointer to a keyboard object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_kb_get_style(const lv_obj_t *kb, lv_kb_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_KB*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_KB_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_label.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_label.h deleted file mode 100644 index abd176a0..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_label.h +++ /dev/null @@ -1,295 +0,0 @@ -/** - * @file lv_rect.h - * - */ - -#ifndef LV_LABEL_H -#define LV_LABEL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LABEL != 0 - -#include "display/lv_core/lv_obj.h" -#include "display/lv_misc/lv_font.h" -#include "display/lv_misc/lv_txt.h" -#include "display/lv_misc/lv_symbol_def.h" - -/********************* - * DEFINES - *********************/ -#define LV_LABEL_DOT_NUM 3 -#define LV_LABEL_POS_LAST 0xFFFF - -/********************** - * TYPEDEFS - **********************/ - -/*Long mode behaviors. Used in 'lv_label_ext_t' */ -enum -{ - LV_LABEL_LONG_EXPAND, /*Expand the object size to the text size*/ - LV_LABEL_LONG_BREAK, /*Keep the object width, break the too long lines and expand the object height*/ - LV_LABEL_LONG_SCROLL, /*Expand the object size and scroll the text on the parent (move the label object)*/ - LV_LABEL_LONG_DOT, /*Keep the size and write dots at the end if the text is too long*/ - LV_LABEL_LONG_ROLL, /*Keep the size and roll the text infinitely*/ - LV_LABEL_LONG_CROP, /*Keep the size and crop the text out of it*/ -}; -typedef uint8_t lv_label_long_mode_t; - -/*Label align policy*/ -enum { - LV_LABEL_ALIGN_LEFT, - LV_LABEL_ALIGN_CENTER, - LV_LABEL_ALIGN_RIGHT, -}; -typedef uint8_t lv_label_align_t; - -/*Data of label*/ -typedef struct -{ - /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ - /*New data for this type */ - char * text; /*Text of the label*/ - lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/ -#if LV_TXT_UTF8 == 0 - char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ -#else - char dot_tmp[LV_LABEL_DOT_NUM * 4 + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ -#endif - -#if USE_LV_MULTI_LANG - uint16_t lang_txt_id; /*The ID of the text to display*/ -#endif - uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/ - uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/ - lv_point_t offset; /*Text draw position offset*/ - uint8_t static_txt :1; /*Flag to indicate the text is static*/ - uint8_t align :2; /*Align type from 'lv_label_align_t'*/ - uint8_t recolor :1; /*Enable in-line letter re-coloring*/ - uint8_t expand :1; /*Ignore real width (used by the library with LV_LABEL_LONG_ROLL)*/ - uint8_t body_draw :1; /*Draw background body*/ -} lv_label_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Create a label objects - * @param par pointer to an object, it will be the parent of the new label - * @param copy pointer to a button object, if not NULL then the new object will be copied from it - * @return pointer to the created button - */ -lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new text for a label. Memory will be allocated to store the text by the label. - * @param label pointer to a label object - * @param text '\0' terminated character string. NULL to refresh with the current text. - */ -void lv_label_set_text(lv_obj_t * label, const char * text); - -/** - * Set a new text for a label from a character array. The array don't has to be '\0' terminated. - * Memory will be allocated to store the array by the label. - * @param label pointer to a label object - * @param array array of characters or NULL to refresh the label - * @param size the size of 'array' in bytes - */ -void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size); - -/** - * Set a static text. It will not be saved by the label so the 'text' variable - * has to be 'alive' while the label exist. - * @param label pointer to a label object - * @param text pointer to a text. NULL to refresh with the current text. - */ -void lv_label_set_static_text(lv_obj_t * label, const char * text); - -/** - *Set a text ID which means a the same text but on different languages - * @param label pointer to a label object - * @param txt_id ID of the text - */ -#if USE_LV_MULTI_LANG -void lv_label_set_text_id(lv_obj_t * label, uint32_t txt_id); -#endif - -/** - * Set the behavior of the label with longer text then the object size - * @param label pointer to a label object - * @param long_mode the new mode from 'lv_label_long_mode' enum. - * In LV_LONG_BREAK/LONG/ROLL the size of the label should be set AFTER this function - */ -void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode); - -/** - * Set the align of the label (left or center) - * @param label pointer to a label object - * @param align 'LV_LABEL_ALIGN_LEFT' or 'LV_LABEL_ALIGN_LEFT' - */ -void lv_label_set_align(lv_obj_t *label, lv_label_align_t align); - -/** - * Enable the recoloring by in-line commands - * @param label pointer to a label object - * @param en true: enable recoloring, false: disable - */ -void lv_label_set_recolor(lv_obj_t * label, bool en); - -/** - * Set the label to draw (or not draw) background specified in its style's body - * @param label pointer to a label object - * @param en true: draw body; false: don't draw body - */ -void lv_label_set_body_draw(lv_obj_t *label, bool en); - -/** - * Set the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes - * @param label pointer to a label object - * @param anim_speed speed of animation in px/sec unit - */ -void lv_label_set_anim_speed(lv_obj_t *label, uint16_t anim_speed); - -/** - * Set the style of an label - * @param label pointer to an label object - * @param style pointer to a style - */ -static inline void lv_label_set_style(lv_obj_t *label, lv_style_t *style) -{ - lv_obj_set_style(label, style); -} -/*===================== - * Getter functions - *====================*/ - -/** - * Get the text of a label - * @param label pointer to a label object - * @return the text of the label - */ -char * lv_label_get_text(const lv_obj_t * label); - -#if USE_LV_MULTI_LANG -/** - * Get the text ID of the label. (Used by the multi-language feature) - * @param label pointer to a label object - * @return ID of the text - */ -uint16_t lv_label_get_text_id(lv_obj_t * label); -#endif - -/** - * Get the long mode of a label - * @param label pointer to a label object - * @return the long mode - */ -lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * label); - -/** - * Get the align attribute - * @param label pointer to a label object - * @return LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER - */ -lv_label_align_t lv_label_get_align(const lv_obj_t * label); - -/** - * Get the recoloring attribute - * @param label pointer to a label object - * @return true: recoloring is enabled, false: disable - */ -bool lv_label_get_recolor(const lv_obj_t * label); - -/** - * Get the body draw attribute - * @param label pointer to a label object - * @return true: draw body; false: don't draw body - */ -bool lv_label_get_body_draw(const lv_obj_t *label); - -/** - * Get the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes - * @param label pointer to a label object - * @return speed of animation in px/sec unit - */ -uint16_t lv_label_get_anim_speed(const lv_obj_t *label); - -/** - * Get the relative x and y coordinates of a letter - * @param label pointer to a label object - * @param index index of the letter [0 ... text length]. Expressed in character index, not byte index (different in UTF-8) - * @param pos store the result here (E.g. index = 0 gives 0;0 coordinates) - */ -void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t * pos); - -/** - * Get the index of letter on a relative point of a label - * @param label pointer to label object - * @param pos pointer to point with coordinates on a the label - * @return the index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter) - * Expressed in character index and not byte index (different in UTF-8) - */ -uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos); - -/** - * Get the style of an label object - * @param label pointer to an label object - * @return pointer to the label's style - */ -static inline lv_style_t* lv_label_get_style(const lv_obj_t *label) -{ - return lv_obj_get_style(label); -} - -/*===================== - * Other functions - *====================*/ - -/** - * Insert a text to the label. The label text can not be static. - * @param label pointer to a label object - * @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8) - * 0: before first char. - * LV_LABEL_POS_LAST: after last char. - * @param txt pointer to the text to insert - */ -void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt); - -/** - * Delete characters from a label. The label text can not be static. - * @param label pointer to a label object - * @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8) - * 0: before first char. - * @param cnt number of characters to cut - */ -void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LABEL*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LABEL_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_led.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_led.h deleted file mode 100644 index f6a18acb..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_led.h +++ /dev/null @@ -1,116 +0,0 @@ -/** - * @file lv_led.h - * - */ - -#ifndef LV_LED_H -#define LV_LED_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LED != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of led*/ -typedef struct -{ - /*No inherited ext.*/ - /*New data for this type */ - uint8_t bright; /*Current brightness of the LED (0..255)*/ -} lv_led_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a led objects - * @param par pointer to an object, it will be the parent of the new led - * @param copy pointer to a led object, if not NULL then the new object will be copied from it - * @return pointer to the created led - */ -lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Set the brightness of a LED object - * @param led pointer to a LED object - * @param bright 0 (max. dark) ... 255 (max. light) - */ -void lv_led_set_bright(lv_obj_t * led, uint8_t bright); - -/** - * Light on a LED - * @param led pointer to a LED object - */ -void lv_led_on(lv_obj_t * led); - -/** - * Light off a LED - * @param led pointer to a LED object - */ -void lv_led_off(lv_obj_t * led); - -/** - * Toggle the state of a LED - * @param led pointer to a LED object - */ -void lv_led_toggle(lv_obj_t * led); - -/** - * Set the style of a led - * @param led pointer to a led object - * @param style pointer to a style - */ -static inline void lv_led_set_style(lv_obj_t *led, lv_style_t *style) -{ - lv_obj_set_style(led, style); -} - -/** - * Get the brightness of a LEd object - * @param led pointer to LED object - * @return bright 0 (max. dark) ... 255 (max. light) - */ -uint8_t lv_led_get_bright(const lv_obj_t * led); - -/** - * Get the style of an led object - * @param led pointer to an led object - * @return pointer to the led's style - */ -static inline lv_style_t* lv_led_get_style(const lv_obj_t *led) -{ - return lv_obj_get_style(led); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LED*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LED_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_line.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_line.h deleted file mode 100644 index e7be8a32..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_line.h +++ /dev/null @@ -1,158 +0,0 @@ -/** - * @file lv_line.h - * - */ - -#ifndef LV_LINE_H -#define LV_LINE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LINE != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of line*/ -typedef struct -{ - /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ - const lv_point_t * point_array; /*Pointer to an array with the points of the line*/ - uint16_t point_num; /*Number of points in 'point_array' */ - uint8_t auto_size :1; /*1: set obj. width to x max and obj. height to y max */ - uint8_t y_inv :1; /*1: y == 0 will be on the bottom*/ -} lv_line_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Create a line objects - * @param par pointer to an object, it will be the parent of the new line - * @return pointer to the created line - */ -lv_obj_t * lv_line_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set an array of points. The line object will connect these points. - * @param line pointer to a line object - * @param point_a an array of points. Only the address is saved, - * so the array can NOT be a local variable which will be destroyed - * @param point_num number of points in 'point_a' - */ -void lv_line_set_points(lv_obj_t * line, const lv_point_t * point_a, uint16_t point_num); - -/** - * Enable (or disable) the auto-size option. The size of the object will fit to its points. - * (set width to x max and height to y max) - * @param line pointer to a line object - * @param en true: auto size is enabled, false: auto size is disabled - */ -void lv_line_set_auto_size(lv_obj_t * line, bool en); - -/** - * Enable (or disable) the y coordinate inversion. - * If enabled then y will be subtracted from the height of the object, - * therefore the y=0 coordinate will be on the bottom. - * @param line pointer to a line object - * @param en true: enable the y inversion, false:disable the y inversion - */ -void lv_line_set_y_invert(lv_obj_t * line, bool en); - -#define lv_line_set_y_inv lv_line_set_y_invert /*The name was inconsistent. In v.6.0 only `lv_line_set_y_invert`will work */ - -/** - * Set the style of a line - * @param line pointer to a line object - * @param style pointer to a style - */ -static inline void lv_line_set_style(lv_obj_t *line, lv_style_t *style) -{ - lv_obj_set_style(line, style); -} - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 - * @param line - - * @param upscale - - */ -static inline void lv_line_set_upscale(lv_obj_t * line, bool upcale) -{ - (void) line; - (void) upcale; -} -/*===================== - * Getter functions - *====================*/ - -/** - * Get the auto size attribute - * @param line pointer to a line object - * @return true: auto size is enabled, false: disabled - */ -bool lv_line_get_auto_size(const lv_obj_t * line); - -/** - * Get the y inversion attribute - * @param line pointer to a line object - * @return true: y inversion is enabled, false: disabled - */ -bool lv_line_get_y_invert(const lv_obj_t * line); - -/** - * Get the style of an line object - * @param line pointer to an line object - * @return pointer to the line's style - */ -static inline lv_style_t* lv_line_get_style(const lv_obj_t *line) -{ - return lv_obj_get_style(line); -} - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 - * @param line - - * @return false - */ -static inline bool lv_line_get_upscale(const lv_obj_t * line) -{ - (void) line; - return false; -} - - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LINE*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LINE_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_list.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_list.h deleted file mode 100644 index 397059a5..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_list.h +++ /dev/null @@ -1,336 +0,0 @@ -/** - * @file lv_list.h - * - */ - -#ifndef LV_LIST_H -#define LV_LIST_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LIST != 0 - -/*Testing of dependencies*/ -#if USE_LV_PAGE == 0 -#error "lv_list: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#if USE_LV_BTN == 0 -#error "lv_list: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_list: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - - -#include "display/lv_core/lv_obj.h" -#include "lv_page.h" -#include "lv_btn.h" -#include "lv_label.h" -#include "lv_img.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of list*/ -typedef struct -{ - lv_page_ext_t page; /*Ext. of ancestor*/ - /*New data for this type */ - uint16_t anim_time; /*Scroll animation time*/ - lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/ - lv_style_t *style_img; /*Style of the list element images on buttons*/ - uint32_t size; /*the number of items(buttons) in the list*/ - bool single_mode; /* whether single selected mode is enabled */ -#if USE_LV_GROUP - lv_obj_t * last_sel; /* The last selected button. It will be reverted when the list is focused again */ - lv_obj_t * selected_btn; /* The button is currently being selected*/ -#endif -} lv_list_ext_t; - -enum { - LV_LIST_STYLE_BG, - LV_LIST_STYLE_SCRL, - LV_LIST_STYLE_SB, - LV_LIST_STYLE_EDGE_FLASH, - LV_LIST_STYLE_BTN_REL, - LV_LIST_STYLE_BTN_PR, - LV_LIST_STYLE_BTN_TGL_REL, - LV_LIST_STYLE_BTN_TGL_PR, - LV_LIST_STYLE_BTN_INA, -}; -typedef uint8_t lv_list_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a list objects - * @param par pointer to an object, it will be the parent of the new list - * @param copy pointer to a list object, if not NULL then the new object will be copied from it - * @return pointer to the created list - */ -lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Delete all children of the scrl object, without deleting scrl child. - * @param obj pointer to an object - */ -void lv_list_clean(lv_obj_t *obj); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Add a list element to the list - * @param list pointer to list object - * @param img_fn file name of an image before the text (NULL if unused) - * @param txt text of the list element (NULL if unused) - * @param rel_action pointer to release action function (like with lv_btn) - * @return pointer to the new list element which can be customized (a button) - */ -lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, lv_action_t rel_action); - -/** - * Remove the index of the button in the list - * @param list pointer to a list object - * @param index pointer to a the button's index in the list, index must be 0 <= index < lv_list_ext_t.size - * @return true: successfully deleted - */ -bool lv_list_remove(const lv_obj_t * list, uint32_t index); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set single button selected mode, only one button will be selected if enabled. - * @param list pointer to the currently pressed list object - * @param mode, enable(true)/disable(false) single selected mode. - */ -void lv_list_set_single_mode(lv_obj_t *list, bool mode); - -#if USE_LV_GROUP - -/** - * Make a button selected. Can be used while navigating in the list with a keypad. - * @param list pointer to a list object - * @param btn pointer to a button to select - */ -void lv_list_set_btn_selected(lv_obj_t * list, lv_obj_t * btn); -#endif - -/** - * Set scroll animation duration on 'list_up()' 'list_down()' 'list_focus()' - * @param list pointer to a list object - * @param anim_time duration of animation [ms] - */ -void lv_list_set_anim_time(lv_obj_t *list, uint16_t anim_time); - -/** - * Set the scroll bar mode of a list - * @param list pointer to a list object - * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum - */ -static inline void lv_list_set_sb_mode(lv_obj_t * list, lv_sb_mode_t mode) -{ - lv_page_set_sb_mode(list, mode); -} - -/** - * Enable the scroll propagation feature. If enabled then the List will move its parent if there is no more space to scroll. - * @param list pointer to a List - * @param en true or false to enable/disable scroll propagation - */ -static inline void lv_list_set_scroll_propagation(lv_obj_t * list, bool en) -{ - lv_page_set_scroll_propagation(list, en); -} - -/** - * Enable the edge flash effect. (Show an arc when the an edge is reached) - * @param list pointer to a List - * @param en true or false to enable/disable end flash - */ -static inline void lv_list_set_edge_flash(lv_obj_t * list, bool en) -{ - lv_page_set_edge_flash(list, en); -} - -/** - * Set a style of a list - * @param list pointer to a list object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_list_set_style(lv_obj_t *list, lv_list_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get single button selected mode. - * @param list pointer to the currently pressed list object. - */ -bool lv_list_get_single_mode(lv_obj_t *list); - -/** - * Get the text of a list element - * @param btn pointer to list element - * @return pointer to the text - */ -const char * lv_list_get_btn_text(const lv_obj_t * btn); -/** - * Get the label object from a list element - * @param btn pointer to a list element (button) - * @return pointer to the label from the list element or NULL if not found - */ -lv_obj_t * lv_list_get_btn_label(const lv_obj_t * btn); - -/** - * Get the image object from a list element - * @param btn pointer to a list element (button) - * @return pointer to the image from the list element or NULL if not found - */ -lv_obj_t * lv_list_get_btn_img(const lv_obj_t * btn); - -/** - * Get the next button from list. (Starts from the bottom button) - * @param list pointer to a list object - * @param prev_btn pointer to button. Search the next after it. - * @return pointer to the next button or NULL when no more buttons - */ -lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn); - -/** - * Get the previous button from list. (Starts from the top button) - * @param list pointer to a list object - * @param prev_btn pointer to button. Search the previous before it. - * @return pointer to the previous button or NULL when no more buttons - */ -lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn); - -/** - * Get the index of the button in the list - * @param list pointer to a list object. If NULL, assumes btn is part of a list. - * @param btn pointer to a list element (button) - * @return the index of the button in the list, or -1 of the button not in this list - */ -int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn); - -/** - * Get the number of buttons in the list - * @param list pointer to a list object - * @return the number of buttons in the list - */ -uint32_t lv_list_get_size(const lv_obj_t * list); - -#if USE_LV_GROUP -/** - * Get the currently selected button. Can be used while navigating in the list with a keypad. - * @param list pointer to a list object - * @return pointer to the selected button - */ -lv_obj_t * lv_list_get_btn_selected(const lv_obj_t * list); -#endif - - -/** - * Get scroll animation duration - * @param list pointer to a list object - * @return duration of animation [ms] - */ -uint16_t lv_list_get_anim_time(const lv_obj_t *list); - - -/** - * Get the scroll bar mode of a list - * @param list pointer to a list object - * @return scrollbar mode from 'lv_page_sb_mode_t' enum - */ -static inline lv_sb_mode_t lv_list_get_sb_mode(const lv_obj_t * list) -{ - return lv_page_get_sb_mode(list); -} - -/** - * Get the scroll propagation property - * @param list pointer to a List - * @return true or false - */ -static inline bool lv_list_get_scroll_propagation(lv_obj_t * list) -{ - return lv_page_get_scroll_propagation(list); -} - -/** - * Get the scroll propagation property - * @param list pointer to a List - * @return true or false - */ -static inline bool lv_list_get_edge_flash(lv_obj_t * list) -{ - return lv_page_get_edge_flash(list); -} - -/** - * Get a style of a list - * @param list pointer to a list object - * @param type which style should be get - * @return style pointer to a style - * */ -lv_style_t * lv_list_get_style(const lv_obj_t *list, lv_list_style_t type); - -/*===================== - * Other functions - *====================*/ - -/** - * Move the list elements up by one - * @param list pointer a to list object - */ -void lv_list_up(const lv_obj_t * list); -/** - * Move the list elements down by one - * @param list pointer to a list object - */ -void lv_list_down(const lv_obj_t * list); - -/** - * Focus on a list button. It ensures that the button will be visible on the list. - * @param btn pointer to a list button to focus - * @param anim_en true: scroll with animation, false: without animation - */ -void lv_list_focus(const lv_obj_t *btn, bool anim_en); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LIST*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LIST_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_lmeter.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_lmeter.h deleted file mode 100644 index dcb42bf4..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_lmeter.h +++ /dev/null @@ -1,153 +0,0 @@ -/** - * @file lv_lmeter.h - * - */ - -#ifndef LV_LMETER_H -#define LV_LMETER_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LMETER != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of line meter*/ -typedef struct -{ - /*No inherited ext.*/ /*Ext. of ancestor*/ - /*New data for this type */ - uint16_t scale_angle; /*Angle of the scale in deg. (0..360)*/ - uint8_t line_cnt; /*Count of lines */ - int16_t cur_value; - int16_t min_value; - int16_t max_value; -} lv_lmeter_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a line meter objects - * @param par pointer to an object, it will be the parent of the new line meter - * @param copy pointer to a line meter object, if not NULL then the new object will be copied from it - * @return pointer to the created line meter - */ -lv_obj_t * lv_lmeter_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new value on the line meter - * @param lmeter pointer to a line meter object - * @param value new value - */ -void lv_lmeter_set_value(lv_obj_t *lmeter, int16_t value); - -/** - * Set minimum and the maximum values of a line meter - * @param lmeter pointer to he line meter object - * @param min minimum value - * @param max maximum value - */ -void lv_lmeter_set_range(lv_obj_t *lmeter, int16_t min, int16_t max); - -/** - * Set the scale settings of a line meter - * @param lmeter pointer to a line meter object - * @param angle angle of the scale (0..360) - * @param line_cnt number of lines - */ -void lv_lmeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint8_t line_cnt); - -/** - * Set the styles of a line meter - * @param lmeter pointer to a line meter object - * @param bg set the style of the line meter - */ -static inline void lv_lmeter_set_style(lv_obj_t *lmeter, lv_style_t *bg) -{ - lv_obj_set_style(lmeter, bg); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a line meter - * @param lmeter pointer to a line meter object - * @return the value of the line meter - */ -int16_t lv_lmeter_get_value(const lv_obj_t *lmeter); - -/** - * Get the minimum value of a line meter - * @param lmeter pointer to a line meter object - * @return the minimum value of the line meter - */ -int16_t lv_lmeter_get_min_value(const lv_obj_t * lmeter); - -/** - * Get the maximum value of a line meter - * @param lmeter pointer to a line meter object - * @return the maximum value of the line meter - */ -int16_t lv_lmeter_get_max_value(const lv_obj_t * lmeter); - -/** - * Get the scale number of a line meter - * @param lmeter pointer to a line meter object - * @return number of the scale units - */ -uint8_t lv_lmeter_get_line_count(const lv_obj_t * lmeter); - -/** - * Get the scale angle of a line meter - * @param lmeter pointer to a line meter object - * @return angle of the scale - */ -uint16_t lv_lmeter_get_scale_angle(const lv_obj_t * lmeter); - -/** - * Get the style of a line meter - * @param lmeter pointer to a line meter object - * @return pointer to the line meter's style - */ -static inline lv_style_t * lv_lmeter_get_style(const lv_obj_t * lmeter) -{ - return lv_obj_get_style(lmeter); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LMETER*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LMETER_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_mbox.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_mbox.h deleted file mode 100644 index 2dc0c6dc..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_mbox.h +++ /dev/null @@ -1,203 +0,0 @@ -/** - * @file lv_mbox.h - * - */ - -#ifndef LV_MBOX_H -#define LV_MBOX_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_MBOX != 0 - -/*Testing of dependencies*/ -#if USE_LV_CONT == 0 -#error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " -#endif - -#if USE_LV_BTNM == 0 -#error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_mbox: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - - -#include "display/lv_core/lv_obj.h" -#include "lv_cont.h" -#include "lv_btnm.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of message box*/ -typedef struct -{ - lv_cont_ext_t bg; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t *text; /*Text of the message box*/ - lv_obj_t *btnm; /*Button matrix for the buttons*/ - uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/ -} lv_mbox_ext_t; - -enum { - LV_MBOX_STYLE_BG, - LV_MBOX_STYLE_BTN_BG, - LV_MBOX_STYLE_BTN_REL, - LV_MBOX_STYLE_BTN_PR, - LV_MBOX_STYLE_BTN_TGL_REL, - LV_MBOX_STYLE_BTN_TGL_PR, - LV_MBOX_STYLE_BTN_INA, -}; -typedef uint8_t lv_mbox_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a message box objects - * @param par pointer to an object, it will be the parent of the new message box - * @param copy pointer to a message box object, if not NULL then the new object will be copied from it - * @return pointer to the created message box - */ -lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Add button to the message box - * @param mbox pointer to message box object - * @param btn_map button descriptor (button matrix map). - * E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable) - * @param action a function which will be called when a button is released - */ -void lv_mbox_add_btns(lv_obj_t * mbox, const char **btn_map, lv_btnm_action_t action); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the text of the message box - * @param mbox pointer to a message box - * @param txt a '\0' terminated character string which will be the message box text - */ -void lv_mbox_set_text(lv_obj_t * mbox, const char * txt); - -/** - * Stop the action to call when button is released - * @param mbox pointer to a message box object - * @param pointer to an 'lv_btnm_action_t' action. In the action you need to use `lv_mbox_get_from_btn()` to get the `mbox`. - */ -void lv_mbox_set_action(lv_obj_t * mbox, lv_btnm_action_t action); - -/** - * Set animation duration - * @param mbox pointer to a message box object - * @param anim_time animation length in milliseconds (0: no animation) - */ -void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time); - -/** - * Automatically delete the message box after a given time - * @param mbox pointer to a message box object - * @param delay a time (in milliseconds) to wait before delete the message box - */ -void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay); - -/** - * Stop the auto. closing of message box - * @param mbox pointer to a message box object - */ -void lv_mbox_stop_auto_close(lv_obj_t * mbox); - -/** - * Set a style of a message box - * @param mbox pointer to a message box object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_mbox_set_style(lv_obj_t *mbox, lv_mbox_style_t type, lv_style_t *style); - -/** - * Set whether recoloring is enabled. Must be called after `lv_mbox_add_btns`. - * @param btnm pointer to button matrix object - * @param en whether recoloring is enabled - */ -void lv_mbox_set_recolor(lv_obj_t * mbox, bool en); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the text of the message box - * @param mbox pointer to a message box object - * @return pointer to the text of the message box - */ -const char * lv_mbox_get_text(const lv_obj_t * mbox); - -/** - * Get the message box object from one of its button. - * It is useful in the button release actions where only the button is known - * @param btn pointer to a button of a message box - * @return pointer to the button's message box - */ -lv_obj_t * lv_mbox_get_from_btn(const lv_obj_t * btn); - -/** - * Get the animation duration (close animation time) - * @param mbox pointer to a message box object - * @return animation length in milliseconds (0: no animation) - */ -uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox); - - -/** - * Get a style of a message box - * @param mbox pointer to a message box object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_mbox_get_style(const lv_obj_t *mbox, lv_mbox_style_t type); - -/** - * Get whether recoloring is enabled - * @param btnm pointer to button matrix object - * @return whether recoloring is enabled - */ -bool lv_mbox_get_recolor(const lv_obj_t * mbox); - -/********************** - * MACROS - **********************/ - - -#endif /*USE_LV_MBOX*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_MBOX_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_objx.mk b/EZ-Template-Example-Project/include/display/lv_objx/lv_objx.mk deleted file mode 100644 index d35252bc..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_objx.mk +++ /dev/null @@ -1,36 +0,0 @@ -CSRCS += lv_arc.c -CSRCS += lv_bar.c -CSRCS += lv_cb.c -CSRCS += lv_ddlist.c -CSRCS += lv_kb.c -CSRCS += lv_line.c -CSRCS += lv_mbox.c -CSRCS += lv_preload.c -CSRCS += lv_roller.c -CSRCS += lv_table.c -CSRCS += lv_tabview.c -CSRCS += lv_tileview.c -CSRCS += lv_btn.c -CSRCS += lv_calendar.c -CSRCS += lv_chart.c -CSRCS += lv_canvas.c -CSRCS += lv_gauge.c -CSRCS += lv_label.c -CSRCS += lv_list.c -CSRCS += lv_slider.c -CSRCS += lv_ta.c -CSRCS += lv_spinbox.c -CSRCS += lv_btnm.c -CSRCS += lv_cont.c -CSRCS += lv_img.c -CSRCS += lv_imgbtn.c -CSRCS += lv_led.c -CSRCS += lv_lmeter.c -CSRCS += lv_page.c -CSRCS += lv_sw.c -CSRCS += lv_win.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_objx -VPATH += :$(LVGL_DIR)/lvgl/lv_objx - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_objx" diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_objx_templ.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_objx_templ.h deleted file mode 100644 index b8473dfb..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_objx_templ.h +++ /dev/null @@ -1,111 +0,0 @@ -/** - * @file lv_templ.h - * - */ - - -/* TODO Remove these instructions - * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) - * templ -> object short name with lower case(e.g. btn, label etc) - * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) - * - */ - -#ifndef LV_TEMPL_H -#define LV_TEMPL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TEMPL != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of template*/ -typedef struct { - lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ - /*New data for this type */ -} lv_templ_ext_t; - - -/*Styles*/ -enum { - LV_TEMPL_STYLE_X, - LV_TEMPL_STYLE_Y, -}; -typedef uint8_t lv_templ_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a template objects - * @param par pointer to an object, it will be the parent of the new template - * @param copy pointer to a template object, if not NULL then the new object will be copied from it - * @return pointer to the created template - */ -lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a style of a template. - * @param templ pointer to template object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get style of a template. - * @param templ pointer to template object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TEMPL*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TEMPL_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_page.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_page.h deleted file mode 100644 index d01de358..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_page.h +++ /dev/null @@ -1,382 +0,0 @@ -/** - * @file lv_page.h - * - */ - -#ifndef LV_PAGE_H -#define LV_PAGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_PAGE != 0 - -/*Testing of dependencies*/ -#if USE_LV_CONT == 0 -#error "lv_page: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " -#endif - -#include "lv_cont.h" -#include "display/lv_core/lv_indev.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Scrollbar modes: shows when should the scrollbars be visible*/ -enum -{ - LV_SB_MODE_OFF = 0x0, /*Never show scrollbars*/ - LV_SB_MODE_ON = 0x1, /*Always show scrollbars*/ - LV_SB_MODE_DRAG = 0x2, /*Show scrollbars when page is being dragged*/ - LV_SB_MODE_AUTO = 0x3, /*Show scrollbars when the scrollable container is large enough to be scrolled*/ - LV_SB_MODE_HIDE = 0x4, /*Hide the scroll bar temporally*/ - LV_SB_MODE_UNHIDE = 0x5, /*Unhide the previously hidden scrollbar. Recover it's type too*/ -}; -typedef uint8_t lv_sb_mode_t; - -/*Data of page*/ -typedef struct -{ - lv_cont_ext_t bg; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * scrl; /*The scrollable object on the background*/ - lv_action_t rel_action; /*Function to call when the page is released*/ - lv_action_t pr_action; /*Function to call when the page is pressed*/ - struct { - lv_style_t *style; /*Style of scrollbars*/ - lv_area_t hor_area; /*Horizontal scrollbar area relative to the page. (Handled by the library) */ - lv_area_t ver_area; /*Vertical scrollbar area relative to the page (Handled by the library)*/ - uint8_t hor_draw :1; /*1: horizontal scrollbar is visible now (Handled by the library)*/ - uint8_t ver_draw :1; /*1: vertical scrollbar is visible now (Handled by the library)*/ - lv_sb_mode_t mode:3; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/ - } sb; - struct { - uint16_t state; /*Store the current size of the edge flash effect*/ - lv_style_t *style; /*Style of edge flash effect (usually homogeneous circle)*/ - uint8_t enabled :1; /*1: Show a flash animation on the edge*/ - uint8_t top_ip :1; /*Used internally to show that top most position is reached (flash is In Progress)*/ - uint8_t bottom_ip :1; /*Used internally to show that bottom most position is reached (flash is In Progress)*/ - uint8_t right_ip :1; /*Used internally to show that right most position is reached (flash is In Progress)*/ - uint8_t left_ip :1; /*Used internally to show that left most position is reached (flash is In Progress)*/ - }edge_flash; - - uint8_t arrow_scroll :1; /*1: Enable scrolling with LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN*/ - uint8_t scroll_prop :1; /*1: Propagate the scrolling the the parent if the edge is reached*/ - uint8_t scroll_prop_ip :1; /*1: Scroll propagation is in progress (used by the library)*/ -} lv_page_ext_t; - -enum { - LV_PAGE_STYLE_BG, - LV_PAGE_STYLE_SCRL, - LV_PAGE_STYLE_SB, - LV_PAGE_STYLE_EDGE_FLASH, -}; -typedef uint8_t lv_page_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a page objects - * @param par pointer to an object, it will be the parent of the new page - * @param copy pointer to a page object, if not NULL then the new object will be copied from it - * @return pointer to the created page - */ -lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Delete all children of the scrl object, without deleting scrl child. - * @param obj pointer to an object - */ -void lv_page_clean(lv_obj_t *obj); - -/** - * Get the press action of the page - * @param page pointer to a page object - * @return a function to call when the page is pressed - */ -lv_action_t lv_page_get_pr_action(lv_obj_t * page); - -/** - * Get the release action of the page - * @param page pointer to a page object - * @return a function to call when the page is released - */ -lv_action_t lv_page_get_rel_action(lv_obj_t * page); - -/** - * Get the scrollable object of a page - * @param page pointer to a page object - * @return pointer to a container which is the scrollable part of the page - */ -lv_obj_t * lv_page_get_scrl(const lv_obj_t * page); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a release action for the page - * @param page pointer to a page object - * @param rel_action a function to call when the page is released - */ -void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action); - -/** - * Set a press action for the page - * @param page pointer to a page object - * @param pr_action a function to call when the page is pressed - */ -void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action); - -/** - * Set the scroll bar mode on a page - * @param page pointer to a page object - * @param sb_mode the new mode from 'lv_page_sb.mode_t' enum - */ -void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode); - -/** - * Enable/Disable scrolling with arrows if the page is in group (arrows: LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) - * @param page pointer to a page object - * @param en true: enable scrolling with arrows - */ -void lv_page_set_arrow_scroll(lv_obj_t * page, bool en); - -/** - * Enable the scroll propagation feature. If enabled then the page will move its parent if there is no more space to scroll. - * @param page pointer to a Page - * @param en true or false to enable/disable scroll propagation - */ -void lv_page_set_scroll_propagation(lv_obj_t * page, bool en); - -/** - * Enable the edge flash effect. (Show an arc when the an edge is reached) - * @param page pointer to a Page - * @param en true or false to enable/disable end flash - */ -void lv_page_set_edge_flash(lv_obj_t * page, bool en); - -/** - * Set the fit attribute of the scrollable part of a page. - * It means it can set its size automatically to involve all children. - * (Can be set separately horizontally and vertically) - * @param page pointer to a page object - * @param hor_en true: enable horizontal fit - * @param ver_en true: enable vertical fit - */ -static inline void lv_page_set_scrl_fit(lv_obj_t *page, bool hor_en, bool ver_en) -{ - lv_cont_set_fit(lv_page_get_scrl(page), hor_en, ver_en); -} - -/** - * Set width of the scrollable part of a page - * @param page pointer to a page object - * @param w the new width of the scrollable (it ha no effect is horizontal fit is enabled) - */ -static inline void lv_page_set_scrl_width(lv_obj_t *page, lv_coord_t w) -{ - lv_obj_set_width(lv_page_get_scrl(page), w); -} - -/** - * Set height of the scrollable part of a page - * @param page pointer to a page object - * @param h the new height of the scrollable (it ha no effect is vertical fit is enabled) - */ -static inline void lv_page_set_scrl_height(lv_obj_t *page, lv_coord_t h) -{ - lv_obj_set_height(lv_page_get_scrl(page), h); - -} - -/** -* Set the layout of the scrollable part of the page -* @param page pointer to a page object -* @param layout a layout from 'lv_cont_layout_t' -*/ -static inline void lv_page_set_scrl_layout(lv_obj_t * page, lv_layout_t layout) -{ - lv_cont_set_layout(lv_page_get_scrl(page), layout); -} - -/** - * Set a style of a page - * @param page pointer to a page object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_page_set_style(lv_obj_t *page, lv_page_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Set the scroll bar mode on a page - * @param page pointer to a page object - * @return the mode from 'lv_page_sb.mode_t' enum - */ -lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page); - - -/** - * Get the the scrolling with arrows (LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) is enabled or not - * @param page pointer to a page object - * @return true: scrolling with arrows is enabled - */ -bool lv_page_get_arrow_scroll(const lv_obj_t * page); - -/** - * Get the scroll propagation property - * @param page pointer to a Page - * @return true or false - */ -bool lv_page_get_scroll_propagation(lv_obj_t * page); - -/** - * Get the edge flash effect property. - * @param page pointer to a Page - * return true or false - */ -bool lv_page_get_edge_flash(lv_obj_t * page); - -/** - * Get that width which can be set to the children to still not cause overflow (show scrollbars) - * @param page pointer to a page object - * @return the width which still fits into the page - */ -lv_coord_t lv_page_get_fit_width(lv_obj_t * page); - -/** - * Get that height which can be set to the children to still not cause overflow (show scrollbars) - * @param page pointer to a page object - * @return the height which still fits into the page - */ -lv_coord_t lv_page_get_fit_height(lv_obj_t * page); - -/** - * Get width of the scrollable part of a page - * @param page pointer to a page object - * @return the width of the scrollable - */ -static inline lv_coord_t lv_page_get_scrl_width(const lv_obj_t *page) -{ - return lv_obj_get_width(lv_page_get_scrl(page)); -} - -/** - * Get height of the scrollable part of a page - * @param page pointer to a page object - * @return the height of the scrollable - */ -static inline lv_coord_t lv_page_get_scrl_height(const lv_obj_t *page) -{ - return lv_obj_get_height(lv_page_get_scrl(page)); -} - -/** -* Get the layout of the scrollable part of a page -* @param page pointer to page object -* @return the layout from 'lv_cont_layout_t' -*/ -static inline lv_layout_t lv_page_get_scrl_layout(const lv_obj_t * page) -{ - return lv_cont_get_layout(lv_page_get_scrl(page)); -} - -/** -* Get horizontal fit attribute of the scrollable part of a page -* @param page pointer to a page object -* @return true: horizontal fit is enabled; false: disabled -*/ -static inline bool lv_page_get_scrl_hor_fit(const lv_obj_t * page) -{ - return lv_cont_get_hor_fit(lv_page_get_scrl(page)); -} - -/** -* Get vertical fit attribute of the scrollable part of a page -* @param page pointer to a page object -* @return true: vertical fit is enabled; false: disabled -*/ -static inline bool lv_page_get_scrl_fit_ver(const lv_obj_t * page) -{ - return lv_cont_get_ver_fit(lv_page_get_scrl(page)); -} - -/** - * Get a style of a page - * @param page pointer to page object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_page_get_style(const lv_obj_t *page, lv_page_style_t type); - -/*===================== - * Other functions - *====================*/ - -/** - * Glue the object to the page. After it the page can be moved (dragged) with this object too. - * @param obj pointer to an object on a page - * @param glue true: enable glue, false: disable glue - */ -void lv_page_glue_obj(lv_obj_t * obj, bool glue); - -/** - * Focus on an object. It ensures that the object will be visible on the page. - * @param page pointer to a page object - * @param obj pointer to an object to focus (must be on the page) - * @param anim_time scroll animation time in milliseconds (0: no animation) - */ -void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time); - -/** - * Scroll the page horizontally - * @param page pointer to a page object - * @param dist the distance to scroll (< 0: scroll left; > 0 scroll right) - */ -void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist); - -/** - * Scroll the page vertically - * @param page pointer to a page object - * @param dist the distance to scroll (< 0: scroll down; > 0 scroll up) - */ -void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist); - -/** - * Not intended to use directly by the user but by other object types internally. - * Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set - * @param page - */ -void lv_page_start_edge_flash(lv_obj_t * page); -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_PAGE*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_PAGE_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_preload.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_preload.h deleted file mode 100644 index 7e228906..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_preload.h +++ /dev/null @@ -1,168 +0,0 @@ -/** - * @file lv_preload.h - * - */ - -#ifndef LV_PRELOAD_H -#define LV_PRELOAD_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_PRELOAD != 0 - -/*Testing of dependencies*/ -#if USE_LV_ARC == 0 -#error "lv_preload: lv_arc is required. Enable it in lv_conf.h (USE_LV_ARC 1) " -#endif - -#if USE_LV_ANIMATION == 0 -#error "lv_preload: animations are required. Enable it in lv_conf.h (USE_LV_ANIMATION 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_arc.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -enum { - LV_PRELOAD_TYPE_SPINNING_ARC, - LV_PRELOAD_TYPE_FILLSPIN_ARC, -}; -typedef uint8_t lv_preloader_type_t; - -/*Data of pre loader*/ -typedef struct { - lv_arc_ext_t arc; /*Ext. of ancestor*/ - /*New data for this type */ - uint16_t arc_length; /*Length of the spinning indicator in degree*/ - uint16_t time; /*Time of one round*/ - lv_preloader_type_t anim_type; /*Type of the arc animation*/ -} lv_preload_ext_t; - - -/*Styles*/ -enum { - LV_PRELOAD_STYLE_MAIN, -}; -typedef uint8_t lv_preload_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a pre loader objects - * @param par pointer to an object, it will be the parent of the new pre loader - * @param copy pointer to a pre loader object, if not NULL then the new object will be copied from it - * @return pointer to the created pre loader - */ -lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Set the length of the spinning arc in degrees - * @param preload pointer to a preload object - * @param deg length of the arc - */ -void lv_preload_set_arc_length(lv_obj_t * preload, uint16_t deg); - -/** - * Set the spin time of the arc - * @param preload pointer to a preload object - * @param time time of one round in milliseconds - */ -void lv_preload_set_spin_time(lv_obj_t * preload, uint16_t time); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a style of a pre loader. - * @param preload pointer to pre loader object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_preload_set_style(lv_obj_t * preload, lv_preload_style_t type, lv_style_t *style); - -/** - * Set the animation type of a preloadeer. - * @param preload pointer to pre loader object - * @param type animation type of the preload - * */ -void lv_preload_set_animation_type(lv_obj_t * preload, lv_preloader_type_t type); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the arc length [degree] of the a pre loader - * @param preload pointer to a pre loader object - */ -uint16_t lv_preload_get_arc_length(const lv_obj_t * preload); - -/** - * Get the spin time of the arc - * @param preload pointer to a pre loader object [milliseconds] - */ -uint16_t lv_preload_get_spin_time(const lv_obj_t * preload); - -/** - * Get style of a pre loader. - * @param preload pointer to pre loader object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_preload_get_style(const lv_obj_t * preload, lv_preload_style_t type); - -/** - * Get the animation type of a preloadeer. - * @param preload pointer to pre loader object - * @return animation type - * */ -lv_preloader_type_t lv_preload_get_animation_type(lv_obj_t * preload); - -/*===================== - * Other functions - *====================*/ - -/** - * Get style of a pre loader. - * @param preload pointer to pre loader object - * @param type which style should be get - * @return style pointer to the style - * */ -void lv_preload_spinner_animation(void * ptr, int32_t val); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_PRELOAD*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_PRELOAD_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_roller.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_roller.h deleted file mode 100644 index 232f5526..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_roller.h +++ /dev/null @@ -1,224 +0,0 @@ -/** - * @file lv_roller.h - * - */ - -#ifndef LV_ROLLER_H -#define LV_ROLLER_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_ROLLER != 0 - -/*Testing of dependencies*/ -#if USE_LV_DDLIST == 0 -#error "lv_roller: lv_ddlist is required. Enable it in lv_conf.h (USE_LV_DDLIST 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_ddlist.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of roller*/ -typedef struct { - lv_ddlist_ext_t ddlist; /*Ext. of ancestor*/ - /*New data for this type */ -} lv_roller_ext_t; - -enum { - LV_ROLLER_STYLE_BG, - LV_ROLLER_STYLE_SEL, -}; -typedef uint8_t lv_roller_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a roller object - * @param par pointer to an object, it will be the parent of the new roller - * @param copy pointer to a roller object, if not NULL then the new object will be copied from it - * @return pointer to the created roller - */ -lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the align of the roller's options (left, right or center[default]) - * @param roller - pointer to a roller object - * @param align - one of lv_label_align_t values (left, right, center) - */ -void lv_roller_set_align(lv_obj_t * roller, lv_label_align_t align); - -/** - * Set the options on a roller - * @param roller pointer to roller object - * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" - */ -static inline void lv_roller_set_options(lv_obj_t * roller, const char * options) -{ - lv_ddlist_set_options(roller, options); -} - -/** - * Set the selected option - * @param roller pointer to a roller object - * @param sel_opt id of the selected option (0 ... number of option - 1); - * @param anim_en true: set with animation; false set immediately - */ -void lv_roller_set_selected(lv_obj_t *roller, uint16_t sel_opt, bool anim_en); - -/** - * Set a function to call when a new option is chosen - * @param roller pointer to a roller - * @param action pointer to a callback function - */ -static inline void lv_roller_set_action(lv_obj_t * roller, lv_action_t action) -{ - lv_ddlist_set_action(roller, action); -} - -/** - * Set the height to show the given number of rows (options) - * @param roller pointer to a roller object - * @param row_cnt number of desired visible rows - */ -void lv_roller_set_visible_row_count(lv_obj_t *roller, uint8_t row_cnt); - -/** - * Enable or disable the horizontal fit to the content - * @param roller pointer to a roller - * @param en true: enable auto fit; false: disable auto fit - */ -static inline void lv_roller_set_hor_fit(lv_obj_t * roller, bool en) -{ - lv_ddlist_set_hor_fit(roller, en); -} - -/** - * Set the open/close animation time. - * @param roller pointer to a roller object - * @param anim_time: open/close animation time [ms] - */ -static inline void lv_roller_set_anim_time(lv_obj_t *roller, uint16_t anim_time) -{ - lv_ddlist_set_anim_time(roller, anim_time); -} - -/** - * Set a style of a roller - * @param roller pointer to a roller object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_roller_set_style(lv_obj_t *roller, lv_roller_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER - * @param roller pointer to a roller object - * @return LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER - */ -lv_label_align_t lv_roller_get_align(const lv_obj_t * roller); - -/** - * Get the options of a roller - * @param roller pointer to roller object - * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") - */ -static inline const char * lv_roller_get_options(const lv_obj_t *roller) -{ - return lv_ddlist_get_options(roller); -} - -/** - * Get the id of the selected option - * @param roller pointer to a roller object - * @return id of the selected option (0 ... number of option - 1); - */ -static inline uint16_t lv_roller_get_selected(const lv_obj_t *roller) -{ - return lv_ddlist_get_selected(roller); -} - -/** - * Get the current selected option as a string - * @param roller pointer to roller object - * @param buf pointer to an array to store the string - */ -static inline void lv_roller_get_selected_str(const lv_obj_t * roller, char * buf) -{ - lv_ddlist_get_selected_str(roller, buf); -} - -/** - * Get the "option selected" callback function - * @param roller pointer to a roller - * @return pointer to the call back function - */ -static inline lv_action_t lv_roller_get_action(const lv_obj_t * roller) -{ - return lv_ddlist_get_action(roller); -} - -/** - * Get the open/close animation time. - * @param roller pointer to a roller - * @return open/close animation time [ms] - */ -static inline uint16_t lv_roller_get_anim_time(const lv_obj_t * roller) -{ - return lv_ddlist_get_anim_time(roller); -} - -/** - * Get the auto width set attribute - * @param roller pointer to a roller object - * @return true: auto size enabled; false: manual width settings enabled - */ -bool lv_roller_get_hor_fit(const lv_obj_t *roller); - -/** - * Get a style of a roller - * @param roller pointer to a roller object - * @param type which style should be get - * @return style pointer to a style - * */ -lv_style_t * lv_roller_get_style(const lv_obj_t *roller, lv_roller_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_ROLLER*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_ROLLER_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_slider.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_slider.h deleted file mode 100644 index 8d0d9d66..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_slider.h +++ /dev/null @@ -1,202 +0,0 @@ -/** - * @file lv_slider.h - * - */ - -#ifndef LV_SLIDER_H -#define LV_SLIDER_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_SLIDER != 0 - -/*Testing of dependencies*/ -#if USE_LV_BAR == 0 -#error "lv_slider: lv_bar is required. Enable it in lv_conf.h (USE_LV_BAR 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_bar.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of slider*/ -typedef struct -{ - lv_bar_ext_t bar; /*Ext. of ancestor*/ - /*New data for this type */ - lv_action_t action; /*Function to call when a new value is set*/ - lv_style_t *style_knob; /*Style of the knob*/ - int16_t drag_value; /*Store a temporal value during press until release (Handled by the library)*/ - uint8_t knob_in :1; /*1: Draw the knob inside the bar*/ -} lv_slider_ext_t; - -/*Built-in styles of slider*/ -enum -{ - LV_SLIDER_STYLE_BG, - LV_SLIDER_STYLE_INDIC, - LV_SLIDER_STYLE_KNOB, -}; -typedef uint8_t lv_slider_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a slider objects - * @param par pointer to an object, it will be the parent of the new slider - * @param copy pointer to a slider object, if not NULL then the new object will be copied from it - * @return pointer to the created slider - */ -lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new value on the slider - * @param slider pointer to a slider object - * @param value new value - */ -static inline void lv_slider_set_value(lv_obj_t * slider, int16_t value) -{ - lv_bar_set_value(slider, value); -} - -/** - * Set a new value with animation on a slider - * @param slider pointer to a slider object - * @param value new value - * @param anim_time animation time in milliseconds - */ -static inline void lv_slider_set_value_anim(lv_obj_t * slider, int16_t value, uint16_t anim_time) -{ - lv_bar_set_value_anim(slider, value, anim_time); -} - -/** - * Set minimum and the maximum values of a bar - * @param slider pointer to the slider object - * @param min minimum value - * @param max maximum value - */ -static inline void lv_slider_set_range(lv_obj_t *slider, int16_t min, int16_t max) -{ - lv_bar_set_range(slider, min, max); -} - -/** - * Set a function which will be called when a new value is set on the slider - * @param slider pointer to slider object - * @param action a callback function - */ -void lv_slider_set_action(lv_obj_t * slider, lv_action_t action); - -/** - * Set the 'knob in' attribute of a slider - * @param slider pointer to slider object - * @param in true: the knob is drawn always in the slider; - * false: the knob can be out on the edges - */ -void lv_slider_set_knob_in(lv_obj_t * slider, bool in); - -/** - * Set a style of a slider - * @param slider pointer to a slider object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_slider_set_style(lv_obj_t *slider, lv_slider_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a slider - * @param slider pointer to a slider object - * @return the value of the slider - */ -int16_t lv_slider_get_value(const lv_obj_t * slider); - -/** - * Get the minimum value of a slider - * @param slider pointer to a slider object - * @return the minimum value of the slider - */ -static inline int16_t lv_slider_get_min_value(const lv_obj_t * slider) -{ - return lv_bar_get_min_value(slider); -} - -/** - * Get the maximum value of a slider - * @param slider pointer to a slider object - * @return the maximum value of the slider - */ -static inline int16_t lv_slider_get_max_value(const lv_obj_t * slider) -{ - return lv_bar_get_max_value(slider); -} - -/** - * Get the slider action function - * @param slider pointer to slider object - * @return the callback function - */ -lv_action_t lv_slider_get_action(const lv_obj_t * slider); - -/** - * Give the slider is being dragged or not - * @param slider pointer to a slider object - * @return true: drag in progress false: not dragged - */ -bool lv_slider_is_dragged(const lv_obj_t * slider); - -/** - * Get the 'knob in' attribute of a slider - * @param slider pointer to slider object - * @return true: the knob is drawn always in the slider; - * false: the knob can be out on the edges - */ -bool lv_slider_get_knob_in(const lv_obj_t * slider); - - -/** - * Get a style of a slider - * @param slider pointer to a slider object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_slider_get_style(const lv_obj_t *slider, lv_slider_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_SLIDER*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_SLIDER_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_spinbox.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_spinbox.h deleted file mode 100644 index 6ec1e667..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_spinbox.h +++ /dev/null @@ -1,201 +0,0 @@ -/** - * @file lv_spinbox.h - * - */ - - -#ifndef LV_SPINBOX_H -#define LV_SPINBOX_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_SPINBOX != 0 - -/*Testing of dependencies*/ -#if USE_LV_TA == 0 -#error "lv_spinbox: lv_ta is required. Enable it in lv_conf.h (USE_LV_TA 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "display/lv_objx/lv_ta.h" - -/********************* - * DEFINES - *********************/ -#define LV_SPINBOX_MAX_DIGIT_COUNT 16 - -/********************** - * TYPEDEFS - **********************/ - -/*callback on value change*/ -typedef void (*lv_spinbox_value_changed_cb_t)(lv_obj_t * spinbox, int32_t new_value); - -/*Data of spinbox*/ -typedef struct { - lv_ta_ext_t ta; /*Ext. of ancestor*/ - /*New data for this type */ - int32_t value; - int32_t range_max; - int32_t range_min; - int32_t step; - uint16_t digit_count:4; - uint16_t dec_point_pos:4; /*if 0, there is no separator and the number is an integer*/ - uint16_t digit_padding_left:4; - lv_spinbox_value_changed_cb_t value_changed_cb; -} lv_spinbox_ext_t; - - -/*Styles*/ -enum { - LV_SPINBOX_STYLE_BG, - LV_SPINBOX_STYLE_SB, - LV_SPINBOX_STYLE_CURSOR, -}; -typedef uint8_t lv_spinbox_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a spinbox objects - * @param par pointer to an object, it will be the parent of the new spinbox - * @param copy pointer to a spinbox object, if not NULL then the new object will be copied from it - * @return pointer to the created spinbox - */ -lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a style of a spinbox. - * @param templ pointer to template object - * @param type which style should be set - * @param style pointer to a style - */ -static inline void lv_spinbox_set_style(lv_obj_t * spinbox, lv_spinbox_style_t type, lv_style_t *style) -{ - lv_ta_set_style(spinbox, type, style); -} - -/** - * Set spinbox value - * @param spinbox pointer to spinbox - * @param i value to be set - */ -void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i); - -/** - * Set spinbox digit format (digit count and decimal format) - * @param spinbox pointer to spinbox - * @param digit_count number of digit excluding the decimal separator and the sign - * @param separator_position number of digit before the decimal point. If 0, decimal point is not shown - */ -void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position); - -/** - * Set spinbox step - * @param spinbox pointer to spinbox - * @param step steps on increment/decrement - */ -void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step); - -/** - * Set spinbox value range - * @param spinbox pointer to spinbox - * @param range_min maximum value, inclusive - * @param range_max minimum value, inclusive - */ -void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max); - -/** - * Set spinbox callback on calue change - * @param spinbox pointer to spinbox - * @param cb Callback function called on value change event - */ -void lv_spinbox_set_value_changed_cb(lv_obj_t * spinbox, lv_spinbox_value_changed_cb_t cb); - -/** - * Set spinbox left padding in digits count (added between sign and first digit) - * @param spinbox pointer to spinbox - * @param cb Callback function called on value change event - */ -void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get style of a spinbox. - * @param templ pointer to template object - * @param type which style should be get - * @return style pointer to the style - */ -static inline lv_style_t * lv_spinbox_get_style(lv_obj_t * spinbox, lv_spinbox_style_t type) -{ - return lv_ta_get_style(spinbox, type); -} - -/** - * Get the spinbox numeral value (user has to convert to float according to its digit format) - * @param spinbox pointer to spinbox - * @return value integer value of the spinbox - */ -int32_t lv_spinbox_get_value(lv_obj_t * spinbox); - -/*===================== - * Other functions - *====================*/ - -/** - * Select next lower digit for edition by dividing the step by 10 - * @param spinbox pointer to spinbox - */ -void lv_spinbox_step_next(lv_obj_t * spinbox); - -/** - * Select next higher digit for edition by multiplying the step by 10 - * @param spinbox pointer to spinbox - */ -void lv_spinbox_step_previous(lv_obj_t * spinbox); - -/** - * Increment spinbox value by one step - * @param spinbox pointer to spinbox - */ -void lv_spinbox_increment(lv_obj_t * spinbox); - -/** - * Decrement spinbox value by one step - * @param spinbox pointer to spinbox - */ -void lv_spinbox_decrement(lv_obj_t * spinbox); - - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_SPINBOX*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_SPINBOX_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_sw.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_sw.h deleted file mode 100644 index 7f4513c8..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_sw.h +++ /dev/null @@ -1,194 +0,0 @@ -/** - * @file lv_sw.h - * - */ - -#ifndef LV_SW_H -#define LV_SW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_SW != 0 - -/*Testing of dependencies*/ -#if USE_LV_SLIDER == 0 -#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1)" -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_slider.h" - -/********************* - * DEFINES - *********************/ -#define LV_SWITCH_SLIDER_ANIM_MAX 1000 - -/********************** - * TYPEDEFS - **********************/ -/*Data of switch*/ -typedef struct -{ - lv_slider_ext_t slider; /*Ext. of ancestor*/ - /*New data for this type */ - lv_style_t *style_knob_off; /*Style of the knob when the switch is OFF*/ - lv_style_t *style_knob_on; /*Style of the knob when the switch is ON (NULL to use the same as OFF)*/ - lv_coord_t start_x; - uint8_t changed :1; /*Indicates the switch state explicitly changed by drag*/ - uint8_t slided :1; -#if USE_LV_ANIMATION - uint16_t anim_time; /*switch animation time */ -#endif -} lv_sw_ext_t; - -enum { - LV_SW_STYLE_BG, - LV_SW_STYLE_INDIC, - LV_SW_STYLE_KNOB_OFF, - LV_SW_STYLE_KNOB_ON, -}; -typedef uint8_t lv_sw_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a switch objects - * @param par pointer to an object, it will be the parent of the new switch - * @param copy pointer to a switch object, if not NULL then the new object will be copied from it - * @return pointer to the created switch - */ -lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Turn ON the switch - * @param sw pointer to a switch object - */ -void lv_sw_on(lv_obj_t *sw); - -/** - * Turn OFF the switch - * @param sw pointer to a switch object - */ -void lv_sw_off(lv_obj_t *sw); - -/** - * Toggle the position of the switch - * @param sw pointer to a switch object - * @return resulting state of the switch. - */ -bool lv_sw_toggle(lv_obj_t *sw); - -/** - * Turn ON the switch with an animation - * @param sw pointer to a switch object - */ -void lv_sw_on_anim(lv_obj_t * sw); - -/** - * Turn OFF the switch with an animation - * @param sw pointer to a switch object - */ -void lv_sw_off_anim(lv_obj_t * sw); - -/** - * Toggle the position of the switch with an animation - * @param sw pointer to a switch object - * @return resulting state of the switch. - */ -bool lv_sw_toggle_anim(lv_obj_t *sw); - -/** - * Set a function which will be called when the switch is toggled by the user - * @param sw pointer to switch object - * @param action a callback function - */ -static inline void lv_sw_set_action(lv_obj_t * sw, lv_action_t action) -{ - lv_slider_set_action(sw, action); -} - -/** - * Set a style of a switch - * @param sw pointer to a switch object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style); - -#if USE_LV_ANIMATION -/** - * Set the animation time of the switch - * @param sw pointer to a switch object - * @param anim_time animation time - * @return style pointer to a style - */ -void lv_sw_set_anim_time(lv_obj_t *sw, uint16_t anim_time); -#endif - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the state of a switch - * @param sw pointer to a switch object - * @return false: OFF; true: ON - */ -static inline bool lv_sw_get_state(const lv_obj_t *sw) -{ - return lv_bar_get_value(sw) < LV_SWITCH_SLIDER_ANIM_MAX / 2 ? false : true; -} - -/** - * Get the switch action function - * @param slider pointer to a switch object - * @return the callback function - */ -static inline lv_action_t lv_sw_get_action(const lv_obj_t * slider) -{ - return lv_slider_get_action(slider); -} - -/** - * Get a style of a switch - * @param sw pointer to a switch object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_sw_get_style(const lv_obj_t *sw, lv_sw_style_t type); - -/** - * Get the animation time of the switch - * @param sw pointer to a switch object - * @return style pointer to a style - */ -uint16_t lv_sw_get_anim_time(const lv_obj_t *sw); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_SW*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_SW_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_ta.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_ta.h deleted file mode 100644 index 8e12314a..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_ta.h +++ /dev/null @@ -1,390 +0,0 @@ -/** - * @file lv_ta.h - * - */ - -#ifndef LV_TA_H -#define LV_TA_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TA != 0 - -/*Testing of dependencies*/ -#if USE_LV_PAGE == 0 -#error "lv_ta: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_ta: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_page.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ -#define LV_TA_CURSOR_LAST (0x7FFF) /*Put the cursor after the last character*/ - -/********************** - * TYPEDEFS - **********************/ - -enum { - LV_CURSOR_NONE, - LV_CURSOR_LINE, - LV_CURSOR_BLOCK, - LV_CURSOR_OUTLINE, - LV_CURSOR_UNDERLINE, - LV_CURSOR_HIDDEN = 0x08, /*Or it to any value to hide the cursor temporally*/ -}; -typedef uint8_t lv_cursor_type_t; - -/*Data of text area*/ -typedef struct -{ - lv_page_ext_t page; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * label; /*Label of the text area*/ - char * pwd_tmp; /*Used to store the original text in password mode*/ - const char * accapted_chars;/*Only these characters will be accepted. NULL: accept all*/ - uint16_t max_length; /*The max. number of characters. 0: no limit*/ - uint8_t pwd_mode :1; /*Replace characters with '*' */ - uint8_t one_line :1; /*One line mode (ignore line breaks)*/ - struct { - lv_style_t *style; /*Style of the cursor (NULL to use label's style)*/ - lv_coord_t valid_x; /*Used when stepping up/down in text area when stepping to a shorter line. (Handled by the library)*/ - uint16_t pos; /*The current cursor position (0: before 1. letter; 1: before 2. letter etc.)*/ - lv_area_t area; /*Cursor area relative to the Text Area*/ - uint16_t txt_byte_pos; /*Byte index of the letter after (on) the cursor*/ - lv_cursor_type_t type:4; /*Shape of the cursor*/ - uint8_t state :1; /*Indicates that the cursor is visible now or not (Handled by the library)*/ - } cursor; -} lv_ta_ext_t; - -enum { - LV_TA_STYLE_BG, - LV_TA_STYLE_SB, - LV_TA_STYLE_EDGE_FLASH, - LV_TA_STYLE_CURSOR, -}; -typedef uint8_t lv_ta_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Create a text area objects - * @param par pointer to an object, it will be the parent of the new text area - * @param copy pointer to a text area object, if not NULL then the new object will be copied from it - * @return pointer to the created text area - */ -lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy); - - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Insert a character to the current cursor position. - * To add a wide char, e.g. 'Á' use `lv_txt_encoded_conv_wc('Á')` - * @param ta pointer to a text area object - * @param c a character (e.g. 'a') - */ -void lv_ta_add_char(lv_obj_t * ta, uint32_t c); - -/** - * Insert a text to the current cursor position - * @param ta pointer to a text area object - * @param txt a '\0' terminated string to insert - */ -void lv_ta_add_text(lv_obj_t * ta, const char * txt); - -/** - * Delete a the left character from the current cursor position - * @param ta pointer to a text area object - */ -void lv_ta_del_char(lv_obj_t * ta); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the text of a text area - * @param ta pointer to a text area - * @param txt pointer to the text - */ -void lv_ta_set_text(lv_obj_t * ta, const char * txt); - -/** - * Set the cursor position - * @param obj pointer to a text area object - * @param pos the new cursor position in character index - * < 0 : index from the end of the text - * LV_TA_CURSOR_LAST: go after the last character - */ -void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos); - -/** - * Set the cursor type. - * @param ta pointer to a text area object - * @param cur_type: element of 'lv_cursor_type_t' - */ -void lv_ta_set_cursor_type(lv_obj_t * ta, lv_cursor_type_t cur_type); - -/** - * Enable/Disable password mode - * @param ta pointer to a text area object - * @param en true: enable, false: disable - */ -void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en); - -/** - * Configure the text area to one line or back to normal - * @param ta pointer to a Text area object - * @param en true: one line, false: normal - */ -void lv_ta_set_one_line(lv_obj_t * ta, bool en); - -/** - * Set the alignment of the text area. - * In one line mode the text can be scrolled only with `LV_LABEL_ALIGN_LEFT`. - * This function should be called if the size of text area changes. - * @param ta pointer to a text are object - * @param align the desired alignment from `lv_label_align_t`. (LV_LABEL_ALIGN_LEFT/CENTER/RIGHT) - */ -void lv_ta_set_text_align(lv_obj_t * ta, lv_label_align_t align); - -/** - * Set a list of characters. Only these characters will be accepted by the text area - * @param ta pointer to Text Area - * @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789" - */ -void lv_ta_set_accepted_chars(lv_obj_t * ta, const char * list); - -/** - * Set max length of a Text Area. - * @param ta pointer to Text Area - * @param num the maximal number of characters can be added (`lv_ta_set_text` ignores it) - */ -void lv_ta_set_max_length(lv_obj_t * ta, uint16_t num); - -/** - * Set an action to call when the Text area is clicked - * @param ta pointer to a Text area - * @param action a function pointer - */ -static inline void lv_ta_set_action(lv_obj_t * ta, lv_action_t action) -{ - lv_page_set_rel_action(ta, action); -} - -/** - * Set the scroll bar mode of a text area - * @param ta pointer to a text area object - * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum - */ -static inline void lv_ta_set_sb_mode(lv_obj_t * ta, lv_sb_mode_t mode) -{ - lv_page_set_sb_mode(ta, mode); -} - -/** - * Enable the scroll propagation feature. If enabled then the Text area will move its parent if there is no more space to scroll. - * @param ta pointer to a Text area - * @param en true or false to enable/disable scroll propagation - */ -static inline void lv_ta_set_scroll_propagation(lv_obj_t * ta, bool en) -{ - lv_page_set_scroll_propagation(ta, en); -} - -/** - * Enable the edge flash effect. (Show an arc when the an edge is reached) - * @param page pointer to a Text Area - * @param en true or false to enable/disable end flash - */ -static inline void lv_ta_set_edge_flash(lv_obj_t * ta, bool en) -{ - lv_page_set_edge_flash(ta, en); -} - -/** - * Set a style of a text area - * @param ta pointer to a text area object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_ta_set_style(lv_obj_t *ta, lv_ta_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the text of a text area. In password mode it gives the real text (not '*'s). - * @param ta pointer to a text area object - * @return pointer to the text - */ -const char * lv_ta_get_text(const lv_obj_t * ta); - -/** - * Get the label of a text area - * @param ta pointer to a text area object - * @return pointer to the label object - */ -lv_obj_t * lv_ta_get_label(const lv_obj_t * ta); - -/** - * Get the current cursor position in character index - * @param ta pointer to a text area object - * @return the cursor position - */ -uint16_t lv_ta_get_cursor_pos(const lv_obj_t * ta); - -/** - * Get the current cursor visibility. - * @param ta pointer to a text area object - * @return true: the cursor is drawn, false: the cursor is hidden - */ -//bool lv_ta_get_cursor_show(const lv_obj_t * ta); - -/** - * Get the current cursor type. - * @param ta pointer to a text area object - * @return element of 'lv_cursor_type_t' - */ -lv_cursor_type_t lv_ta_get_cursor_type(const lv_obj_t * ta); - -/** - * Get the password mode attribute - * @param ta pointer to a text area object - * @return true: password mode is enabled, false: disabled - */ -bool lv_ta_get_pwd_mode(const lv_obj_t * ta); - -/** - * Get the one line configuration attribute - * @param ta pointer to a text area object - * @return true: one line configuration is enabled, false: disabled - */ -bool lv_ta_get_one_line(const lv_obj_t * ta); - -/** - * Get a list of accepted characters. - * @param ta pointer to Text Area - * @return list of accented characters. - */ -const char * lv_ta_get_accepted_chars(lv_obj_t * ta); - -/** - * Set max length of a Text Area. - * @param ta pointer to Text Area - * @return the maximal number of characters to be add - */ -uint16_t lv_ta_get_max_length(lv_obj_t * ta); - -/** - * Set an action to call when the Text area is clicked - * @param ta pointer to a Text area - * @param action a function pointer - */ -static inline lv_action_t lv_ta_get_action(lv_obj_t * ta) -{ - return lv_page_get_rel_action(ta); -} - -/** - * Get the scroll bar mode of a text area - * @param ta pointer to a text area object - * @return scrollbar mode from 'lv_page_sb_mode_t' enum - */ -static inline lv_sb_mode_t lv_ta_get_sb_mode(const lv_obj_t * ta) -{ - return lv_page_get_sb_mode(ta); -} - -/** - * Get the scroll propagation property - * @param ta pointer to a Text area - * @return true or false - */ -static inline bool lv_ta_get_scroll_propagation(lv_obj_t * ta) -{ - return lv_page_get_scroll_propagation(ta); -} - -/** - * Get the scroll propagation property - * @param ta pointer to a Text area - * @return true or false - */ -static inline bool lv_ta_get_edge_flash(lv_obj_t * ta) -{ - return lv_page_get_edge_flash(ta); -} - -/** - * Get a style of a text area - * @param ta pointer to a text area object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_ta_get_style(const lv_obj_t *ta, lv_ta_style_t type); - -/*===================== - * Other functions - *====================*/ - -/** - * Move the cursor one character right - * @param ta pointer to a text area object - */ -void lv_ta_cursor_right(lv_obj_t * ta); - -/** - * Move the cursor one character left - * @param ta pointer to a text area object - */ -void lv_ta_cursor_left(lv_obj_t * ta); - -/** - * Move the cursor one line down - * @param ta pointer to a text area object - */ -void lv_ta_cursor_down(lv_obj_t * ta); - -/** - * Move the cursor one line up - * @param ta pointer to a text area object - */ -void lv_ta_cursor_up(lv_obj_t * ta); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TA_H*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TA_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_table.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_table.h deleted file mode 100644 index 79ba22dc..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_table.h +++ /dev/null @@ -1,261 +0,0 @@ -/** - * @file lv_table.h - * - */ - -#ifndef LV_TABLE_H -#define LV_TABLE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TABLE != 0 - -/*Testing of dependencies*/ -#if USE_LV_LABEL == 0 -#error "lv_table: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ -#ifndef LV_TABLE_COL_MAX -#define LV_TABLE_COL_MAX 12 -#endif - -#define LV_TABLE_CELL_STYLE_CNT 4 -/********************** - * TYPEDEFS - **********************/ - -typedef union { - struct { - uint8_t align:2; - uint8_t right_merge:1; - uint8_t type:2; - uint8_t crop:1; - }; - uint8_t format_byte; -}lv_table_cell_format_t; - -/*Data of table*/ -typedef struct { - /*New data for this type */ - uint16_t col_cnt; - uint16_t row_cnt; - char ** cell_data; - lv_style_t * cell_style[LV_TABLE_CELL_STYLE_CNT]; - lv_coord_t col_w[LV_TABLE_COL_MAX]; -} lv_table_ext_t; - - -/*Styles*/ -enum { - LV_TABLE_STYLE_BG, - LV_TABLE_STYLE_CELL1, - LV_TABLE_STYLE_CELL2, - LV_TABLE_STYLE_CELL3, - LV_TABLE_STYLE_CELL4, -}; -typedef uint8_t lv_table_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a table object - * @param par pointer to an object, it will be the parent of the new table - * @param copy pointer to a table object, if not NULL then the new object will be copied from it - * @return pointer to the created table - */ -lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the value of a cell. - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param txt text to display in the cell. It will be copied and saved so this variable is not required after this function call. - */ -void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const char * txt); - -/** - * Set the number of rows - * @param table table pointer to a Table object - * @param row_cnt number of rows - */ -void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt); - -/** - * Set the number of columns - * @param table table pointer to a Table object - * @param col_cnt number of columns. Must be < LV_TABLE_COL_MAX - */ -void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt); - -/** - * Set the width of a column - * @param table table pointer to a Table object - * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] - * @param w width of the column - */ -void lv_table_set_col_width(lv_obj_t * table, uint16_t col_id, lv_coord_t w); - -/** - * Set the text align in a cell - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param align LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT - */ -void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_label_align_t align); - -/** - * Set the type of a cell. - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param type 1,2,3 or 4. The cell style will be chosen accordingly. - */ -void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_t type); - -/** - * Set the cell crop. (Don't adjust the height of the cell according to its content) - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param crop true: crop the cell content; false: set the cell height to the content. - */ -void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool crop); - -/** - * Merge a cell with the right neighbor. The value of the cell to the right won't be displayed. - * @param table table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param en true: merge right; false: don't merge right - */ -void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col, bool en); - -/** - * Set a style of a table. - * @param table pointer to table object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_table_set_style(lv_obj_t * table, lv_table_style_t type, lv_style_t * style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a cell. - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return text in the cell - */ -const char * lv_table_get_cell_value(lv_obj_t * table, uint16_t row, uint16_t col); - -/** - * Get the number of rows. - * @param table table pointer to a Table object - * @return number of rows. - */ -uint16_t lv_table_get_row_cnt(lv_obj_t * table); - -/** - * Get the number of columns. - * @param table table pointer to a Table object - * @return number of columns. - */ -uint16_t lv_table_get_col_cnt(lv_obj_t * table); - -/** - * Get the width of a column - * @param table table pointer to a Table object - * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] - * @return width of the column - */ -lv_coord_t lv_table_get_col_width(lv_obj_t * table, uint16_t col_id); - -/** - * Get the text align of a cell - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return LV_LABEL_ALIGN_LEFT (default in case of error) or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT - */ -lv_label_align_t lv_table_get_cell_align(lv_obj_t * table, uint16_t row, uint16_t col); - -/** - * Get the type of a cell - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return 1,2,3 or 4 - */ -lv_label_align_t lv_table_get_cell_type(lv_obj_t * table, uint16_t row, uint16_t col); - - -/** - * Get the crop property of a cell - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return true: text crop enabled; false: disabled - */ -lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col); - -/** - * Get the cell merge attribute. - * @param table table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return true: merge right; false: don't merge right - */ -bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col); - -/** - * Get style of a table. - * @param table pointer to table object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_table_get_style(const lv_obj_t * table, lv_table_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TABLE*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TABLE_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_tabview.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_tabview.h deleted file mode 100644 index 73d8b17c..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_tabview.h +++ /dev/null @@ -1,252 +0,0 @@ -/** - * @file lv_tabview.h - * - */ - -#ifndef LV_TABVIEW_H -#define LV_TABVIEW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TABVIEW != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTNM == 0 -#error "lv_tabview: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " -#endif - -#if USE_LV_PAGE == 0 -#error "lv_tabview: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "display/lv_objx/lv_win.h" -#include "display/lv_objx/lv_page.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/* parametes: pointer to a tabview object, tab_id - * return: LV_RES_INV: to prevent the loading of the tab; LV_RES_OK: if everything is fine*/ -typedef lv_res_t (*lv_tabview_action_t)(lv_obj_t *, uint16_t); - - -enum { - LV_TABVIEW_BTNS_POS_TOP, - LV_TABVIEW_BTNS_POS_BOTTOM, -}; -typedef uint8_t lv_tabview_btns_pos_t; - -/*Data of tab*/ -typedef struct -{ - /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * btns; - lv_obj_t * indic; - lv_obj_t * content; /*A rectangle to show the current tab*/ - const char ** tab_name_ptr; - lv_point_t point_last; - uint16_t tab_cur; - uint16_t tab_cnt; - uint16_t anim_time; - uint8_t slide_enable :1; /*1: enable horizontal sliding by touch pad*/ - uint8_t draging :1; - uint8_t drag_hor :1; - uint8_t btns_hide :1; - lv_tabview_btns_pos_t btns_pos :1; - lv_tabview_action_t tab_load_action; -} lv_tabview_ext_t; - -enum { - LV_TABVIEW_STYLE_BG, - LV_TABVIEW_STYLE_INDIC, - LV_TABVIEW_STYLE_BTN_BG, - LV_TABVIEW_STYLE_BTN_REL, - LV_TABVIEW_STYLE_BTN_PR, - LV_TABVIEW_STYLE_BTN_TGL_REL, - LV_TABVIEW_STYLE_BTN_TGL_PR, -}; -typedef uint8_t lv_tabview_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Create a Tab view object - * @param par pointer to an object, it will be the parent of the new tab - * @param copy pointer to a tab object, if not NULL then the new object will be copied from it - * @return pointer to the created tab - */ -lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Delete all children of the scrl object, without deleting scrl child. - * @param obj pointer to an object - */ -void lv_tabview_clean(lv_obj_t *obj); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Add a new tab with the given name - * @param tabview pointer to Tab view object where to ass the new tab - * @param name the text on the tab button - * @return pointer to the created page object (lv_page). You can create your content here - */ -lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new tab - * @param tabview pointer to Tab view object - * @param id index of a tab to load - * @param anim_en true: set with sliding animation; false: set immediately - */ -void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en); - -/** - * Set an action to call when a tab is loaded (Good to create content only if required) - * lv_tabview_get_act() still gives the current (old) tab (to remove content from here) - * @param tabview pointer to a tabview object - * @param action pointer to a function to call when a tab is loaded - */ -void lv_tabview_set_tab_load_action(lv_obj_t *tabview, lv_tabview_action_t action); - -/** - * Enable horizontal sliding with touch pad - * @param tabview pointer to Tab view object - * @param en true: enable sliding; false: disable sliding - */ -void lv_tabview_set_sliding(lv_obj_t * tabview, bool en); - -/** - * Set the animation time of tab view when a new tab is loaded - * @param tabview pointer to Tab view object - * @param anim_time time of animation in milliseconds - */ -void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time); - -/** - * Set the style of a tab view - * @param tabview pointer to a tan view object - * @param type which style should be set - * @param style pointer to the new style - */ -void lv_tabview_set_style(lv_obj_t *tabview, lv_tabview_style_t type, lv_style_t *style); - -/** - * Set the position of tab select buttons - * @param tabview pointer to a tab view object - * @param btns_pos which button position - */ -void lv_tabview_set_btns_pos(lv_obj_t *tabview, lv_tabview_btns_pos_t btns_pos); - -/** - * Set whether tab buttons are hidden - * @param tabview pointer to a tab view object - * @param en whether tab buttons are hidden - */ -void lv_tabview_set_btns_hidden(lv_obj_t *tabview, bool en); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the index of the currently active tab - * @param tabview pointer to Tab view object - * @return the active tab index - */ -uint16_t lv_tabview_get_tab_act(const lv_obj_t * tabview); - -/** - * Get the number of tabs - * @param tabview pointer to Tab view object - * @return tab count - */ -uint16_t lv_tabview_get_tab_count(const lv_obj_t * tabview); -/** - * Get the page (content area) of a tab - * @param tabview pointer to Tab view object - * @param id index of the tab (>= 0) - * @return pointer to page (lv_page) object - */ -lv_obj_t * lv_tabview_get_tab(const lv_obj_t * tabview, uint16_t id); - -/** - * Get the tab load action - * @param tabview pointer to a tabview object - * @param return the current tab load action - */ -lv_tabview_action_t lv_tabview_get_tab_load_action(const lv_obj_t *tabview); - -/** - * Get horizontal sliding is enabled or not - * @param tabview pointer to Tab view object - * @return true: enable sliding; false: disable sliding - */ -bool lv_tabview_get_sliding(const lv_obj_t * tabview); - -/** - * Get the animation time of tab view when a new tab is loaded - * @param tabview pointer to Tab view object - * @return time of animation in milliseconds - */ -uint16_t lv_tabview_get_anim_time(const lv_obj_t * tabview); - -/** - * Get a style of a tab view - * @param tabview pointer to a ab view object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_tabview_get_style(const lv_obj_t *tabview, lv_tabview_style_t type); - -/** - * Get position of tab select buttons - * @param tabview pointer to a ab view object - */ -lv_tabview_btns_pos_t lv_tabview_get_btns_pos(const lv_obj_t *tabview); - -/** - * Get whether tab buttons are hidden - * @param tabview pointer to a tab view object - * @return whether tab buttons are hidden - */ -bool lv_tabview_get_btns_hidden(const lv_obj_t *tabview); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TABVIEW*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TABVIEW_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_tileview.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_tileview.h deleted file mode 100644 index b869e7ce..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_tileview.h +++ /dev/null @@ -1,163 +0,0 @@ -/** - * @file lv_tileview.h - * - */ - - -#ifndef LV_TILEVIEW_H -#define LV_TILEVIEW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TILEVIEW != 0 - -#include "display/lv_objx/lv_page.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - - - -/* parametes: pointer to a tileview object, x, y (tile coordinates to load) - * return: LV_RES_INV: to prevent the loading of the tab; LV_RES_OK: if everything is fine*/ -typedef lv_res_t (*lv_tileview_action_t)(lv_obj_t *, lv_coord_t, lv_coord_t); - -/*Data of tileview*/ -typedef struct { - lv_page_ext_t page; - /*New data for this type */ - const lv_point_t * valid_pos; - uint16_t anim_time; - lv_tileview_action_t action; - lv_point_t act_id; - uint8_t drag_top_en :1; - uint8_t drag_bottom_en :1; - uint8_t drag_left_en :1; - uint8_t drag_right_en :1; - uint8_t drag_hor :1; - uint8_t drag_ver :1; -} lv_tileview_ext_t; - - -/*Styles*/ -enum { - LV_TILEVIEW_STYLE_BG, -}; -typedef uint8_t lv_tileview_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a tileview objects - * @param par pointer to an object, it will be the parent of the new tileview - * @param copy pointer to a tileview object, if not NULL then the new object will be copied from it - * @return pointer to the created tileview - */ -lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Register an object on the tileview. The register object will able to slide the tileview - * @param element pointer to an object - */ -void lv_tileview_add_element(lv_obj_t * element); - -/*===================== - * Setter functions - *====================*/ - - -/** - * Set the valid position's indices. The scrolling will be possible only to these positions. - * @param tileview pointer to a Tileview object - * @param valid_pos array width the indices. E.g. `lv_point_t p[] = {{0,0}, {1,0}, {1,1}, {LV_COORD_MIN, LV_COORD_MIN}};` - * Must be closed with `{LV_COORD_MIN, LV_COORD_MIN}`. Only the pointer is saved so can't be a local variable. - */ -void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos); - -/** - * Set the tile to be shown - * @param tileview pointer to a tileview object - * @param x column id (0, 1, 2...) - * @param y line id (0, 1, 2...) - * @param anim_en true: move with animation - */ -void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, bool anim_en); - -/** - * Enable the edge flash effect. (Show an arc when the an edge is reached) - * @param tileview pointer to a Tileview - * @param en true or false to enable/disable end flash - */ -static inline void lv_tileview_set_edge_flash(lv_obj_t * tileview, bool en) -{ - lv_page_set_edge_flash(tileview, en); -} - -/** - * Set a style of a tileview. - * @param tileview pointer to tileview object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the scroll propagation property - * @param tileview pointer to a Tileview - * @return true or false - */ -static inline bool lv_tileview_get_edge_flash(lv_obj_t * tileview) -{ - return lv_page_get_edge_flash(tileview); -} - -/** - * Get style of a tileview. - * @param tileview pointer to tileview object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_tileview_get_style(const lv_obj_t * tileview, lv_tileview_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TILEVIEW*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TILEVIEW_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_objx/lv_win.h b/EZ-Template-Example-Project/include/display/lv_objx/lv_win.h deleted file mode 100644 index 4a64aa81..00000000 --- a/EZ-Template-Example-Project/include/display/lv_objx/lv_win.h +++ /dev/null @@ -1,282 +0,0 @@ -/** - * @file lv_win.h - * - */ - -#ifndef LV_WIN_H -#define LV_WIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_WIN != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTN == 0 -#error "lv_win: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_win: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#if USE_LV_IMG == 0 -#error "lv_win: lv_img is required. Enable it in lv_conf.h (USE_LV_IMG 1) " -#endif - - -#if USE_LV_PAGE == 0 -#error "lv_win: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_cont.h" -#include "lv_btn.h" -#include "lv_label.h" -#include "lv_img.h" -#include "lv_page.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of window*/ -typedef struct -{ - /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * page; /*Pointer to a page which holds the content*/ - lv_obj_t * header; /*Pointer to the header container of the window*/ - lv_obj_t * title; /*Pointer to the title label of the window*/ - lv_style_t * style_header; /*Style of the header container*/ - lv_style_t * style_btn_rel; /*Control button releases style*/ - lv_style_t * style_btn_pr; /*Control button pressed style*/ - lv_coord_t btn_size; /*Size of the control buttons (square)*/ -} lv_win_ext_t; - -enum { - LV_WIN_STYLE_BG, - LV_WIN_STYLE_CONTENT_BG, - LV_WIN_STYLE_CONTENT_SCRL, - LV_WIN_STYLE_SB, - LV_WIN_STYLE_HEADER, - LV_WIN_STYLE_BTN_REL, - LV_WIN_STYLE_BTN_PR, -}; -typedef uint8_t lv_win_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a window objects - * @param par pointer to an object, it will be the parent of the new window - * @param copy pointer to a window object, if not NULL then the new object will be copied from it - * @return pointer to the created window - */ -lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Delete all children of the scrl object, without deleting scrl child. - * @param obj pointer to an object - */ -void lv_win_clean(lv_obj_t *obj); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Add control button to the header of the window - * @param win pointer to a window object - * @param img_src an image source ('lv_img_t' variable, path to file or a symbol) - * @param rel_action a function pointer to call when the button is released - * @return pointer to the created button object - */ -lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, lv_action_t rel_action); - -/*===================== - * Setter functions - *====================*/ - -/** - * A release action which can be assigned to a window control button to close it - * @param btn pointer to the released button - * @return always LV_ACTION_RES_INV because the button is deleted with the window - */ -lv_res_t lv_win_close_action(lv_obj_t * btn); - -/** - * Set the title of a window - * @param win pointer to a window object - * @param title string of the new title - */ -void lv_win_set_title(lv_obj_t * win, const char * title); - -/** - * Set the control button size of a window - * @param win pointer to a window object - * @return control button size - */ -void lv_win_set_btn_size(lv_obj_t * win, lv_coord_t size); - -/** - * Set the layout of the window - * @param win pointer to a window object - * @param layout the layout from 'lv_layout_t' - */ -void lv_win_set_layout(lv_obj_t *win, lv_layout_t layout); - -/** - * Set the scroll bar mode of a window - * @param win pointer to a window object - * @param sb_mode the new scroll bar mode from 'lv_sb_mode_t' - */ -void lv_win_set_sb_mode(lv_obj_t *win, lv_sb_mode_t sb_mode); - -/** - * Set a style of a window - * @param win pointer to a window object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_win_set_style(lv_obj_t *win, lv_win_style_t type, lv_style_t *style); - -/** - * Set drag status of a window. If set to 'true' window can be dragged like on a PC. - * @param win pointer to a window object - * @param en whether dragging is enabled - */ -void lv_win_set_drag(lv_obj_t *win, bool en); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the title of a window - * @param win pointer to a window object - * @return title string of the window - */ -const char * lv_win_get_title(const lv_obj_t * win); - -/** -* Get the content holder object of window (`lv_page`) to allow additional customization -* @param win pointer to a window object -* @return the Page object where the window's content is -*/ -lv_obj_t * lv_win_get_content(const lv_obj_t * win); - -/** - * Get the control button size of a window - * @param win pointer to a window object - * @return control button size - */ -lv_coord_t lv_win_get_btn_size(const lv_obj_t * win); - -/** - * Get the pointer of a widow from one of its control button. - * It is useful in the action of the control buttons where only button is known. - * @param ctrl_btn pointer to a control button of a window - * @return pointer to the window of 'ctrl_btn' - */ -lv_obj_t * lv_win_get_from_btn(const lv_obj_t * ctrl_btn); - -/** - * Get the layout of a window - * @param win pointer to a window object - * @return the layout of the window (from 'lv_layout_t') - */ -lv_layout_t lv_win_get_layout(lv_obj_t *win); - -/** - * Get the scroll bar mode of a window - * @param win pointer to a window object - * @return the scroll bar mode of the window (from 'lv_sb_mode_t') - */ -lv_sb_mode_t lv_win_get_sb_mode(lv_obj_t *win); - -/** - * Get width of the content area (page scrollable) of the window - * @param win pointer to a window object - * @return the width of the content area - */ -lv_coord_t lv_win_get_width(lv_obj_t * win); - -/** - * Get a style of a window - * @param win pointer to a button object - * @param type which style window be get - * @return style pointer to a style - */ -lv_style_t * lv_win_get_style(const lv_obj_t *win, lv_win_style_t type); - -/** - * Get drag status of a window. If set to 'true' window can be dragged like on a PC. - * @param win pointer to a window object - * @return whether window is draggable - */ -static inline bool lv_win_get_drag(const lv_obj_t *win) -{ - return lv_obj_get_drag(win); -} - -/*===================== - * Other functions - *====================*/ - -/** - * Focus on an object. It ensures that the object will be visible in the window. - * @param win pointer to a window object - * @param obj pointer to an object to focus (must be in the window) - * @param anim_time scroll animation time in milliseconds (0: no animation) - */ -void lv_win_focus(lv_obj_t * win, lv_obj_t * obj, uint16_t anim_time); - -/** - * Scroll the window horizontally - * @param win pointer to a window object - * @param dist the distance to scroll (< 0: scroll right; > 0 scroll left) - */ -static inline void lv_win_scroll_hor(lv_obj_t * win, lv_coord_t dist) -{ - lv_win_ext_t * ext = (lv_win_ext_t *)lv_obj_get_ext_attr(win); - lv_page_scroll_hor(ext->page, dist); -} -/** - * Scroll the window vertically - * @param win pointer to a window object - * @param dist the distance to scroll (< 0: scroll down; > 0 scroll up) - */ -static inline void lv_win_scroll_ver(lv_obj_t * win, lv_coord_t dist) -{ - lv_win_ext_t * ext = (lv_win_ext_t *)lv_obj_get_ext_attr(win); - lv_page_scroll_ver(ext->page, dist); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_WIN*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_WIN_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme.h deleted file mode 100644 index 69aae29f..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme.h +++ /dev/null @@ -1,332 +0,0 @@ -/** - *@file lv_themes.h - * - */ - -#ifndef LV_THEMES_H -#define LV_THEMES_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include "display/lv_core/lv_style.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -typedef struct { - lv_style_t *bg; - lv_style_t *panel; - -#if USE_LV_CONT != 0 - lv_style_t *cont; -#endif - -#if USE_LV_BTN != 0 - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; -#endif - - -#if USE_LV_IMGBTN != 0 - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } imgbtn; -#endif - -#if USE_LV_LABEL != 0 - struct { - lv_style_t *prim; - lv_style_t *sec; - lv_style_t *hint; - } label; -#endif - -#if USE_LV_IMG != 0 - struct { - lv_style_t *light; - lv_style_t *dark; - } img; -#endif - -#if USE_LV_LINE != 0 - struct { - lv_style_t *decor; - } line; -#endif - -#if USE_LV_LED != 0 - lv_style_t *led; -#endif - -#if USE_LV_BAR != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - } bar; -#endif - -#if USE_LV_SLIDER != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - lv_style_t *knob; - } slider; -#endif - -#if USE_LV_LMETER != 0 - lv_style_t *lmeter; -#endif - -#if USE_LV_GAUGE != 0 - lv_style_t *gauge; -#endif - -#if USE_LV_ARC != 0 - lv_style_t *arc; -#endif - -#if USE_LV_PRELOAD != 0 - lv_style_t *preload; -#endif - -#if USE_LV_SW != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - lv_style_t *knob_off; - lv_style_t *knob_on; - } sw; -#endif - -#if USE_LV_CHART != 0 - lv_style_t *chart; -#endif - -#if USE_LV_CALENDAR != 0 - struct { - lv_style_t *bg; - lv_style_t *header; - lv_style_t *header_pr; - lv_style_t *day_names; - lv_style_t *highlighted_days; - lv_style_t *inactive_days; - lv_style_t *week_box; - lv_style_t *today_box; - } calendar; -#endif - -#if USE_LV_CB != 0 - struct { - lv_style_t *bg; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } box; - } cb; -#endif - -#if USE_LV_BTNM != 0 - struct { - lv_style_t *bg; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } btnm; -#endif - -#if USE_LV_KB != 0 - struct { - lv_style_t *bg; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } kb; -#endif - -#if USE_LV_MBOX != 0 - struct { - lv_style_t *bg; - struct { - lv_style_t *bg; - lv_style_t *rel; - lv_style_t *pr; - } btn; - } mbox; -#endif - -#if USE_LV_PAGE != 0 - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - } page; -#endif - -#if USE_LV_TA != 0 - struct { - lv_style_t *area; - lv_style_t *oneline; - lv_style_t *cursor; - lv_style_t *sb; - } ta; -#endif - -#if USE_LV_SPINBOX != 0 - struct { - lv_style_t *bg; - lv_style_t *cursor; - lv_style_t *sb; - } spinbox; -#endif - -#if USE_LV_LIST - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } list; -#endif - -#if USE_LV_DDLIST != 0 - struct { - lv_style_t *bg; - lv_style_t *sel; - lv_style_t *sb; - } ddlist; -#endif - -#if USE_LV_ROLLER != 0 - struct { - lv_style_t *bg; - lv_style_t *sel; - } roller; -#endif - -#if USE_LV_TABVIEW != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - struct { - lv_style_t *bg; - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - } btn; - } tabview; -#endif - -#if USE_LV_TILEVIEW != 0 - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - } tileview; -#endif - -#if USE_LV_TABLE != 0 - struct { - lv_style_t *bg; - lv_style_t *cell; - } table; -#endif - -#if USE_LV_WIN != 0 - struct { - lv_style_t *bg; - lv_style_t *sb; - lv_style_t *header; - struct { - lv_style_t *bg; - lv_style_t *scrl; - } content; - struct { - lv_style_t *rel; - lv_style_t *pr; - } btn; - } win; -#endif -} lv_theme_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Set a theme for the system. - * From now, all the created objects will use styles from this theme by default - * @param th pointer to theme (return value of: 'lv_theme_init_xxx()') - */ -void lv_theme_set_current(lv_theme_t *th); - -/** - * Get the current system theme. - * @return pointer to the current system theme. NULL if not set. - */ -lv_theme_t * lv_theme_get_current(void); - -/********************** - * MACROS - **********************/ - -/********************** - * POST INCLUDE - *********************/ -#include "lv_theme_templ.h" -#include "lv_theme_default.h" -#include "lv_theme_alien.h" -#include "lv_theme_night.h" -#include "lv_theme_zen.h" -#include "lv_theme_mono.h" -#include "lv_theme_nemo.h" -#include "lv_theme_material.h" - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEMES_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_alien.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_alien.h deleted file mode 100644 index 1f62315d..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_alien.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @file lv_theme_alien.h - * - */ - -#ifndef LV_THEME_ALIEN_H -#define LV_THEME_ALIEN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_ALIEN - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the alien theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t *font); -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_alien(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_ALIEN_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_default.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_default.h deleted file mode 100644 index 1348f1fc..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_default.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_default.h - * - */ - -#ifndef LV_THEME_DEFAULT_H -#define LV_THEME_DEFAULT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_DEFAULT - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the default theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_default_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_default(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_TEMPL_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_material.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_material.h deleted file mode 100644 index d9da6646..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_material.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_material.h - * - */ - -#ifndef LV_THEME_MATERIAL_H -#define LV_THEME_MATERIAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_MATERIAL - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the material theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_material_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_material(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_MATERIAL_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_mono.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_mono.h deleted file mode 100644 index 63039fa9..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_mono.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_mono.h - * - */ - -#ifndef LV_THEME_MONO_H -#define LV_THEME_MONO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_MONO - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the mono theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_mono(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_MONO_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_nemo.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_nemo.h deleted file mode 100644 index 46d43bdb..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_nemo.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_nemo.h - * - */ - -#ifndef LV_THEME_NEMO_H -#define LV_THEME_NEMO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_NEMO - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the material theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_nemo(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_NEMO_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_night.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_night.h deleted file mode 100644 index 3e5efb8f..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_night.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_night.h - * - */ - -#ifndef LV_THEME_NIGHT_H -#define LV_THEME_NIGHT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_NIGHT - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the night theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_night_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_night(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_NIGHT_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_templ.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_templ.h deleted file mode 100644 index e7176636..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_templ.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_templ.h - * - */ - -#ifndef LV_THEME_TEMPL_H -#define LV_THEME_TEMPL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_TEMPL - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the templ theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_templ(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_TEMPL_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_zen.h b/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_zen.h deleted file mode 100644 index ddd7cb35..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_theme_zen.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_zen.h - * - */ - -#ifndef LV_THEME_ZEN_H -#define LV_THEME_ZEN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_ZEN - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the zen theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_zen_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_zen(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_ZEN_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_themes/lv_themes.mk b/EZ-Template-Example-Project/include/display/lv_themes/lv_themes.mk deleted file mode 100644 index 0e4a81a5..00000000 --- a/EZ-Template-Example-Project/include/display/lv_themes/lv_themes.mk +++ /dev/null @@ -1,14 +0,0 @@ -CSRCS += lv_theme_alien.c -CSRCS += lv_theme.c -CSRCS += lv_theme_default.c -CSRCS += lv_theme_night.c -CSRCS += lv_theme_templ.c -CSRCS += lv_theme_zen.c -CSRCS += lv_theme_material.c -CSRCS += lv_theme_nemo.c -CSRCS += lv_theme_mono.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_themes -VPATH += :$(LVGL_DIR)/lvgl/lv_themes - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_themes" diff --git a/EZ-Template-Example-Project/include/display/lv_version.h b/EZ-Template-Example-Project/include/display/lv_version.h deleted file mode 100644 index 1e62e1e2..00000000 --- a/EZ-Template-Example-Project/include/display/lv_version.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - * @file lv_version.h - * - */ - -#ifndef LV_VERSION_H -#define LV_VERSION_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -/*Current version of LittlevGL*/ -#define LVGL_VERSION_MAJOR 5 -#define LVGL_VERSION_MINOR 3 -#define LVGL_VERSION_PATCH 0 -#define LVGL_VERSION_INFO "" - - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/********************** - * MACROS - **********************/ -/* Gives 1 if the x.y.z version is supported in the current version - * Usage: - * - * - Require v6 - * #if LV_VERSION_CHECK(6,0,0) - * new_func_in_v6(); - * #endif - * - * - * - Require at least v5.3 - * #if LV_VERSION_CHECK(5,3,0) - * new_feature_from_v5_3(); - * #endif - * - * - * - Require v5.3.2 bugfixes - * #if LV_VERSION_CHECK(5,3,2) - * bugfix_in_v5_3_2(); - * #endif - * - * */ -#define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_VERSION_H*/ diff --git a/EZ-Template-Example-Project/include/display/lvgl.h b/EZ-Template-Example-Project/include/display/lvgl.h deleted file mode 100644 index d2c93b4e..00000000 --- a/EZ-Template-Example-Project/include/display/lvgl.h +++ /dev/null @@ -1,88 +0,0 @@ -/** - * @file lvgl.h - * Include all LittleV GL related headers - */ - -#ifndef LVGL_H -#define LVGL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#include "lv_version.h" - -#include "lv_misc/lv_log.h" -#include "lv_misc/lv_task.h" - -#include "lv_hal/lv_hal.h" - -#include "lv_core/lv_obj.h" -#include "lv_core/lv_group.h" -#include "lv_core/lv_lang.h" -#include "lv_core/lv_vdb.h" -#include "lv_core/lv_refr.h" - -#include "lv_themes/lv_theme.h" - -#include "lv_objx/lv_btn.h" -#include "lv_objx/lv_imgbtn.h" -#include "lv_objx/lv_img.h" -#include "lv_objx/lv_label.h" -#include "lv_objx/lv_line.h" -#include "lv_objx/lv_page.h" -#include "lv_objx/lv_cont.h" -#include "lv_objx/lv_list.h" -#include "lv_objx/lv_chart.h" -#include "lv_objx/lv_table.h" -#include "lv_objx/lv_cb.h" -#include "lv_objx/lv_bar.h" -#include "lv_objx/lv_slider.h" -#include "lv_objx/lv_led.h" -#include "lv_objx/lv_btnm.h" -#include "lv_objx/lv_kb.h" -#include "lv_objx/lv_ddlist.h" -#include "lv_objx/lv_roller.h" -#include "lv_objx/lv_ta.h" -#include "lv_objx/lv_canvas.h" -#include "lv_objx/lv_win.h" -#include "lv_objx/lv_tabview.h" -#include "lv_objx/lv_tileview.h" -#include "lv_objx/lv_mbox.h" -#include "lv_objx/lv_gauge.h" -#include "lv_objx/lv_lmeter.h" -#include "lv_objx/lv_sw.h" -#include "lv_objx/lv_kb.h" -#include "lv_objx/lv_arc.h" -#include "lv_objx/lv_preload.h" -#include "lv_objx/lv_calendar.h" -#include "lv_objx/lv_spinbox.h" -#pragma GCC diagnostic pop - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} -#endif - -#endif /*LVGL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_disp.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_disp.h new file mode 100644 index 00000000..cd6efcc2 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_disp.h @@ -0,0 +1,264 @@ +/** + * @file lv_disp.h + * + */ + +#ifndef LV_DISP_H +#define LV_DISP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/hal/lv_hal.h" +#include "lv_obj.h" +#include "lv_theme.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef enum { + LV_SCR_LOAD_ANIM_NONE, + LV_SCR_LOAD_ANIM_OVER_LEFT, + LV_SCR_LOAD_ANIM_OVER_RIGHT, + LV_SCR_LOAD_ANIM_OVER_TOP, + LV_SCR_LOAD_ANIM_OVER_BOTTOM, + LV_SCR_LOAD_ANIM_MOVE_LEFT, + LV_SCR_LOAD_ANIM_MOVE_RIGHT, + LV_SCR_LOAD_ANIM_MOVE_TOP, + LV_SCR_LOAD_ANIM_MOVE_BOTTOM, + LV_SCR_LOAD_ANIM_FADE_IN, + LV_SCR_LOAD_ANIM_FADE_ON = LV_SCR_LOAD_ANIM_FADE_IN, /*For backward compatibility*/ + LV_SCR_LOAD_ANIM_FADE_OUT, + LV_SCR_LOAD_ANIM_OUT_LEFT, + LV_SCR_LOAD_ANIM_OUT_RIGHT, + LV_SCR_LOAD_ANIM_OUT_TOP, + LV_SCR_LOAD_ANIM_OUT_BOTTOM, +} lv_scr_load_anim_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Return with a pointer to the active screen + * @param disp pointer to display which active screen should be get. (NULL to use the default + * screen) + * @return pointer to the active screen object (loaded by 'lv_scr_load()') + */ +lv_obj_t * lv_disp_get_scr_act(lv_disp_t * disp); + +/** + * Return with a pointer to the previous screen. Only used during screen transitions. + * @param disp pointer to display which previous screen should be get. (NULL to use the default + * screen) + * @return pointer to the previous screen object or NULL if not used now + */ +lv_obj_t * lv_disp_get_scr_prev(lv_disp_t * disp); + +/** + * Make a screen active + * @param scr pointer to a screen + */ +void lv_disp_load_scr(lv_obj_t * scr); + +/** + * Return with the top layer. (Same on every screen and it is above the normal screen layer) + * @param disp pointer to display which top layer should be get. (NULL to use the default screen) + * @return pointer to the top layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_disp_get_layer_top(lv_disp_t * disp); + +/** + * Return with the sys. layer. (Same on every screen and it is above the normal screen and the top + * layer) + * @param disp pointer to display which sys. layer should be retrieved. (NULL to use the default screen) + * @return pointer to the sys layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_disp_get_layer_sys(lv_disp_t * disp); + +/** + * Set the theme of a display + * @param disp pointer to a display + */ +void lv_disp_set_theme(lv_disp_t * disp, lv_theme_t * th); + +/** + * Get the theme of a display + * @param disp pointer to a display + * @return the display's theme (can be NULL) + */ +lv_theme_t * lv_disp_get_theme(lv_disp_t * disp); + +/** + * Set the background color of a display + * @param disp pointer to a display + * @param color color of the background + */ +void lv_disp_set_bg_color(lv_disp_t * disp, lv_color_t color); + +/** + * Set the background image of a display + * @param disp pointer to a display + * @param img_src path to file or pointer to an `lv_img_dsc_t` variable + */ +void lv_disp_set_bg_image(lv_disp_t * disp, const void * img_src); + +/** + * Set opacity of the background + * @param disp pointer to a display + * @param opa opacity (0..255) + */ +void lv_disp_set_bg_opa(lv_disp_t * disp, lv_opa_t opa); + +/** + * Switch screen with animation + * @param scr pointer to the new screen to load + * @param anim_type type of the animation from `lv_scr_load_anim_t`, e.g. `LV_SCR_LOAD_ANIM_MOVE_LEFT` + * @param time time of the animation + * @param delay delay before the transition + * @param auto_del true: automatically delete the old screen + */ +void lv_scr_load_anim(lv_obj_t * scr, lv_scr_load_anim_t anim_type, uint32_t time, uint32_t delay, bool auto_del); + +/** + * Get elapsed time since last user activity on a display (e.g. click) + * @param disp pointer to a display (NULL to get the overall smallest inactivity) + * @return elapsed ticks (milliseconds) since the last activity + */ +uint32_t lv_disp_get_inactive_time(const lv_disp_t * disp); + +/** + * Manually trigger an activity on a display + * @param disp pointer to a display (NULL to use the default display) + */ +void lv_disp_trig_activity(lv_disp_t * disp); + +/** + * Clean any CPU cache that is related to the display. + * @param disp pointer to a display (NULL to use the default display) + */ +void lv_disp_clean_dcache(lv_disp_t * disp); + +/** + * Temporarily enable and disable the invalidation of the display. + * @param disp pointer to a display (NULL to use the default display) + * @param en true: enable invalidation; false: invalidation + */ +void lv_disp_enable_invalidation(lv_disp_t * disp, bool en); + +/** + * Get display invalidation is enabled. + * @param disp pointer to a display (NULL to use the default display) + * @return return true if invalidation is enabled + */ +bool lv_disp_is_invalidation_enabled(lv_disp_t * disp); + +/** + * Get a pointer to the screen refresher timer to + * modify its parameters with `lv_timer_...` functions. + * @param disp pointer to a display + * @return pointer to the display refresher timer. (NULL on error) + */ +lv_timer_t * _lv_disp_get_refr_timer(lv_disp_t * disp); + +/*------------------------------------------------ + * To improve backward compatibility + * Recommended only if you have one display + *------------------------------------------------*/ + +/** + * Get the active screen of the default display + * @return pointer to the active screen + */ +static inline lv_obj_t * lv_scr_act(void) +{ + return lv_disp_get_scr_act(lv_disp_get_default()); +} + +/** + * Get the top layer of the default display + * @return pointer to the top layer + */ +static inline lv_obj_t * lv_layer_top(void) +{ + return lv_disp_get_layer_top(lv_disp_get_default()); +} + +/** + * Get the active screen of the default display + * @return pointer to the sys layer + */ +static inline lv_obj_t * lv_layer_sys(void) +{ + return lv_disp_get_layer_sys(lv_disp_get_default()); +} + +static inline void lv_scr_load(lv_obj_t * scr) +{ + lv_disp_load_scr(scr); +} + +/********************** + * MACROS + **********************/ + +/*------------------------------------------------ + * To improve backward compatibility + * Recommended only if you have one display + *------------------------------------------------*/ + +#ifndef LV_HOR_RES +/** + * The horizontal resolution of the currently active display. + */ +#define LV_HOR_RES lv_disp_get_hor_res(lv_disp_get_default()) +#endif + +#ifndef LV_VER_RES +/** + * The vertical resolution of the currently active display. + */ +#define LV_VER_RES lv_disp_get_ver_res(lv_disp_get_default()) +#endif + +/** + * Scale the given number of pixels (a distance or size) relative to a 160 DPI display + * considering the DPI of the default display. + * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the + * DPI of the display. + * @param n the number of pixels to scale + * @return `n x current_dpi/160` + */ +static inline lv_coord_t lv_dpx(lv_coord_t n) +{ + return LV_DPX(n); +} + +/** + * Scale the given number of pixels (a distance or size) relative to a 160 DPI display + * considering the DPI of the given display. + * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the + * DPI of the display. + * @param obj a display whose dpi should be considered + * @param n the number of pixels to scale + * @return `n x current_dpi/160` + */ +static inline lv_coord_t lv_disp_dpx(const lv_disp_t * disp, lv_coord_t n) +{ + return _LV_DPX_CALC(lv_disp_get_dpi(disp), n); +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DISP_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_event.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_event.h new file mode 100644 index 00000000..d5a9eb6b --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_event.h @@ -0,0 +1,363 @@ +/** + * @file lv_event.h + * + */ + +#ifndef LV_EVENT_H +#define LV_EVENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_event_dsc_t; + +/** + * Type of event being sent to the object. + */ +typedef enum { + LV_EVENT_ALL = 0, + + /** Input device events*/ + LV_EVENT_PRESSED, /**< The object has been pressed*/ + LV_EVENT_PRESSING, /**< The object is being pressed (called continuously while pressing)*/ + LV_EVENT_PRESS_LOST, /**< The object is still being pressed but slid cursor/finger off of the object */ + LV_EVENT_SHORT_CLICKED, /**< The object was pressed for a short period of time, then released it. Not called if scrolled.*/ + LV_EVENT_LONG_PRESSED, /**< Object has been pressed for at least `long_press_time`. Not called if scrolled.*/ + LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `long_press_time` in every `long_press_repeat_time` ms. Not called if scrolled.*/ + LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/ + LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/ + LV_EVENT_SCROLL_BEGIN, /**< Scrolling begins. The event parameter is a pointer to the animation of the scroll. Can be modified*/ + LV_EVENT_SCROLL_END, /**< Scrolling ends*/ + LV_EVENT_SCROLL, /**< Scrolling*/ + LV_EVENT_GESTURE, /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` */ + LV_EVENT_KEY, /**< A key is sent to the object. Get the key with `lv_indev_get_key(lv_indev_get_act());`*/ + LV_EVENT_FOCUSED, /**< The object is focused*/ + LV_EVENT_DEFOCUSED, /**< The object is defocused*/ + LV_EVENT_LEAVE, /**< The object is defocused but still selected*/ + LV_EVENT_HIT_TEST, /**< Perform advanced hit-testing*/ + + /** Drawing events*/ + LV_EVENT_COVER_CHECK, /**< Check if the object fully covers an area. The event parameter is `lv_cover_check_info_t *`.*/ + LV_EVENT_REFR_EXT_DRAW_SIZE, /**< Get the required extra draw area around the object (e.g. for shadow). The event parameter is `lv_coord_t *` to store the size.*/ + LV_EVENT_DRAW_MAIN_BEGIN, /**< Starting the main drawing phase*/ + LV_EVENT_DRAW_MAIN, /**< Perform the main drawing*/ + LV_EVENT_DRAW_MAIN_END, /**< Finishing the main drawing phase*/ + LV_EVENT_DRAW_POST_BEGIN, /**< Starting the post draw phase (when all children are drawn)*/ + LV_EVENT_DRAW_POST, /**< Perform the post draw phase (when all children are drawn)*/ + LV_EVENT_DRAW_POST_END, /**< Finishing the post draw phase (when all children are drawn)*/ + LV_EVENT_DRAW_PART_BEGIN, /**< Starting to draw a part. The event parameter is `lv_obj_draw_dsc_t *`. */ + LV_EVENT_DRAW_PART_END, /**< Finishing to draw a part. The event parameter is `lv_obj_draw_dsc_t *`. */ + + /** Special events*/ + LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved)*/ + LV_EVENT_INSERT, /**< A text is inserted to the object. The event data is `char *` being inserted.*/ + LV_EVENT_REFRESH, /**< Notify the object to refresh something on it (for the user)*/ + LV_EVENT_READY, /**< A process has finished*/ + LV_EVENT_CANCEL, /**< A process has been cancelled */ + + /** Other events*/ + LV_EVENT_DELETE, /**< Object is being deleted*/ + LV_EVENT_CHILD_CHANGED, /**< Child was removed, added, or its size, position were changed */ + LV_EVENT_CHILD_CREATED, /**< Child was created, always bubbles up to all parents*/ + LV_EVENT_CHILD_DELETED, /**< Child was deleted, always bubbles up to all parents*/ + LV_EVENT_SCREEN_UNLOAD_START, /**< A screen unload started, fired immediately when scr_load is called*/ + LV_EVENT_SCREEN_LOAD_START, /**< A screen load started, fired when the screen change delay is expired*/ + LV_EVENT_SCREEN_LOADED, /**< A screen was loaded*/ + LV_EVENT_SCREEN_UNLOADED, /**< A screen was unloaded*/ + LV_EVENT_SIZE_CHANGED, /**< Object coordinates/size have changed*/ + LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/ + LV_EVENT_LAYOUT_CHANGED, /**< The children position has changed due to a layout recalculation*/ + LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/ + + _LV_EVENT_LAST, /** Number of default events*/ + + + LV_EVENT_PREPROCESS = 0x80, /** This is a flag that can be set with an event so it's processed + before the class default event processing */ +} lv_event_code_t; + +typedef struct _lv_event_t { + struct _lv_obj_t * target; + struct _lv_obj_t * current_target; + lv_event_code_t code; + void * user_data; + void * param; + struct _lv_event_t * prev; + uint8_t deleted : 1; + uint8_t stop_processing : 1; + uint8_t stop_bubbling : 1; +} lv_event_t; + +/** + * @brief Event callback. + * Events are used to notify the user of some action being taken on the object. + * For details, see ::lv_event_t. + */ +typedef void (*lv_event_cb_t)(lv_event_t * e); + +/** + * Used as the event parameter of ::LV_EVENT_HIT_TEST to check if an `point` can click the object or not. + * `res` should be set like this: + * - If already set to `false` an other event wants that point non clickable. If you want to respect it leave it as `false` or set `true` to overwrite it. + * - If already set `true` and `point` shouldn't be clickable set to `false` + * - If already set to `true` you agree that `point` can click the object leave it as `true` + */ +typedef struct { + const lv_point_t * point; /**< A point relative to screen to check if it can click the object or not*/ + bool res; /**< true: `point` can click the object; false: it cannot*/ +} lv_hit_test_info_t; + +/** + * Used as the event parameter of ::LV_EVENT_COVER_CHECK to check if an area is covered by the object or not. + * In the event use `const lv_area_t * area = lv_event_get_cover_area(e)` to get the area to check + * and `lv_event_set_cover_res(e, res)` to set the result. + */ +typedef struct { + lv_cover_res_t res; + const lv_area_t * area; +} lv_cover_check_info_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Send an event to the object + * @param obj pointer to an object + * @param event_code the type of the event from `lv_event_t` + * @param param arbitrary data depending on the widget type and the event. (Usually `NULL`) + * @return LV_RES_OK: `obj` was not deleted in the event; LV_RES_INV: `obj` was deleted in the event_code + */ +lv_res_t lv_event_send(struct _lv_obj_t * obj, lv_event_code_t event_code, void * param); + +/** + * Used by the widgets internally to call the ancestor widget types's event handler + * @param class_p pointer to the class of the widget (NOT the ancestor class) + * @param e pointer to the event descriptor + * @return LV_RES_OK: the target object was not deleted in the event; LV_RES_INV: it was deleted in the event_code + */ +lv_res_t lv_obj_event_base(const lv_obj_class_t * class_p, lv_event_t * e); + +/** + * Get the object originally targeted by the event. It's the same even if the event is bubbled. + * @param e pointer to the event descriptor + * @return the target of the event_code + */ +struct _lv_obj_t * lv_event_get_target(lv_event_t * e); + +/** + * Get the current target of the event. It's the object which event handler being called. + * If the event is not bubbled it's the same as "normal" target. + * @param e pointer to the event descriptor + * @return pointer to the current target of the event_code + */ +struct _lv_obj_t * lv_event_get_current_target(lv_event_t * e); + +/** + * Get the event code of an event + * @param e pointer to the event descriptor + * @return the event code. (E.g. `LV_EVENT_CLICKED`, `LV_EVENT_FOCUSED`, etc) + */ +lv_event_code_t lv_event_get_code(lv_event_t * e); + +/** + * Get the parameter passed when the event was sent + * @param e pointer to the event descriptor + * @return pointer to the parameter + */ +void * lv_event_get_param(lv_event_t * e); + +/** + * Get the user_data passed when the event was registered on the object + * @param e pointer to the event descriptor + * @return pointer to the user_data + */ +void * lv_event_get_user_data(lv_event_t * e); + +/** + * Stop the event from bubbling. + * This is only valid when called in the middle of an event processing chain. + * @param e pointer to the event descriptor + */ +void lv_event_stop_bubbling(lv_event_t * e); + +/** + * Stop processing this event. + * This is only valid when called in the middle of an event processing chain. + * @param e pointer to the event descriptor + */ +void lv_event_stop_processing(lv_event_t * e); + +/** + * Register a new, custom event ID. + * It can be used the same way as e.g. `LV_EVENT_CLICKED` to send custom events + * @return the new event id + * @example + * uint32_t LV_EVENT_MINE = 0; + * ... + * e = lv_event_register_id(); + * ... + * lv_event_send(obj, LV_EVENT_MINE, &some_data); + */ +uint32_t lv_event_register_id(void); + +/** + * Nested events can be called and one of them might belong to an object that is being deleted. + * Mark this object's `event_temp_data` deleted to know that its `lv_event_send` should return `LV_RES_INV` + * @param obj pointer to an object to mark as deleted + */ +void _lv_event_mark_deleted(struct _lv_obj_t * obj); + + +/** + * Add an event handler function for an object. + * Used by the user to react on event which happens with the object. + * An object can have multiple event handler. They will be called in the same order as they were added. + * @param obj pointer to an object + * @param filter and event code (e.g. `LV_EVENT_CLICKED`) on which the event should be called. `LV_EVENT_ALL` can be sued the receive all the events. + * @param event_cb the new event function + * @param user_data custom data data will be available in `event_cb` + * @return a pointer the event descriptor. Can be used in ::lv_obj_remove_event_dsc + */ +struct _lv_event_dsc_t * lv_obj_add_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter, + void * user_data); + +/** + * Remove an event handler function for an object. + * @param obj pointer to an object + * @param event_cb the event function to remove, or `NULL` to remove the firstly added event callback + * @return true if any event handlers were removed + */ +bool lv_obj_remove_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb); + +/** + * Remove an event handler function with a specific user_data from an object. + * @param obj pointer to an object + * @param event_cb the event function to remove, or `NULL` only `user_data` matters. + * @param event_user_data the user_data specified in ::lv_obj_add_event_cb + * @return true if any event handlers were removed + */ +bool lv_obj_remove_event_cb_with_user_data(struct _lv_obj_t * obj, lv_event_cb_t event_cb, + const void * event_user_data); + +/** + * DEPRECATED because doesn't work if multiple event handlers are added to an object. + * Remove an event handler function for an object. + * @param obj pointer to an object + * @param event_dsc pointer to an event descriptor to remove (returned by ::lv_obj_add_event_cb) + * @return true if any event handlers were removed + */ +bool lv_obj_remove_event_dsc(struct _lv_obj_t * obj, struct _lv_event_dsc_t * event_dsc); + +/** + * The user data of an event object event callback. Always the first match with `event_cb` will be returned. + * @param obj pointer to an object + * @param event_cb the event function + * @return the user_data + */ +void * lv_obj_get_event_user_data(struct _lv_obj_t * obj, lv_event_cb_t event_cb); + +/** + * Get the input device passed as parameter to indev related events. + * @param e pointer to an event + * @return the indev that triggered the event or NULL if called on a not indev related event + */ +lv_indev_t * lv_event_get_indev(lv_event_t * e); + +/** + * Get the part draw descriptor passed as parameter to `LV_EVENT_DRAW_PART_BEGIN/END`. + * @param e pointer to an event + * @return the part draw descriptor to hook the drawing or NULL if called on an unrelated event + */ +lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e); + +/** + * Get the draw context which should be the first parameter of the draw functions. + * Namely: `LV_EVENT_DRAW_MAIN/POST`, `LV_EVENT_DRAW_MAIN/POST_BEGIN`, `LV_EVENT_DRAW_MAIN/POST_END` + * @param e pointer to an event + * @return pointer to a draw context or NULL if called on an unrelated event + */ +lv_draw_ctx_t * lv_event_get_draw_ctx(lv_event_t * e); + +/** + * Get the old area of the object before its size was changed. Can be used in `LV_EVENT_SIZE_CHANGED` + * @param e pointer to an event + * @return the old absolute area of the object or NULL if called on an unrelated event + */ +const lv_area_t * lv_event_get_old_size(lv_event_t * e); + +/** + * Get the key passed as parameter to an event. Can be used in `LV_EVENT_KEY` + * @param e pointer to an event + * @return the triggering key or NULL if called on an unrelated event + */ +uint32_t lv_event_get_key(lv_event_t * e); + +/** + * Get the animation descriptor of a scrolling. Can be used in `LV_EVENT_SCROLL_BEGIN` + * @param e pointer to an event + * @return the animation that will scroll the object. (can be modified as required) + */ +lv_anim_t * lv_event_get_scroll_anim(lv_event_t * e); + +/** + * Set the new extra draw size. Can be used in `LV_EVENT_REFR_EXT_DRAW_SIZE` + * @param e pointer to an event + * @param size The new extra draw size + */ +void lv_event_set_ext_draw_size(lv_event_t * e, lv_coord_t size); + +/** + * Get a pointer to an `lv_point_t` variable in which the self size should be saved (width in `point->x` and height `point->y`). + * Can be used in `LV_EVENT_GET_SELF_SIZE` + * @param e pointer to an event + * @return pointer to `lv_point_t` or NULL if called on an unrelated event + */ +lv_point_t * lv_event_get_self_size_info(lv_event_t * e); + +/** + * Get a pointer to an `lv_hit_test_info_t` variable in which the hit test result should be saved. Can be used in `LV_EVENT_HIT_TEST` + * @param e pointer to an event + * @return pointer to `lv_hit_test_info_t` or NULL if called on an unrelated event + */ +lv_hit_test_info_t * lv_event_get_hit_test_info(lv_event_t * e); + +/** + * Get a pointer to an area which should be examined whether the object fully covers it or not. + * Can be used in `LV_EVENT_HIT_TEST` + * @param e pointer to an event + * @return an area with absolute coordinates to check + */ +const lv_area_t * lv_event_get_cover_area(lv_event_t * e); + +/** + * Set the result of cover checking. Can be used in `LV_EVENT_COVER_CHECK` + * @param e pointer to an event + * @param res an element of ::lv_cover_check_info_t + */ +void lv_event_set_cover_res(lv_event_t * e, lv_cover_res_t res); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_EVENT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_group.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_group.h new file mode 100644 index 00000000..85df325a --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_group.h @@ -0,0 +1,266 @@ +/** + * @file lv_group.h + * + */ + +#ifndef LV_GROUP_H +#define LV_GROUP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include "liblvgl/misc/lv_ll.h" +#include "liblvgl/misc/lv_types.h" + +/********************* + * DEFINES + *********************/ +/*Predefined keys to control the focused object via lv_group_send(group, c)*/ + +enum { + LV_KEY_UP = 17, /*0x11*/ + LV_KEY_DOWN = 18, /*0x12*/ + LV_KEY_RIGHT = 19, /*0x13*/ + LV_KEY_LEFT = 20, /*0x14*/ + LV_KEY_ESC = 27, /*0x1B*/ + LV_KEY_DEL = 127, /*0x7F*/ + LV_KEY_BACKSPACE = 8, /*0x08*/ + LV_KEY_ENTER = 10, /*0x0A, '\n'*/ + LV_KEY_NEXT = 9, /*0x09, '\t'*/ + LV_KEY_PREV = 11, /*0x0B, '*/ + LV_KEY_HOME = 2, /*0x02, STX*/ + LV_KEY_END = 3, /*0x03, ETX*/ +}; +typedef uint8_t lv_key_t; + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_group_t; + +typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *); +typedef void (*lv_group_edge_cb_t)(struct _lv_group_t *, bool); + +/** + * Groups can be used to logically hold objects so that they can be individually focused. + * They are NOT for laying out objects on a screen (try layouts for that). + */ +typedef struct _lv_group_t { + lv_ll_t obj_ll; /**< Linked list to store the objects in the group*/ + struct _lv_obj_t ** obj_focus; /**< The object in focus*/ + + lv_group_focus_cb_t focus_cb; /**< A function to call when a new object is focused (optional)*/ + lv_group_edge_cb_t edge_cb; /**< A function to call when an edge is reached, no more focus + targets are available in this direction (to allow edge feedback + like a sound or a scroll bounce) */ + +#if LV_USE_USER_DATA + void * user_data; +#endif + + uint8_t frozen : 1; /**< 1: can't focus to new object*/ + uint8_t editing : 1; /**< 1: Edit mode, 0: Navigate mode*/ + uint8_t refocus_policy : 1; /**< 1: Focus prev if focused on deletion. 0: Focus next if focused on + deletion.*/ + uint8_t wrap : 1; /**< 1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end + of list.*/ +} lv_group_t; + + +typedef enum { + LV_GROUP_REFOCUS_POLICY_NEXT = 0, + LV_GROUP_REFOCUS_POLICY_PREV = 1 +} lv_group_refocus_policy_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Init. the group module + * @remarks Internal function, do not call directly. + */ +void _lv_group_init(void); + +/** + * Create a new object group + * @return pointer to the new object group + */ +lv_group_t * lv_group_create(void); + +/** + * Delete a group object + * @param group pointer to a group + */ +void lv_group_del(lv_group_t * group); + +/** + * Set a default group. New object are added to this group if it's enabled in their class with `add_to_def_group = true` + * @param group pointer to a group (can be `NULL`) + */ +void lv_group_set_default(lv_group_t * group); + +/** + * Get the default group + * @return pointer to the default group + */ +lv_group_t * lv_group_get_default(void); + +/** + * Add an object to a group + * @param group pointer to a group + * @param obj pointer to an object to add + */ +void lv_group_add_obj(lv_group_t * group, struct _lv_obj_t * obj); + +/** + * Swap 2 object in a group. The object must be in the same group + * @param obj1 pointer to an object + * @param obj2 pointer to an other object + */ +void lv_group_swap_obj(struct _lv_obj_t * obj1, struct _lv_obj_t * obj2); + +/** + * Remove an object from its group + * @param obj pointer to an object to remove + */ +void lv_group_remove_obj(struct _lv_obj_t * obj); + +/** + * Remove all objects from a group + * @param group pointer to a group + */ +void lv_group_remove_all_objs(lv_group_t * group); + +/** + * Focus on an object (defocus the current) + * @param obj pointer to an object to focus on + */ +void lv_group_focus_obj(struct _lv_obj_t * obj); + +/** + * Focus the next object in a group (defocus the current) + * @param group pointer to a group + */ +void lv_group_focus_next(lv_group_t * group); + +/** + * Focus the previous object in a group (defocus the current) + * @param group pointer to a group + */ +void lv_group_focus_prev(lv_group_t * group); + +/** + * Do not let to change the focus from the current object + * @param group pointer to a group + * @param en true: freeze, false: release freezing (normal mode) + */ +void lv_group_focus_freeze(lv_group_t * group, bool en); + +/** + * Send a control character to the focuses object of a group + * @param group pointer to a group + * @param c a character (use LV_KEY_.. to navigate) + * @return result of focused object in group. + */ +lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c); + +/** + * Set a function for a group which will be called when a new object is focused + * @param group pointer to a group + * @param focus_cb the call back function or NULL if unused + */ +void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb); + +/** + * Set a function for a group which will be called when a focus edge is reached + * @param group pointer to a group + * @param edge_cb the call back function or NULL if unused + */ +void lv_group_set_edge_cb(lv_group_t * group, lv_group_edge_cb_t edge_cb); + + +/** + * Set whether the next or previous item in a group is focused if the currently focused obj is + * deleted. + * @param group pointer to a group + * @param policy new refocus policy enum + */ +void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy); + +/** + * Manually set the current mode (edit or navigate). + * @param group pointer to group + * @param edit true: edit mode; false: navigate mode + */ +void lv_group_set_editing(lv_group_t * group, bool edit); + +/** + * Set whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en true: wrapping enabled; false: wrapping disabled + */ +void lv_group_set_wrap(lv_group_t * group, bool en); + +/** + * Get the focused object or NULL if there isn't one + * @param group pointer to a group + * @return pointer to the focused object + */ +struct _lv_obj_t * lv_group_get_focused(const lv_group_t * group); + +/** + * Get the focus callback function of a group + * @param group pointer to a group + * @return the call back function or NULL if not set + */ +lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group); + +/** + * Get the edge callback function of a group + * @param group pointer to a group + * @return the call back function or NULL if not set + */ +lv_group_edge_cb_t lv_group_get_edge_cb(const lv_group_t * group); + +/** + * Get the current mode (edit or navigate). + * @param group pointer to group + * @return true: edit mode; false: navigate mode + */ +bool lv_group_get_editing(const lv_group_t * group); + +/** + * Get whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en true: wrapping enabled; false: wrapping disabled + */ +bool lv_group_get_wrap(lv_group_t * group); + +/** + * Get the number of object in the group + * @param group pointer to a group + * @return number of objects in the group + */ +uint32_t lv_group_get_obj_count(lv_group_t * group); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GROUP_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_indev.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_indev.h new file mode 100644 index 00000000..4692ef37 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_indev.h @@ -0,0 +1,176 @@ +/** + * @file lv_indev.h + * + */ + +#ifndef LV_INDEV_H +#define LV_INDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" +#include "liblvgl/hal/lv_hal_indev.h" +#include "lv_group.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Called periodically to read the input devices + * @param timer pointer to a timer to read + */ +void lv_indev_read_timer_cb(lv_timer_t * timer); + +/** + * Enable or disable one or all input devices (default enabled) + * @param indev pointer to an input device or NULL to enable/disable all of them + * @param en true to enable, false to disable + */ +void lv_indev_enable(lv_indev_t * indev, bool en); + +/** + * Get the currently processed input device. Can be used in action functions too. + * @return pointer to the currently processed input device or NULL if no input device processing + * right now + */ +lv_indev_t * lv_indev_get_act(void); + +/** + * Get the type of an input device + * @param indev pointer to an input device + * @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`) + */ +lv_indev_type_t lv_indev_get_type(const lv_indev_t * indev); + +/** + * Reset one or all input devices + * @param indev pointer to an input device to reset or NULL to reset all of them + * @param obj pointer to an object which triggers the reset. + */ +void lv_indev_reset(lv_indev_t * indev, lv_obj_t * obj); + +/** + * Reset the long press state of an input device + * @param indev pointer to an input device + */ +void lv_indev_reset_long_press(lv_indev_t * indev); + +/** + * Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON) + * @param indev pointer to an input device + * @param cur_obj pointer to an object to be used as cursor + */ +void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj); + +/** + * Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD) + * @param indev pointer to an input device + * @param group point to a group + */ +void lv_indev_set_group(lv_indev_t * indev, lv_group_t * group); + +/** + * Set the an array of points for LV_INDEV_TYPE_BUTTON. + * These points will be assigned to the buttons to press a specific point on the screen + * @param indev pointer to an input device + * @param group point to a group + */ +void lv_indev_set_button_points(lv_indev_t * indev, const lv_point_t points[]); + +/** + * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @param point pointer to a point to store the result + */ +void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point); + +/** +* Get the current gesture direct +* @param indev pointer to an input device +* @return current gesture direct +*/ +lv_dir_t lv_indev_get_gesture_dir(const lv_indev_t * indev); + +/** + * Get the last pressed key of an input device (for LV_INDEV_TYPE_KEYPAD) + * @param indev pointer to an input device + * @return the last pressed key (0 on error) + */ +uint32_t lv_indev_get_key(const lv_indev_t * indev); + +/** + * Check the current scroll direction of an input device (for LV_INDEV_TYPE_POINTER and + * LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @return LV_DIR_NONE: no scrolling now + * LV_DIR_HOR/VER + */ +lv_dir_t lv_indev_get_scroll_dir(const lv_indev_t * indev); + +/** + * Get the currently scrolled object (for LV_INDEV_TYPE_POINTER and + * LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @return pointer to the currently scrolled object or NULL if no scrolling by this indev + */ +lv_obj_t * lv_indev_get_scroll_obj(const lv_indev_t * indev); + +/** + * Get the movement vector of an input device (for LV_INDEV_TYPE_POINTER and + * LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @param point pointer to a point to store the types.pointer.vector + */ +void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point); + +/** + * Do nothing until the next release + * @param indev pointer to an input device + */ +void lv_indev_wait_release(lv_indev_t * indev); + +/** + * Gets a pointer to the currently active object in the currently processed input device. + * @return pointer to currently active object or NULL if no active object + */ +lv_obj_t * lv_indev_get_obj_act(void); + +/** + * Get a pointer to the indev read timer to + * modify its parameters with `lv_timer_...` functions. + * @param indev pointer to an input device + * @return pointer to the indev read refresher timer. (NULL on error) + */ +lv_timer_t * lv_indev_get_read_timer(lv_disp_t * indev); + +/** + * Search the most top, clickable object by a point + * @param obj pointer to a start object, typically the screen + * @param point pointer to a point for searching the most top child + * @return pointer to the found object or NULL if there was no suitable object + */ +lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_INDEV_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_indev_scroll.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_indev_scroll.h new file mode 100644 index 00000000..76c64d17 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_indev_scroll.h @@ -0,0 +1,65 @@ +/** + * @file lv_indev_scroll.h + * + */ + +#ifndef LV_INDEV_SCROLL_H +#define LV_INDEV_SCROLL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Handle scrolling. Called by LVGL during input device processing + * @param proc pointer to an input device's proc field + */ +void _lv_indev_scroll_handler(_lv_indev_proc_t * proc); + +/** + * Handle throwing after scrolling. Called by LVGL during input device processing + * @param proc pointer to an input device's proc field + */ +void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc); + +/** + * Predict where would a scroll throw end + * @param indev pointer to an input device + * @param dir ` LV_DIR_VER` or `LV_DIR_HOR` + * @return the difference compared to the current position when the throw would be finished + */ +lv_coord_t lv_indev_scroll_throw_predict(lv_indev_t * indev, lv_dir_t dir); + +/** + * Get the distance of the nearest snap point + * @param obj the object on which snap points should be found + * @param p save the distance of the found snap point there + */ +void lv_indev_scroll_get_snap_dist(lv_obj_t * obj, lv_point_t * p); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_INDEV_SCROLL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_obj.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj.h new file mode 100644 index 00000000..c89e4609 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj.h @@ -0,0 +1,409 @@ +/** + * @file lv_obj.h + * + */ + +#ifndef LV_OBJ_H +#define LV_OBJ_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../lv_conf_internal.h" + +#include +#include +#include "../misc/lv_style.h" +#include "../misc/lv_types.h" +#include "../misc/lv_area.h" +#include "../misc/lv_color.h" +#include "../misc/lv_assert.h" +#include "../hal/lv_hal.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; + +/** + * Possible states of a widget. + * OR-ed values are possible + */ +enum { + LV_STATE_DEFAULT = 0x0000, + LV_STATE_CHECKED = 0x0001, + LV_STATE_FOCUSED = 0x0002, + LV_STATE_FOCUS_KEY = 0x0004, + LV_STATE_EDITED = 0x0008, + LV_STATE_HOVERED = 0x0010, + LV_STATE_PRESSED = 0x0020, + LV_STATE_SCROLLED = 0x0040, + LV_STATE_DISABLED = 0x0080, + + LV_STATE_USER_1 = 0x1000, + LV_STATE_USER_2 = 0x2000, + LV_STATE_USER_3 = 0x4000, + LV_STATE_USER_4 = 0x8000, + + LV_STATE_ANY = 0xFFFF, /**< Special value can be used in some functions to target all states*/ +}; + +typedef uint16_t lv_state_t; + +/** + * The possible parts of widgets. + * The parts can be considered as the internal building block of the widgets. + * E.g. slider = background + indicator + knob + * Not all parts are used by every widget + */ +enum { + LV_PART_MAIN = 0x000000, /**< A background like rectangle*/ + LV_PART_SCROLLBAR = 0x010000, /**< The scrollbar(s)*/ + LV_PART_INDICATOR = 0x020000, /**< Indicator, e.g. for slider, bar, switch, or the tick box of the checkbox*/ + LV_PART_KNOB = 0x030000, /**< Like handle to grab to adjust the value*/ + LV_PART_SELECTED = 0x040000, /**< Indicate the currently selected option or section*/ + LV_PART_ITEMS = 0x050000, /**< Used if the widget has multiple similar elements (e.g. table cells)*/ + LV_PART_TICKS = 0x060000, /**< Ticks on scale e.g. for a chart or meter*/ + LV_PART_CURSOR = 0x070000, /**< Mark a specific place e.g. for text area's cursor or on a chart*/ + + LV_PART_CUSTOM_FIRST = 0x080000, /**< Extension point for custom widgets*/ + + LV_PART_ANY = 0x0F0000, /**< Special value can be used in some functions to target all parts*/ +}; + +typedef uint32_t lv_part_t; + +/** + * On/Off features controlling the object's behavior. + * OR-ed values are possible + */ +enum { + LV_OBJ_FLAG_HIDDEN = (1L << 0), /**< Make the object hidden. (Like it wasn't there at all)*/ + LV_OBJ_FLAG_CLICKABLE = (1L << 1), /**< Make the object clickable by the input devices*/ + LV_OBJ_FLAG_CLICK_FOCUSABLE = (1L << 2), /**< Add focused state to the object when clicked*/ + LV_OBJ_FLAG_CHECKABLE = (1L << 3), /**< Toggle checked state when the object is clicked*/ + LV_OBJ_FLAG_SCROLLABLE = (1L << 4), /**< Make the object scrollable*/ + LV_OBJ_FLAG_SCROLL_ELASTIC = (1L << 5), /**< Allow scrolling inside but with slower speed*/ + LV_OBJ_FLAG_SCROLL_MOMENTUM = (1L << 6), /**< Make the object scroll further when "thrown"*/ + LV_OBJ_FLAG_SCROLL_ONE = (1L << 7), /**< Allow scrolling only one snappable children*/ + LV_OBJ_FLAG_SCROLL_CHAIN_HOR = (1L << 8), /**< Allow propagating the horizontal scroll to a parent*/ + LV_OBJ_FLAG_SCROLL_CHAIN_VER = (1L << 9), /**< Allow propagating the vertical scroll to a parent*/ + LV_OBJ_FLAG_SCROLL_CHAIN = (LV_OBJ_FLAG_SCROLL_CHAIN_HOR | LV_OBJ_FLAG_SCROLL_CHAIN_VER), + LV_OBJ_FLAG_SCROLL_ON_FOCUS = (1L << 10), /**< Automatically scroll object to make it visible when focused*/ + LV_OBJ_FLAG_SCROLL_WITH_ARROW = (1L << 11), /**< Allow scrolling the focused object with arrow keys*/ + LV_OBJ_FLAG_SNAPPABLE = (1L << 12), /**< If scroll snap is enabled on the parent it can snap to this object*/ + LV_OBJ_FLAG_PRESS_LOCK = (1L << 13), /**< Keep the object pressed even if the press slid from the object*/ + LV_OBJ_FLAG_EVENT_BUBBLE = (1L << 14), /**< Propagate the events to the parent too*/ + LV_OBJ_FLAG_GESTURE_BUBBLE = (1L << 15), /**< Propagate the gestures to the parent*/ + LV_OBJ_FLAG_ADV_HITTEST = (1L << 16), /**< Allow performing more accurate hit (click) test. E.g. consider rounded corners.*/ + LV_OBJ_FLAG_IGNORE_LAYOUT = (1L << 17), /**< Make the object position-able by the layouts*/ + LV_OBJ_FLAG_FLOATING = (1L << 18), /**< Do not scroll the object when the parent scrolls and ignore layout*/ + LV_OBJ_FLAG_OVERFLOW_VISIBLE = (1L << 19), /**< Do not clip the children's content to the parent's boundary*/ + + LV_OBJ_FLAG_LAYOUT_1 = (1L << 23), /**< Custom flag, free to use by layouts*/ + LV_OBJ_FLAG_LAYOUT_2 = (1L << 24), /**< Custom flag, free to use by layouts*/ + + LV_OBJ_FLAG_WIDGET_1 = (1L << 25), /**< Custom flag, free to use by widget*/ + LV_OBJ_FLAG_WIDGET_2 = (1L << 26), /**< Custom flag, free to use by widget*/ + LV_OBJ_FLAG_USER_1 = (1L << 27), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_2 = (1L << 28), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_3 = (1L << 29), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_4 = (1L << 30), /**< Custom flag, free to use by user*/ + +}; + + +typedef uint32_t lv_obj_flag_t; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_obj_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_OBJ_DRAW_PART_RECTANGLE, /**< The main rectangle*/ + LV_OBJ_DRAW_PART_BORDER_POST,/**< The border if style_border_post = true*/ + LV_OBJ_DRAW_PART_SCROLLBAR, /**< The scrollbar*/ +} lv_obj_draw_part_type_t; + +#include "lv_obj_tree.h" +#include "lv_obj_pos.h" +#include "lv_obj_scroll.h" +#include "lv_obj_style.h" +#include "lv_obj_draw.h" +#include "lv_obj_class.h" +#include "lv_event.h" +#include "lv_group.h" + +/** + * Make the base object's class publicly available. + */ +extern const lv_obj_class_t lv_obj_class; + +/** + * Special, rarely used attributes. + * They are allocated automatically if any elements is set. + */ +typedef struct { + struct _lv_obj_t ** children; /**< Store the pointer of the children in an array.*/ + uint32_t child_cnt; /**< Number of children*/ + lv_group_t * group_p; + + struct _lv_event_dsc_t * event_dsc; /**< Dynamically allocated event callback and user data array*/ + lv_point_t scroll; /**< The current X/Y scroll offset*/ + + lv_coord_t ext_click_pad; /**< Extra click padding in all direction*/ + lv_coord_t ext_draw_size; /**< EXTend the size in every direction for drawing.*/ + + lv_scrollbar_mode_t scrollbar_mode : 2; /**< How to display scrollbars*/ + lv_scroll_snap_t scroll_snap_x : 2; /**< Where to align the snappable children horizontally*/ + lv_scroll_snap_t scroll_snap_y : 2; /**< Where to align the snappable children vertically*/ + lv_dir_t scroll_dir : 4; /**< The allowed scroll direction(s)*/ + uint8_t event_dsc_cnt : 6; /**< Number of event callbacks stored in `event_dsc` array*/ + uint8_t layer_type : 2; /**< Cache the layer type here. Element of @lv_intermediate_layer_type_t */ +} _lv_obj_spec_attr_t; + +typedef struct _lv_obj_t { + const lv_obj_class_t * class_p; + struct _lv_obj_t * parent; + _lv_obj_spec_attr_t * spec_attr; + _lv_obj_style_t * styles; +#if LV_USE_USER_DATA + void * user_data; +#endif + lv_area_t coords; + lv_obj_flag_t flags; + lv_state_t state; + uint16_t layout_inv : 1; + uint16_t scr_layout_inv : 1; + uint16_t skip_trans : 1; + uint16_t style_cnt : 6; + uint16_t h_layout : 1; + uint16_t w_layout : 1; +} lv_obj_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize LVGL library. + * Should be called before any other LVGL related function. + */ +void lv_init(void); + +#if LV_ENABLE_GC || !LV_MEM_CUSTOM + +/** + * Deinit the 'lv' library + * Currently only implemented when not using custom allocators, or GC is enabled. + */ +void lv_deinit(void); + +#endif + +/** + * Returns whether the 'lv' library is currently initialized + */ +bool lv_is_initialized(void); + +/** + * Create a base object (a rectangle) + * @param parent pointer to a parent object. If NULL then a screen will be created. + * @return pointer to the new object + */ +lv_obj_t * lv_obj_create(lv_obj_t * parent); + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set one or more flags + * @param obj pointer to an object + * @param f R-ed values from `lv_obj_flag_t` to set. + */ +void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f); + +/** + * Clear one or more flags + * @param obj pointer to an object + * @param f OR-ed values from `lv_obj_flag_t` to set. + */ +void lv_obj_clear_flag(lv_obj_t * obj, lv_obj_flag_t f); + + +/** + * Add one or more states to the object. The other state bits will remain unchanged. + * If specified in the styles, transition animation will be started from the previous state to the current. + * @param obj pointer to an object + * @param state the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` + */ +void lv_obj_add_state(lv_obj_t * obj, lv_state_t state); + +/** + * Remove one or more states to the object. The other state bits will remain unchanged. + * If specified in the styles, transition animation will be started from the previous state to the current. + * @param obj pointer to an object + * @param state the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` + */ +void lv_obj_clear_state(lv_obj_t * obj, lv_state_t state); + +/** + * Set the user_data field of the object + * @param obj pointer to an object + * @param user_data pointer to the new user_data. + */ +#if LV_USE_USER_DATA +static inline void lv_obj_set_user_data(lv_obj_t * obj, void * user_data) +{ + obj->user_data = user_data; +} +#endif + +/*======================= + * Getter functions + *======================*/ + +/** + * Check if a given flag or all the given flags are set on an object. + * @param obj pointer to an object + * @param f the flag(s) to check (OR-ed values can be used) + * @return true: all flags are set; false: not all flags are set + */ +bool lv_obj_has_flag(const lv_obj_t * obj, lv_obj_flag_t f); + +/** + * Check if a given flag or any of the flags are set on an object. + * @param obj pointer to an object + * @param f the flag(s) to check (OR-ed values can be used) + * @return true: at lest one flag flag is set; false: none of the flags are set + */ +bool lv_obj_has_flag_any(const lv_obj_t * obj, lv_obj_flag_t f); + +/** + * Get the state of an object + * @param obj pointer to an object + * @return the state (OR-ed values from `lv_state_t`) + */ +lv_state_t lv_obj_get_state(const lv_obj_t * obj); + +/** + * Check if the object is in a given state or not. + * @param obj pointer to an object + * @param state a state or combination of states to check + * @return true: `obj` is in `state`; false: `obj` is not in `state` + */ +bool lv_obj_has_state(const lv_obj_t * obj, lv_state_t state); + +/** + * Get the group of the object + * @param obj pointer to an object + * @return the pointer to group of the object + */ +void * lv_obj_get_group(const lv_obj_t * obj); + +/** + * Get the user_data field of the object + * @param obj pointer to an object + * @return the pointer to the user_data of the object + */ +#if LV_USE_USER_DATA +static inline void * lv_obj_get_user_data(lv_obj_t * obj) +{ + return obj->user_data; +} +#endif + +/*======================= + * Other functions + *======================*/ + +/** + * Allocate special data for an object if not allocated yet. + * @param obj pointer to an object + */ +void lv_obj_allocate_spec_attr(lv_obj_t * obj); + +/** + * Check the type of obj. + * @param obj pointer to an object + * @param class_p a class to check (e.g. `lv_slider_class`) + * @return true: `class_p` is the `obj` class. + */ +bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p); + +/** + * Check if any object has a given class (type). + * It checks the ancestor classes too. + * @param obj pointer to an object + * @param class_p a class to check (e.g. `lv_slider_class`) + * @return true: `obj` has the given class + */ +bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p); + +/** + * Get the class (type) of the object + * @param obj pointer to an object + * @return the class (type) of the object + */ +const lv_obj_class_t * lv_obj_get_class(const lv_obj_t * obj); + +/** + * Check if any object is still "alive". + * @param obj pointer to an object + * @return true: valid + */ +bool lv_obj_is_valid(const lv_obj_t * obj); + +/** + * Scale the given number of pixels (a distance or size) relative to a 160 DPI display + * considering the DPI of the `obj`'s display. + * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the + * DPI of the display. + * @param obj an object whose display's dpi should be considered + * @param n the number of pixels to scale + * @return `n x current_dpi/160` + */ +static inline lv_coord_t lv_obj_dpx(const lv_obj_t * obj, lv_coord_t n) +{ + return _LV_DPX_CALC(lv_disp_get_dpi(lv_obj_get_disp(obj)), n); +} + +/********************** + * MACROS + **********************/ + +#if LV_USE_ASSERT_OBJ +# define LV_ASSERT_OBJ(obj_p, obj_class) \ + do { \ + LV_ASSERT_MSG(obj_p != NULL, "The object is NULL"); \ + LV_ASSERT_MSG(lv_obj_has_class(obj_p, obj_class) == true, "Incompatible object type."); \ + LV_ASSERT_MSG(lv_obj_is_valid(obj_p) == true, "The object is invalid, deleted or corrupted?"); \ + } while(0) +# else +# define LV_ASSERT_OBJ(obj_p, obj_class) do{}while(0) +#endif + +#if LV_USE_LOG && LV_LOG_TRACE_OBJ_CREATE +# define LV_TRACE_OBJ_CREATE(...) LV_LOG_TRACE(__VA_ARGS__) +#else +# define LV_TRACE_OBJ_CREATE(...) +#endif + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_class.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_class.h new file mode 100644 index 00000000..01a7248b --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_class.h @@ -0,0 +1,94 @@ +/** + * @file lv_obj_class.h + * + */ + +#ifndef LV_OBJ_CLASS_H +#define LV_OBJ_CLASS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include + +/********************* + * DEFINES + *********************/ + + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_obj_class_t; +struct _lv_event_t; + +typedef enum { + LV_OBJ_CLASS_EDITABLE_INHERIT, /**< Check the base class. Must have 0 value to let zero initialized class inherit*/ + LV_OBJ_CLASS_EDITABLE_TRUE, + LV_OBJ_CLASS_EDITABLE_FALSE, +} lv_obj_class_editable_t; + +typedef enum { + LV_OBJ_CLASS_GROUP_DEF_INHERIT, /**< Check the base class. Must have 0 value to let zero initialized class inherit*/ + LV_OBJ_CLASS_GROUP_DEF_TRUE, + LV_OBJ_CLASS_GROUP_DEF_FALSE, +} lv_obj_class_group_def_t; + +typedef void (*lv_obj_class_event_cb_t)(struct _lv_obj_class_t * class_p, struct _lv_event_t * e); +/** + * Describe the common methods of every object. + * Similar to a C++ class. + */ +typedef struct _lv_obj_class_t { + const struct _lv_obj_class_t * base_class; + void (*constructor_cb)(const struct _lv_obj_class_t * class_p, struct _lv_obj_t * obj); + void (*destructor_cb)(const struct _lv_obj_class_t * class_p, struct _lv_obj_t * obj); +#if LV_USE_USER_DATA + void * user_data; +#endif + void (*event_cb)(const struct _lv_obj_class_t * class_p, + struct _lv_event_t * e); /**< Widget type specific event function*/ + lv_coord_t width_def; + lv_coord_t height_def; + uint32_t editable : 2; /**< Value from ::lv_obj_class_editable_t*/ + uint32_t group_def : 2; /**< Value from ::lv_obj_class_group_def_t*/ + uint32_t instance_size : 16; +} lv_obj_class_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an object form a class descriptor + * @param class_p pointer to a class + * @param parent pointer to an object where the new object should be created + * @return pointer to the created object + */ +struct _lv_obj_t * lv_obj_class_create_obj(const struct _lv_obj_class_t * class_p, struct _lv_obj_t * parent); + +void lv_obj_class_init_obj(struct _lv_obj_t * obj); + +void _lv_obj_destruct(struct _lv_obj_t * obj); + +bool lv_obj_is_editable(struct _lv_obj_t * obj); + +bool lv_obj_is_group_def(struct _lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_CLASS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_draw.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_draw.h new file mode 100644 index 00000000..a107e556 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_draw.h @@ -0,0 +1,172 @@ +/** + * @file lv_obj_draw.h + * + */ + +#ifndef LV_OBJ_DRAW_H +#define LV_OBJ_DRAW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_obj_class_t; + +/** Cover check results.*/ +typedef enum { + LV_COVER_RES_COVER = 0, + LV_COVER_RES_NOT_COVER = 1, + LV_COVER_RES_MASKED = 2, +} lv_cover_res_t; + +typedef enum { + LV_LAYER_TYPE_NONE, + LV_LAYER_TYPE_SIMPLE, + LV_LAYER_TYPE_TRANSFORM, +} lv_layer_type_t; + +typedef struct { + lv_draw_ctx_t * draw_ctx; /**< Draw context*/ + const struct _lv_obj_class_t * class_p; /**< The class that sent the event */ + uint32_t type; /**< The type if part being draw. Element of `lv__draw_part_type_t` */ + lv_area_t * draw_area; /**< The area of the part being drawn*/ + lv_draw_rect_dsc_t * + rect_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for rectangle-like parts*/ + lv_draw_label_dsc_t * + label_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for text-like parts*/ + lv_draw_line_dsc_t * + line_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for line-like parts*/ + lv_draw_img_dsc_t * + img_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for image-like parts*/ + lv_draw_arc_dsc_t * + arc_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for arc-like parts*/ + const lv_point_t * + p1; /**< A point calculated during drawing. E.g. a point of chart or the center of an arc.*/ + const lv_point_t * p2; /**< A point calculated during drawing. E.g. a point of chart.*/ + char * text; /**< A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis.*/ + uint32_t text_length; /**< Size of the text buffer containing null-terminated text string calculated during drawing.*/ + uint32_t part; /**< The current part for which the event is sent*/ + uint32_t id; /**< The index of the part. E.g. a button's index on button matrix or table cell index.*/ + lv_coord_t radius; /**< E.g. the radius of an arc (not the corner radius).*/ + int32_t value; /**< A value calculated during drawing. E.g. Chart's tick line value.*/ + const void * sub_part_ptr; /**< A pointer the identifies something in the part. E.g. chart series. */ +} lv_obj_draw_part_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize a rectangle draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * If an `..._opa` field is set to `LV_OPA_TRANSP` the related properties won't be initialized. + * Should be initialized with `lv_draw_rect_dsc_init(draw_dsc)`. + * @note Only the relevant fields will be set. + * E.g. if `border width == 0` the other border properties won't be evaluated. + */ +void lv_obj_init_draw_rect_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_rect_dsc_t * draw_dsc); + +/** + * Initialize a label draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * If the `opa` field is set to or the property is equal to `LV_OPA_TRANSP` the rest won't be initialized. + * Should be initialized with `lv_draw_label_dsc_init(draw_dsc)`. + */ +void lv_obj_init_draw_label_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_label_dsc_t * draw_dsc); + +/** + * Initialize an image draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * Should be initialized with `lv_draw_image_dsc_init(draw_dsc)`. + */ +void lv_obj_init_draw_img_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_img_dsc_t * draw_dsc); + + +/** + * Initialize a line draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * Should be initialized with `lv_draw_line_dsc_init(draw_dsc)`. + */ +void lv_obj_init_draw_line_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_line_dsc_t * draw_dsc); + +/** + * Initialize an arc draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * Should be initialized with `lv_draw_arc_dsc_init(draw_dsc)`. + */ +void lv_obj_init_draw_arc_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_arc_dsc_t * draw_dsc); + +/** + * Get the required extra size (around the object's part) to draw shadow, outline, value etc. + * @param obj pointer to an object + * @param part part of the object + * @return the extra size required around the object + */ +lv_coord_t lv_obj_calculate_ext_draw_size(struct _lv_obj_t * obj, uint32_t part); + +/** + * Initialize a draw descriptor used in events. + * @param dsc pointer to a descriptor. Later it should be passed as parameter to an `LV_EVENT_DRAW_PART_BEGIN/END` event. + * @param draw the current draw context. (usually returned by `lv_event_get_draw_ctx(e)`) + */ +void lv_obj_draw_dsc_init(lv_obj_draw_part_dsc_t * dsc, lv_draw_ctx_t * draw_ctx); + +/** + * Check the type obj a part draw descriptor + * @param dsc the descriptor (normally the event parameter) + * @param class_p pointer to class to which `type` is related + * @param type element of `lv__draw_part_type_t` + * @return true if ::dsc is related to ::class_p and ::type + */ +bool lv_obj_draw_part_check_type(lv_obj_draw_part_dsc_t * dsc, const struct _lv_obj_class_t * class_p, uint32_t type); + +/** + * Send a 'LV_EVENT_REFR_EXT_DRAW_SIZE' Call the ancestor's event handler to the object to refresh the value of the extended draw size. + * The result will be saved in `obj`. + * @param obj pointer to an object + */ +void lv_obj_refresh_ext_draw_size(struct _lv_obj_t * obj); + +/** + * Get the extended draw area of an object. + * @param obj pointer to an object + * @return the size extended draw area around the real coordinates + */ +lv_coord_t _lv_obj_get_ext_draw_size(const struct _lv_obj_t * obj); + + +lv_layer_type_t _lv_obj_get_layer_type(const struct _lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_DRAW_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_pos.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_pos.h new file mode 100644 index 00000000..fdc64767 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_pos.h @@ -0,0 +1,449 @@ +/** + * @file lv_obj_pos.h + * + */ + +#ifndef LV_OBJ_POS_H +#define LV_OBJ_POS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct _lv_obj_t; + +typedef void (*lv_layout_update_cb_t)(struct _lv_obj_t *, void * user_data); +typedef struct { + lv_layout_update_cb_t cb; + void * user_data; +} lv_layout_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Set the position of an object relative to the set alignment. + * @param obj pointer to an object + * @param x new x coordinate + * @param y new y coordinate + * @note With default alignment it's the distance from the top left corner + * @note E.g. LV_ALIGN_CENTER alignment it's the offset from the center of the parent + * @note The position is interpreted on the content area of the parent + * @note The values can be set in pixel or in percentage of parent size with `lv_pct(v)` + */ +void lv_obj_set_pos(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + +/** + * Set the x coordinate of an object + * @param obj pointer to an object + * @param x new x coordinate + * @note With default alignment it's the distance from the top left corner + * @note E.g. LV_ALIGN_CENTER alignment it's the offset from the center of the parent + * @note The position is interpreted on the content area of the parent + * @note The values can be set in pixel or in percentage of parent size with `lv_pct(v)` + */ +void lv_obj_set_x(struct _lv_obj_t * obj, lv_coord_t x); + +/** + * Set the y coordinate of an object + * @param obj pointer to an object + * @param y new y coordinate + * @note With default alignment it's the distance from the top left corner + * @note E.g. LV_ALIGN_CENTER alignment it's the offset from the center of the parent + * @note The position is interpreted on the content area of the parent + * @note The values can be set in pixel or in percentage of parent size with `lv_pct(v)` + */ +void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y); + +/** + * Set the size of an object. + * @param obj pointer to an object + * @param w the new width + * @param h the new height + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * LV_SIZE_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range + */ +void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h); + +/** + * Recalculate the size of the object + * @param obj pointer to an object + * @return true: the size has been changed + */ +bool lv_obj_refr_size(struct _lv_obj_t * obj); + +/** + * Set the width of an object + * @param obj pointer to an object + * @param w the new width + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * lv_pct(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range + */ +void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w); + +/** + * Set the height of an object + * @param obj pointer to an object + * @param h the new height + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * lv_pct(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range + */ +void lv_obj_set_height(struct _lv_obj_t * obj, lv_coord_t h); + +/** + * Set the width reduced by the left and right padding and the border width. + * @param obj pointer to an object + * @param w the width without paddings in pixels + */ +void lv_obj_set_content_width(struct _lv_obj_t * obj, lv_coord_t w); + +/** + * Set the height reduced by the top and bottom padding and the border width. + * @param obj pointer to an object + * @param h the height without paddings in pixels + */ +void lv_obj_set_content_height(struct _lv_obj_t * obj, lv_coord_t h); + +/** + * Set a layout for an object + * @param obj pointer to an object + * @param layout pointer to a layout descriptor to set + */ +void lv_obj_set_layout(struct _lv_obj_t * obj, uint32_t layout); + +/** + * Test whether the and object is positioned by a layout or not + * @param obj pointer to an object to test + * @return true: positioned by a layout; false: not positioned by a layout + */ +bool lv_obj_is_layout_positioned(const struct _lv_obj_t * obj); + +/** + * Mark the object for layout update. + * @param obj pointer to an object whose children needs to be updated + */ +void lv_obj_mark_layout_as_dirty(struct _lv_obj_t * obj); + +/** + * Update the layout of an object. + * @param obj pointer to an object whose children needs to be updated + */ +void lv_obj_update_layout(const struct _lv_obj_t * obj); + +/** + * Register a new layout + * @param cb the layout update callback + * @param user_data custom data that will be passed to `cb` + * @return the ID of the new layout + */ +uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data); + +/** + * Change the alignment of an object. + * @param obj pointer to an object to align + * @param align type of alignment (see 'lv_align_t' enum) `LV_ALIGN_OUT_...` can't be used. + */ +void lv_obj_set_align(struct _lv_obj_t * obj, lv_align_t align); + +/** + * Change the alignment of an object and set new coordinates. + * Equivalent to: + * lv_obj_set_align(obj, align); + * lv_obj_set_pos(obj, x_ofs, y_ofs); + * @param obj pointer to an object to align + * @param align type of alignment (see 'lv_align_t' enum) `LV_ALIGN_OUT_...` can't be used. + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment + */ +void lv_obj_align(struct _lv_obj_t * obj, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs); + +/** + * Align an object to an other object. + * @param obj pointer to an object to align + * @param base pointer to an other object (if NULL `obj`s parent is used). 'obj' will be aligned to it. + * @param align type of alignment (see 'lv_align_t' enum) + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment + * @note if the position or size of `base` changes `obj` needs to be aligned manually again + */ +void lv_obj_align_to(struct _lv_obj_t * obj, const struct _lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, + lv_coord_t y_ofs); + +/** + * Align an object to the center on its parent. + * @param obj pointer to an object to align + * @note if the parent size changes `obj` needs to be aligned manually again + */ +static inline void lv_obj_center(struct _lv_obj_t * obj) +{ + lv_obj_align(obj, LV_ALIGN_CENTER, 0, 0); +} + + +/** + * Copy the coordinates of an object to an area + * @param obj pointer to an object + * @param coords pointer to an area to store the coordinates + */ +void lv_obj_get_coords(const struct _lv_obj_t * obj, lv_area_t * coords); + +/** + * Get the x coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the left side of its parent plus the parent's left padding + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @note Zero return value means the object is on the left padding of the parent, and not on the left edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_x(const struct _lv_obj_t * obj); + +/** + * Get the x2 coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the right side of its parent plus the parent's right padding + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @note Zero return value means the object is on the right padding of the parent, and not on the right edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_x2(const struct _lv_obj_t * obj); + +/** + * Get the y coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the top side of its parent plus the parent's top padding + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @note Zero return value means the object is on the top padding of the parent, and not on the top edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_y(const struct _lv_obj_t * obj); + +/** + * Get the y2 coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the bottom side of its parent plus the parent's bottom padding + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @note Zero return value means the object is on the bottom padding of the parent, and not on the bottom edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_y2(const struct _lv_obj_t * obj); + +/** + * Get the actually set x coordinate of object, i.e. the offset form the set alignment + * @param obj pointer to an object + * @return the set x coordinate + */ +lv_coord_t lv_obj_get_x_aligned(const struct _lv_obj_t * obj); + +/** + * Get the actually set y coordinate of object, i.e. the offset form the set alignment + * @param obj pointer to an object + * @return the set y coordinate + */ +lv_coord_t lv_obj_get_y_aligned(const struct _lv_obj_t * obj); + +/** + * Get the width of an object + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @return the width in pixels + */ +lv_coord_t lv_obj_get_width(const struct _lv_obj_t * obj); + +/** + * Get the height of an object + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @return the height in pixels + */ +lv_coord_t lv_obj_get_height(const struct _lv_obj_t * obj); + +/** + * Get the width reduced by the left and right padding and the border width. + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @return the width which still fits into its parent without causing overflow (making the parent scrollable) + */ +lv_coord_t lv_obj_get_content_width(const struct _lv_obj_t * obj); + +/** + * Get the height reduced by the top and bottom padding and the border width. + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @return the height which still fits into the parent without causing overflow (making the parent scrollable) + */ +lv_coord_t lv_obj_get_content_height(const struct _lv_obj_t * obj); + +/** + * Get the area reduced by the paddings and the border width. + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @param area the area which still fits into the parent without causing overflow (making the parent scrollable) + */ +void lv_obj_get_content_coords(const struct _lv_obj_t * obj, lv_area_t * area); + +/** + * Get the width occupied by the "parts" of the widget. E.g. the width of all columns of a table. + * @param obj pointer to an objects + * @return the width of the virtually drawn content + * @note This size independent from the real size of the widget. + * It just tells how large the internal ("virtual") content is. + */ +lv_coord_t lv_obj_get_self_width(const struct _lv_obj_t * obj); + +/** + * Get the height occupied by the "parts" of the widget. E.g. the height of all rows of a table. + * @param obj pointer to an objects + * @return the width of the virtually drawn content + * @note This size independent from the real size of the widget. + * It just tells how large the internal ("virtual") content is. + */ +lv_coord_t lv_obj_get_self_height(const struct _lv_obj_t * obj); + +/** + * Handle if the size of the internal ("virtual") content of an object has changed. + * @param obj pointer to an object + * @return false: nothing happened; true: refresh happened + */ +bool lv_obj_refresh_self_size(struct _lv_obj_t * obj); + +void lv_obj_refr_pos(struct _lv_obj_t * obj); + +void lv_obj_move_to(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + + +void lv_obj_move_children_by(struct _lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff, bool ignore_floating); + +/** + * Transform a point using the angle and zoom style properties of an object + * @param obj pointer to an object whose style properties should be used + * @param p a point to transform, the result will be written back here too + * @param recursive consider the transformation properties of the parents too + * @param inv do the inverse of the transformation (-angle and 1/zoom) + */ +void lv_obj_transform_point(const struct _lv_obj_t * obj, lv_point_t * p, bool recursive, bool inv); + +/** + * Transform an area using the angle and zoom style properties of an object + * @param obj pointer to an object whose style properties should be used + * @param area an area to transform, the result will be written back here too + * @param recursive consider the transformation properties of the parents too + * @param inv do the inverse of the transformation (-angle and 1/zoom) + */ +void lv_obj_get_transformed_area(const struct _lv_obj_t * obj, lv_area_t * area, bool recursive, bool inv); + +/** + * Mark an area of an object as invalid. + * The area will be truncated to the object's area and marked for redraw. + * @param obj pointer to an object + * @param area the area to redraw + */ +void lv_obj_invalidate_area(const struct _lv_obj_t * obj, const lv_area_t * area); + +/** + * Mark the object as invalid to redrawn its area + * @param obj pointer to an object + */ +void lv_obj_invalidate(const struct _lv_obj_t * obj); + +/** + * Tell whether an area of an object is visible (even partially) now or not + * @param obj pointer to an object + * @param area the are to check. The visible part of the area will be written back here. + * @return true visible; false not visible (hidden, out of parent, on other screen, etc) + */ +bool lv_obj_area_is_visible(const struct _lv_obj_t * obj, lv_area_t * area); + +/** + * Tell whether an object is visible (even partially) now or not + * @param obj pointer to an object + * @return true: visible; false not visible (hidden, out of parent, on other screen, etc) + */ +bool lv_obj_is_visible(const struct _lv_obj_t * obj); + +/** + * Set the size of an extended clickable area + * @param obj pointer to an object + * @param size extended clickable area in all 4 directions [px] + */ +void lv_obj_set_ext_click_area(struct _lv_obj_t * obj, lv_coord_t size); + +/** + * Get the an area where to object can be clicked. + * It's the object's normal area plus the extended click area. + * @param obj pointer to an object + * @param area store the result area here + */ +void lv_obj_get_click_area(const struct _lv_obj_t * obj, lv_area_t * area); + +/** + * Hit-test an object given a particular point in screen space. + * @param obj object to hit-test + * @param point screen-space point (absolute coordinate) + * @return true: if the object is considered under the point + */ +bool lv_obj_hit_test(struct _lv_obj_t * obj, const lv_point_t * point); + +/** + * Clamp a width between min and max width. If the min/max width is in percentage value use the ref_width + * @param width width to clamp + * @param min_width the minimal width + * @param max_width the maximal width + * @param ref_width the reference width used when min/max width is in percentage + * @return the clamped width + */ +lv_coord_t lv_clamp_width(lv_coord_t width, lv_coord_t min_width, lv_coord_t max_width, lv_coord_t ref_width); + +/** + * Clamp a height between min and max height. If the min/max height is in percentage value use the ref_height + * @param height height to clamp + * @param min_height the minimal height + * @param max_height the maximal height + * @param ref_height the reference height used when min/max height is in percentage + * @return the clamped height + */ +lv_coord_t lv_clamp_height(lv_coord_t height, lv_coord_t min_height, lv_coord_t max_height, lv_coord_t ref_height); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_POS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_scroll.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_scroll.h new file mode 100644 index 00000000..3717dec4 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_scroll.h @@ -0,0 +1,307 @@ +/** + * @file lv_obj_scroll.h + * + */ + +#ifndef LV_OBJ_SCROLL_H +#define LV_OBJ_SCROLL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_anim.h" +#include "liblvgl/misc/lv_types.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Can't include lv_obj.h because it includes this header file*/ +struct _lv_obj_t; + +/** Scrollbar modes: shows when should the scrollbars be visible*/ +enum { + LV_SCROLLBAR_MODE_OFF, /**< Never show scrollbars*/ + LV_SCROLLBAR_MODE_ON, /**< Always show scrollbars*/ + LV_SCROLLBAR_MODE_ACTIVE, /**< Show scroll bars when object is being scrolled*/ + LV_SCROLLBAR_MODE_AUTO, /**< Show scroll bars when the content is large enough to be scrolled*/ +}; +typedef uint8_t lv_scrollbar_mode_t; + + +/** Scroll span align options. Tells where to align the snappable children when scroll stops.*/ +enum { + LV_SCROLL_SNAP_NONE, /**< Do not align, leave where it is*/ + LV_SCROLL_SNAP_START, /**< Align to the left/top*/ + LV_SCROLL_SNAP_END, /**< Align to the right/bottom*/ + LV_SCROLL_SNAP_CENTER /**< Align to the center*/ +}; +typedef uint8_t lv_scroll_snap_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*===================== + * Setter functions + *====================*/ + +/** + * Set how the scrollbars should behave. + * @param obj pointer to an object + * @param mode LV_SCROLL_MODE_ON/OFF/AUTO/ACTIVE + */ +void lv_obj_set_scrollbar_mode(struct _lv_obj_t * obj, lv_scrollbar_mode_t mode); + +/** + * Set the object in which directions can be scrolled + * @param obj pointer to an object + * @param dir the allow scroll directions. An element or OR-ed values of `lv_dir_t` + */ +void lv_obj_set_scroll_dir(struct _lv_obj_t * obj, lv_dir_t dir); + +/** + * Set where to snap the children when scrolling ends horizontally + * @param obj pointer to an object + * @param align the snap align to set from `lv_scroll_snap_t` + */ +void lv_obj_set_scroll_snap_x(struct _lv_obj_t * obj, lv_scroll_snap_t align); + +/** + * Set where to snap the children when scrolling ends vertically + * @param obj pointer to an object + * @param align the snap align to set from `lv_scroll_snap_t` + */ +void lv_obj_set_scroll_snap_y(struct _lv_obj_t * obj, lv_scroll_snap_t align); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current scroll mode (when to hide the scrollbars) + * @param obj pointer to an object + * @return the current scroll mode from `lv_scrollbar_mode_t` + */ +lv_scrollbar_mode_t lv_obj_get_scrollbar_mode(const struct _lv_obj_t * obj); + +/** + * Get the object in which directions can be scrolled + * @param obj pointer to an object + * @param dir the allow scroll directions. An element or OR-ed values of `lv_dir_t` + */ +lv_dir_t lv_obj_get_scroll_dir(const struct _lv_obj_t * obj); + +/** + * Get where to snap the children when scrolling ends horizontally + * @param obj pointer to an object + * @return the current snap align from `lv_scroll_snap_t` + */ +lv_scroll_snap_t lv_obj_get_scroll_snap_x(const struct _lv_obj_t * obj); + +/** + * Get where to snap the children when scrolling ends vertically + * @param obj pointer to an object + * @return the current snap align from `lv_scroll_snap_t` + */ +lv_scroll_snap_t lv_obj_get_scroll_snap_y(const struct _lv_obj_t * obj); + +/** + * Get current X scroll position. + * @param obj pointer to an object + * @return the current scroll position from the left edge. + * If the object is not scrolled return 0 + * If scrolled return > 0 + * If scrolled in (elastic scroll) return < 0 + */ +lv_coord_t lv_obj_get_scroll_x(const struct _lv_obj_t * obj); + +/** + * Get current Y scroll position. + * @param obj pointer to an object + * @return the current scroll position from the top edge. + * If the object is not scrolled return 0 + * If scrolled return > 0 + * If scrolled inside return < 0 + */ +lv_coord_t lv_obj_get_scroll_y(const struct _lv_obj_t * obj); + +/** + * Return the height of the area above the object. + * That is the number of pixels the object can be scrolled down. + * Normally positive but can be negative when scrolled inside. + * @param obj pointer to an object + * @return the scrollable area above the object in pixels + */ +lv_coord_t lv_obj_get_scroll_top(struct _lv_obj_t * obj); + +/** + * Return the height of the area below the object. + * That is the number of pixels the object can be scrolled down. + * Normally positive but can be negative when scrolled inside. + * @param obj pointer to an object + * @return the scrollable area below the object in pixels + */ +lv_coord_t lv_obj_get_scroll_bottom(struct _lv_obj_t * obj); + +/** + * Return the width of the area on the left the object. + * That is the number of pixels the object can be scrolled down. + * Normally positive but can be negative when scrolled inside. + * @param obj pointer to an object + * @return the scrollable area on the left the object in pixels + */ +lv_coord_t lv_obj_get_scroll_left(struct _lv_obj_t * obj); + +/** + * Return the width of the area on the right the object. + * That is the number of pixels the object can be scrolled down. + * Normally positive but can be negative when scrolled inside. + * @param obj pointer to an object + * @return the scrollable area on the right the object in pixels + */ +lv_coord_t lv_obj_get_scroll_right(struct _lv_obj_t * obj); + +/** + * Get the X and Y coordinates where the scrolling will end for this object if a scrolling animation is in progress. + * If no scrolling animation, give the current `x` or `y` scroll position. + * @param obj pointer to an object + * @param end pointer to store the result + */ +void lv_obj_get_scroll_end(struct _lv_obj_t * obj, lv_point_t * end); + +/*===================== + * Other functions + *====================*/ + +/** + * Scroll by a given amount of pixels + * @param obj pointer to an object to scroll + * @param dx pixels to scroll horizontally + * @param dy pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * @note > 0 value means scroll right/bottom (show the more content on the right/bottom) + * @note e.g. dy = -20 means scroll down 20 px + */ +void lv_obj_scroll_by(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim_en); + +/** + * Scroll by a given amount of pixels. + * `dx` and `dy` will be limited internally to allow scrolling only on the content area. + * @param obj pointer to an object to scroll + * @param dx pixels to scroll horizontally + * @param dy pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * @note e.g. dy = -20 means scroll down 20 px + */ +void lv_obj_scroll_by_bounded(struct _lv_obj_t * obj, lv_coord_t dx, lv_coord_t dy, lv_anim_enable_t anim_en); + +/** + * Scroll to a given coordinate on an object. + * `x` and `y` will be limited internally to allow scrolling only on the content area. + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param y pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim_en); + +/** + * Scroll to a given X coordinate on an object. + * `x` will be limited internally to allow scrolling only on the content area. + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_x(struct _lv_obj_t * obj, lv_coord_t x, lv_anim_enable_t anim_en); + +/** + * Scroll to a given Y coordinate on an object + * `y` will be limited internally to allow scrolling only on the content area. + * @param obj pointer to an object to scroll + * @param y pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_y(struct _lv_obj_t * obj, lv_coord_t y, lv_anim_enable_t anim_en); + +/** + * Scroll to an object until it becomes visible on its parent + * @param obj pointer to an object to scroll into view + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_view(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + +/** + * Scroll to an object until it becomes visible on its parent. + * Do the same on the parent's parent, and so on. + * Therefore the object will be scrolled into view even it has nested scrollable parents + * @param obj pointer to an object to scroll into view + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_view_recursive(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + + +/** + * Low level function to scroll by given x and y coordinates. + * `LV_EVENT_SCROLL` is sent. + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param y pixels to scroll vertically + * @return `LV_RES_INV`: to object was deleted in `LV_EVENT_SCROLL`; + * `LV_RES_OK`: if the object is still valid + */ +lv_res_t _lv_obj_scroll_by_raw(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + +/** + * Tell whether an object is being scrolled or not at this moment + * @param obj pointer to an object + * @return true: `obj` is being scrolled + */ +bool lv_obj_is_scrolling(const struct _lv_obj_t * obj); + +/** + * Check the children of `obj` and scroll `obj` to fulfill the scroll_snap settings + * @param obj an object whose children needs to checked and snapped + * @param anim_en LV_ANIM_ON/OFF + */ +void lv_obj_update_snap(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + +/** + * Get the area of the scrollbars + * @param obj pointer to an object + * @param hor pointer to store the area of the horizontal scrollbar + * @param ver pointer to store the area of the vertical scrollbar + */ +void lv_obj_get_scrollbar_area(struct _lv_obj_t * obj, lv_area_t * hor, lv_area_t * ver); + +/** + * Invalidate the area of the scrollbars + * @param obj pointer to an object + */ +void lv_obj_scrollbar_invalidate(struct _lv_obj_t * obj); + +/** + * Checked if the content is scrolled "in" and adjusts it to a normal position. + * @param obj pointer to an object + * @param anim_en LV_ANIM_ON/OFF + */ +void lv_obj_readjust_scroll(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_SCROLL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_style.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_style.h new file mode 100644 index 00000000..18e530a6 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_style.h @@ -0,0 +1,248 @@ +/** + * @file lv_obj_style.h + * + */ + +#ifndef LV_OBJ_STYLE_H +#define LV_OBJ_STYLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include +#include "liblvgl/misc/lv_bidi.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Can't include lv_obj.h because it includes this header file*/ +struct _lv_obj_t; + +typedef enum { + _LV_STYLE_STATE_CMP_SAME, /*The style properties in the 2 states are identical*/ + _LV_STYLE_STATE_CMP_DIFF_REDRAW, /*The differences can be shown with a simple redraw*/ + _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD, /*The differences can be shown with a simple redraw*/ + _LV_STYLE_STATE_CMP_DIFF_LAYOUT, /*The differences can be shown with a simple redraw*/ +} _lv_style_state_cmp_t; + +typedef uint32_t lv_style_selector_t; + +typedef struct { + lv_style_t * style; + uint32_t selector : 24; + uint32_t is_local : 1; + uint32_t is_trans : 1; +} _lv_obj_style_t; + +typedef struct { + uint16_t time; + uint16_t delay; + lv_style_selector_t selector; + lv_style_prop_t prop; + lv_anim_path_cb_t path_cb; +#if LV_USE_USER_DATA + void * user_data; +#endif +} _lv_obj_style_transition_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the object related style manager module. + * Called by LVGL in `lv_init()` + */ +void _lv_obj_style_init(void); + +/** + * Add a style to an object. + * @param obj pointer to an object + * @param style pointer to a style to add + * @param selector OR-ed value of parts and state to which the style should be added + * @example lv_obj_add_style(btn, &style_btn, 0); //Default button style + * @example lv_obj_add_style(btn, &btn_red, LV_STATE_PRESSED); //Overwrite only some colors to red when pressed + */ +void lv_obj_add_style(struct _lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector); + +/** + * Add a style to an object. + * @param obj pointer to an object + * @param style pointer to a style to remove. Can be NULL to check only the selector + * @param selector OR-ed values of states and a part to remove only styles with matching selectors. LV_STATE_ANY and LV_PART_ANY can be used + * @example lv_obj_remove_style(obj, &style, LV_PART_ANY | LV_STATE_ANY); //Remove a specific style + * @example lv_obj_remove_style(obj, NULL, LV_PART_MAIN | LV_STATE_ANY); //Remove all styles from the main part + * @example lv_obj_remove_style(obj, NULL, LV_PART_ANY | LV_STATE_ANY); //Remove all styles + */ +void lv_obj_remove_style(struct _lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector); + +/** + * Remove all styles from an object + * @param obj pointer to an object + */ +static inline void lv_obj_remove_style_all(struct _lv_obj_t * obj) +{ + lv_obj_remove_style(obj, NULL, LV_PART_ANY | LV_STATE_ANY); +} + +/** + * Notify all object if a style is modified + * @param style pointer to a style. Only the objects with this style will be notified + * (NULL to notify all objects) + */ +void lv_obj_report_style_change(lv_style_t * style); + +/** + * Notify an object and its children about its style is modified. + * @param obj pointer to an object + * @param part the part whose style was changed. E.g. `LV_PART_ANY`, `LV_PART_MAIN` + * @param prop `LV_STYLE_PROP_ANY` or an `LV_STYLE_...` property. + * It is used to optimize what needs to be refreshed. + * `LV_STYLE_PROP_INV` to perform only a style cache update + */ +void lv_obj_refresh_style(struct _lv_obj_t * obj, lv_part_t part, lv_style_prop_t prop); + +/** + * Enable or disable automatic style refreshing when a new style is added/removed to/from an object + * or any other style change happens. + * @param en true: enable refreshing; false: disable refreshing + */ +void lv_obj_enable_style_refresh(bool en); + +/** + * Get the value of a style property. The current state of the object will be considered. + * Inherited properties will be inherited. + * If a property is not set a default value will be returned. + * @param obj pointer to an object + * @param part a part from which the property should be get + * @param prop the property to get + * @return the value of the property. + * Should be read from the correct field of the `lv_style_value_t` according to the type of the property. + */ +lv_style_value_t lv_obj_get_style_prop(const struct _lv_obj_t * obj, lv_part_t part, lv_style_prop_t prop); + +/** + * Set local style property on an object's part and state. + * @param obj pointer to an object + * @param prop the property + * @param value value of the property. The correct element should be set according to the type of the property + * @param selector OR-ed value of parts and state for which the style should be set + */ +void lv_obj_set_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t value, + lv_style_selector_t selector); + +void lv_obj_set_local_style_prop_meta(struct _lv_obj_t * obj, lv_style_prop_t prop, uint16_t meta, + lv_style_selector_t selector); + +lv_style_res_t lv_obj_get_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t * value, + lv_style_selector_t selector); + +/** + * Remove a local style property from a part of an object with a given state. + * @param obj pointer to an object + * @param prop a style property to remove. + * @param selector OR-ed value of parts and state for which the style should be removed + * @return true the property was found and removed; false: the property was not found + */ +bool lv_obj_remove_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_selector_t selector); + +/** + * Used internally for color filtering + */ +lv_style_value_t _lv_obj_style_apply_color_filter(const struct _lv_obj_t * obj, uint32_t part, lv_style_value_t v); + +/** + * Used internally to create a style transition + * @param obj + * @param part + * @param prev_state + * @param new_state + * @param tr + */ +void _lv_obj_style_create_transition(struct _lv_obj_t * obj, lv_part_t part, lv_state_t prev_state, + lv_state_t new_state, const _lv_obj_style_transition_dsc_t * tr); + +/** + * Used internally to compare the appearance of an object in 2 states + * @param obj + * @param state1 + * @param state2 + * @return + */ +_lv_style_state_cmp_t _lv_obj_style_state_compare(struct _lv_obj_t * obj, lv_state_t state1, lv_state_t state2); + +/** + * Fade in an an object and all its children. + * @param obj the object to fade in + * @param time time of fade + * @param delay delay to start the animation + */ +void lv_obj_fade_in(struct _lv_obj_t * obj, uint32_t time, uint32_t delay); + +/** + * Fade out an an object and all its children. + * @param obj the object to fade out + * @param time time of fade + * @param delay delay to start the animation + */ +void lv_obj_fade_out(struct _lv_obj_t * obj, uint32_t time, uint32_t delay); + +lv_state_t lv_obj_style_get_selector_state(lv_style_selector_t selector); + +lv_part_t lv_obj_style_get_selector_part(lv_style_selector_t selector); + +#include "lv_obj_style_gen.h" + +static inline void lv_obj_set_style_pad_all(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_pad_left(obj, value, selector); + lv_obj_set_style_pad_right(obj, value, selector); + lv_obj_set_style_pad_top(obj, value, selector); + lv_obj_set_style_pad_bottom(obj, value, selector); +} + +static inline void lv_obj_set_style_pad_hor(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_pad_left(obj, value, selector); + lv_obj_set_style_pad_right(obj, value, selector); +} + +static inline void lv_obj_set_style_pad_ver(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_pad_top(obj, value, selector); + lv_obj_set_style_pad_bottom(obj, value, selector); +} + +static inline void lv_obj_set_style_pad_gap(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_pad_row(obj, value, selector); + lv_obj_set_style_pad_column(obj, value, selector); +} + +static inline void lv_obj_set_style_size(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_width(obj, value, selector); + lv_obj_set_style_height(obj, value, selector); +} + +lv_text_align_t lv_obj_calculate_style_text_align(const struct _lv_obj_t * obj, lv_part_t part, const char * txt); + + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_STYLE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_style_gen.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_style_gen.h new file mode 100644 index 00000000..576927d9 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_style_gen.h @@ -0,0 +1,648 @@ +static inline lv_coord_t lv_obj_get_style_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_min_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_MIN_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_max_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_MAX_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_min_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_MIN_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_max_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_MAX_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_Y); + return (lv_coord_t)v.num; +} + +static inline lv_align_t lv_obj_get_style_align(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ALIGN); + return (lv_align_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_translate_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_translate_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_Y); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_zoom(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_ZOOM); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_angle(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_ANGLE); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_pivot_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_PIVOT_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_pivot_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_PIVOT_Y); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_top(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_TOP); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_bottom(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_BOTTOM); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_left(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_LEFT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_right(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_RIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_row(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_ROW); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_column(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_COLUMN); + return (lv_coord_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_bg_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_bg_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_BG_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_bg_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_bg_grad_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_bg_grad_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD_COLOR)); + return v.color; +} + +static inline lv_grad_dir_t lv_obj_get_style_bg_grad_dir(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD_DIR); + return (lv_grad_dir_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_bg_main_stop(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_MAIN_STOP); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_bg_grad_stop(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD_STOP); + return (lv_coord_t)v.num; +} + +static inline const lv_grad_dsc_t * lv_obj_get_style_bg_grad(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD); + return (const lv_grad_dsc_t *)v.ptr; +} + +static inline lv_dither_mode_t lv_obj_get_style_bg_dither_mode(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_DITHER_MODE); + return (lv_dither_mode_t)v.num; +} + +static inline const void * lv_obj_get_style_bg_img_src(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_SRC); + return (const void *)v.ptr; +} + +static inline lv_opa_t lv_obj_get_style_bg_img_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_bg_img_recolor(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_RECOLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_bg_img_recolor_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_RECOLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_bg_img_recolor_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_RECOLOR_OPA); + return (lv_opa_t)v.num; +} + +static inline bool lv_obj_get_style_bg_img_tiled(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_TILED); + return (bool)v.num; +} + +static inline lv_color_t lv_obj_get_style_border_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_border_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_border_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_border_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_border_side_t lv_obj_get_style_border_side(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_SIDE); + return (lv_border_side_t)v.num; +} + +static inline bool lv_obj_get_style_border_post(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_POST); + return (bool)v.num; +} + +static inline lv_coord_t lv_obj_get_style_outline_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_outline_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_outline_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_outline_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_outline_pad(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_PAD); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_shadow_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_shadow_ofs_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_OFS_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_shadow_ofs_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_OFS_Y); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_shadow_spread(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_SPREAD); + return (lv_coord_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_shadow_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_shadow_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_shadow_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_opa_t lv_obj_get_style_img_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_IMG_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_img_recolor(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_IMG_RECOLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_img_recolor_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_IMG_RECOLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_img_recolor_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_IMG_RECOLOR_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_line_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_line_dash_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_DASH_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_line_dash_gap(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_DASH_GAP); + return (lv_coord_t)v.num; +} + +static inline bool lv_obj_get_style_line_rounded(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_ROUNDED); + return (bool)v.num; +} + +static inline lv_color_t lv_obj_get_style_line_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_line_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_line_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_arc_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_WIDTH); + return (lv_coord_t)v.num; +} + +static inline bool lv_obj_get_style_arc_rounded(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_ROUNDED); + return (bool)v.num; +} + +static inline lv_color_t lv_obj_get_style_arc_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_arc_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_arc_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_OPA); + return (lv_opa_t)v.num; +} + +static inline const void * lv_obj_get_style_arc_img_src(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_IMG_SRC); + return (const void *)v.ptr; +} + +static inline lv_color_t lv_obj_get_style_text_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_text_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_text_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_OPA); + return (lv_opa_t)v.num; +} + +static inline const lv_font_t * lv_obj_get_style_text_font(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_FONT); + return (const lv_font_t *)v.ptr; +} + +static inline lv_coord_t lv_obj_get_style_text_letter_space(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_LETTER_SPACE); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_text_line_space(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_LINE_SPACE); + return (lv_coord_t)v.num; +} + +static inline lv_text_decor_t lv_obj_get_style_text_decor(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_DECOR); + return (lv_text_decor_t)v.num; +} + +static inline lv_text_align_t lv_obj_get_style_text_align(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_ALIGN); + return (lv_text_align_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_radius(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_RADIUS); + return (lv_coord_t)v.num; +} + +static inline bool lv_obj_get_style_clip_corner(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CLIP_CORNER); + return (bool)v.num; +} + +static inline lv_opa_t lv_obj_get_style_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OPA); + return (lv_opa_t)v.num; +} + +static inline const lv_color_filter_dsc_t * lv_obj_get_style_color_filter_dsc(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_COLOR_FILTER_DSC); + return (const lv_color_filter_dsc_t *)v.ptr; +} + +static inline lv_opa_t lv_obj_get_style_color_filter_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_COLOR_FILTER_OPA); + return (lv_opa_t)v.num; +} + +static inline const lv_anim_t * lv_obj_get_style_anim(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ANIM); + return (const lv_anim_t *)v.ptr; +} + +static inline uint32_t lv_obj_get_style_anim_time(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ANIM_TIME); + return (uint32_t)v.num; +} + +static inline uint32_t lv_obj_get_style_anim_speed(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ANIM_SPEED); + return (uint32_t)v.num; +} + +static inline const lv_style_transition_dsc_t * lv_obj_get_style_transition(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION); + return (const lv_style_transition_dsc_t *)v.ptr; +} + +static inline lv_blend_mode_t lv_obj_get_style_blend_mode(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BLEND_MODE); + return (lv_blend_mode_t)v.num; +} + +static inline uint16_t lv_obj_get_style_layout(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LAYOUT); + return (uint16_t)v.num; +} + +static inline lv_base_dir_t lv_obj_get_style_base_dir(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BASE_DIR); + return (lv_base_dir_t)v.num; +} + +void lv_obj_set_style_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_min_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_max_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_min_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_max_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_align(struct _lv_obj_t * obj, lv_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_translate_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_translate_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_zoom(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_angle(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_pivot_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_pivot_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_top(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_bottom(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_left(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_right(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_row(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_column(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_grad_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_grad_dir(struct _lv_obj_t * obj, lv_grad_dir_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_main_stop(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_grad_stop(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_grad(struct _lv_obj_t * obj, const lv_grad_dsc_t * value, lv_style_selector_t selector); +void lv_obj_set_style_bg_dither_mode(struct _lv_obj_t * obj, lv_dither_mode_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_src(struct _lv_obj_t * obj, const void * value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_recolor(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_recolor_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_tiled(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_border_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_border_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_border_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_border_side(struct _lv_obj_t * obj, lv_border_side_t value, lv_style_selector_t selector); +void lv_obj_set_style_border_post(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_outline_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_outline_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_outline_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_outline_pad(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_ofs_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_ofs_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_spread(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_img_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_img_recolor(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_img_recolor_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_dash_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_dash_gap(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_rounded(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_line_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_arc_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_arc_rounded(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_arc_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_arc_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_arc_img_src(struct _lv_obj_t * obj, const void * value, lv_style_selector_t selector); +void lv_obj_set_style_text_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_font(struct _lv_obj_t * obj, const lv_font_t * value, lv_style_selector_t selector); +void lv_obj_set_style_text_letter_space(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_line_space(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_decor(struct _lv_obj_t * obj, lv_text_decor_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_align(struct _lv_obj_t * obj, lv_text_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_radius(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_clip_corner(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value, lv_style_selector_t selector); +void lv_obj_set_style_color_filter_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_anim(struct _lv_obj_t * obj, const lv_anim_t * value, lv_style_selector_t selector); +void lv_obj_set_style_anim_time(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector); +void lv_obj_set_style_anim_speed(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector); +void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, lv_style_selector_t selector); +void lv_obj_set_style_blend_mode(struct _lv_obj_t * obj, lv_blend_mode_t value, lv_style_selector_t selector); +void lv_obj_set_style_layout(struct _lv_obj_t * obj, uint16_t value, lv_style_selector_t selector); +void lv_obj_set_style_base_dir(struct _lv_obj_t * obj, lv_base_dir_t value, lv_style_selector_t selector); diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_tree.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_tree.h new file mode 100644 index 00000000..bee9e160 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_obj_tree.h @@ -0,0 +1,172 @@ +/** + * @file struct _lv_obj_tree.h + * + */ + +#ifndef LV_OBJ_TREE_H +#define LV_OBJ_TREE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include + +/********************* + * DEFINES + *********************/ + + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_obj_class_t; + +typedef enum { + LV_OBJ_TREE_WALK_NEXT, + LV_OBJ_TREE_WALK_SKIP_CHILDREN, + LV_OBJ_TREE_WALK_END, +} lv_obj_tree_walk_res_t; + +typedef lv_obj_tree_walk_res_t (*lv_obj_tree_walk_cb_t)(struct _lv_obj_t *, void *); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Delete an object and all of its children. + * Also remove the objects from their group and remove all animations (if any). + * Send `LV_EVENT_DELETED` to deleted objects. + * @param obj pointer to an object + */ +void lv_obj_del(struct _lv_obj_t * obj); + +/** + * Delete all children of an object. + * Also remove the objects from their group and remove all animations (if any). + * Send `LV_EVENT_DELETED` to deleted objects. + * @param obj pointer to an object + */ +void lv_obj_clean(struct _lv_obj_t * obj); + +/** + * Delete an object after some delay + * @param obj pointer to an object + * @param delay_ms time to wait before delete in milliseconds + */ +void lv_obj_del_delayed(struct _lv_obj_t * obj, uint32_t delay_ms); + +/** + * A function to be easily used in animation ready callback to delete an object when the animation is ready + * @param a pointer to the animation + */ +void lv_obj_del_anim_ready_cb(lv_anim_t * a); + +/** + * Helper function for asynchronously deleting objects. + * Useful for cases where you can't delete an object directly in an `LV_EVENT_DELETE` handler (i.e. parent). + * @param obj object to delete + * @see lv_async_call + */ +void lv_obj_del_async(struct _lv_obj_t * obj); + +/** + * Move the parent of an object. The relative coordinates will be kept. + * + * @param obj pointer to an object whose parent needs to be changed + * @param parent pointer to the new parent + */ +void lv_obj_set_parent(struct _lv_obj_t * obj, struct _lv_obj_t * parent); + +/** + * Swap the positions of two objects. + * When used in listboxes, it can be used to sort the listbox items. + * @param obj1 pointer to the first object + * @param obj2 pointer to the second object + */ +void lv_obj_swap(struct _lv_obj_t * obj1, struct _lv_obj_t * obj2); + +/** + * moves the object to the given index in its parent. + * When used in listboxes, it can be used to sort the listbox items. + * @param obj pointer to the object to be moved. + * @param index new index in parent. -1 to count from the back + * @note to move to the background: lv_obj_move_to_index(obj, 0) + * @note to move forward (up): lv_obj_move_to_index(obj, lv_obj_get_index(obj) - 1) + */ +void lv_obj_move_to_index(struct _lv_obj_t * obj, int32_t index); + +/** + * Get the screen of an object + * @param obj pointer to an object + * @return pointer to the object's screen + */ +struct _lv_obj_t * lv_obj_get_screen(const struct _lv_obj_t * obj); + +/** + * Get the display of the object + * @param obj pointer to an object + * @return pointer to the object's display + */ +lv_disp_t * lv_obj_get_disp(const struct _lv_obj_t * obj); + +/** + * Get the parent of an object + * @param obj pointer to an object + * @return the parent of the object. (NULL if `obj` was a screen) + */ +struct _lv_obj_t * lv_obj_get_parent(const struct _lv_obj_t * obj); + +/** + * Get the child of an object by the child's index. + * @param obj pointer to an object whose child should be get + * @param id the index of the child. + * 0: the oldest (firstly created) child + * 1: the second oldest + * child count-1: the youngest + * -1: the youngest + * -2: the second youngest + * @return pointer to the child or NULL if the index was invalid + */ +struct _lv_obj_t * lv_obj_get_child(const struct _lv_obj_t * obj, int32_t id); + +/** + * Get the number of children + * @param obj pointer to an object + * @return the number of children + */ +uint32_t lv_obj_get_child_cnt(const struct _lv_obj_t * obj); + +/** + * Get the index of a child. + * @param obj pointer to an object + * @return the child index of the object. + * E.g. 0: the oldest (firstly created child) + */ +uint32_t lv_obj_get_index(const struct _lv_obj_t * obj); + +/** + * Iterate through all children of any object. + * @param start_obj start integrating from this object + * @param cb call this callback on the objects + * @param user_data pointer to any user related data (will be passed to `cb`) + */ +void lv_obj_tree_walk(struct _lv_obj_t * start_obj, lv_obj_tree_walk_cb_t cb, void * user_data); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_TREE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_refr.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_refr.h new file mode 100644 index 00000000..72e8d6c3 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_refr.h @@ -0,0 +1,115 @@ +/** + * @file lv_refr.h + * + */ + +#ifndef LV_REFR_H +#define LV_REFR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" +#include + +/********************* + * DEFINES + *********************/ + +#define LV_REFR_TASK_PRIO LV_TASK_PRIO_MID + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the screen refresh subsystem + */ +void _lv_refr_init(void); + +/** + * Redraw the invalidated areas now. + * Normally the redrawing is periodically executed in `lv_timer_handler` but a long blocking process + * can prevent the call of `lv_timer_handler`. In this case if the GUI is updated in the process + * (e.g. progress bar) this function can be called when the screen should be updated. + * @param disp pointer to display to refresh. NULL to refresh all displays. + */ +void lv_refr_now(lv_disp_t * disp); + +/** + * Redrawn on object an all its children using the passed draw context + * @param draw pointer to an initialized draw context + * @param obj the start object from the redraw should start + */ +void lv_obj_redraw(lv_draw_ctx_t * draw_ctx, lv_obj_t * obj); + +/** + * Invalidate an area on display to redraw it + * @param area_p pointer to area which should be invalidated (NULL: delete the invalidated areas) + * @param disp pointer to display where the area should be invalidated (NULL can be used if there is + * only one display) + */ +void _lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p); + +/** + * Get the display which is being refreshed + * @return the display being refreshed + */ +lv_disp_t * _lv_refr_get_disp_refreshing(void); + +/** + * Set the display which is being refreshed. + * It shouldn't be used directly by the user. + * It can be used to trick the drawing functions about there is an active display. + * @param the display being refreshed + */ +void _lv_refr_set_disp_refreshing(lv_disp_t * disp); + +#if LV_USE_PERF_MONITOR +/** + * Reset FPS counter + */ +void lv_refr_reset_fps_counter(void); + +/** + * Get the average FPS + * @return the average FPS + */ +uint32_t lv_refr_get_fps_avg(void); +#endif + +/** + * Called periodically to handle the refreshing + * @param timer pointer to the timer itself + */ +void _lv_disp_refr_timer(lv_timer_t * timer); + +/********************** + * STATIC FUNCTIONS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_REFR_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/core/lv_theme.h b/EZ-Template-Example-Project/include/liblvgl/core/lv_theme.h new file mode 100644 index 00000000..80da522c --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/core/lv_theme.h @@ -0,0 +1,120 @@ +/** + *@file lv_theme.h + * + */ + +#ifndef LV_THEME_H +#define LV_THEME_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_theme_t; +struct _lv_disp_t; + +typedef void (*lv_theme_apply_cb_t)(struct _lv_theme_t *, lv_obj_t *); + +typedef struct _lv_theme_t { + lv_theme_apply_cb_t apply_cb; + struct _lv_theme_t * parent; /**< Apply the current theme's style on top of this theme.*/ + void * user_data; + struct _lv_disp_t * disp; + lv_color_t color_primary; + lv_color_t color_secondary; + const lv_font_t * font_small; + const lv_font_t * font_normal; + const lv_font_t * font_large; + uint32_t flags; /*Any custom flag used by the theme*/ +} lv_theme_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Get the theme assigned to the display of the object + * @param obj pointer to a theme object + * @return the theme of the object's display (can be NULL) + */ +lv_theme_t * lv_theme_get_from_obj(lv_obj_t * obj); + +/** + * Apply the active theme on an object + * @param obj pointer to an object + */ +void lv_theme_apply(lv_obj_t * obj); + +/** + * Set a base theme for a theme. + * The styles from the base them will be added before the styles of the current theme. + * Arbitrary long chain of themes can be created by setting base themes. + * @param new_theme pointer to theme which base should be set + * @param parent pointer to the base theme + */ +void lv_theme_set_parent(lv_theme_t * new_theme, lv_theme_t * parent); + +/** + * Set an apply callback for a theme. + * The apply callback is used to add styles to different objects + * @param theme pointer to theme which callback should be set + * @param apply_cb pointer to the callback + */ +void lv_theme_set_apply_cb(lv_theme_t * theme, lv_theme_apply_cb_t apply_cb); + +/** + * Get the small font of the theme + * @param obj pointer to an object + * @return pointer to the font + */ +const lv_font_t * lv_theme_get_font_small(lv_obj_t * obj); +/** + * Get the normal font of the theme + * @param obj pointer to an object + * @return pointer to the font + */ +const lv_font_t * lv_theme_get_font_normal(lv_obj_t * obj); + +/** + * Get the subtitle font of the theme + * @param obj pointer to an object + * @return pointer to the font + */ +const lv_font_t * lv_theme_get_font_large(lv_obj_t * obj); + +/** + * Get the primary color of the theme + * @param obj pointer to an object + * @return the color + */ +lv_color_t lv_theme_get_color_primary(lv_obj_t * obj); + +/** + * Get the secondary color of the theme + * @param obj pointer to an object + * @return the color + */ +lv_color_t lv_theme_get_color_secondary(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_THEME_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/arm2d/lv_gpu_arm2d.h b/EZ-Template-Example-Project/include/liblvgl/draw/arm2d/lv_gpu_arm2d.h new file mode 100644 index 00000000..cc669901 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/arm2d/lv_gpu_arm2d.h @@ -0,0 +1,51 @@ +/** + * @file lv_gpu_arm2d.h + * + */ + +#ifndef LV_GPU_ARM2D_H +#define LV_GPU_ARM2D_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/hal/lv_hal_disp.h" +#include "liblvgl/draw/sw/lv_draw_sw.h" + +#if LV_USE_GPU_ARM2D + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef lv_draw_sw_ctx_t lv_draw_arm2d_ctx_t; + +struct _lv_disp_drv_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_arm2d_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_arm2d_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_ARM2D*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_ARM2D_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw.h new file mode 100644 index 00000000..c8aed722 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw.h @@ -0,0 +1,218 @@ +/** + * @file lv_draw.h + * + */ + +#ifndef LV_DRAW_H +#define LV_DRAW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include "liblvgl/misc/lv_style.h" +#include "liblvgl/misc/lv_txt.h" +#include "lv_img_decoder.h" +#include "lv_img_cache.h" + +#include "lv_draw_rect.h" +#include "lv_draw_label.h" +#include "lv_draw_img.h" +#include "lv_draw_line.h" +#include "lv_draw_triangle.h" +#include "lv_draw_arc.h" +#include "lv_draw_mask.h" +#include "lv_draw_transform.h" +#include "lv_draw_layer.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + void * user_data; +} lv_draw_mask_t; + +typedef struct _lv_draw_layer_ctx_t { + lv_area_t area_full; + lv_area_t area_act; + lv_coord_t max_row_with_alpha; + lv_coord_t max_row_with_no_alpha; + void * buf; + struct { + const lv_area_t * clip_area; + lv_area_t * buf_area; + void * buf; + bool screen_transp; + } original; +} lv_draw_layer_ctx_t; + +typedef struct _lv_draw_ctx_t { + /** + * Pointer to a buffer to draw into + */ + void * buf; + + /** + * The position and size of `buf` (absolute coordinates) + */ + lv_area_t * buf_area; + + /** + * The current clip area with absolute coordinates, always the same or smaller than `buf_area` + */ + const lv_area_t * clip_area; + + + void (*draw_rect)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); + + void (*draw_arc)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, + uint16_t radius, uint16_t start_angle, uint16_t end_angle); + + void (*draw_img_decoded)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc, + const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t color_format); + + lv_res_t (*draw_img)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * draw_dsc, + const lv_area_t * coords, const void * src); + + void (*draw_letter)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p, + uint32_t letter); + + + void (*draw_line)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1, + const lv_point_t * point2); + + + void (*draw_polygon)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, + const lv_point_t * points, uint16_t point_cnt); + + + /** + * Get an area of a transformed image (zoomed and/or rotated) + * @param draw_ctx pointer to a draw context + * @param dest_area get this area of the result image. It assumes that the original image is placed to the 0;0 position. + * @param src_buf the source image + * @param src_w width of the source image in [px] + * @param src_h height of the source image in [px] + * @param src_stride the stride in [px]. + * @param draw_dsc an `lv_draw_img_dsc_t` descriptor containing the transformation parameters + * @param cf the color format of `src_buf` + * @param cbuf place the colors of the pixels on `dest_area` here in RGB format + * @param abuf place the opacity of the pixels on `dest_area` here + */ + void (*draw_transform)(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf, + lv_coord_t src_w, lv_coord_t src_h, lv_coord_t src_stride, + const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf); + + /** + * Replace the buffer with a rect without decoration like radius or borders + */ + void (*draw_bg)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_area_t * coords); + + /** + * Wait until all background operations are finished. (E.g. GPU operations) + */ + void (*wait_for_finish)(struct _lv_draw_ctx_t * draw_ctx); + + /** + * Copy an area from buffer to an other + * @param draw_ctx pointer to a draw context + * @param dest_buf copy the buffer into this buffer + * @param dest_stride the width of the dest_buf in pixels + * @param dest_area the destination area + * @param src_buf copy from this buffer + * @param src_stride the width of src_buf in pixels + * @param src_area the source area. + * + * @note dest_area and src_area must have the same width and height + * but can have different x and y position. + * @note dest_area and src_area must be clipped to the real dimensions of the buffers + */ + void (*buffer_copy)(struct _lv_draw_ctx_t * draw_ctx, void * dest_buf, lv_coord_t dest_stride, + const lv_area_t * dest_area, + void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area); + + /** + * Initialize a new layer context. + * The original buffer and area data are already saved from `draw_ctx` to `layer_ctx` + * @param draw_ctx pointer to the current draw context + * @param layer_area the coordinates of the layer + * @param flags OR-ed flags from @lv_draw_layer_flags_t + * @return pointer to the layer context, or NULL on error + */ + struct _lv_draw_layer_ctx_t * (*layer_init)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + + /** + * Adjust the layer_ctx and/or draw_ctx based on the `layer_ctx->area_act`. + * It's called only if flags has `LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE` + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + * @param flags OR-ed flags from @lv_draw_layer_flags_t + */ + void (*layer_adjust)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + + /** + * Blend a rendered layer to `layer_ctx->area_act` + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + * @param draw_dsc pointer to an image draw descriptor + */ + void (*layer_blend)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + const lv_draw_img_dsc_t * draw_dsc); + + /** + * Destroy a layer context. The original buffer and area data of the `draw_ctx` will be restored + * and the `layer_ctx` itself will be freed automatically. + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + */ + void (*layer_destroy)(struct _lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx); + + /** + * Size of a layer context in bytes. + */ + size_t layer_instance_size; + +#if LV_USE_USER_DATA + void * user_data; +#endif + +} lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_init(void); + + +void lv_draw_wait_for_finish(lv_draw_ctx_t * draw_ctx); + +/********************** + * GLOBAL VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * POST INCLUDES + *********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_arc.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_arc.h new file mode 100644 index 00000000..8633af5f --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_arc.h @@ -0,0 +1,83 @@ +/** + * @file lv_draw_arc.h + * + */ + +#ifndef LV_DRAW_ARC_H +#define LV_DRAW_ARC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_style.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_color_t color; + lv_coord_t width; + uint16_t start_angle; + uint16_t end_angle; + const void * img_src; + lv_opa_t opa; + lv_blend_mode_t blend_mode : 2; + uint8_t rounded : 1; +} lv_draw_arc_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_arc_dsc_init(lv_draw_arc_dsc_t * dsc); + +/** + * Draw an arc. (Can draw pie too with great thickness.) + * @param center_x the x coordinate of the center of the arc + * @param center_y the y coordinate of the center of the arc + * @param radius the radius of the arc + * @param mask the arc will be drawn only in this mask + * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) + * @param end_angle the end angle of the arc + * @param clip_area the arc will be drawn only in this area + * @param dsc pointer to an initialized `lv_draw_line_dsc_t` variable + */ +void lv_draw_arc(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, + uint16_t radius, uint16_t start_angle, uint16_t end_angle); + +/** + * Get an area the should be invalidated when the arcs angle changed between start_angle and end_ange + * @param x the x coordinate of the center of the arc + * @param y the y coordinate of the center of the arc + * @param radius the radius of the arc + * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) + * @param end_angle the end angle of the arc + * @param w width of the arc + * @param rounded true: the arc is rounded + * @param area store the area to invalidate here + */ +void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, + lv_coord_t w, bool rounded, lv_area_t * area); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_ARC_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_img.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_img.h new file mode 100644 index 00000000..dcb71136 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_img.h @@ -0,0 +1,104 @@ +/** + * @file lv_draw_img.h + * + */ + +#ifndef LV_DRAW_IMG_H +#define LV_DRAW_IMG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_img_decoder.h" +#include "lv_img_buf.h" +#include "liblvgl/misc/lv_style.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + + int16_t angle; + uint16_t zoom; + lv_point_t pivot; + + lv_color_t recolor; + lv_opa_t recolor_opa; + + lv_opa_t opa; + lv_blend_mode_t blend_mode : 4; + + int32_t frame_id; + uint8_t antialias : 1; +} lv_draw_img_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_img_dsc_init(lv_draw_img_dsc_t * dsc); +/** + * Draw an image + * @param coords the coordinates of the image + * @param mask the image will be drawn only in this area + * @param src pointer to a lv_color_t array which contains the pixels of the image + * @param dsc pointer to an initialized `lv_draw_img_dsc_t` variable + */ +void lv_draw_img(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc, const lv_area_t * coords, + const void * src); + + +void lv_draw_img_decoded(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc, + const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t color_format); + +/** + * Get the type of an image source + * @param src pointer to an image source: + * - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code) + * - a path to a file (e.g. "S:/folder/image.bin") + * - or a symbol (e.g. LV_SYMBOL_CLOSE) + * @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKNOWN + */ +lv_img_src_t lv_img_src_get_type(const void * src); + +/** + * Get the pixel size of a color format in bits + * @param cf a color format (`LV_IMG_CF_...`) + * @return the pixel size in bits + */ +uint8_t lv_img_cf_get_px_size(lv_img_cf_t cf); + +/** + * Check if a color format is chroma keyed or not + * @param cf a color format (`LV_IMG_CF_...`) + * @return true: chroma keyed; false: not chroma keyed + */ +bool lv_img_cf_is_chroma_keyed(lv_img_cf_t cf); + +/** + * Check if a color format has alpha channel or not + * @param cf a color format (`LV_IMG_CF_...`) + * @return true: has alpha channel; false: doesn't have alpha channel + */ +bool lv_img_cf_has_alpha(lv_img_cf_t cf); + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_IMG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_label.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_label.h new file mode 100644 index 00000000..736aa728 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_label.h @@ -0,0 +1,100 @@ +/** + * @file lv_draw_label.h + * + */ + +#ifndef LV_DRAW_LABEL_H +#define LV_DRAW_LABEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_bidi.h" +#include "liblvgl/misc/lv_txt.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_style.h" + +/********************* + * DEFINES + *********************/ +#define LV_DRAW_LABEL_NO_TXT_SEL (0xFFFF) + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + const lv_font_t * font; + uint32_t sel_start; + uint32_t sel_end; + lv_color_t color; + lv_color_t sel_color; + lv_color_t sel_bg_color; + lv_coord_t line_space; + lv_coord_t letter_space; + lv_coord_t ofs_x; + lv_coord_t ofs_y; + lv_opa_t opa; + lv_base_dir_t bidi_dir; + lv_text_align_t align; + lv_text_flag_t flag; + lv_text_decor_t decor : 3; + lv_blend_mode_t blend_mode: 3; +} lv_draw_label_dsc_t; + +/** Store some info to speed up drawing of very large texts + * It takes a lot of time to get the first visible character because + * all the previous characters needs to be checked to calculate the positions. + * This structure stores an earlier (e.g. at -1000 px) coordinate and the index of that line. + * Therefore the calculations can start from here.*/ +typedef struct _lv_draw_label_hint_t { + /** Index of the line at `y` coordinate*/ + int32_t line_start; + + /** Give the `y` coordinate of the first letter at `line start` index. Relative to the label's coordinates*/ + int32_t y; + + /** The 'y1' coordinate of the label when the hint was saved. + * Used to invalidate the hint if the label has moved too much.*/ + int32_t coord_y; +} lv_draw_label_hint_t; + +struct _lv_draw_ctx_t; +/********************** + * GLOBAL PROTOTYPES + **********************/ + +LV_ATTRIBUTE_FAST_MEM void lv_draw_label_dsc_init(lv_draw_label_dsc_t * dsc); + +/** + * Write a text + * @param coords coordinates of the label + * @param mask the label will be drawn only in this area + * @param dsc pointer to draw descriptor + * @param txt `\0` terminated text to write + * @param hint pointer to a `lv_draw_label_hint_t` variable. + * It is managed by the draw to speed up the drawing of very long texts (thousands of lines). + */ +LV_ATTRIBUTE_FAST_MEM void lv_draw_label(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, + const lv_area_t * coords, const char * txt, lv_draw_label_hint_t * hint); + +void lv_draw_letter(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p, + uint32_t letter); + +/*********************** + * GLOBAL VARIABLES + ***********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_LABEL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_layer.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_layer.h new file mode 100644 index 00000000..1280d33a --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_layer.h @@ -0,0 +1,83 @@ +/** + * @file lv_draw_layer.h + * + */ + +#ifndef LV_DRAW_LAYER_H +#define LV_DRAW_LAYER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct _lv_draw_ctx_t; +struct _lv_draw_layer_ctx_t; + +typedef enum { + LV_DRAW_LAYER_FLAG_NONE, + LV_DRAW_LAYER_FLAG_HAS_ALPHA, + LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE, +} lv_draw_layer_flags_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a new layer context. It is used to start and independent rendering session + * with the current draw_ctx + * @param draw_ctx pointer to the current draw context + * @param layer_area the coordinates of the layer + * @param flags OR-ed flags from @lv_draw_layer_flags_t + * @return pointer to the layer context, or NULL on error + */ +struct _lv_draw_layer_ctx_t * lv_draw_layer_create(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * layer_area, + lv_draw_layer_flags_t flags); + +/** + * Adjust the layer_ctx and/or draw_ctx based on the `layer_ctx->area_act`. + * It's called only if flags has `LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE` + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + * @param flags OR-ed flags from @lv_draw_layer_flags_t + */ +void lv_draw_layer_adjust(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + +/** + * Blend a rendered layer to `layer_ctx->area_act` + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + * @param draw_dsc pointer to an image draw descriptor + */ +void lv_draw_layer_blend(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_img_dsc_t * draw_dsc); + +/** + * Destroy a layer context. + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + */ +void lv_draw_layer_destroy(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_LAYER_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_line.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_line.h new file mode 100644 index 00000000..79ca0dcf --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_line.h @@ -0,0 +1,67 @@ +/** + * @file lv_draw_line.h + * + */ + +#ifndef LV_DRAW_LINE_H +#define LV_DRAW_LINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_style.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_color_t color; + lv_coord_t width; + lv_coord_t dash_width; + lv_coord_t dash_gap; + lv_opa_t opa; + lv_blend_mode_t blend_mode : 2; + uint8_t round_start : 1; + uint8_t round_end : 1; + uint8_t raw_end : 1; /*Do not bother with perpendicular line ending if it's not visible for any reason*/ +} lv_draw_line_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +LV_ATTRIBUTE_FAST_MEM void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc); + +/** + * Draw a line + * @param point1 first point of the line + * @param point2 second point of the line + * @param clip the line will be drawn only in this area + * @param dsc pointer to an initialized `lv_draw_line_dsc_t` variable + */ +void lv_draw_line(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1, + const lv_point_t * point2); + + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_LINE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_mask.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_mask.h new file mode 100644 index 00000000..f3c49e5d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_mask.h @@ -0,0 +1,394 @@ +/** + * @file lv_draw_mask.h + * + */ + +#ifndef LV_DRAW_MASK_H +#define LV_DRAW_MASK_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#include +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define LV_MASK_ID_INV (-1) +#if LV_DRAW_COMPLEX +# define _LV_MASK_MAX_NUM 16 +#else +# define _LV_MASK_MAX_NUM 1 +#endif + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_DRAW_MASK_RES_TRANSP, + LV_DRAW_MASK_RES_FULL_COVER, + LV_DRAW_MASK_RES_CHANGED, + LV_DRAW_MASK_RES_UNKNOWN +}; + +typedef uint8_t lv_draw_mask_res_t; + +typedef struct { + void * param; + void * custom_id; +} _lv_draw_mask_saved_t; + +typedef _lv_draw_mask_saved_t _lv_draw_mask_saved_arr_t[_LV_MASK_MAX_NUM]; + + + +#if LV_DRAW_COMPLEX == 0 +static inline uint8_t lv_draw_mask_get_cnt(void) +{ + return 0; +} + +static inline bool lv_draw_mask_is_any(const lv_area_t * a) +{ + LV_UNUSED(a); + return false; +} + +#endif + +#if LV_DRAW_COMPLEX + +enum { + LV_DRAW_MASK_TYPE_LINE, + LV_DRAW_MASK_TYPE_ANGLE, + LV_DRAW_MASK_TYPE_RADIUS, + LV_DRAW_MASK_TYPE_FADE, + LV_DRAW_MASK_TYPE_MAP, + LV_DRAW_MASK_TYPE_POLYGON, +}; + +typedef uint8_t lv_draw_mask_type_t; + +enum { + LV_DRAW_MASK_LINE_SIDE_LEFT = 0, + LV_DRAW_MASK_LINE_SIDE_RIGHT, + LV_DRAW_MASK_LINE_SIDE_TOP, + LV_DRAW_MASK_LINE_SIDE_BOTTOM, +}; + +/** + * A common callback type for every mask type. + * Used internally by the library. + */ +typedef lv_draw_mask_res_t (*lv_draw_mask_xcb_t)(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, + lv_coord_t len, + void * p); + +typedef uint8_t lv_draw_mask_line_side_t; + +typedef struct { + lv_draw_mask_xcb_t cb; + lv_draw_mask_type_t type; +} _lv_draw_mask_common_dsc_t; + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + /*First point*/ + lv_point_t p1; + + /*Second point*/ + lv_point_t p2; + + /*Which side to keep?*/ + lv_draw_mask_line_side_t side : 2; + } cfg; + + /*A point of the line*/ + lv_point_t origo; + + /*X / (1024*Y) steepness (X is 0..1023 range). What is the change of X in 1024 Y?*/ + int32_t xy_steep; + + /*Y / (1024*X) steepness (Y is 0..1023 range). What is the change of Y in 1024 X?*/ + int32_t yx_steep; + + /*Helper which stores yx_steep for flat lines and xy_steep for steep (non flat) lines*/ + int32_t steep; + + /*Steepness in 1 px in 0..255 range. Used only by flat lines.*/ + int32_t spx; + + /*1: It's a flat line? (Near to horizontal)*/ + uint8_t flat : 1; + + /*Invert the mask. The default is: Keep the left part. + *It is used to select left/right/top/bottom*/ + uint8_t inv: 1; +} lv_draw_mask_line_param_t; + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_point_t vertex_p; + lv_coord_t start_angle; + lv_coord_t end_angle; + } cfg; + + lv_draw_mask_line_param_t start_line; + lv_draw_mask_line_param_t end_line; + uint16_t delta_deg; +} lv_draw_mask_angle_param_t; + +typedef struct { + uint8_t * buf; + lv_opa_t * cir_opa; /*Opacity of values on the circumference of an 1/4 circle*/ + uint16_t * x_start_on_y; /*The x coordinate of the circle for each y value*/ + uint16_t * opa_start_on_y; /*The index of `cir_opa` for each y value*/ + int32_t life; /*How many times the entry way used*/ + uint32_t used_cnt; /*Like a semaphore to count the referencing masks*/ + lv_coord_t radius; /*The radius of the entry*/ +} _lv_draw_mask_radius_circle_dsc_t; + +typedef _lv_draw_mask_radius_circle_dsc_t _lv_draw_mask_radius_circle_dsc_arr_t[LV_CIRCLE_CACHE_SIZE]; + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_area_t rect; + lv_coord_t radius; + /*Invert the mask. 0: Keep the pixels inside.*/ + uint8_t outer: 1; + } cfg; + + _lv_draw_mask_radius_circle_dsc_t * circle; +} lv_draw_mask_radius_param_t; + + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_area_t coords; + lv_coord_t y_top; + lv_coord_t y_bottom; + lv_opa_t opa_top; + lv_opa_t opa_bottom; + } cfg; + +} lv_draw_mask_fade_param_t; + + +typedef struct _lv_draw_mask_map_param_t { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_area_t coords; + const lv_opa_t * map; + } cfg; +} lv_draw_mask_map_param_t; + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_point_t * points; + uint16_t point_cnt; + } cfg; +} lv_draw_mask_polygon_param_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Add a draw mask. Everything drawn after it (until removing the mask) will be affected by the mask. + * @param param an initialized mask parameter. Only the pointer is saved. + * @param custom_id a custom pointer to identify the mask. Used in `lv_draw_mask_remove_custom`. + * @return the an integer, the ID of the mask. Can be used in `lv_draw_mask_remove_id`. + */ +int16_t lv_draw_mask_add(void * param, void * custom_id); + +//! @cond Doxygen_Suppress + +/** + * Apply the added buffers on a line. Used internally by the library's drawing routines. + * @param mask_buf store the result mask here. Has to be `len` byte long. Should be initialized with `0xFF`. + * @param abs_x absolute X coordinate where the line to calculate start + * @param abs_y absolute Y coordinate where the line to calculate start + * @param len length of the line to calculate (in pixel count) + * @return One of these values: + * - `LV_DRAW_MASK_RES_FULL_TRANSP`: the whole line is transparent. `mask_buf` is not set to zero + * - `LV_DRAW_MASK_RES_FULL_COVER`: the whole line is fully visible. `mask_buf` is unchanged + * - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line + */ +LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, + lv_coord_t len); + +/** + * Apply the specified buffers on a line. Used internally by the library's drawing routines. + * @param mask_buf store the result mask here. Has to be `len` byte long. Should be initialized with `0xFF`. + * @param abs_x absolute X coordinate where the line to calculate start + * @param abs_y absolute Y coordinate where the line to calculate start + * @param len length of the line to calculate (in pixel count) + * @param ids ID array of added buffers + * @param ids_count number of ID array + * @return One of these values: + * - `LV_DRAW_MASK_RES_FULL_TRANSP`: the whole line is transparent. `mask_buf` is not set to zero + * - `LV_DRAW_MASK_RES_FULL_COVER`: the whole line is fully visible. `mask_buf` is unchanged + * - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line + */ +LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply_ids(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, + lv_coord_t len, const int16_t * ids, int16_t ids_count); + +//! @endcond + +/** + * Remove a mask with a given ID + * @param id the ID of the mask. Returned by `lv_draw_mask_add` + * @return the parameter of the removed mask. + * If more masks have `custom_id` ID then the last mask's parameter will be returned + */ +void * lv_draw_mask_remove_id(int16_t id); + +/** + * Remove all mask with a given custom ID + * @param custom_id a pointer used in `lv_draw_mask_add` + * @return return the parameter of the removed mask. + * If more masks have `custom_id` ID then the last mask's parameter will be returned + */ +void * lv_draw_mask_remove_custom(void * custom_id); + +/** + * Free the data from the parameter. + * It's called inside `lv_draw_mask_remove_id` and `lv_draw_mask_remove_custom` + * Needs to be called only in special cases when the mask is not added by `lv_draw_mask_add` + * and not removed by `lv_draw_mask_remove_id` or `lv_draw_mask_remove_custom` + * @param p pointer to a mask parameter + */ +void lv_draw_mask_free_param(void * p); + +/** + * Called by LVGL the rendering of a screen is ready to clean up + * the temporal (cache) data of the masks + */ +void _lv_draw_mask_cleanup(void); + +//! @cond Doxygen_Suppress + +/** + * Count the currently added masks + * @return number of active masks + */ +LV_ATTRIBUTE_FAST_MEM uint8_t lv_draw_mask_get_cnt(void); + + +/** + * Check if there is any added draw mask + * @param a an area to test for affecting masks. + * @return true: there is t least 1 draw mask; false: there are no draw masks + */ +bool lv_draw_mask_is_any(const lv_area_t * a); + +//! @endcond + +/** + *Initialize a line mask from two points. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param p1x X coordinate of the first point of the line + * @param p1y Y coordinate of the first point of the line + * @param p2x X coordinate of the second point of the line + * @param p2y y coordinate of the second point of the line + * @param side and element of `lv_draw_mask_line_side_t` to describe which side to keep. + * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept + * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept + */ +void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, + lv_coord_t p2y, lv_draw_mask_line_side_t side); + +/** + *Initialize a line mask from a point and an angle. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param px X coordinate of a point of the line + * @param py X coordinate of a point of the line + * @param angle right 0 deg, bottom: 90 + * @param side and element of `lv_draw_mask_line_side_t` to describe which side to keep. + * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept + * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept + */ +void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t py, int16_t angle, + lv_draw_mask_line_side_t side); + +/** + * Initialize an angle mask. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param vertex_x X coordinate of the angle vertex (absolute coordinates) + * @param vertex_y Y coordinate of the angle vertex (absolute coordinates) + * @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom + * @param end_angle end angle + */ +void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y, + lv_coord_t start_angle, lv_coord_t end_angle); + +/** + * Initialize a fade mask. + * @param param pointer to an `lv_draw_mask_radius_param_t` to initialize + * @param rect coordinates of the rectangle to affect (absolute coordinates) + * @param radius radius of the rectangle + * @param inv true: keep the pixels inside the rectangle; keep the pixels outside of the rectangle + */ +void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t * param, const lv_area_t * rect, lv_coord_t radius, bool inv); + +/** + * Initialize a fade mask. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param coords coordinates of the area to affect (absolute coordinates) + * @param opa_top opacity on the top + * @param y_top at which coordinate start to change to opacity to `opa_bottom` + * @param opa_bottom opacity at the bottom + * @param y_bottom at which coordinate reach `opa_bottom`. + */ +void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, const lv_area_t * coords, lv_opa_t opa_top, + lv_coord_t y_top, + lv_opa_t opa_bottom, lv_coord_t y_bottom); + +/** + * Initialize a map mask. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param coords coordinates of the map (absolute coordinates) + * @param map array of bytes with the mask values + */ +void lv_draw_mask_map_init(lv_draw_mask_map_param_t * param, const lv_area_t * coords, const lv_opa_t * map); + +void lv_draw_mask_polygon_init(lv_draw_mask_polygon_param_t * param, const lv_point_t * points, uint16_t point_cnt); + +#endif /*LV_DRAW_COMPLEX*/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_MASK_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_rect.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_rect.h new file mode 100644 index 00000000..e259446e --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_rect.h @@ -0,0 +1,96 @@ +/** + * @file lv_draw_rect.h + * + */ + +#ifndef LV_DRAW_RECT_H +#define LV_DRAW_RECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_style.h" +#include "sw/lv_draw_sw_gradient.h" + +/********************* + * DEFINES + *********************/ +#define LV_RADIUS_CIRCLE 0x7FFF /**< A very big radius to always draw as circle*/ +LV_EXPORT_CONST_INT(LV_RADIUS_CIRCLE); + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_coord_t radius; + lv_blend_mode_t blend_mode; + + /*Background*/ + lv_opa_t bg_opa; + lv_color_t bg_color; /**< First element of a gradient is a color, so it maps well here*/ + lv_grad_dsc_t bg_grad; + + /*Background img*/ + const void * bg_img_src; + const void * bg_img_symbol_font; + lv_color_t bg_img_recolor; + lv_opa_t bg_img_opa; + lv_opa_t bg_img_recolor_opa; + uint8_t bg_img_tiled; + + /*Border*/ + lv_color_t border_color; + lv_coord_t border_width; + lv_opa_t border_opa; + uint8_t border_post : 1; /*There is a border it will be drawn later.*/ + lv_border_side_t border_side : 5; + + /*Outline*/ + lv_color_t outline_color; + lv_coord_t outline_width; + lv_coord_t outline_pad; + lv_opa_t outline_opa; + + /*Shadow*/ + lv_color_t shadow_color; + lv_coord_t shadow_width; + lv_coord_t shadow_ofs_x; + lv_coord_t shadow_ofs_y; + lv_coord_t shadow_spread; + lv_opa_t shadow_opa; +} lv_draw_rect_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +LV_ATTRIBUTE_FAST_MEM void lv_draw_rect_dsc_init(lv_draw_rect_dsc_t * dsc); + + +/** + * Draw a rectangle + * @param coords the coordinates of the rectangle + * @param clip the rectangle will be drawn only in this area + * @param dsc pointer to an initialized `lv_draw_rect_dsc_t` variable + */ +void lv_draw_rect(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_RECT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_transform.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_transform.h new file mode 100644 index 00000000..6e6236ca --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_transform.h @@ -0,0 +1,44 @@ +/** + * @file lv_draw_transform.h + * + */ + +#ifndef LV_DRAW_TRANSFORM_H +#define LV_DRAW_TRANSFORM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_transform(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf, + lv_coord_t src_w, lv_coord_t src_h, + lv_coord_t src_stride, const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_TRANSFORM_H*/ diff --git a/include/display/lv_draw/lv_draw_triangle.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_triangle.h similarity index 57% rename from include/display/lv_draw/lv_draw_triangle.h rename to EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_triangle.h index c3c6208d..e8d85750 100644 --- a/include/display/lv_draw/lv_draw_triangle.h +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_draw_triangle.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "lv_draw.h" +#include "lv_draw_rect.h" /********************* * DEFINES @@ -26,26 +26,17 @@ extern "C" { /********************** * GLOBAL PROTOTYPES **********************/ -/*Experimental use for 3D modeling*/ -#define USE_LV_TRIANGLE 1 -#if USE_LV_TRIANGLE != 0 -/** - * - * @param points pointer to an array with 3 points - * @param mask the triangle will be drawn only in this mask - * @param color color of the triangle - */ -void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color); -#endif +void lv_draw_polygon(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t points[], + uint16_t point_cnt); +void lv_draw_triangle(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t points[]); /********************** * MACROS **********************/ - #ifdef __cplusplus -} /* extern "C" */ +} /*extern "C"*/ #endif #endif /*LV_DRAW_TRIANGLE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_buf.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_buf.h new file mode 100644 index 00000000..8998839b --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_buf.h @@ -0,0 +1,249 @@ +/** + * @file lv_img_buf.h + * + */ + +#ifndef LV_IMG_BUF_H +#define LV_IMG_BUF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ +/*If image pixels contains alpha we need to know how much byte is a pixel*/ +#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8 +#define LV_IMG_PX_SIZE_ALPHA_BYTE 2 +#elif LV_COLOR_DEPTH == 16 +#define LV_IMG_PX_SIZE_ALPHA_BYTE 3 +#elif LV_COLOR_DEPTH == 32 +#define LV_IMG_PX_SIZE_ALPHA_BYTE 4 +#endif + +#define LV_IMG_BUF_SIZE_TRUE_COLOR(w, h) ((LV_COLOR_SIZE / 8) * w * h) +#define LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h) ((LV_COLOR_SIZE / 8) * w * h) +#define LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h) (LV_IMG_PX_SIZE_ALPHA_BYTE * w * h) + +/*+ 1: to be sure no fractional row*/ +#define LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) ((((w / 8) + 1) * h)) +#define LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h) ((((w / 4) + 1) * h)) +#define LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h) ((((w / 2) + 1) * h)) +#define LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h) ((w * h)) + +/*4 * X: for palette*/ +#define LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2) +#define LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h) + 4 * 4) +#define LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h) + 4 * 16) +#define LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h) + 4 * 256) + +#define _LV_ZOOM_INV_UPSCALE 5 + +/********************** + * TYPEDEFS + **********************/ + +/*Image color format*/ +enum { + LV_IMG_CF_UNKNOWN = 0, + + LV_IMG_CF_RAW, /**< Contains the file as it is. Needs custom decoder function*/ + LV_IMG_CF_RAW_ALPHA, /**< Contains the file as it is. The image has alpha. Needs custom decoder + function*/ + LV_IMG_CF_RAW_CHROMA_KEYED, /**< Contains the file as it is. The image is chroma keyed. Needs + custom decoder function*/ + + LV_IMG_CF_TRUE_COLOR, /**< Color format and depth should match with LV_COLOR settings*/ + LV_IMG_CF_TRUE_COLOR_ALPHA, /**< Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/ + LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /**< Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels + will be transparent*/ + + LV_IMG_CF_INDEXED_1BIT, /**< Can have 2 different colors in a palette (can't be chroma keyed)*/ + LV_IMG_CF_INDEXED_2BIT, /**< Can have 4 different colors in a palette (can't be chroma keyed)*/ + LV_IMG_CF_INDEXED_4BIT, /**< Can have 16 different colors in a palette (can't be chroma keyed)*/ + LV_IMG_CF_INDEXED_8BIT, /**< Can have 256 different colors in a palette (can't be chroma keyed)*/ + + LV_IMG_CF_ALPHA_1BIT, /**< Can have one color and it can be drawn or not*/ + LV_IMG_CF_ALPHA_2BIT, /**< Can have one color but 4 different alpha value*/ + LV_IMG_CF_ALPHA_4BIT, /**< Can have one color but 16 different alpha value*/ + LV_IMG_CF_ALPHA_8BIT, /**< Can have one color but 256 different alpha value*/ + + LV_IMG_CF_RGB888, + LV_IMG_CF_RGBA8888, + LV_IMG_CF_RGBX8888, + LV_IMG_CF_RGB565, + LV_IMG_CF_RGBA5658, + LV_IMG_CF_RGB565A8, + + LV_IMG_CF_RESERVED_15, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_16, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_17, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_18, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_19, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_20, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_21, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_22, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_23, /**< Reserved for further use.*/ + + LV_IMG_CF_USER_ENCODED_0, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_1, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_2, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_3, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_4, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_5, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_6, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_7, /**< User holder encoding format.*/ +}; +typedef uint8_t lv_img_cf_t; + + +/** + * The first 8 bit is very important to distinguish the different source types. + * For more info see `lv_img_get_src_type()` in lv_img.c + * On big endian systems the order is reversed so cf and always_zero must be at + * the end of the struct. + */ +#if LV_BIG_ENDIAN_SYSTEM +typedef struct { + + uint32_t h : 11; /*Height of the image map*/ + uint32_t w : 11; /*Width of the image map*/ + uint32_t reserved : 2; /*Reserved to be used later*/ + uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a + non-printable character*/ + uint32_t cf : 5; /*Color format: See `lv_img_color_format_t`*/ + +} lv_img_header_t; +#else +typedef struct { + + uint32_t cf : 5; /*Color format: See `lv_img_color_format_t`*/ + uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a + non-printable character*/ + + uint32_t reserved : 2; /*Reserved to be used later*/ + + uint32_t w : 11; /*Width of the image map*/ + uint32_t h : 11; /*Height of the image map*/ +} lv_img_header_t; +#endif + +/** Image header it is compatible with + * the result from image converter utility*/ +typedef struct { + lv_img_header_t header; /**< A header describing the basics of the image*/ + uint32_t data_size; /**< Size of the image in bytes*/ + const uint8_t * data; /**< Pointer to the data of the image*/ +} lv_img_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Allocate an image buffer in RAM + * @param w width of image + * @param h height of image + * @param cf a color format (`LV_IMG_CF_...`) + * @return an allocated image, or NULL on failure + */ +lv_img_dsc_t * lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); + +/** + * Get the color of an image's pixel + * @param dsc an image descriptor + * @param x x coordinate of the point to get + * @param y x coordinate of the point to get + * @param color the color of the image. In case of `LV_IMG_CF_ALPHA_1/2/4/8` this color is used. + * Not used in other cases. + * @param safe true: check out of bounds + * @return color of the point + */ +lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t color); + +/** + * Get the alpha value of an image's pixel + * @param dsc pointer to an image descriptor + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param safe true: check out of bounds + * @return alpha value of the point + */ +lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y); + +/** + * Set the color of a pixel of an image. The alpha channel won't be affected. + * @param dsc pointer to an image descriptor + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param c color of the point + * @param safe true: check out of bounds + */ +void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t c); + +/** + * Set the alpha value of a pixel of an image. The color won't be affected + * @param dsc pointer to an image descriptor + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param opa the desired opacity + * @param safe true: check out of bounds + */ +void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_opa_t opa); + +/** + * Set the palette color of an indexed image. Valid only for `LV_IMG_CF_INDEXED1/2/4/8` + * @param dsc pointer to an image descriptor + * @param id the palette color to set: + * - for `LV_IMG_CF_INDEXED1`: 0..1 + * - for `LV_IMG_CF_INDEXED2`: 0..3 + * - for `LV_IMG_CF_INDEXED4`: 0..15 + * - for `LV_IMG_CF_INDEXED8`: 0..255 + * @param c the color to set + */ +void lv_img_buf_set_palette(lv_img_dsc_t * dsc, uint8_t id, lv_color_t c); + +/** + * Free an allocated image buffer + * @param dsc image buffer to free + */ +void lv_img_buf_free(lv_img_dsc_t * dsc); + +/** + * Get the memory consumption of a raw bitmap, given color format and dimensions. + * @param w width + * @param h height + * @param cf color format + * @return size in bytes + */ +uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); + +/** + * Get the area of a rectangle if its rotated and scaled + * @param res store the coordinates here + * @param w width of the rectangle to transform + * @param h height of the rectangle to transform + * @param angle angle of rotation + * @param zoom zoom, (256 no zoom) + * @param pivot x,y pivot coordinates of rotation + */ +void _lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, + const lv_point_t * pivot); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMG_BUF_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_cache.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_cache.h new file mode 100644 index 00000000..dc0c5d98 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_cache.h @@ -0,0 +1,78 @@ +/** + * @file lv_img_cache.h + * + */ + +#ifndef LV_IMG_CACHE_H +#define LV_IMG_CACHE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_img_decoder.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * When loading images from the network it can take a long time to download and decode the image. + * + * To avoid repeating this heavy load images can be cached. + */ +typedef struct { + lv_img_decoder_dsc_t dec_dsc; /**< Image information*/ + + /** Count the cache entries's life. Add `time_to_open` to `life` when the entry is used. + * Decrement all lifes by one every in every ::lv_img_cache_open. + * If life == 0 the entry can be reused*/ + int32_t life; +} _lv_img_cache_entry_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Open an image using the image decoder interface and cache it. + * The image will be left open meaning if the image decoder open callback allocated memory then it will remain. + * The image is closed if a new image is opened and the new image takes its place in the cache. + * @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable + * @param color The color of the image with `LV_IMG_CF_ALPHA_...` + * @param frame_id the index of the frame. Used only with animated images, set 0 for normal images + * @return pointer to the cache entry or NULL if can open the image + */ +_lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color, int32_t frame_id); + +/** + * Set the number of images to be cached. + * More cached images mean more opened image at same time which might mean more memory usage. + * E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache. + * @param new_entry_cnt number of image to cache + */ +void lv_img_cache_set_size(uint16_t new_slot_num); + +/** + * Invalidate an image source in the cache. + * Useful if the image source is updated therefore it needs to be cached again. + * @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable. + */ +void lv_img_cache_invalidate_src(const void * src); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMG_CACHE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_decoder.h b/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_decoder.h new file mode 100644 index 00000000..c0c5860e --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/lv_img_decoder.h @@ -0,0 +1,274 @@ +/** + * @file lv_img_decoder.h + * + */ + +#ifndef LV_IMG_DECODER_H +#define LV_IMG_DECODER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include "lv_img_buf.h" +#include "liblvgl/misc/lv_fs.h" +#include "liblvgl/misc/lv_types.h" +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Source of image.*/ +enum { + LV_IMG_SRC_VARIABLE, /** Binary/C variable*/ + LV_IMG_SRC_FILE, /** File in filesystem*/ + LV_IMG_SRC_SYMBOL, /** Symbol (@ref lv_symbol_def.h)*/ + LV_IMG_SRC_UNKNOWN, /** Unknown source*/ +}; + +typedef uint8_t lv_img_src_t; + +/*Decoder function definitions*/ +struct _lv_img_decoder_dsc_t; +struct _lv_img_decoder_t; + +/** + * Get info from an image and store in the `header` + * @param src the image source. Can be a pointer to a C array or a file name (Use + * `lv_img_src_get_type` to determine the type) + * @param header store the info here + * @return LV_RES_OK: info written correctly; LV_RES_INV: failed + */ +typedef lv_res_t (*lv_img_decoder_info_f_t)(struct _lv_img_decoder_t * decoder, const void * src, + lv_img_header_t * header); + +/** + * Open an image for decoding. Prepare it as it is required to read it later + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor. `src`, `color` are already initialized in it. + */ +typedef lv_res_t (*lv_img_decoder_open_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc); + +/** + * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`. + * Required only if the "open" function can't return with the whole decoded pixel array. + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor + * @param x start x coordinate + * @param y start y coordinate + * @param len number of pixels to decode + * @param buf a buffer to store the decoded pixels + * @return LV_RES_OK: ok; LV_RES_INV: failed + */ +typedef lv_res_t (*lv_img_decoder_read_line_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc, + lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); + +/** + * Close the pending decoding. Free resources etc. + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor + */ +typedef void (*lv_img_decoder_close_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc); + + +typedef struct _lv_img_decoder_t { + lv_img_decoder_info_f_t info_cb; + lv_img_decoder_open_f_t open_cb; + lv_img_decoder_read_line_f_t read_line_cb; + lv_img_decoder_close_f_t close_cb; + +#if LV_USE_USER_DATA + void * user_data; +#endif +} lv_img_decoder_t; + + +/**Describe an image decoding session. Stores data about the decoding*/ +typedef struct _lv_img_decoder_dsc_t { + /**The decoder which was able to open the image source*/ + lv_img_decoder_t * decoder; + + /**The image source. A file path like "S:my_img.png" or pointer to an `lv_img_dsc_t` variable*/ + const void * src; + + /**Color to draw the image. USed when the image has alpha channel only*/ + lv_color_t color; + + /**Frame of the image, using with animated images*/ + int32_t frame_id; + + /**Type of the source: file or variable. Can be set in `open` function if required*/ + lv_img_src_t src_type; + + /**Info about the opened image: color format, size, etc. MUST be set in `open` function*/ + lv_img_header_t header; + + /** Pointer to a buffer where the image's data (pixels) are stored in a decoded, plain format. + * MUST be set in `open` function*/ + const uint8_t * img_data; + + /** How much time did it take to open the image. [ms] + * If not set `lv_img_cache` will measure and set the time to open*/ + uint32_t time_to_open; + + /**A text to display instead of the image when the image can't be opened. + * Can be set in `open` function or set NULL.*/ + const char * error_msg; + + /**Store any custom data here is required*/ + void * user_data; +} lv_img_decoder_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the image decoder module + */ +void _lv_img_decoder_init(void); + +/** + * Get information about an image. + * Try the created image decoder one by one. Once one is able to get info that info will be used. + * @param src the image source. Can be + * 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via `lv_fs_drv_register()`) + * 2) Variable: Pointer to an `lv_img_dsc_t` variable + * 3) Symbol: E.g. `LV_SYMBOL_OK` + * @param header the image info will be stored here + * @return LV_RES_OK: success; LV_RES_INV: wasn't able to get info about the image + */ +lv_res_t lv_img_decoder_get_info(const void * src, lv_img_header_t * header); + +/** + * Open an image. + * Try the created image decoders one by one. Once one is able to open the image that decoder is saved in `dsc` + * @param dsc describes a decoding session. Simply a pointer to an `lv_img_decoder_dsc_t` variable. + * @param src the image source. Can be + * 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via `lv_fs_drv_register())`) + * 2) Variable: Pointer to an `lv_img_dsc_t` variable + * 3) Symbol: E.g. `LV_SYMBOL_OK` + * @param color The color of the image with `LV_IMG_CF_ALPHA_...` + * @param frame_id the index of the frame. Used only with animated images, set 0 for normal images + * @return LV_RES_OK: opened the image. `dsc->img_data` and `dsc->header` are set. + * LV_RES_INV: none of the registered image decoders were able to open the image. + */ +lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_color_t color, int32_t frame_id); + +/** + * Read a line from an opened image + * @param dsc pointer to `lv_img_decoder_dsc_t` used in `lv_img_decoder_open` + * @param x start X coordinate (from left) + * @param y start Y coordinate (from top) + * @param len number of pixels to read + * @param buf store the data here + * @return LV_RES_OK: success; LV_RES_INV: an error occurred + */ +lv_res_t lv_img_decoder_read_line(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_coord_t len, + uint8_t * buf); + +/** + * Close a decoding session + * @param dsc pointer to `lv_img_decoder_dsc_t` used in `lv_img_decoder_open` + */ +void lv_img_decoder_close(lv_img_decoder_dsc_t * dsc); + +/** + * Create a new image decoder + * @return pointer to the new image decoder + */ +lv_img_decoder_t * lv_img_decoder_create(void); + +/** + * Delete an image decoder + * @param decoder pointer to an image decoder + */ +void lv_img_decoder_delete(lv_img_decoder_t * decoder); + +/** + * Set a callback to get information about the image + * @param decoder pointer to an image decoder + * @param info_cb a function to collect info about an image (fill an `lv_img_header_t` struct) + */ +void lv_img_decoder_set_info_cb(lv_img_decoder_t * decoder, lv_img_decoder_info_f_t info_cb); + +/** + * Set a callback to open an image + * @param decoder pointer to an image decoder + * @param open_cb a function to open an image + */ +void lv_img_decoder_set_open_cb(lv_img_decoder_t * decoder, lv_img_decoder_open_f_t open_cb); + +/** + * Set a callback to a decoded line of an image + * @param decoder pointer to an image decoder + * @param read_line_cb a function to read a line of an image + */ +void lv_img_decoder_set_read_line_cb(lv_img_decoder_t * decoder, lv_img_decoder_read_line_f_t read_line_cb); + +/** + * Set a callback to close a decoding session. E.g. close files and free other resources. + * @param decoder pointer to an image decoder + * @param close_cb a function to close a decoding session + */ +void lv_img_decoder_set_close_cb(lv_img_decoder_t * decoder, lv_img_decoder_close_f_t close_cb); + +/** + * Get info about a built-in image + * @param decoder the decoder where this function belongs + * @param src the image source: pointer to an `lv_img_dsc_t` variable, a file path or a symbol + * @param header store the image data here + * @return LV_RES_OK: the info is successfully stored in `header`; LV_RES_INV: unknown format or other error. + */ +lv_res_t lv_img_decoder_built_in_info(lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header); + +/** + * Open a built in image + * @param decoder the decoder where this function belongs + * @param dsc pointer to decoder descriptor. `src`, `style` are already initialized in it. + * @return LV_RES_OK: the info is successfully stored in `header`; LV_RES_INV: unknown format or other error. + */ +lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc); + +/** + * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`. + * Required only if the "open" function can't return with the whole decoded pixel array. + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor + * @param x start x coordinate + * @param y start y coordinate + * @param len number of pixels to decode + * @param buf a buffer to store the decoded pixels + * @return LV_RES_OK: ok; LV_RES_INV: failed + */ +lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x, + lv_coord_t y, lv_coord_t len, uint8_t * buf); + +/** + * Close the pending decoding. Free resources etc. + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor + */ +void lv_img_decoder_built_in_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMG_DECODER_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/nxp/lv_gpu_nxp.h b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/lv_gpu_nxp.h new file mode 100644 index 00000000..853da566 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/lv_gpu_nxp.h @@ -0,0 +1,71 @@ +/** + * @file lv_gpu_nxp.h + * + */ + +/** + * MIT License + * + * Copyright 2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_GPU_NXP_H +#define LV_GPU_NXP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_GPU_NXP_PXP || LV_USE_GPU_NXP_VG_LITE +#include "../sw/lv_draw_sw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef lv_draw_sw_ctx_t lv_draw_nxp_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_nxp_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_nxp_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_GPU_NXP_PXP || LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_NXP_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_draw_pxp_blend.h b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_draw_pxp_blend.h new file mode 100644 index 00000000..acce8713 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_draw_pxp_blend.h @@ -0,0 +1,143 @@ +/** + * @file lv_draw_pxp_blend.h + * + */ + +/** + * MIT License + * + * Copyright 2020-2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_DRAW_PXP_BLEND_H +#define LV_DRAW_PXP_BLEND_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_PXP +#include "lv_gpu_nxp_pxp.h" +#include "../../sw/lv_draw_sw.h" + +/********************* + * DEFINES + *********************/ + +#ifndef LV_GPU_NXP_PXP_BLIT_SIZE_LIMIT +/** Minimum area (in pixels) for image copy with 100% opacity to be handled by PXP*/ +#define LV_GPU_NXP_PXP_BLIT_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_PXP_BLIT_OPA_SIZE_LIMIT +/** Minimum area (in pixels) for image copy with transparency to be handled by PXP*/ +#define LV_GPU_NXP_PXP_BLIT_OPA_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_PXP_BUFF_SYNC_BLIT_SIZE_LIMIT +/** Minimum invalidated area (in pixels) to be synchronized by PXP during buffer sync */ +#define LV_GPU_NXP_PXP_BUFF_SYNC_BLIT_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_PXP_FILL_SIZE_LIMIT +/** Minimum area (in pixels) to be filled by PXP with 100% opacity*/ +#define LV_GPU_NXP_PXP_FILL_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_PXP_FILL_OPA_SIZE_LIMIT +/** Minimum area (in pixels) to be filled by PXP with transparency*/ +#define LV_GPU_NXP_PXP_FILL_OPA_SIZE_LIMIT 5000 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Fill area, with optional opacity. + * + * @param[in/out] dest_buf destination buffer + * @param[in] dest_stride width (stride) of destination buffer in pixels + * @param[in] fill_area area to fill + * @param[in] color color + * @param[in] opa transparency of the color + * @retval LV_RES_OK Fill completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_pxp_fill(lv_color_t * dest_buf, lv_coord_t dest_stride, const lv_area_t * fill_area, + lv_color_t color, lv_opa_t opa); + +/** + * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with effects. + * By default, image is copied directly, with optional opacity. This function can also + * rotate the display output buffer to a specified angle (90x step). + * + * @param[in/out] dest_buf destination buffer + * @param[in] dest_area destination area + * @param[in] dest_stride width (stride) of destination buffer in pixels + * @param[in] src_buf source buffer + * @param[in] src_area source area with absolute coordinates to draw on destination buffer + * @param[in] opa opacity of the result + * @param[in] angle display rotation angle (90x) + * @retval LV_RES_OK Fill completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_pxp_blit(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride, + const lv_color_t * src_buf, const lv_area_t * src_area, lv_opa_t opa, lv_disp_rot_t angle); + +/** + * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with transformation. + * + * + * @param[in/out] dest_buf destination buffer + * @param[in] dest_area destination area + * @param[in] dest_stride width (stride) of destination buffer in pixels + * @param[in] src_buf source buffer + * @param[in] src_area source area with absolute coordinates to draw on destination buffer + * @param[in] dsc image descriptor + * @param[in] cf color format + * @retval LV_RES_OK Fill completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_pxp_blit_transform(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride, + const lv_color_t * src_buf, const lv_area_t * src_area, const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_PXP*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_PXP_BLEND_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp.h b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp.h new file mode 100644 index 00000000..aeb9d6c0 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp.h @@ -0,0 +1,153 @@ +/** + * @file lv_gpu_nxp_pxp.h + * + */ + +/** + * MIT License + * + * Copyright 2020-2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_GPU_NXP_PXP_H +#define LV_GPU_NXP_PXP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_PXP +#include "fsl_cache.h" +#include "fsl_pxp.h" + +#include "../../../misc/lv_log.h" + +/********************* + * DEFINES + *********************/ + +/** PXP module instance to use*/ +#define LV_GPU_NXP_PXP_ID PXP + +/** PXP interrupt line ID*/ +#define LV_GPU_NXP_PXP_IRQ_ID PXP_IRQn + +#ifndef LV_GPU_NXP_PXP_LOG_ERRORS +/** Enable logging of PXP errors (\see LV_LOG_ERROR)*/ +#define LV_GPU_NXP_PXP_LOG_ERRORS 1 +#endif + +#ifndef LV_GPU_NXP_PXP_LOG_TRACES +/** Enable logging of PXP errors (\see LV_LOG_ERROR)*/ +#define LV_GPU_NXP_PXP_LOG_TRACES 0 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/** + * NXP PXP device configuration - call-backs used for + * interrupt init/wait/deinit. + */ +typedef struct { + /** Callback for PXP interrupt initialization*/ + lv_res_t (*pxp_interrupt_init)(void); + + /** Callback for PXP interrupt de-initialization*/ + void (*pxp_interrupt_deinit)(void); + + /** Callback that should start PXP and wait for operation complete*/ + void (*pxp_run)(void); +} lv_nxp_pxp_cfg_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Reset and initialize PXP device. This function should be called as a part + * of display init sequence. + * + * @retval LV_RES_OK PXP init completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_pxp_init(void); + +/** + * Disable PXP device. Should be called during display deinit sequence. + */ +void lv_gpu_nxp_pxp_deinit(void); + +/** + * Start PXP job and wait for completion. + */ +void lv_gpu_nxp_pxp_run(void); + +/********************** + * MACROS + **********************/ + +#define PXP_COND_STOP(cond, txt) \ + do { \ + if (cond) { \ + LV_LOG_ERROR("%s. STOP!", txt); \ + for ( ; ; ); \ + } \ + } while(0) + +#if LV_GPU_NXP_PXP_LOG_ERRORS +#define PXP_RETURN_INV(fmt, ...) \ + do { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + return LV_RES_INV; \ + } while (0) +#else +#define PXP_RETURN_INV(fmt, ...) \ + do { \ + return LV_RES_INV; \ + }while(0) +#endif /*LV_GPU_NXP_PXP_LOG_ERRORS*/ + +#if LV_GPU_NXP_PXP_LOG_TRACES +#define PXP_LOG_TRACE(fmt, ...) \ + do { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + } while (0) +#else +#define PXP_LOG_TRACE(fmt, ...) \ + do { \ + } while (0) +#endif /*LV_GPU_NXP_PXP_LOG_TRACES*/ + +#endif /*LV_USE_GPU_NXP_PXP*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_NXP_PXP_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.h b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.h new file mode 100644 index 00000000..d9074472 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.h @@ -0,0 +1,78 @@ +/** + * @file lv_gpu_nxp_pxp_osa.h + * + */ + +/** + * MIT License + * + * Copyright 2020, 2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_GPU_NXP_PXP_OSA_H +#define LV_GPU_NXP_PXP_OSA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT +#include "lv_gpu_nxp_pxp.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * PXP device interrupt handler. Used to check PXP task completion status. + */ +void PXP_IRQHandler(void); + +/** + * Helper function to get the PXP default configuration. + */ +lv_nxp_pxp_cfg_t * lv_gpu_nxp_pxp_get_cfg(void); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_NXP_PXP_OSA_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_arc.h b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_arc.h new file mode 100644 index 00000000..e2da4190 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_arc.h @@ -0,0 +1,79 @@ +/** + * @file lv_draw_vglite_arc.h + * + */ + +/** + * MIT License + * + * Copyright 2021, 2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_DRAW_VGLITE_ARC_H +#define LV_DRAW_VGLITE_ARC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_VG_LITE +#include "lv_gpu_nxp_vglite.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*** + * Draw arc shape with effects + * @param draw_ctx drawing context + * @param dsc the arc description structure (width, rounded ending, opacity) + * @param center the coordinates of the arc center + * @param radius the radius of external arc + * @param start_angle the starting angle in degrees + * @param end_angle the ending angle in degrees + */ +lv_res_t lv_gpu_nxp_vglite_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, + int32_t radius, int32_t start_angle, int32_t end_angle); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_VGLITE_ARC_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_blend.h b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_blend.h new file mode 100644 index 00000000..1726dcd9 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_blend.h @@ -0,0 +1,149 @@ +/** + * @file lv_draw_vglite_blend.h + * + */ + +/** + * MIT License + * + * Copyright 2020-2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_DRAW_VGLITE_BLEND_H +#define LV_DRAW_VGLITE_BLEND_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_VG_LITE +#include "lv_gpu_nxp_vglite.h" + +/********************* + * DEFINES + *********************/ + +#ifndef LV_GPU_NXP_VG_LITE_FILL_SIZE_LIMIT +/** Minimum area (in pixels) to be filled by VG-Lite with 100% opacity*/ +#define LV_GPU_NXP_VG_LITE_FILL_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_FILL_OPA_SIZE_LIMIT +/** Minimum area (in pixels) to be filled by VG-Lite with transparency*/ +#define LV_GPU_NXP_VG_LITE_FILL_OPA_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_BLIT_SIZE_LIMIT +/** Minimum area (in pixels) for image copy with 100% opacity to be handled by VG-Lite*/ +#define LV_GPU_NXP_VG_LITE_BLIT_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_BUFF_SYNC_BLIT_SIZE_LIMIT +/** Minimum invalidated area (in pixels) to be synchronized by VG-Lite during buffer sync */ +#define LV_GPU_NXP_VG_LITE_BUFF_SYNC_BLIT_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_BLIT_OPA_SIZE_LIMIT +/** Minimum area (in pixels) for image copy with transparency to be handled by VG-Lite*/ +#define LV_GPU_NXP_VG_LITE_BLIT_OPA_SIZE_LIMIT 5000 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/** + * BLock Image Transfer descriptor structure + */ +typedef struct { + + const lv_color_t * src; /**< Source buffer pointer (must be aligned on 32 bytes)*/ + lv_area_t src_area; /**< Area to be copied from source*/ + lv_coord_t src_width; /**< Source buffer width*/ + lv_coord_t src_height; /**< Source buffer height*/ + int32_t src_stride; /**< Source buffer stride in bytes (must be aligned on 16 px)*/ + + const lv_color_t * dst; /**< Destination buffer pointer (must be aligned on 32 bytes)*/ + lv_area_t dst_area; /**< Target area in destination buffer (must be the same as src_area)*/ + lv_coord_t dst_width; /**< Destination buffer width*/ + lv_coord_t dst_height; /**< Destination buffer height*/ + int32_t dst_stride; /**< Destination buffer stride in bytes (must be aligned on 16 px)*/ + + lv_opa_t opa; /**< Opacity - alpha mix (0 = source not copied, 255 = 100% opaque)*/ + uint32_t angle; /**< Rotation angle (1/10 of degree)*/ + uint32_t zoom; /**< 256 = no zoom (1:1 scale ratio)*/ + lv_point_t pivot; /**< The coordinates of rotation pivot in source image buffer*/ +} lv_gpu_nxp_vglite_blit_info_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Fill area, with optional opacity. + * + * @param[in/out] dest_buf Destination buffer pointer (must be aligned on 32 bytes) + * @param[in] dest_width Destination buffer width in pixels (must be aligned on 16 px) + * @param[in] dest_height Destination buffer height in pixels + * @param[in] fill_area Area to be filled + * @param[in] color Fill color + * @param[in] opa Opacity (255 = full, 128 = 50% background/50% color, 0 = no fill) + * @retval LV_RES_OK Fill completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_vglite_fill(lv_color_t * dest_buf, lv_coord_t dest_width, lv_coord_t dest_height, + const lv_area_t * fill_area, lv_color_t color, lv_opa_t opa); + +/** + * BLock Image Transfer. + * + * @param[in] blit Description of the transfer + * @retval LV_RES_OK Transfer complete + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_vglite_blit(lv_gpu_nxp_vglite_blit_info_t * blit); + +/** + * BLock Image Transfer with transformation. + * + * @param[in] blit Description of the transfer + * @retval LV_RES_OK Transfer complete + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_vglite_blit_transform(lv_gpu_nxp_vglite_blit_info_t * blit); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_VGLITE_BLEND_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_rect.h b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_rect.h new file mode 100644 index 00000000..8a641707 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_rect.h @@ -0,0 +1,77 @@ +/** + * @file lv_draw_vglite_rect.h + * + */ + +/** + * MIT License + * + * Copyright 2021, 2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_DRAW_VGLITE_RECT_H +#define LV_DRAW_VGLITE_RECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_VG_LITE +#include "lv_gpu_nxp_vglite.h" +#include "../../lv_draw_rect.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Draw rectangle shape with effects (rounded corners, gradient) + * + * @param draw_ctx drawing context + * @param dsc description of the rectangle + * @param coords the area where rectangle is clipped + */ +lv_res_t lv_gpu_nxp_vglite_draw_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_VGLITE_RECT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_gpu_nxp_vglite.h b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_gpu_nxp_vglite.h new file mode 100644 index 00000000..87544925 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/nxp/vglite/lv_gpu_nxp_vglite.h @@ -0,0 +1,185 @@ +/** + * @file lv_gpu_nxp_vglite.h + * + */ + +/** + * MIT License + * + * Copyright 2020-2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_GPU_NXP_VGLITE_H +#define LV_GPU_NXP_VGLITE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_VG_LITE +#include "vg_lite.h" +#include "../../sw/lv_draw_sw.h" +#include "../../../misc/lv_log.h" +#include "fsl_debug_console.h" + +/********************* + * DEFINES + *********************/ + +/** Use this symbol as limit to disable feature (value has to be larger than supported resolution) */ +#define LV_GPU_NXP_VG_LITE_FEATURE_DISABLED (1920*1080+1) + +/** Stride in px required by VG-Lite HW. Don't change this. */ +#define LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX 16U + +#ifndef LV_GPU_NXP_VG_LITE_LOG_ERRORS +/** Enable logging of VG-Lite errors (\see LV_LOG_ERROR)*/ +#define LV_GPU_NXP_VG_LITE_LOG_ERRORS 1 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_LOG_TRACES +/** Enable logging of VG-Lite errors (\see LV_LOG_ERROR)*/ +#define LV_GPU_NXP_VG_LITE_LOG_TRACES 0 +#endif + +/* Draw rectangles around BLIT tiles */ +#define BLIT_DBG_AREAS 0 + +/* Print detailed info to SDK console (NOT to LVGL log system) */ +#define BLIT_DBG_VERBOSE 0 + +/* Verbose debug print */ +#if BLIT_DBG_VERBOSE +#define PRINT_BLT PRINTF +#else +#define PRINT_BLT(...) +#endif + +/* The optimal Bezier control point offset for radial unit + * see: https://spencermortensen.com/articles/bezier-circle/ + **/ +#define BEZIER_OPTIM_CIRCLE 0.551915024494f + +/* Draw lines for control points of Bezier curves */ +#define BEZIER_DBG_CONTROL_POINTS 0 + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Fills vg_lite_buffer_t structure according given parameters. + * + * @param[in/out] vgbuf Buffer structure to be filled + * @param[in] width Width of buffer in pixels + * @param[in] height Height of buffer in pixels + * @param[in] stride Stride of the buffer in bytes + * @param[in] ptr Pointer to the buffer (must be aligned according VG-Lite requirements) + * @param[in] source Boolean to check if this is a source buffer + */ +lv_res_t lv_vglite_init_buf(vg_lite_buffer_t * vgbuf, uint32_t width, uint32_t height, uint32_t stride, + const lv_color_t * ptr, bool source); + +#if BLIT_DBG_AREAS +/** + * Draw a simple rectangle, 1 px line width. + * + * @param dest_buf Destination buffer + * @param dest_width Destination buffer width (must be aligned on 16px) + * @param dest_height Destination buffer height + * @param fill_area Rectangle coordinates + * @param color Rectangle color + */ +void lv_vglite_dbg_draw_rectangle(lv_color_t * dest_buf, lv_coord_t dest_width, lv_coord_t dest_height, + lv_area_t * fill_area, lv_color_t color); +#endif + +/** + * Clean & invalidate cache. + */ +void lv_vglite_invalidate_cache(void); + +/********************** + * MACROS + **********************/ + +#define VG_LITE_COND_STOP(cond, txt) \ + do { \ + if (cond) { \ + LV_LOG_ERROR("%s. STOP!", txt); \ + for ( ; ; ); \ + } \ + } while(0) + +#if LV_GPU_NXP_VG_LITE_LOG_ERRORS +#define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \ + do { \ + if(err != VG_LITE_SUCCESS) { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + return LV_RES_INV; \ + } \ + } while (0) +#else +#define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \ + do { \ + if(err != VG_LITE_SUCCESS) { \ + return LV_RES_INV; \ + } \ + }while(0) +#endif /*LV_GPU_NXP_VG_LITE_LOG_ERRORS*/ + +#if LV_GPU_NXP_VG_LITE_LOG_TRACES +#define VG_LITE_LOG_TRACE(fmt, ...) \ + do { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + } while (0) + +#define VG_LITE_RETURN_INV(fmt, ...) \ + do { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + return LV_RES_INV; \ + } while (0) +#else +#define VG_LITE_LOG_TRACE(fmt, ...) \ + do { \ + } while (0) +#define VG_LITE_RETURN_INV(fmt, ...) \ + do { \ + return LV_RES_INV; \ + }while(0) +#endif /*LV_GPU_NXP_VG_LITE_LOG_TRACES*/ + +#endif /*LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_NXP_VGLITE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl.h new file mode 100644 index 00000000..7708d5b7 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl.h @@ -0,0 +1,96 @@ +/** + * @file lv_draw_sdl.h + * + */ + +#ifndef LV_DRAW_SDL_H +#define LV_DRAW_SDL_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "../lv_draw.h" +#include "../../core/lv_disp.h" + +/********************* + * DEFINES + *********************/ + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +#define LV_DRAW_SDL_TEXTURE_FORMAT SDL_PIXELFORMAT_ARGB8888 +#else +#define LV_DRAW_SDL_TEXTURE_FORMAT SDL_PIXELFORMAT_RGBA8888 +#endif + +/********************** + * TYPEDEFS + **********************/ + +struct lv_draw_sdl_context_internals_t; + +typedef struct { + /** + * Render for display driver + */ + SDL_Renderer * renderer; + void * user_data; +} lv_draw_sdl_drv_param_t; + +typedef struct { + lv_draw_ctx_t base_draw; + SDL_Renderer * renderer; + struct lv_draw_sdl_context_internals_t * internals; +} lv_draw_sdl_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_sdl_init_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); + +/** + * @brief Free caches + * + */ +void lv_draw_sdl_deinit_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); + +SDL_Texture * lv_draw_sdl_create_screen_texture(SDL_Renderer * renderer, lv_coord_t hor, lv_coord_t ver); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_composite.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_composite.h new file mode 100644 index 00000000..3a598d76 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_composite.h @@ -0,0 +1,73 @@ +/** + * @file lv_draw_sdl_composite.h + * + */ + +#ifndef LV_DRAW_SDL_COMPOSITE_H +#define LV_DRAW_SDL_COMPOSITE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "lv_draw_sdl.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_color.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef enum lv_draw_sdl_composite_texture_id_t { + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM0, + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1, + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0, + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET1, + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TRANSFORM0, +} lv_draw_sdl_composite_texture_id_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Begin drawing with mask. Render target will be switched to a temporary texture, + * and drawing coordinates may get clipped or translated + * @param coords_in Original coordinates + * @param clip_in Original clip area + * @param extension Useful for shadows or outlines, can be NULL + * @param coords_out Translated coords + * @param clip_out Translated clip area + * @param apply_area Area of actual composited texture will be drawn + * @return true if there are any mask needs to be drawn, false otherwise + */ +bool lv_draw_sdl_composite_begin(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords_in, const lv_area_t * clip_in, + const lv_area_t * extension, lv_blend_mode_t blend_mode, lv_area_t * coords_out, + lv_area_t * clip_out, lv_area_t * apply_area); + +void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_area, lv_blend_mode_t blend_mode); + +SDL_Texture * lv_draw_sdl_composite_texture_obtain(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_composite_texture_id_t id, + lv_coord_t w, lv_coord_t h); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_COMPOSITE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_img.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_img.h new file mode 100644 index 00000000..d6e3758c --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_img.h @@ -0,0 +1,72 @@ +/** + * @file lv_draw_sdl_img.h + * + */ + +#ifndef LV_DRAW_SDL_IMG_H +#define LV_DRAW_SDL_IMG_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "../lv_draw.h" + +#include "lv_draw_sdl_texture_cache.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct lv_draw_sdl_img_header_t { + lv_img_header_t base; + SDL_Rect rect; +} lv_draw_sdl_img_header_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ +bool lv_draw_sdl_img_load_texture(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_cache_key_head_img_t * key, size_t key_size, + const void * src, int32_t frame_id, SDL_Texture ** texture, + lv_draw_sdl_img_header_t ** header); +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_IMG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_layer.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_layer.h new file mode 100644 index 00000000..b60303c4 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_layer.h @@ -0,0 +1,55 @@ +/** + * @file lv_draw_sdl_refr.h + * + */ + +#ifndef LV_TEMPL_H +#define LV_TEMPL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_sdl.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct _lv_draw_sdl_layer_ctx_t { + lv_draw_layer_ctx_t base; + + SDL_Texture * orig_target; + SDL_Texture * target; + SDL_Rect target_rect; + lv_draw_layer_flags_t flags; +} lv_draw_sdl_layer_ctx_t; +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_draw_layer_ctx_t * lv_draw_sdl_layer_init(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + +void lv_draw_sdl_layer_blend(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * transform_ctx, + const lv_draw_img_dsc_t * draw_dsc); + +void lv_draw_sdl_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx); + +void lv_draw_sdl_transform_areas_offset(lv_draw_sdl_ctx_t * ctx, bool has_composite, lv_area_t * apply_area, + lv_area_t * coords, lv_area_t * clip); +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TEMPL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_mask.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_mask.h new file mode 100644 index 00000000..aa4dd2b8 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_mask.h @@ -0,0 +1,51 @@ +/** + * @file lv_draw_sdl_mask.h + * + */ + +#ifndef LV_DRAW_SDL_MASK_H +#define LV_DRAW_SDL_MASK_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "lv_draw_sdl.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_color.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_opa_t * lv_draw_sdl_mask_dump_opa(const lv_area_t * coords, const int16_t * ids, int16_t ids_count); + +SDL_Texture * lv_draw_sdl_mask_dump_texture(SDL_Renderer * renderer, const lv_area_t * coords, const int16_t * ids, + int16_t ids_count); + + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_MASK_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_priv.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_priv.h new file mode 100644 index 00000000..736fe89f --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_priv.h @@ -0,0 +1,72 @@ +/** + * @file lv_draw_sdl_priv.h + * + */ + +#ifndef LV_DRAW_SDL_PRIV_H +#define LV_DRAW_SDL_PRIV_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "../lv_draw.h" +#include "../../misc/lv_lru.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct lv_draw_sdl_context_internals_t { + lv_lru_t * texture_cache; + SDL_Texture * mask; + SDL_Texture * composition; + SDL_Texture * target_backup; + uint8_t transform_count; +} lv_draw_sdl_context_internals_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_PRIV_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_rect.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_rect.h new file mode 100644 index 00000000..fc968945 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_rect.h @@ -0,0 +1,75 @@ +/** + * @file lv_draw_sdl_rect.h + * + */ + +#ifndef LV_DRAW_SDL_RECT_H +#define LV_DRAW_SDL_RECT_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "../lv_draw.h" + +#include "lv_draw_sdl_texture_cache.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct lv_draw_sdl_rect_header_t { + lv_img_header_t base; + SDL_Rect rect; +} lv_draw_sdl_rect_header_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ + +SDL_Texture * lv_draw_sdl_rect_bg_frag_obtain(lv_draw_sdl_ctx_t * ctx, lv_coord_t radius); + +void lv_draw_sdl_rect_bg_frag_draw_corners(lv_draw_sdl_ctx_t * ctx, SDL_Texture * frag, lv_coord_t frag_size, + const lv_area_t * coords, const lv_area_t * clip, bool full); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_RECT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_stack_blur.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_stack_blur.h new file mode 100644 index 00000000..3d854e3a --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_stack_blur.h @@ -0,0 +1,46 @@ +/** + * @file lv_draw_sdl_stack_blur.h + * + */ +#ifndef LV_DRAW_SDL_STACK_BLUR_H +#define LV_DRAW_SDL_STACK_BLUR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include "../../misc/lv_color.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_stack_blur_grayscale(lv_opa_t * buf, uint16_t w, uint16_t h, uint16_t r); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_STACK_BLUR_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_texture_cache.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_texture_cache.h new file mode 100644 index 00000000..0b54246f --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_texture_cache.h @@ -0,0 +1,102 @@ +/** + * @file lv_draw_sdl_texture_cache.h + * + */ + +#ifndef LV_DRAW_SDL_TEXTURE_CACHE_H +#define LV_DRAW_SDL_TEXTURE_CACHE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH +#include "lv_draw_sdl.h" +#include "lv_draw_sdl_priv.h" +#include "../../draw/lv_img_decoder.h" +#include "../../misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +#define LV_DRAW_SDL_DEC_DSC_TEXTURE_HEAD "@LVSDLTex" + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + char head[8]; + SDL_Texture * texture; + SDL_Rect rect; + bool texture_managed; + bool texture_referenced; +} lv_draw_sdl_dec_dsc_userdata_t; + +typedef enum { + LV_GPU_CACHE_KEY_MAGIC_ARC = 0x01, + LV_GPU_CACHE_KEY_MAGIC_IMG = 0x11, + LV_GPU_CACHE_KEY_MAGIC_IMG_ROUNDED_CORNERS = 0x12, + LV_GPU_CACHE_KEY_MAGIC_LINE = 0x21, + LV_GPU_CACHE_KEY_MAGIC_RECT_BG = 0x31, + LV_GPU_CACHE_KEY_MAGIC_RECT_SHADOW = 0x32, + LV_GPU_CACHE_KEY_MAGIC_RECT_BORDER = 0x33, + LV_GPU_CACHE_KEY_MAGIC_FONT_GLYPH = 0x41, + LV_GPU_CACHE_KEY_MAGIC_MASK = 0x51, +} lv_sdl_cache_key_magic_t; + +typedef enum { + LV_DRAW_SDL_CACHE_FLAG_NONE = 0, + LV_DRAW_SDL_CACHE_FLAG_MANAGED = 1, +} lv_draw_sdl_cache_flag_t; + +typedef struct { + lv_sdl_cache_key_magic_t magic; + lv_img_src_t type; + int32_t frame_id; +} lv_draw_sdl_cache_key_head_img_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_sdl_texture_cache_init(lv_draw_sdl_ctx_t * ctx); + +void lv_draw_sdl_texture_cache_deinit(lv_draw_sdl_ctx_t * ctx); + +/** + * Find cached texture by key. The texture can be destroyed during usage. + */ +SDL_Texture * lv_draw_sdl_texture_cache_get(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, bool * found); + +SDL_Texture * lv_draw_sdl_texture_cache_get_with_userdata(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, + bool * found, void ** userdata); + +void lv_draw_sdl_texture_cache_put(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, SDL_Texture * texture); + +void lv_draw_sdl_texture_cache_put_advanced(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, + SDL_Texture * texture, void * userdata, void userdata_free(void *), + lv_draw_sdl_cache_flag_t flags); + +lv_draw_sdl_cache_key_head_img_t * lv_draw_sdl_texture_img_key_create(const void * src, int32_t frame_id, + size_t * size); + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_TEXTURE_CACHE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_utils.h b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_utils.h new file mode 100644 index 00000000..943bda3b --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sdl/lv_draw_sdl_utils.h @@ -0,0 +1,65 @@ +/** + * @file lv_draw_sdl_utils.h + * + */ +#ifndef LV_DRAW_SDL_UTILS_H +#define LV_DRAW_SDL_UTILS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_GPU_SDL + +#include "lv_draw_sdl.h" +#include "../../misc/lv_color.h" +#include "../../misc/lv_area.h" + +#include LV_GPU_SDL_INCLUDE_PATH + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void _lv_draw_sdl_utils_init(); + +void _lv_draw_sdl_utils_deinit(); + +void lv_area_to_sdl_rect(const lv_area_t * in, SDL_Rect * out); + +void lv_color_to_sdl_color(const lv_color_t * in, SDL_Color * out); + +void lv_area_zoom_to_sdl_rect(const lv_area_t * in, SDL_Rect * out, uint16_t zoom, const lv_point_t * pivot); + +SDL_Palette * lv_sdl_alloc_palette_for_bpp(const uint8_t * mapping, uint8_t bpp); + +SDL_Surface * lv_sdl_create_opa_surface(lv_opa_t * opa, lv_coord_t width, lv_coord_t height, lv_coord_t stride); + +SDL_Texture * lv_sdl_create_opa_texture(SDL_Renderer * renderer, lv_opa_t * pixels, lv_coord_t width, + lv_coord_t height, lv_coord_t stride); + +void lv_sdl_to_8bpp(uint8_t * dest, const uint8_t * src, int width, int height, int stride, uint8_t bpp); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_UTILS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/stm32_dma2d/lv_gpu_stm32_dma2d.h b/EZ-Template-Example-Project/include/liblvgl/draw/stm32_dma2d/lv_gpu_stm32_dma2d.h new file mode 100644 index 00000000..f2bcdbea --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/stm32_dma2d/lv_gpu_stm32_dma2d.h @@ -0,0 +1,70 @@ +/** + * @file lv_gpu_stm32_dma2d.h + * + */ + +#ifndef LV_GPU_STM32_DMA2D_H +#define LV_GPU_STM32_DMA2D_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/hal/lv_hal_disp.h" +#include "liblvgl/draw/sw/lv_draw_sw.h" + +#if LV_USE_GPU_STM32_DMA2D + +/********************* + * DEFINES + *********************/ + +#define LV_DMA2D_ARGB8888 0 +#define LV_DMA2D_RGB888 1 +#define LV_DMA2D_RGB565 2 +#define LV_DMA2D_ARGB1555 3 +#define LV_DMA2D_ARGB4444 4 + +/********************** + * TYPEDEFS + **********************/ +typedef lv_draw_sw_ctx_t lv_draw_stm32_dma2d_ctx_t; + +struct _lv_disp_drv_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Turn on the peripheral and set output color mode, this only needs to be done once + */ +void lv_draw_stm32_dma2d_init(void); + +void lv_draw_stm32_dma2d_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_stm32_dma2d_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_stm32_dma2d_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); + +void lv_draw_stm32_dma2d_buffer_copy(lv_draw_ctx_t * draw_ctx, + void * dest_buf, lv_coord_t dest_stride, const lv_area_t * dest_area, + void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area); + +void lv_gpu_stm32_dma2d_wait_cb(lv_draw_ctx_t * draw_ctx); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_STM32_DMA2D*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_STM32_DMA2D_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw.h b/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw.h new file mode 100644 index 00000000..4496612d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw.h @@ -0,0 +1,104 @@ +/** + * @file lv_draw_sw.h + * + */ + +#ifndef LV_DRAW_SW_H +#define LV_DRAW_SW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_sw_blend.h" +#include "liblvgl/draw/lv_draw.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/hal/lv_hal_disp.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_disp_drv_t; + +typedef struct { + lv_draw_ctx_t base_draw; + + /** Fill an area of the destination buffer with a color*/ + void (*blend)(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); +} lv_draw_sw_ctx_t; + +typedef struct { + lv_draw_layer_ctx_t base_draw; + + uint32_t buf_size_bytes: 31; + uint32_t has_alpha : 1; +} lv_draw_sw_layer_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_sw_init_ctx(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); +void lv_draw_sw_deinit_ctx(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_sw_wait_for_finish(lv_draw_ctx_t * draw_ctx); + +void lv_draw_sw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, uint16_t radius, + uint16_t start_angle, uint16_t end_angle); + +void lv_draw_sw_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); + +void lv_draw_sw_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); +void lv_draw_sw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p, + uint32_t letter); + +LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_img_decoded(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * draw_dsc, + const lv_area_t * coords, const uint8_t * src_buf, lv_img_cf_t cf); + +LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_line(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, + const lv_point_t * point1, const lv_point_t * point2); + +void lv_draw_sw_polygon(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, + const lv_point_t * points, uint16_t point_cnt); + +void lv_draw_sw_buffer_copy(lv_draw_ctx_t * draw_ctx, + void * dest_buf, lv_coord_t dest_stride, const lv_area_t * dest_area, + void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area); + +void lv_draw_sw_transform(lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf, + lv_coord_t src_w, lv_coord_t src_h, lv_coord_t src_stride, + const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf); + +struct _lv_draw_layer_ctx_t * lv_draw_sw_layer_create(struct _lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + +void lv_draw_sw_layer_adjust(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + +void lv_draw_sw_layer_blend(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + const lv_draw_img_dsc_t * draw_dsc); + +void lv_draw_sw_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx); + +/*********************** + * GLOBAL VARIABLES + ***********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SW_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_blend.h b/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_blend.h new file mode 100644 index 00000000..6fa859c9 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_blend.h @@ -0,0 +1,69 @@ +/** + * @file lv_draw_sw_blend.h + * + */ + +#ifndef LV_DRAW_SW_BLEND_H +#define LV_DRAW_SW_BLEND_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_style.h" +#include "liblvgl/draw/lv_draw_mask.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + const lv_area_t * blend_area; /**< The area with absolute coordinates to draw on `draw_ctx->buf` + * will be clipped to `draw_ctx->clip_area` */ + const lv_color_t * src_buf; /**< Pointer to an image to blend. If set `fill_color` is ignored */ + lv_color_t color; /**< Fill color*/ + lv_opa_t * mask_buf; /**< NULL if ignored, or an alpha mask to apply on `blend_area`*/ + lv_draw_mask_res_t mask_res; /**< The result of the previous mask operation */ + const lv_area_t * mask_area; /**< The area of `mask_buf` with absolute coordinates*/ + lv_opa_t opa; /**< The overall opacity*/ + lv_blend_mode_t blend_mode; /**< E.g. LV_BLEND_MODE_ADDITIVE*/ +} lv_draw_sw_blend_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Call the blend function of the `draw_ctx`. + * @param draw_ctx pointer to a draw context + * @param dsc pointer to an initialized blend descriptor + */ +void lv_draw_sw_blend(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); + +/** + * The basic blend function used with software rendering. + * @param draw_ctx pointer to a draw context + * @param dsc pointer to an initialized blend descriptor + */ +LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_blend_basic(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SW_BLEND_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_dither.h b/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_dither.h new file mode 100644 index 00000000..9785e187 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_dither.h @@ -0,0 +1,70 @@ +/** + * @file lv_draw_sw_dither.h + * + */ + +#ifndef LV_DRAW_SW_DITHER_H +#define LV_DRAW_SW_DITHER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj_pos.h" + + +/********************* + * DEFINES + *********************/ +#if LV_COLOR_DEPTH < 32 && LV_DITHER_GRADIENT == 1 +#define _DITHER_GRADIENT 1 +#else +#define _DITHER_GRADIENT 0 +#endif + +/********************** + * TYPEDEFS + **********************/ +#if _DITHER_GRADIENT +/*A signed error color component*/ +typedef struct { + int8_t r, g, b; +} lv_scolor24_t; + +struct _lv_gradient_cache_t; +typedef void (*lv_dither_func_t)(struct _lv_gradient_cache_t * grad, lv_coord_t x, lv_coord_t y, lv_coord_t w); + +#endif + + +/********************** + * PROTOTYPES + **********************/ +#if LV_DRAW_COMPLEX +#if _DITHER_GRADIENT +LV_ATTRIBUTE_FAST_MEM void lv_dither_none(struct _lv_gradient_cache_t * grad, lv_coord_t x, lv_coord_t y, lv_coord_t w); + +LV_ATTRIBUTE_FAST_MEM void lv_dither_ordered_hor(struct _lv_gradient_cache_t * grad, const lv_coord_t xs, + const lv_coord_t y, const lv_coord_t w); +LV_ATTRIBUTE_FAST_MEM void lv_dither_ordered_ver(struct _lv_gradient_cache_t * grad, const lv_coord_t xs, + const lv_coord_t y, const lv_coord_t w); + +#if LV_DITHER_ERROR_DIFFUSION == 1 +LV_ATTRIBUTE_FAST_MEM void lv_dither_err_diff_hor(struct _lv_gradient_cache_t * grad, const lv_coord_t xs, + const lv_coord_t y, const lv_coord_t w); +LV_ATTRIBUTE_FAST_MEM void lv_dither_err_diff_ver(struct _lv_gradient_cache_t * grad, const lv_coord_t xs, + const lv_coord_t y, const lv_coord_t w); +#endif /* LV_DITHER_ERROR_DIFFUSION */ + +#endif /* _DITHER_GRADIENT */ +#endif + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_gradient.h b/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_gradient.h new file mode 100644 index 00000000..0860d50d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/sw/lv_draw_sw_gradient.h @@ -0,0 +1,97 @@ +/** + * @file lv_draw_sw_gradient.h + * + */ + +#ifndef LV_DRAW_SW_GRADIENT_H +#define LV_DRAW_SW_GRADIENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_style.h" +#include "lv_draw_sw_dither.h" + +/********************* + * DEFINES + *********************/ +#if LV_GRADIENT_MAX_STOPS < 2 +#error LVGL needs at least 2 stops for gradients. Please increase the LV_GRADIENT_MAX_STOPS +#endif + + +/********************** + * TYPEDEFS + **********************/ +#if _DITHER_GRADIENT +typedef lv_color32_t lv_grad_color_t; +#else +typedef lv_color_t lv_grad_color_t; +#endif + +/** To avoid recomputing gradient for each draw operation, + * it's possible to cache the computation in this structure instance. + * Whenever possible, this structure is reused instead of recomputing the gradient map */ +typedef struct _lv_gradient_cache_t { + uint32_t key; /**< A discriminating key that's built from the drawing operation. + * If the key does not match, the cache item is not used */ + uint32_t life : 30; /**< A life counter that's incremented on usage. Higher counter is + * less likely to be evicted from the cache */ + uint32_t filled : 1; /**< Used to skip dithering in it if already done */ + uint32_t not_cached: 1; /**< The cache was too small so this item is not managed by the cache*/ + lv_color_t * map; /**< The computed gradient low bitdepth color map, points into the + * cache's buffer, no free needed */ + lv_coord_t alloc_size; /**< The map allocated size in colors */ + lv_coord_t size; /**< The computed gradient color map size, in colors */ +#if _DITHER_GRADIENT + lv_color32_t * hmap; /**< If dithering, we need to store the current, high bitdepth gradient + * map too, points to the cache's buffer, no free needed */ +#if LV_DITHER_ERROR_DIFFUSION == 1 + lv_scolor24_t * error_acc; /**< Error diffusion dithering algorithm requires storing the last error + * drawn, points to the cache's buffer, no free needed */ + lv_coord_t w; /**< The error array width in pixels */ +#endif +#endif +} lv_grad_t; + + +/********************** + * PROTOTYPES + **********************/ +/** Compute the color in the given gradient and fraction + * Gradient are specified in a virtual [0-255] range, so this function scales the virtual range to the given range + * @param dsc The gradient descriptor to use + * @param range The range to use in computation. + * @param frac The current part used in the range. frac is in [0; range] + */ +LV_ATTRIBUTE_FAST_MEM lv_grad_color_t lv_gradient_calculate(const lv_grad_dsc_t * dsc, lv_coord_t range, + lv_coord_t frac); + +/** + * Set the gradient cache size + * @param max_bytes Max cahce size + */ +void lv_gradient_set_cache_size(size_t max_bytes); + +/** Free the gradient cache */ +void lv_gradient_free_cache(void); + +/** Get a gradient cache from the given parameters */ +lv_grad_t * lv_gradient_get(const lv_grad_dsc_t * gradient, lv_coord_t w, lv_coord_t h); + +/** + * Clean up the gradient item after it was get with `lv_grad_get_from_cache`. + * @param grad pointer to a gradient + */ +void lv_gradient_cleanup(lv_grad_t * grad); + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_GRADIENT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/draw/swm341_dma2d/lv_gpu_swm341_dma2d.h b/EZ-Template-Example-Project/include/liblvgl/draw/swm341_dma2d/lv_gpu_swm341_dma2d.h new file mode 100644 index 00000000..baec7fea --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/draw/swm341_dma2d/lv_gpu_swm341_dma2d.h @@ -0,0 +1,64 @@ +/** + * @file lv_gpu_swm341_dma2d.h + * + */ + +#ifndef LV_GPU_SWM341_DMA2D_H +#define LV_GPU_SWM341_DMA2D_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/hal/lv_hal_disp.h" +#include "liblvgl/draw/sw/lv_draw_sw.h" + +#if LV_USE_GPU_SWM341_DMA2D + +/********************* + * DEFINES + *********************/ + +#define LV_SWM341_DMA2D_ARGB8888 0 +#define LV_SWM341_DMA2D_RGB888 1 +#define LV_SWM341_DMA2D_RGB565 2 + +/********************** + * TYPEDEFS + **********************/ +typedef lv_draw_sw_ctx_t lv_draw_swm341_dma2d_ctx_t; + +struct _lv_disp_drv_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Turn on the peripheral and set output color mode, this only needs to be done once + */ +void lv_draw_swm341_dma2d_init(void); + +void lv_draw_swm341_dma2d_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_swm341_dma2d_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_swm341_dma2d_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); + +void lv_gpu_swm341_dma2d_wait_cb(lv_draw_ctx_t * draw_ctx); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SWM341_DMA2D*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_SWM341_DMA2D_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/layouts/flex/lv_flex.h b/EZ-Template-Example-Project/include/liblvgl/extra/layouts/flex/lv_flex.h new file mode 100644 index 00000000..d9619610 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/layouts/flex/lv_flex.h @@ -0,0 +1,152 @@ +/** + * @file lv_flex.h + * + */ + +#ifndef LV_FLEX_H +#define LV_FLEX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_FLEX + +/********************* + * DEFINES + *********************/ + +#define LV_OBJ_FLAG_FLEX_IN_NEW_TRACK LV_OBJ_FLAG_LAYOUT_1 +LV_EXPORT_CONST_INT(LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); + +#define _LV_FLEX_COLUMN (1 << 0) +#define _LV_FLEX_WRAP (1 << 2) +#define _LV_FLEX_REVERSE (1 << 3) + +/********************** + * TYPEDEFS + **********************/ + +/*Can't include lv_obj.h because it includes this header file*/ +struct _lv_obj_t; + +typedef enum { + LV_FLEX_ALIGN_START, + LV_FLEX_ALIGN_END, + LV_FLEX_ALIGN_CENTER, + LV_FLEX_ALIGN_SPACE_EVENLY, + LV_FLEX_ALIGN_SPACE_AROUND, + LV_FLEX_ALIGN_SPACE_BETWEEN, +} lv_flex_align_t; + +typedef enum { + LV_FLEX_FLOW_ROW = 0x00, + LV_FLEX_FLOW_COLUMN = _LV_FLEX_COLUMN, + LV_FLEX_FLOW_ROW_WRAP = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP, + LV_FLEX_FLOW_ROW_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_REVERSE, + LV_FLEX_FLOW_ROW_WRAP_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, + LV_FLEX_FLOW_COLUMN_WRAP = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP, + LV_FLEX_FLOW_COLUMN_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_REVERSE, + LV_FLEX_FLOW_COLUMN_WRAP_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, +} lv_flex_flow_t; + +/********************** + * GLOBAL VARIABLES + **********************/ +extern uint16_t LV_LAYOUT_FLEX; +extern lv_style_prop_t LV_STYLE_FLEX_FLOW; +extern lv_style_prop_t LV_STYLE_FLEX_MAIN_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_CROSS_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_TRACK_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_GROW; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize a flex layout the default values + * @param flex pointer to a flex layout descriptor + */ +void lv_flex_init(void); + +/** + * Set hot the item should flow + * @param flex pointer to a flex layout descriptor + * @param flow an element of `lv_flex_flow_t`. + */ +void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow); + +/** + * Set how to place (where to align) the items and tracks + * @param flex pointer: to a flex layout descriptor + * @param main_place where to place the items on main axis (in their track). Any value of `lv_flex_align_t`. + * @param cross_place where to place the item in their track on the cross axis. `LV_FLEX_ALIGN_START/END/CENTER` + * @param track_place where to place the tracks in the cross direction. Any value of `lv_flex_align_t`. + */ +void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place, + lv_flex_align_t track_cross_place); + +/** + * Sets the width or height (on main axis) to grow the object in order fill the free space + * @param obj pointer to an object. The parent must have flex layout else nothing will happen. + * @param grow a value to set how much free space to take proportionally to other growing items. + */ +void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow); + +void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value); +void lv_style_set_flex_main_place(lv_style_t * style, lv_flex_align_t value); +void lv_style_set_flex_cross_place(lv_style_t * style, lv_flex_align_t value); +void lv_style_set_flex_track_place(lv_style_t * style, lv_flex_align_t value); +void lv_style_set_flex_grow(lv_style_t * style, uint8_t value); +void lv_obj_set_style_flex_flow(lv_obj_t * obj, lv_flex_flow_t value, lv_style_selector_t selector); +void lv_obj_set_style_flex_main_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_flex_cross_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_flex_track_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_flex_grow(lv_obj_t * obj, uint8_t value, lv_style_selector_t selector); + +static inline lv_flex_flow_t lv_obj_get_style_flex_flow(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_FLOW); + return (lv_flex_flow_t)v.num; +} + +static inline lv_flex_align_t lv_obj_get_style_flex_main_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_MAIN_PLACE); + return (lv_flex_align_t)v.num; +} + +static inline lv_flex_align_t lv_obj_get_style_flex_cross_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_CROSS_PLACE); + return (lv_flex_align_t)v.num; +} + +static inline lv_flex_align_t lv_obj_get_style_flex_track_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_TRACK_PLACE); + return (lv_flex_align_t)v.num; +} + +static inline uint8_t lv_obj_get_style_flex_grow(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_GROW); + return (uint8_t)v.num; +} + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_FLEX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FLEX_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/layouts/grid/lv_grid.h b/EZ-Template-Example-Project/include/liblvgl/extra/layouts/grid/lv_grid.h new file mode 100644 index 00000000..8e57fd9c --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/layouts/grid/lv_grid.h @@ -0,0 +1,194 @@ +/** + * @file lv_grid.h + * + */ + +#ifndef LV_GRID_H +#define LV_GRID_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_GRID + +/********************* + * DEFINES + *********************/ +/** + * Can be used track size to make the track fill the free space. + * @param x how much space to take proportionally to other FR tracks + * @return a special track size + */ +#define LV_GRID_FR(x) (LV_COORD_MAX - 100 + x) + +#define LV_GRID_CONTENT (LV_COORD_MAX - 101) +LV_EXPORT_CONST_INT(LV_GRID_CONTENT); + +#define LV_GRID_TEMPLATE_LAST (LV_COORD_MAX) +LV_EXPORT_CONST_INT(LV_GRID_TEMPLATE_LAST); + +/********************** + * TYPEDEFS + **********************/ + +/*Can't include lv_obj.h because it includes this header file*/ +struct _lv_obj_t; + +typedef enum { + LV_GRID_ALIGN_START, + LV_GRID_ALIGN_CENTER, + LV_GRID_ALIGN_END, + LV_GRID_ALIGN_STRETCH, + LV_GRID_ALIGN_SPACE_EVENLY, + LV_GRID_ALIGN_SPACE_AROUND, + LV_GRID_ALIGN_SPACE_BETWEEN, +} lv_grid_align_t; + +/********************** + * GLOBAL VARIABLES + **********************/ + +extern uint16_t LV_LAYOUT_GRID; +extern lv_style_prop_t LV_STYLE_GRID_COLUMN_DSC_ARRAY; +extern lv_style_prop_t LV_STYLE_GRID_COLUMN_ALIGN; +extern lv_style_prop_t LV_STYLE_GRID_ROW_DSC_ARRAY; +extern lv_style_prop_t LV_STYLE_GRID_ROW_ALIGN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_COLUMN_POS; +extern lv_style_prop_t LV_STYLE_GRID_CELL_COLUMN_SPAN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_X_ALIGN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_POS; +extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_SPAN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_Y_ALIGN; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_grid_init(void); + +void lv_obj_set_grid_dsc_array(lv_obj_t * obj, const lv_coord_t col_dsc[], const lv_coord_t row_dsc[]); + +void lv_obj_set_grid_align(lv_obj_t * obj, lv_grid_align_t column_align, lv_grid_align_t row_align); + +/** + * Set the cell of an object. The object's parent needs to have grid layout, else nothing will happen + * @param obj pointer to an object + * @param column_align the vertical alignment in the cell. `LV_GRID_START/END/CENTER/STRETCH` + * @param col_pos column ID + * @param col_span number of columns to take (>= 1) + * @param row_align the horizontal alignment in the cell. `LV_GRID_START/END/CENTER/STRETCH` + * @param row_pos row ID + * @param row_span number of rows to take (>= 1) + */ +void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_align_t column_align, uint8_t col_pos, uint8_t col_span, + lv_grid_align_t row_align, uint8_t row_pos, uint8_t row_span); + +/** + * Just a wrapper to `LV_GRID_FR` for bindings. + */ +static inline lv_coord_t lv_grid_fr(uint8_t x) +{ + return LV_GRID_FR(x); +} + +void lv_style_set_grid_row_dsc_array(lv_style_t * style, const lv_coord_t value[]); +void lv_style_set_grid_column_dsc_array(lv_style_t * style, const lv_coord_t value[]); +void lv_style_set_grid_row_align(lv_style_t * style, lv_grid_align_t value); +void lv_style_set_grid_column_align(lv_style_t * style, lv_grid_align_t value); +void lv_style_set_grid_cell_column_pos(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_column_span(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_row_pos(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_row_span(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_x_align(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_y_align(lv_style_t * style, lv_coord_t value); + +void lv_obj_set_style_grid_row_dsc_array(lv_obj_t * obj, const lv_coord_t value[], lv_style_selector_t selector); +void lv_obj_set_style_grid_column_dsc_array(lv_obj_t * obj, const lv_coord_t value[], lv_style_selector_t selector); +void lv_obj_set_style_grid_row_align(lv_obj_t * obj, lv_grid_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_column_align(lv_obj_t * obj, lv_grid_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_column_pos(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_column_span(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_row_pos(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_row_span(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_x_align(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_y_align(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); + +static inline const lv_coord_t * lv_obj_get_style_grid_row_dsc_array(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_DSC_ARRAY); + return (const lv_coord_t *)v.ptr; +} + +static inline const lv_coord_t * lv_obj_get_style_grid_column_dsc_array(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COLUMN_DSC_ARRAY); + return (const lv_coord_t *)v.ptr; +} + +static inline lv_grid_align_t lv_obj_get_style_grid_row_align(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_ALIGN); + return (lv_grid_align_t)v.num; +} + +static inline lv_grid_align_t lv_obj_get_style_grid_column_align(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COLUMN_ALIGN); + return (lv_grid_align_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_column_pos(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COLUMN_POS); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_column_span(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COLUMN_SPAN); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_row_pos(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_POS); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_row_span(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_SPAN); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_x_align(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_X_ALIGN); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_y_align(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_Y_ALIGN); + return (lv_coord_t)v.num; +} + +/********************** + * GLOBAL VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_GRID*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GRID_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/layouts/lv_layouts.h b/EZ-Template-Example-Project/include/liblvgl/extra/layouts/lv_layouts.h new file mode 100644 index 00000000..9c1e958d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/layouts/lv_layouts.h @@ -0,0 +1,44 @@ +/** + * @file lv_layouts.h + * + */ + +#ifndef LV_LAYOUTS_H +#define LV_LAYOUTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "flex/lv_flex.h" +#include "grid/lv_grid.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ +#if LV_USE_LOG && LV_LOG_TRACE_LAYOUT +# define LV_TRACE_LAYOUT(...) LV_LOG_TRACE(__VA_ARGS__) +#else +# define LV_TRACE_LAYOUT(...) +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LAYOUTS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/bmp/lv_bmp.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/bmp/lv_bmp.h new file mode 100644 index 00000000..3d9e9484 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/bmp/lv_bmp.h @@ -0,0 +1,42 @@ +/** + * @file lv_bmp.h + * + */ + +#ifndef LV_BMP_H +#define LV_BMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_BMP + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void lv_bmp_init(void); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_BMP*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_BMP_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/ffmpeg/lv_ffmpeg.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/ffmpeg/lv_ffmpeg.h new file mode 100644 index 00000000..f3a365c3 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/ffmpeg/lv_ffmpeg.h @@ -0,0 +1,104 @@ +/** + * @file lv_ffmpeg.h + * + */ +#ifndef LV_FFMPEG_H +#define LV_FFMPEG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" +#if LV_USE_FFMPEG != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct ffmpeg_context_s; + +extern const lv_obj_class_t lv_ffmpeg_player_class; + +typedef struct { + lv_img_t img; + lv_timer_t * timer; + lv_img_dsc_t imgdsc; + bool auto_restart; + struct ffmpeg_context_s * ffmpeg_ctx; +} lv_ffmpeg_player_t; + +typedef enum { + LV_FFMPEG_PLAYER_CMD_START, + LV_FFMPEG_PLAYER_CMD_STOP, + LV_FFMPEG_PLAYER_CMD_PAUSE, + LV_FFMPEG_PLAYER_CMD_RESUME, + _LV_FFMPEG_PLAYER_CMD_LAST +} lv_ffmpeg_player_cmd_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Register FFMPEG image decoder + */ +void lv_ffmpeg_init(void); + +/** + * Get the number of frames contained in the file + * @param path image or video file name + * @return Number of frames, less than 0 means failed + */ +int lv_ffmpeg_get_frame_num(const char * path); + +/** + * Create ffmpeg_player object + * @param parent pointer to an object, it will be the parent of the new player + * @return pointer to the created ffmpeg_player + */ +lv_obj_t * lv_ffmpeg_player_create(lv_obj_t * parent); + +/** + * Set the path of the file to be played + * @param obj pointer to a ffmpeg_player object + * @param path video file path + * @return LV_RES_OK: no error; LV_RES_INV: can't get the info. + */ +lv_res_t lv_ffmpeg_player_set_src(lv_obj_t * obj, const char * path); + +/** + * Set command control video player + * @param obj pointer to a ffmpeg_player object + * @param cmd control commands + */ +void lv_ffmpeg_player_set_cmd(lv_obj_t * obj, lv_ffmpeg_player_cmd_t cmd); + +/** + * Set the video to automatically replay + * @param obj pointer to a ffmpeg_player object + * @param en true: enable the auto restart + */ +void lv_ffmpeg_player_set_auto_restart(lv_obj_t * obj, bool en); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_FFMPEG*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FFMPEG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/freetype/lv_freetype.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/freetype/lv_freetype.h new file mode 100644 index 00000000..e576c2e1 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/freetype/lv_freetype.h @@ -0,0 +1,83 @@ +/** + * @file lv_freetype.h + * + */ +#ifndef LV_FREETYPE_H +#define LV_FREETYPE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" +#if LV_USE_FREETYPE + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef enum { + FT_FONT_STYLE_NORMAL = 0, + FT_FONT_STYLE_ITALIC = 1 << 0, + FT_FONT_STYLE_BOLD = 1 << 1 +} LV_FT_FONT_STYLE; + +typedef struct { + const char * name; /* The name of the font file */ + const void * mem; /* The pointer of the font file */ + size_t mem_size; /* The size of the memory */ + lv_font_t * font; /* point to lvgl font */ + uint16_t weight; /* font size */ + uint16_t style; /* font style */ +} lv_ft_info_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * init freetype library + * @param max_faces Maximum number of opened FT_Face objects managed by this cache instance. Use 0 for defaults. + * @param max_sizes Maximum number of opened FT_Size objects managed by this cache instance. Use 0 for defaults. + * @param max_bytes Maximum number of bytes to use for cached data nodes. Use 0 for defaults. + * Note that this value does not account for managed FT_Face and FT_Size objects. + * @return true on success, otherwise false. + */ +bool lv_freetype_init(uint16_t max_faces, uint16_t max_sizes, uint32_t max_bytes); + +/** + * Destroy freetype library + */ +void lv_freetype_destroy(void); + +/** + * Creates a font with info parameter specified. + * @param info See lv_ft_info_t for details. + * when success, lv_ft_info_t->font point to the font you created. + * @return true on success, otherwise false. + */ +bool lv_ft_font_init(lv_ft_info_t * info); + +/** + * Destroy a font that has been created. + * @param font pointer to font. + */ +void lv_ft_font_destroy(lv_font_t * font); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_FREETYPE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* LV_FREETYPE_H */ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/fsdrv/lv_fsdrv.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/fsdrv/lv_fsdrv.h new file mode 100644 index 00000000..2b0adfd0 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/fsdrv/lv_fsdrv.h @@ -0,0 +1,55 @@ +/** + * @file lv_fsdrv.h + * + */ + +#ifndef LV_FSDRV_H +#define LV_FSDRV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +#if LV_USE_FS_FATFS != '\0' +void lv_fs_fatfs_init(void); +#endif + +#if LV_USE_FS_STDIO != '\0' +void lv_fs_stdio_init(void); +#endif + +#if LV_USE_FS_POSIX != '\0' +void lv_fs_posix_init(void); +#endif + +#if LV_USE_FS_WIN32 != '\0' +void lv_fs_win32_init(void); +#endif + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_FSDRV_H*/ + diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/gif/gifdec.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/gif/gifdec.h new file mode 100644 index 00000000..eaa4cadd --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/gif/gifdec.h @@ -0,0 +1,60 @@ +#ifndef GIFDEC_H +#define GIFDEC_H + +#include +#include "liblvgl/misc/lv_fs.h" + +#if LV_USE_GIF + +typedef struct gd_Palette { + int size; + uint8_t colors[0x100 * 3]; +} gd_Palette; + +typedef struct gd_GCE { + uint16_t delay; + uint8_t tindex; + uint8_t disposal; + int input; + int transparency; +} gd_GCE; + + + +typedef struct gd_GIF { + lv_fs_file_t fd; + const char * data; + uint8_t is_file; + uint32_t f_rw_p; + int32_t anim_start; + uint16_t width, height; + uint16_t depth; + uint16_t loop_count; + gd_GCE gce; + gd_Palette *palette; + gd_Palette lct, gct; + void (*plain_text)( + struct gd_GIF *gif, uint16_t tx, uint16_t ty, + uint16_t tw, uint16_t th, uint8_t cw, uint8_t ch, + uint8_t fg, uint8_t bg + ); + void (*comment)(struct gd_GIF *gif); + void (*application)(struct gd_GIF *gif, char id[8], char auth[3]); + uint16_t fx, fy, fw, fh; + uint8_t bgindex; + uint8_t *canvas, *frame; +} gd_GIF; + +gd_GIF * gd_open_gif_file(const char *fname); + +gd_GIF * gd_open_gif_data(const void *data); + +void gd_render_frame(gd_GIF *gif, uint8_t *buffer); + +int gd_get_frame(gd_GIF *gif); +void gd_rewind(gd_GIF *gif); +void gd_close_gif(gd_GIF *gif); + +#endif /*LV_USE_GIF*/ + +#endif /* GIFDEC_H */ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/gif/lv_gif.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/gif/lv_gif.h new file mode 100644 index 00000000..b40b690a --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/gif/lv_gif.h @@ -0,0 +1,58 @@ +/** + * @file lv_gif.h + * + */ + +#ifndef LV_GIF_H +#define LV_GIF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lvgl.h" +#if LV_USE_GIF + +#include "gifdec.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_img_t img; + gd_GIF * gif; + lv_timer_t * timer; + lv_img_dsc_t imgdsc; + uint32_t last_call; +} lv_gif_t; + +extern const lv_obj_class_t lv_gif_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_gif_create(lv_obj_t * parent); +void lv_gif_set_src(lv_obj_t * obj, const void * src); +void lv_gif_restart(lv_obj_t * gif); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GIF*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_GIF_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/lv_libs.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/lv_libs.h new file mode 100644 index 00000000..6782b1d0 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/lv_libs.h @@ -0,0 +1,46 @@ +/** + * @file lv_libs.h + * + */ + +#ifndef LV_LIBS_H +#define LV_LIBS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "bmp/lv_bmp.h" +#include "fsdrv/lv_fsdrv.h" +#include "png/lv_png.h" +#include "gif/lv_gif.h" +#include "qrcode/lv_qrcode.h" +#include "sjpg/lv_sjpg.h" +#include "freetype/lv_freetype.h" +#include "rlottie/lv_rlottie.h" +#include "ffmpeg/lv_ffmpeg.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LIBS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/png/lodepng.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/png/lodepng.h new file mode 100644 index 00000000..4068d4b1 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/png/lodepng.h @@ -0,0 +1,1981 @@ +/* +LodePNG version 20201017 + +Copyright (c) 2005-2020 Lode Vandevenne + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ + +#ifndef LODEPNG_H +#define LODEPNG_H + +#include /*for size_t*/ + +#include "liblvgl/lvgl.h" +#if LV_USE_PNG +extern const char* LODEPNG_VERSION_STRING; + +/* +The following #defines are used to create code sections. They can be disabled +to disable code sections, which can give faster compile time and smaller binary. +The "NO_COMPILE" defines are designed to be used to pass as defines to the +compiler command to disable them without modifying this header, e.g. +-DLODEPNG_NO_COMPILE_ZLIB for gcc. +In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to +allow implementing a custom lodepng_crc32. +*/ +/*deflate & zlib. If disabled, you must specify alternative zlib functions in +the custom_zlib field of the compress and decompress settings*/ +#ifndef LODEPNG_NO_COMPILE_ZLIB +#define LODEPNG_COMPILE_ZLIB +#endif + +/*png encoder and png decoder*/ +#ifndef LODEPNG_NO_COMPILE_PNG +#define LODEPNG_COMPILE_PNG +#endif + +/*deflate&zlib decoder and png decoder*/ +#ifndef LODEPNG_NO_COMPILE_DECODER +#define LODEPNG_COMPILE_DECODER +#endif + +/*deflate&zlib encoder and png encoder*/ +#ifndef LODEPNG_NO_COMPILE_ENCODER +#define LODEPNG_COMPILE_ENCODER +#endif + +/*the optional built in harddisk file loading and saving functions*/ +#ifndef LODEPNG_NO_COMPILE_DISK +#define LODEPNG_COMPILE_DISK +#endif + +/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/ +#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS +#define LODEPNG_COMPILE_ANCILLARY_CHUNKS +#endif + +/*ability to convert error numerical codes to English text string*/ +#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT +#define LODEPNG_COMPILE_ERROR_TEXT +#endif + +/*Compile the default allocators (C's free, malloc and realloc). If you disable this, +you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your +source files with custom allocators.*/ +#ifndef LODEPNG_NO_COMPILE_ALLOCATORS +#define LODEPNG_COMPILE_ALLOCATORS +#endif + +/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/ +#ifdef __cplusplus +#ifndef LODEPNG_NO_COMPILE_CPP +#define LODEPNG_COMPILE_CPP +#endif +#endif + +#ifdef LODEPNG_COMPILE_CPP +#include +#include +#endif /*LODEPNG_COMPILE_CPP*/ + +#ifdef LODEPNG_COMPILE_PNG +/*The PNG color types (also used for raw image).*/ +typedef enum LodePNGColorType { + LCT_GREY = 0, /*grayscale: 1,2,4,8,16 bit*/ + LCT_RGB = 2, /*RGB: 8,16 bit*/ + LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/ + LCT_GREY_ALPHA = 4, /*grayscale with alpha: 8,16 bit*/ + LCT_RGBA = 6, /*RGB with alpha: 8,16 bit*/ + /*LCT_MAX_OCTET_VALUE lets the compiler allow this enum to represent any invalid + byte value from 0 to 255 that could be present in an invalid PNG file header. Do + not use, compare with or set the name LCT_MAX_OCTET_VALUE, instead either use + the valid color type names above, or numeric values like 1 or 7 when checking for + particular disallowed color type byte values, or cast to integer to print it.*/ + LCT_MAX_OCTET_VALUE = 255 +} LodePNGColorType; + +#ifdef LODEPNG_COMPILE_DECODER +/* +Converts PNG data in memory to raw pixel data. +out: Output parameter. Pointer to buffer that will contain the raw pixel data. + After decoding, its size is w * h * (bytes per pixel) bytes larger than + initially. Bytes per pixel depends on colortype and bitdepth. + Must be freed after usage with free(*out). + Note: for 16-bit per channel colors, uses big endian format like PNG does. +w: Output parameter. Pointer to width of pixel data. +h: Output parameter. Pointer to height of pixel data. +in: Memory buffer with the PNG file. +insize: size of the in buffer. +colortype: the desired color type for the raw output image. See explanation on PNG color types. +bitdepth: the desired bit depth for the raw output image. See explanation on PNG color types. +Return value: LodePNG error code (0 means no error). +*/ +unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_decode_memory, but always decodes to 32-bit RGBA raw image*/ +unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize); + +/*Same as lodepng_decode_memory, but always decodes to 24-bit RGB raw image*/ +unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize); + +#ifdef LODEPNG_COMPILE_DISK +/* +Load PNG from disk, from file with given name. +Same as the other decode functions, but instead takes a filename as input. +*/ +unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/ +unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename); + +/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/ +unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename); +#endif /*LODEPNG_COMPILE_DISK*/ +#endif /*LODEPNG_COMPILE_DECODER*/ + + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Converts raw pixel data into a PNG image in memory. The colortype and bitdepth + of the output PNG image cannot be chosen, they are automatically determined + by the colortype, bitdepth and content of the input pixel data. + Note: for 16-bit per channel colors, needs big endian format like PNG does. +out: Output parameter. Pointer to buffer that will contain the PNG image data. + Must be freed after usage with free(*out). +outsize: Output parameter. Pointer to the size in bytes of the out buffer. +image: The raw pixel data to encode. The size of this buffer should be + w * h * (bytes per pixel), bytes per pixel depends on colortype and bitdepth. +w: width of the raw pixel data in pixels. +h: height of the raw pixel data in pixels. +colortype: the color type of the raw input image. See explanation on PNG color types. +bitdepth: the bit depth of the raw input image. See explanation on PNG color types. +Return value: LodePNG error code (0 means no error). +*/ +unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_encode_memory, but always encodes from 32-bit RGBA raw image.*/ +unsigned lodepng_encode32(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h); + +/*Same as lodepng_encode_memory, but always encodes from 24-bit RGB raw image.*/ +unsigned lodepng_encode24(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h); + +#ifdef LODEPNG_COMPILE_DISK +/* +Converts raw pixel data into a PNG file on disk. +Same as the other encode functions, but instead takes a filename as output. +NOTE: This overwrites existing files without warning! +*/ +unsigned lodepng_encode_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/ +unsigned lodepng_encode32_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h); + +/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/ +unsigned lodepng_encode24_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h); +#endif /*LODEPNG_COMPILE_DISK*/ +#endif /*LODEPNG_COMPILE_ENCODER*/ + + +#ifdef LODEPNG_COMPILE_CPP +namespace lodepng { +#ifdef LODEPNG_COMPILE_DECODER +/*Same as lodepng_decode_memory, but decodes to an std::vector. The colortype +is the format to output the pixels to. Default is RGBA 8-bit per channel.*/ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const unsigned char* in, size_t insize, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::vector& in, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#ifdef LODEPNG_COMPILE_DISK +/* +Converts PNG file from disk to raw pixel data in memory. +Same as the other decode functions, but instead takes a filename as input. +*/ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::string& filename, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_DECODER */ + +#ifdef LODEPNG_COMPILE_ENCODER +/*Same as lodepng_encode_memory, but encodes to an std::vector. colortype +is that of the raw input data. The output PNG color type will be auto chosen.*/ +unsigned encode(std::vector& out, + const unsigned char* in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#ifdef LODEPNG_COMPILE_DISK +/* +Converts 32-bit RGBA raw pixel data into a PNG file on disk. +Same as the other encode functions, but instead takes a filename as output. +NOTE: This overwrites existing files without warning! +*/ +unsigned encode(const std::string& filename, + const unsigned char* in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned encode(const std::string& filename, + const std::vector& in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_ENCODER */ +} /* namespace lodepng */ +#endif /*LODEPNG_COMPILE_CPP*/ +#endif /*LODEPNG_COMPILE_PNG*/ + +#ifdef LODEPNG_COMPILE_ERROR_TEXT +/*Returns an English description of the numerical error code.*/ +const char* lodepng_error_text(unsigned code); +#endif /*LODEPNG_COMPILE_ERROR_TEXT*/ + +#ifdef LODEPNG_COMPILE_DECODER +/*Settings for zlib decompression*/ +typedef struct LodePNGDecompressSettings LodePNGDecompressSettings; +struct LodePNGDecompressSettings { + /* Check LodePNGDecoderSettings for more ignorable errors such as ignore_crc */ + unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/ + unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/ + + /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding, + return an error, output a data size > max_output_size and all the data up to that point. This is + not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is + ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones. + Set to 0 to impose no limit (the default).*/ + size_t max_output_size; + + /*use custom zlib decoder instead of built in one (default: null). + Should return 0 if success, any non-0 if error (numeric value not exposed).*/ + unsigned (*custom_zlib)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGDecompressSettings*); + /*use custom deflate decoder instead of built in one (default: null) + if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate). + Should return 0 if success, any non-0 if error (numeric value not exposed).*/ + unsigned (*custom_inflate)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGDecompressSettings*); + + const void* custom_context; /*optional custom settings for custom functions*/ +}; + +extern const LodePNGDecompressSettings lodepng_default_decompress_settings; +void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Settings for zlib compression. Tweaking these settings tweaks the balance +between speed and compression ratio. +*/ +typedef struct LodePNGCompressSettings LodePNGCompressSettings; +struct LodePNGCompressSettings /*deflate = compress*/ { + /*LZ77 related settings*/ + unsigned btype; /*the block type for LZ (0, 1, 2 or 3, see zlib standard). Should be 2 for proper compression.*/ + unsigned use_lz77; /*whether or not to use LZ77. Should be 1 for proper compression.*/ + unsigned windowsize; /*must be a power of two <= 32768. higher compresses more but is slower. Default value: 2048.*/ + unsigned minmatch; /*minimum lz77 length. 3 is normally best, 6 can be better for some PNGs. Default: 0*/ + unsigned nicematch; /*stop searching if >= this length found. Set to 258 for best compression. Default: 128*/ + unsigned lazymatching; /*use lazy matching: better compression but a bit slower. Default: true*/ + + /*use custom zlib encoder instead of built in one (default: null)*/ + unsigned (*custom_zlib)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGCompressSettings*); + /*use custom deflate encoder instead of built in one (default: null) + if custom_zlib is used, custom_deflate is ignored since only the built in + zlib function will call custom_deflate*/ + unsigned (*custom_deflate)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGCompressSettings*); + + const void* custom_context; /*optional custom settings for custom functions*/ +}; + +extern const LodePNGCompressSettings lodepng_default_compress_settings; +void lodepng_compress_settings_init(LodePNGCompressSettings* settings); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#ifdef LODEPNG_COMPILE_PNG +/* +Color mode of an image. Contains all information required to decode the pixel +bits to RGBA colors. This information is the same as used in the PNG file +format, and is used both for PNG and raw image data in LodePNG. +*/ +typedef struct LodePNGColorMode { + /*header (IHDR)*/ + LodePNGColorType colortype; /*color type, see PNG standard or documentation further in this header file*/ + unsigned bitdepth; /*bits per sample, see PNG standard or documentation further in this header file*/ + + /* + palette (PLTE and tRNS) + + Dynamically allocated with the colors of the palette, including alpha. + This field may not be allocated directly, use lodepng_color_mode_init first, + then lodepng_palette_add per color to correctly initialize it (to ensure size + of exactly 1024 bytes). + + The alpha channels must be set as well, set them to 255 for opaque images. + + When decoding, by default you can ignore this palette, since LodePNG already + fills the palette colors in the pixels of the raw RGBA output. + + The palette is only supported for color type 3. + */ + unsigned char* palette; /*palette in RGBARGBA... order. Must be either 0, or when allocated must have 1024 bytes*/ + size_t palettesize; /*palette size in number of colors (amount of used bytes is 4 * palettesize)*/ + + /* + transparent color key (tRNS) + + This color uses the same bit depth as the bitdepth value in this struct, which can be 1-bit to 16-bit. + For grayscale PNGs, r, g and b will all 3 be set to the same. + + When decoding, by default you can ignore this information, since LodePNG sets + pixels with this key to transparent already in the raw RGBA output. + + The color key is only supported for color types 0 and 2. + */ + unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/ + unsigned key_r; /*red/grayscale component of color key*/ + unsigned key_g; /*green component of color key*/ + unsigned key_b; /*blue component of color key*/ +} LodePNGColorMode; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_color_mode_init(LodePNGColorMode* info); +void lodepng_color_mode_cleanup(LodePNGColorMode* info); +/*return value is error code (0 means no error)*/ +unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source); +/* Makes a temporary LodePNGColorMode that does not need cleanup (no palette) */ +LodePNGColorMode lodepng_color_mode_make(LodePNGColorType colortype, unsigned bitdepth); + +void lodepng_palette_clear(LodePNGColorMode* info); +/*add 1 color to the palette*/ +unsigned lodepng_palette_add(LodePNGColorMode* info, + unsigned char r, unsigned char g, unsigned char b, unsigned char a); + +/*get the total amount of bits per pixel, based on colortype and bitdepth in the struct*/ +unsigned lodepng_get_bpp(const LodePNGColorMode* info); +/*get the amount of color channels used, based on colortype in the struct. +If a palette is used, it counts as 1 channel.*/ +unsigned lodepng_get_channels(const LodePNGColorMode* info); +/*is it a grayscale type? (only colortype 0 or 4)*/ +unsigned lodepng_is_greyscale_type(const LodePNGColorMode* info); +/*has it got an alpha channel? (only colortype 2 or 6)*/ +unsigned lodepng_is_alpha_type(const LodePNGColorMode* info); +/*has it got a palette? (only colortype 3)*/ +unsigned lodepng_is_palette_type(const LodePNGColorMode* info); +/*only returns true if there is a palette and there is a value in the palette with alpha < 255. +Loops through the palette to check this.*/ +unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info); +/* +Check if the given color info indicates the possibility of having non-opaque pixels in the PNG image. +Returns true if the image can have translucent or invisible pixels (it still be opaque if it doesn't use such pixels). +Returns false if the image can only have opaque pixels. +In detail, it returns true only if it's a color type with alpha, or has a palette with non-opaque values, +or if "key_defined" is true. +*/ +unsigned lodepng_can_have_alpha(const LodePNGColorMode* info); +/*Returns the byte size of a raw image buffer with given width, height and color mode*/ +size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color); + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +/*The information of a Time chunk in PNG.*/ +typedef struct LodePNGTime { + unsigned year; /*2 bytes used (0-65535)*/ + unsigned month; /*1-12*/ + unsigned day; /*1-31*/ + unsigned hour; /*0-23*/ + unsigned minute; /*0-59*/ + unsigned second; /*0-60 (to allow for leap seconds)*/ +} LodePNGTime; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +/*Information about the PNG image, except pixels, width and height.*/ +typedef struct LodePNGInfo { + /*header (IHDR), palette (PLTE) and transparency (tRNS) chunks*/ + unsigned compression_method;/*compression method of the original file. Always 0.*/ + unsigned filter_method; /*filter method of the original file*/ + unsigned interlace_method; /*interlace method of the original file: 0=none, 1=Adam7*/ + LodePNGColorMode color; /*color type and bits, palette and transparency of the PNG file*/ + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /* + Suggested background color chunk (bKGD) + + This uses the same color mode and bit depth as the PNG (except no alpha channel), + with values truncated to the bit depth in the unsigned integer. + + For grayscale and palette PNGs, the value is stored in background_r. The values + in background_g and background_b are then unused. + + So when decoding, you may get these in a different color mode than the one you requested + for the raw pixels. + + When encoding with auto_convert, you must use the color model defined in info_png.color for + these values. The encoder normally ignores info_png.color when auto_convert is on, but will + use it to interpret these values (and convert copies of them to its chosen color model). + + When encoding, avoid setting this to an expensive color, such as a non-gray value + when the image is gray, or the compression will be worse since it will be forced to + write the PNG with a more expensive color mode (when auto_convert is on). + + The decoder does not use this background color to edit the color of pixels. This is a + completely optional metadata feature. + */ + unsigned background_defined; /*is a suggested background color given?*/ + unsigned background_r; /*red/gray/palette component of suggested background color*/ + unsigned background_g; /*green component of suggested background color*/ + unsigned background_b; /*blue component of suggested background color*/ + + /* + Non-international text chunks (tEXt and zTXt) + + The char** arrays each contain num strings. The actual messages are in + text_strings, while text_keys are keywords that give a short description what + the actual text represents, e.g. Title, Author, Description, or anything else. + + All the string fields below including strings, keys, names and language tags are null terminated. + The PNG specification uses null characters for the keys, names and tags, and forbids null + characters to appear in the main text which is why we can use null termination everywhere here. + + A keyword is minimum 1 character and maximum 79 characters long (plus the + additional null terminator). It's discouraged to use a single line length + longer than 79 characters for texts. + + Don't allocate these text buffers yourself. Use the init/cleanup functions + correctly and use lodepng_add_text and lodepng_clear_text. + + Standard text chunk keywords and strings are encoded using Latin-1. + */ + size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/ + char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/ + char** text_strings; /*the actual text*/ + + /* + International text chunks (iTXt) + Similar to the non-international text chunks, but with additional strings + "langtags" and "transkeys", and the following text encodings are used: + keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8. + keys must be 1-79 characters (plus the additional null terminator), the other + strings are any length. + */ + size_t itext_num; /*the amount of international texts in this PNG*/ + char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/ + char** itext_langtags; /*language tag for this text's language, ISO/IEC 646 string, e.g. ISO 639 language tag*/ + char** itext_transkeys; /*keyword translated to the international language - UTF-8 string*/ + char** itext_strings; /*the actual international text - UTF-8 string*/ + + /*time chunk (tIME)*/ + unsigned time_defined; /*set to 1 to make the encoder generate a tIME chunk*/ + LodePNGTime time; + + /*phys chunk (pHYs)*/ + unsigned phys_defined; /*if 0, there is no pHYs chunk and the values below are undefined, if 1 else there is one*/ + unsigned phys_x; /*pixels per unit in x direction*/ + unsigned phys_y; /*pixels per unit in y direction*/ + unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/ + + /* + Color profile related chunks: gAMA, cHRM, sRGB, iCPP + + LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color + profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please + use these values with a color management library. + + See the PNG, ICC and sRGB specifications for more information about the meaning of these values. + */ + + /* gAMA chunk: optional, overridden by sRGB or iCCP if those are present. */ + unsigned gama_defined; /* Whether a gAMA chunk is present (0 = not present, 1 = present). */ + unsigned gama_gamma; /* Gamma exponent times 100000 */ + + /* cHRM chunk: optional, overridden by sRGB or iCCP if those are present. */ + unsigned chrm_defined; /* Whether a cHRM chunk is present (0 = not present, 1 = present). */ + unsigned chrm_white_x; /* White Point x times 100000 */ + unsigned chrm_white_y; /* White Point y times 100000 */ + unsigned chrm_red_x; /* Red x times 100000 */ + unsigned chrm_red_y; /* Red y times 100000 */ + unsigned chrm_green_x; /* Green x times 100000 */ + unsigned chrm_green_y; /* Green y times 100000 */ + unsigned chrm_blue_x; /* Blue x times 100000 */ + unsigned chrm_blue_y; /* Blue y times 100000 */ + + /* + sRGB chunk: optional. May not appear at the same time as iCCP. + If gAMA is also present gAMA must contain value 45455. + If cHRM is also present cHRM must contain respectively 31270,32900,64000,33000,30000,60000,15000,6000. + */ + unsigned srgb_defined; /* Whether an sRGB chunk is present (0 = not present, 1 = present). */ + unsigned srgb_intent; /* Rendering intent: 0=perceptual, 1=rel. colorimetric, 2=saturation, 3=abs. colorimetric */ + + /* + iCCP chunk: optional. May not appear at the same time as sRGB. + + LodePNG does not parse or use the ICC profile (except its color space header field for an edge case), a + separate library to handle the ICC data (not included in LodePNG) format is needed to use it for color + management and conversions. + + For encoding, if iCCP is present, gAMA and cHRM are recommended to be added as well with values that match the ICC + profile as closely as possible, if you wish to do this you should provide the correct values for gAMA and cHRM and + enable their '_defined' flags since LodePNG will not automatically compute them from the ICC profile. + + For encoding, the ICC profile is required by the PNG specification to be an "RGB" profile for non-gray + PNG color types and a "GRAY" profile for gray PNG color types. If you disable auto_convert, you must ensure + the ICC profile type matches your requested color type, else the encoder gives an error. If auto_convert is + enabled (the default), and the ICC profile is not a good match for the pixel data, this will result in an encoder + error if the pixel data has non-gray pixels for a GRAY profile, or a silent less-optimal compression of the pixel + data if the pixels could be encoded as grayscale but the ICC profile is RGB. + + To avoid this do not set an ICC profile in the image unless there is a good reason for it, and when doing so + make sure you compute it carefully to avoid the above problems. + */ + unsigned iccp_defined; /* Whether an iCCP chunk is present (0 = not present, 1 = present). */ + char* iccp_name; /* Null terminated string with profile name, 1-79 bytes */ + /* + The ICC profile in iccp_profile_size bytes. + Don't allocate this buffer yourself. Use the init/cleanup functions + correctly and use lodepng_set_icc and lodepng_clear_icc. + */ + unsigned char* iccp_profile; + unsigned iccp_profile_size; /* The size of iccp_profile in bytes */ + + /* End of color profile related chunks */ + + + /* + unknown chunks: chunks not known by LodePNG, passed on byte for byte. + + There are 3 buffers, one for each position in the PNG where unknown chunks can appear. + Each buffer contains all unknown chunks for that position consecutively. + The 3 positions are: + 0: between IHDR and PLTE, 1: between PLTE and IDAT, 2: between IDAT and IEND. + + For encoding, do not store critical chunks or known chunks that are enabled with a "_defined" flag + above in here, since the encoder will blindly follow this and could then encode an invalid PNG file + (such as one with two IHDR chunks or the disallowed combination of sRGB with iCCP). But do use + this if you wish to store an ancillary chunk that is not supported by LodePNG (such as sPLT or hIST), + or any non-standard PNG chunk. + + Do not allocate or traverse this data yourself. Use the chunk traversing functions declared + later, such as lodepng_chunk_next and lodepng_chunk_append, to read/write this struct. + */ + unsigned char* unknown_chunks_data[3]; + size_t unknown_chunks_size[3]; /*size in bytes of the unknown chunks, given for protection*/ +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGInfo; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_info_init(LodePNGInfo* info); +void lodepng_info_cleanup(LodePNGInfo* info); +/*return value is error code (0 means no error)*/ +unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source); + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str); /*push back both texts at once*/ +void lodepng_clear_text(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ + +unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langtag, + const char* transkey, const char* str); /*push back the 4 texts of 1 chunk at once*/ +void lodepng_clear_itext(LodePNGInfo* info); /*use this to clear the itexts again after you filled them in*/ + +/*replaces if exists*/ +unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size); +void lodepng_clear_icc(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +/* +Converts raw buffer from one color type to another color type, based on +LodePNGColorMode structs to describe the input and output color type. +See the reference manual at the end of this header file to see which color conversions are supported. +return value = LodePNG error code (0 if all went ok, an error if the conversion isn't supported) +The out buffer must have size (w * h * bpp + 7) / 8, where bpp is the bits per pixel +of the output color type (lodepng_get_bpp). +For < 8 bpp images, there should not be padding bits at the end of scanlines. +For 16-bit per channel colors, uses big endian format like PNG does. +Return value is LodePNG error code +*/ +unsigned lodepng_convert(unsigned char* out, const unsigned char* in, + const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, + unsigned w, unsigned h); + +#ifdef LODEPNG_COMPILE_DECODER +/* +Settings for the decoder. This contains settings for the PNG and the Zlib +decoder, but not the Info settings from the Info structs. +*/ +typedef struct LodePNGDecoderSettings { + LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/ + + /* Check LodePNGDecompressSettings for more ignorable errors such as ignore_adler32 */ + unsigned ignore_crc; /*ignore CRC checksums*/ + unsigned ignore_critical; /*ignore unknown critical chunks*/ + unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/ + /* TODO: make a system involving warnings with levels and a strict mode instead. Other potentially recoverable + errors: srgb rendering intent value, size of content of ancillary chunks, more than 79 characters for some + strings, placement/combination rules for ancillary chunks, crc of unknown chunks, allowed characters + in string keys, etc... */ + + unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/ + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/ + + /*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/ + unsigned remember_unknown_chunks; + + /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned, + unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size. + By default it is a value that prevents unreasonably large strings from hogging memory. */ + size_t max_text_size; + + /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to + 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any + legitimate profile could be to hog memory. */ + size_t max_icc_size; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGDecoderSettings; + +void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/*automatically use color type with less bits per pixel if losslessly possible. Default: AUTO*/ +typedef enum LodePNGFilterStrategy { + /*every filter at zero*/ + LFS_ZERO = 0, + /*every filter at 1, 2, 3 or 4 (paeth), unlike LFS_ZERO not a good choice, but for testing*/ + LFS_ONE = 1, + LFS_TWO = 2, + LFS_THREE = 3, + LFS_FOUR = 4, + /*Use filter that gives minimum sum, as described in the official PNG filter heuristic.*/ + LFS_MINSUM, + /*Use the filter type that gives smallest Shannon entropy for this scanline. Depending + on the image, this is better or worse than minsum.*/ + LFS_ENTROPY, + /* + Brute-force-search PNG filters by compressing each filter for each scanline. + Experimental, very slow, and only rarely gives better compression than MINSUM. + */ + LFS_BRUTE_FORCE, + /*use predefined_filters buffer: you specify the filter type for each scanline*/ + LFS_PREDEFINED +} LodePNGFilterStrategy; + +/*Gives characteristics about the integer RGBA colors of the image (count, alpha channel usage, bit depth, ...), +which helps decide which color model to use for encoding. +Used internally by default if "auto_convert" is enabled. Public because it's useful for custom algorithms.*/ +typedef struct LodePNGColorStats { + unsigned colored; /*not grayscale*/ + unsigned key; /*image is not opaque and color key is possible instead of full alpha*/ + unsigned short key_r; /*key values, always as 16-bit, in 8-bit case the byte is duplicated, e.g. 65535 means 255*/ + unsigned short key_g; + unsigned short key_b; + unsigned alpha; /*image is not opaque and alpha channel or alpha palette required*/ + unsigned numcolors; /*amount of colors, up to 257. Not valid if bits == 16 or allow_palette is disabled.*/ + unsigned char palette[1024]; /*Remembers up to the first 256 RGBA colors, in no particular order, only valid when numcolors is valid*/ + unsigned bits; /*bits per channel (not for palette). 1,2 or 4 for grayscale only. 16 if 16-bit per channel required.*/ + size_t numpixels; + + /*user settings for computing/using the stats*/ + unsigned allow_palette; /*default 1. if 0, disallow choosing palette colortype in auto_choose_color, and don't count numcolors*/ + unsigned allow_greyscale; /*default 1. if 0, choose RGB or RGBA even if the image only has gray colors*/ +} LodePNGColorStats; + +void lodepng_color_stats_init(LodePNGColorStats* stats); + +/*Get a LodePNGColorStats of the image. The stats must already have been inited. +Returns error code (e.g. alloc fail) or 0 if ok.*/ +unsigned lodepng_compute_color_stats(LodePNGColorStats* stats, + const unsigned char* image, unsigned w, unsigned h, + const LodePNGColorMode* mode_in); + +/*Settings for the encoder.*/ +typedef struct LodePNGEncoderSettings { + LodePNGCompressSettings zlibsettings; /*settings for the zlib encoder, such as window size, ...*/ + + unsigned auto_convert; /*automatically choose output PNG color type. Default: true*/ + + /*If true, follows the official PNG heuristic: if the PNG uses a palette or lower than + 8 bit depth, set all filters to zero. Otherwise use the filter_strategy. Note that to + completely follow the official PNG heuristic, filter_palette_zero must be true and + filter_strategy must be LFS_MINSUM*/ + unsigned filter_palette_zero; + /*Which filter strategy to use when not using zeroes due to filter_palette_zero. + Set filter_palette_zero to 0 to ensure always using your chosen strategy. Default: LFS_MINSUM*/ + LodePNGFilterStrategy filter_strategy; + /*used if filter_strategy is LFS_PREDEFINED. In that case, this must point to a buffer with + the same length as the amount of scanlines in the image, and each value must <= 5. You + have to cleanup this buffer, LodePNG will never free it. Don't forget that filter_palette_zero + must be set to 0 to ensure this is also used on palette or low bitdepth images.*/ + const unsigned char* predefined_filters; + + /*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette). + If colortype is 3, PLTE is _always_ created.*/ + unsigned force_palette; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /*add LodePNG identifier and version as a text chunk, for debugging*/ + unsigned add_id; + /*encode text chunks as zTXt chunks instead of tEXt chunks, and use compression in iTXt chunks*/ + unsigned text_compression; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGEncoderSettings; + +void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings); +#endif /*LODEPNG_COMPILE_ENCODER*/ + + +#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) +/*The settings, state and information for extended encoding and decoding.*/ +typedef struct LodePNGState { +#ifdef LODEPNG_COMPILE_DECODER + LodePNGDecoderSettings decoder; /*the decoding settings*/ +#endif /*LODEPNG_COMPILE_DECODER*/ +#ifdef LODEPNG_COMPILE_ENCODER + LodePNGEncoderSettings encoder; /*the encoding settings*/ +#endif /*LODEPNG_COMPILE_ENCODER*/ + LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/ + LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/ + unsigned error; +} LodePNGState; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_state_init(LodePNGState* state); +void lodepng_state_cleanup(LodePNGState* state); +void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source); +#endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */ + +#ifdef LODEPNG_COMPILE_DECODER +/* +Same as lodepng_decode_memory, but uses a LodePNGState to allow custom settings and +getting much more information about the PNG image and color mode. +*/ +unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, + LodePNGState* state, + const unsigned char* in, size_t insize); + +/* +Read the PNG header, but not the actual data. This returns only the information +that is in the IHDR chunk of the PNG, such as width, height and color type. The +information is placed in the info_png field of the LodePNGState. +*/ +unsigned lodepng_inspect(unsigned* w, unsigned* h, + LodePNGState* state, + const unsigned char* in, size_t insize); +#endif /*LODEPNG_COMPILE_DECODER*/ + +/* +Reads one metadata chunk (other than IHDR) of the PNG file and outputs what it +read in the state. Returns error code on failure. +Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const +to find the desired chunk type, and if non null use lodepng_inspect_chunk (with +chunk_pointer - start_of_file as pos). +Supports most metadata chunks from the PNG standard (gAMA, bKGD, tEXt, ...). +Ignores unsupported, unknown, non-metadata or IHDR chunks (without error). +Requirements: &in[pos] must point to start of a chunk, must use regular +lodepng_inspect first since format of most other chunks depends on IHDR, and if +there is a PLTE chunk, that one must be inspected before tRNS or bKGD. +*/ +unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos, + const unsigned char* in, size_t insize); + +#ifdef LODEPNG_COMPILE_ENCODER +/*This function allocates the out buffer with standard malloc and stores the size in *outsize.*/ +unsigned lodepng_encode(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h, + LodePNGState* state); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +/* +The lodepng_chunk functions are normally not needed, except to traverse the +unknown chunks stored in the LodePNGInfo struct, or add new ones to it. +It also allows traversing the chunks of an encoded PNG file yourself. + +The chunk pointer always points to the beginning of the chunk itself, that is +the first byte of the 4 length bytes. + +In the PNG file format, chunks have the following format: +-4 bytes length: length of the data of the chunk in bytes (chunk itself is 12 bytes longer) +-4 bytes chunk type (ASCII a-z,A-Z only, see below) +-length bytes of data (may be 0 bytes if length was 0) +-4 bytes of CRC, computed on chunk name + data + +The first chunk starts at the 8th byte of the PNG file, the entire rest of the file +exists out of concatenated chunks with the above format. + +PNG standard chunk ASCII naming conventions: +-First byte: uppercase = critical, lowercase = ancillary +-Second byte: uppercase = public, lowercase = private +-Third byte: must be uppercase +-Fourth byte: uppercase = unsafe to copy, lowercase = safe to copy +*/ + +/* +Gets the length of the data of the chunk. Total chunk length has 12 bytes more. +There must be at least 4 bytes to read from. If the result value is too large, +it may be corrupt data. +*/ +unsigned lodepng_chunk_length(const unsigned char* chunk); + +/*puts the 4-byte type in null terminated string*/ +void lodepng_chunk_type(char type[5], const unsigned char* chunk); + +/*check if the type is the given type*/ +unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type); + +/*0: it's one of the critical chunk types, 1: it's an ancillary chunk (see PNG standard)*/ +unsigned char lodepng_chunk_ancillary(const unsigned char* chunk); + +/*0: public, 1: private (see PNG standard)*/ +unsigned char lodepng_chunk_private(const unsigned char* chunk); + +/*0: the chunk is unsafe to copy, 1: the chunk is safe to copy (see PNG standard)*/ +unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk); + +/*get pointer to the data of the chunk, where the input points to the header of the chunk*/ +unsigned char* lodepng_chunk_data(unsigned char* chunk); +const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk); + +/*returns 0 if the crc is correct, 1 if it's incorrect (0 for OK as usual!)*/ +unsigned lodepng_chunk_check_crc(const unsigned char* chunk); + +/*generates the correct CRC from the data and puts it in the last 4 bytes of the chunk*/ +void lodepng_chunk_generate_crc(unsigned char* chunk); + +/* +Iterate to next chunks, allows iterating through all chunks of the PNG file. +Input must be at the beginning of a chunk (result of a previous lodepng_chunk_next call, +or the 8th byte of a PNG file which always has the first chunk), or alternatively may +point to the first byte of the PNG file (which is not a chunk but the magic header, the +function will then skip over it and return the first real chunk). +Will output pointer to the start of the next chunk, or at or beyond end of the file if there +is no more chunk after this or possibly if the chunk is corrupt. +Start this process at the 8th byte of the PNG file. +In a non-corrupt PNG file, the last chunk should have name "IEND". +*/ +unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end); +const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end); + +/*Finds the first chunk with the given type in the range [chunk, end), or returns NULL if not found.*/ +unsigned char* lodepng_chunk_find(unsigned char* chunk, unsigned char* end, const char type[5]); +const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const unsigned char* end, const char type[5]); + +/* +Appends chunk to the data in out. The given chunk should already have its chunk header. +The out variable and outsize are updated to reflect the new reallocated buffer. +Returns error code (0 if it went ok) +*/ +unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk); + +/* +Appends new chunk to out. The chunk to append is given by giving its length, type +and data separately. The type is a 4-letter string. +The out variable and outsize are updated to reflect the new reallocated buffer. +Returne error code (0 if it went ok) +*/ +unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, + const char* type, const unsigned char* data); + + +/*Calculate CRC32 of buffer*/ +unsigned lodepng_crc32(const unsigned char* buf, size_t len); +#endif /*LODEPNG_COMPILE_PNG*/ + + +#ifdef LODEPNG_COMPILE_ZLIB +/* +This zlib part can be used independently to zlib compress and decompress a +buffer. It cannot be used to create gzip files however, and it only supports the +part of zlib that is required for PNG, it does not support dictionaries. +*/ + +#ifdef LODEPNG_COMPILE_DECODER +/*Inflate a buffer. Inflate is the decompression step of deflate. Out buffer must be freed after use.*/ +unsigned lodepng_inflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings); + +/* +Decompresses Zlib data. Reallocates the out buffer and appends the data. The +data must be according to the zlib specification. +Either, *out must be NULL and *outsize must be 0, or, *out must be a valid +buffer and *outsize its size in bytes. out must be freed by user after usage. +*/ +unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Compresses data with Zlib. Reallocates the out buffer and appends the data. +Zlib adds a small header and trailer around the deflate data. +The data is output in the format of the zlib specification. +Either, *out must be NULL and *outsize must be 0, or, *out must be a valid +buffer and *outsize its size in bytes. out must be freed by user after usage. +*/ +unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings); + +/* +Find length-limited Huffman code for given frequencies. This function is in the +public interface only for tests, it's used internally by lodepng_deflate. +*/ +unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies, + size_t numcodes, unsigned maxbitlen); + +/*Compress a buffer with deflate. See RFC 1951. Out buffer must be freed after use.*/ +unsigned lodepng_deflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings); + +#endif /*LODEPNG_COMPILE_ENCODER*/ +#endif /*LODEPNG_COMPILE_ZLIB*/ + +#ifdef LODEPNG_COMPILE_DISK +/* +Load a file from disk into buffer. The function allocates the out buffer, and +after usage you should free it. +out: output parameter, contains pointer to loaded buffer. +outsize: output parameter, size of the allocated out buffer +filename: the path to the file to load +return value: error code (0 means ok) +*/ +unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename); + +/* +Save a file from buffer to disk. Warning, if it exists, this function overwrites +the file without warning! +buffer: the buffer to write +buffersize: size of the buffer to write +filename: the path to the file to save to +return value: error code (0 means ok) +*/ +unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename); +#endif /*LODEPNG_COMPILE_DISK*/ + +#ifdef LODEPNG_COMPILE_CPP +/* The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. */ +namespace lodepng { +#ifdef LODEPNG_COMPILE_PNG +class State : public LodePNGState { + public: + State(); + State(const State& other); + ~State(); + State& operator=(const State& other); +}; + +#ifdef LODEPNG_COMPILE_DECODER +/* Same as other lodepng::decode, but using a State for more settings and information. */ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + State& state, + const unsigned char* in, size_t insize); +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + State& state, + const std::vector& in); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* Same as other lodepng::encode, but using a State for more settings and information. */ +unsigned encode(std::vector& out, + const unsigned char* in, unsigned w, unsigned h, + State& state); +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, + State& state); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#ifdef LODEPNG_COMPILE_DISK +/* +Load a file from disk into an std::vector. +return value: error code (0 means ok) +*/ +unsigned load_file(std::vector& buffer, const std::string& filename); + +/* +Save the binary data in an std::vector to a file on disk. The file is overwritten +without warning. +*/ +unsigned save_file(const std::vector& buffer, const std::string& filename); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_PNG */ + +#ifdef LODEPNG_COMPILE_ZLIB +#ifdef LODEPNG_COMPILE_DECODER +/* Zlib-decompress an unsigned char buffer */ +unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, + const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); + +/* Zlib-decompress an std::vector */ +unsigned decompress(std::vector& out, const std::vector& in, + const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); +#endif /* LODEPNG_COMPILE_DECODER */ + +#ifdef LODEPNG_COMPILE_ENCODER +/* Zlib-compress an unsigned char buffer */ +unsigned compress(std::vector& out, const unsigned char* in, size_t insize, + const LodePNGCompressSettings& settings = lodepng_default_compress_settings); + +/* Zlib-compress an std::vector */ +unsigned compress(std::vector& out, const std::vector& in, + const LodePNGCompressSettings& settings = lodepng_default_compress_settings); +#endif /* LODEPNG_COMPILE_ENCODER */ +#endif /* LODEPNG_COMPILE_ZLIB */ +} /* namespace lodepng */ +#endif /*LODEPNG_COMPILE_CPP*/ + +/* +TODO: +[.] test if there are no memory leaks or security exploits - done a lot but needs to be checked often +[.] check compatibility with various compilers - done but needs to be redone for every newer version +[X] converting color to 16-bit per channel types +[X] support color profile chunk types (but never let them touch RGB values by default) +[ ] support all public PNG chunk types (almost done except sBIT, sPLT and hIST) +[ ] make sure encoder generates no chunks with size > (2^31)-1 +[ ] partial decoding (stream processing) +[X] let the "isFullyOpaque" function check color keys and transparent palettes too +[X] better name for the variables "codes", "codesD", "codelengthcodes", "clcl" and "lldl" +[ ] allow treating some errors like warnings, when image is recoverable (e.g. 69, 57, 58) +[ ] make warnings like: oob palette, checksum fail, data after iend, wrong/unknown crit chunk, no null terminator in text, ... +[ ] error messages with line numbers (and version) +[ ] errors in state instead of as return code? +[ ] new errors/warnings like suspiciously big decompressed ztxt or iccp chunk +[ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes +[ ] allow user to provide custom color conversion functions, e.g. for premultiplied alpha, padding bits or not, ... +[ ] allow user to give data (void*) to custom allocator +[X] provide alternatives for C library functions not present on some platforms (memcpy, ...) +*/ + +#endif /*LV_USE_PNG*/ + +#endif /*LODEPNG_H inclusion guard*/ + +/* +LodePNG Documentation +--------------------- + +0. table of contents +-------------------- + + 1. about + 1.1. supported features + 1.2. features not supported + 2. C and C++ version + 3. security + 4. decoding + 5. encoding + 6. color conversions + 6.1. PNG color types + 6.2. color conversions + 6.3. padding bits + 6.4. A note about 16-bits per channel and endianness + 7. error values + 8. chunks and PNG editing + 9. compiler support + 10. examples + 10.1. decoder C++ example + 10.2. decoder C example + 11. state settings reference + 12. changes + 13. contact information + + +1. about +-------- + +PNG is a file format to store raster images losslessly with good compression, +supporting different color types and alpha channel. + +LodePNG is a PNG codec according to the Portable Network Graphics (PNG) +Specification (Second Edition) - W3C Recommendation 10 November 2003. + +The specifications used are: + +*) Portable Network Graphics (PNG) Specification (Second Edition): + http://www.w3.org/TR/2003/REC-PNG-20031110 +*) RFC 1950 ZLIB Compressed Data Format version 3.3: + http://www.gzip.org/zlib/rfc-zlib.html +*) RFC 1951 DEFLATE Compressed Data Format Specification ver 1.3: + http://www.gzip.org/zlib/rfc-deflate.html + +The most recent version of LodePNG can currently be found at +http://lodev.org/lodepng/ + +LodePNG works both in C (ISO C90) and C++, with a C++ wrapper that adds +extra functionality. + +LodePNG exists out of two files: +-lodepng.h: the header file for both C and C++ +-lodepng.c(pp): give it the name lodepng.c or lodepng.cpp (or .cc) depending on your usage + +If you want to start using LodePNG right away without reading this doc, get the +examples from the LodePNG website to see how to use it in code, or check the +smaller examples in chapter 13 here. + +LodePNG is simple but only supports the basic requirements. To achieve +simplicity, the following design choices were made: There are no dependencies +on any external library. There are functions to decode and encode a PNG with +a single function call, and extended versions of these functions taking a +LodePNGState struct allowing to specify or get more information. By default +the colors of the raw image are always RGB or RGBA, no matter what color type +the PNG file uses. To read and write files, there are simple functions to +convert the files to/from buffers in memory. + +This all makes LodePNG suitable for loading textures in games, demos and small +programs, ... It's less suitable for full fledged image editors, loading PNGs +over network (it requires all the image data to be available before decoding can +begin), life-critical systems, ... + +1.1. supported features +----------------------- + +The following features are supported by the decoder: + +*) decoding of PNGs with any color type, bit depth and interlace mode, to a 24- or 32-bit color raw image, + or the same color type as the PNG +*) encoding of PNGs, from any raw image to 24- or 32-bit color, or the same color type as the raw image +*) Adam7 interlace and deinterlace for any color type +*) loading the image from harddisk or decoding it from a buffer from other sources than harddisk +*) support for alpha channels, including RGBA color model, translucent palettes and color keying +*) zlib decompression (inflate) +*) zlib compression (deflate) +*) CRC32 and ADLER32 checksums +*) colorimetric color profile conversions: currently experimentally available in lodepng_util.cpp only, + plus alternatively ability to pass on chroma/gamma/ICC profile information to other color management system. +*) handling of unknown chunks, allowing making a PNG editor that stores custom and unknown chunks. +*) the following chunks are supported by both encoder and decoder: + IHDR: header information + PLTE: color palette + IDAT: pixel data + IEND: the final chunk + tRNS: transparency for palettized images + tEXt: textual information + zTXt: compressed textual information + iTXt: international textual information + bKGD: suggested background color + pHYs: physical dimensions + tIME: modification time + cHRM: RGB chromaticities + gAMA: RGB gamma correction + iCCP: ICC color profile + sRGB: rendering intent + +1.2. features not supported +--------------------------- + +The following features are _not_ supported: + +*) some features needed to make a conformant PNG-Editor might be still missing. +*) partial loading/stream processing. All data must be available and is processed in one call. +*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG: + sBIT + hIST + sPLT + + +2. C and C++ version +-------------------- + +The C version uses buffers allocated with alloc that you need to free() +yourself. You need to use init and cleanup functions for each struct whenever +using a struct from the C version to avoid exploits and memory leaks. + +The C++ version has extra functions with std::vectors in the interface and the +lodepng::State class which is a LodePNGState with constructor and destructor. + +These files work without modification for both C and C++ compilers because all +the additional C++ code is in "#ifdef __cplusplus" blocks that make C-compilers +ignore it, and the C code is made to compile both with strict ISO C90 and C++. + +To use the C++ version, you need to rename the source file to lodepng.cpp +(instead of lodepng.c), and compile it with a C++ compiler. + +To use the C version, you need to rename the source file to lodepng.c (instead +of lodepng.cpp), and compile it with a C compiler. + + +3. Security +----------- + +Even if carefully designed, it's always possible that LodePNG contains possible +exploits. If you discover one, please let me know, and it will be fixed. + +When using LodePNG, care has to be taken with the C version of LodePNG, as well +as the C-style structs when working with C++. The following conventions are used +for all C-style structs: + +-if a struct has a corresponding init function, always call the init function when making a new one +-if a struct has a corresponding cleanup function, call it before the struct disappears to avoid memory leaks +-if a struct has a corresponding copy function, use the copy function instead of "=". + The destination must also be inited already. + + +4. Decoding +----------- + +Decoding converts a PNG compressed image to a raw pixel buffer. + +Most documentation on using the decoder is at its declarations in the header +above. For C, simple decoding can be done with functions such as +lodepng_decode32, and more advanced decoding can be done with the struct +LodePNGState and lodepng_decode. For C++, all decoding can be done with the +various lodepng::decode functions, and lodepng::State can be used for advanced +features. + +When using the LodePNGState, it uses the following fields for decoding: +*) LodePNGInfo info_png: it stores extra information about the PNG (the input) in here +*) LodePNGColorMode info_raw: here you can say what color mode of the raw image (the output) you want to get +*) LodePNGDecoderSettings decoder: you can specify a few extra settings for the decoder to use + +LodePNGInfo info_png +-------------------- + +After decoding, this contains extra information of the PNG image, except the actual +pixels, width and height because these are already gotten directly from the decoder +functions. + +It contains for example the original color type of the PNG image, text comments, +suggested background color, etc... More details about the LodePNGInfo struct are +at its declaration documentation. + +LodePNGColorMode info_raw +------------------------- + +When decoding, here you can specify which color type you want +the resulting raw image to be. If this is different from the colortype of the +PNG, then the decoder will automatically convert the result. This conversion +always works, except if you want it to convert a color PNG to grayscale or to +a palette with missing colors. + +By default, 32-bit color is used for the result. + +LodePNGDecoderSettings decoder +------------------------------ + +The settings can be used to ignore the errors created by invalid CRC and Adler32 +chunks, and to disable the decoding of tEXt chunks. + +There's also a setting color_convert, true by default. If false, no conversion +is done, the resulting data will be as it was in the PNG (after decompression) +and you'll have to puzzle the colors of the pixels together yourself using the +color type information in the LodePNGInfo. + + +5. Encoding +----------- + +Encoding converts a raw pixel buffer to a PNG compressed image. + +Most documentation on using the encoder is at its declarations in the header +above. For C, simple encoding can be done with functions such as +lodepng_encode32, and more advanced decoding can be done with the struct +LodePNGState and lodepng_encode. For C++, all encoding can be done with the +various lodepng::encode functions, and lodepng::State can be used for advanced +features. + +Like the decoder, the encoder can also give errors. However it gives less errors +since the encoder input is trusted, the decoder input (a PNG image that could +be forged by anyone) is not trusted. + +When using the LodePNGState, it uses the following fields for encoding: +*) LodePNGInfo info_png: here you specify how you want the PNG (the output) to be. +*) LodePNGColorMode info_raw: here you say what color type of the raw image (the input) has +*) LodePNGEncoderSettings encoder: you can specify a few settings for the encoder to use + +LodePNGInfo info_png +-------------------- + +When encoding, you use this the opposite way as when decoding: for encoding, +you fill in the values you want the PNG to have before encoding. By default it's +not needed to specify a color type for the PNG since it's automatically chosen, +but it's possible to choose it yourself given the right settings. + +The encoder will not always exactly match the LodePNGInfo struct you give, +it tries as close as possible. Some things are ignored by the encoder. The +encoder uses, for example, the following settings from it when applicable: +colortype and bitdepth, text chunks, time chunk, the color key, the palette, the +background color, the interlace method, unknown chunks, ... + +When encoding to a PNG with colortype 3, the encoder will generate a PLTE chunk. +If the palette contains any colors for which the alpha channel is not 255 (so +there are translucent colors in the palette), it'll add a tRNS chunk. + +LodePNGColorMode info_raw +------------------------- + +You specify the color type of the raw image that you give to the input here, +including a possible transparent color key and palette you happen to be using in +your raw image data. + +By default, 32-bit color is assumed, meaning your input has to be in RGBA +format with 4 bytes (unsigned chars) per pixel. + +LodePNGEncoderSettings encoder +------------------------------ + +The following settings are supported (some are in sub-structs): +*) auto_convert: when this option is enabled, the encoder will +automatically choose the smallest possible color mode (including color key) that +can encode the colors of all pixels without information loss. +*) btype: the block type for LZ77. 0 = uncompressed, 1 = fixed huffman tree, + 2 = dynamic huffman tree (best compression). Should be 2 for proper + compression. +*) use_lz77: whether or not to use LZ77 for compressed block types. Should be + true for proper compression. +*) windowsize: the window size used by the LZ77 encoder (1 - 32768). Has value + 2048 by default, but can be set to 32768 for better, but slow, compression. +*) force_palette: if colortype is 2 or 6, you can make the encoder write a PLTE + chunk if force_palette is true. This can used as suggested palette to convert + to by viewers that don't support more than 256 colors (if those still exist) +*) add_id: add text chunk "Encoder: LodePNG " to the image. +*) text_compression: default 1. If 1, it'll store texts as zTXt instead of tEXt chunks. + zTXt chunks use zlib compression on the text. This gives a smaller result on + large texts but a larger result on small texts (such as a single program name). + It's all tEXt or all zTXt though, there's no separate setting per text yet. + + +6. color conversions +-------------------- + +An important thing to note about LodePNG, is that the color type of the PNG, and +the color type of the raw image, are completely independent. By default, when +you decode a PNG, you get the result as a raw image in the color type you want, +no matter whether the PNG was encoded with a palette, grayscale or RGBA color. +And if you encode an image, by default LodePNG will automatically choose the PNG +color type that gives good compression based on the values of colors and amount +of colors in the image. It can be configured to let you control it instead as +well, though. + +To be able to do this, LodePNG does conversions from one color mode to another. +It can convert from almost any color type to any other color type, except the +following conversions: RGB to grayscale is not supported, and converting to a +palette when the palette doesn't have a required color is not supported. This is +not supported on purpose: this is information loss which requires a color +reduction algorithm that is beyond the scope of a PNG encoder (yes, RGB to gray +is easy, but there are multiple ways if you want to give some channels more +weight). + +By default, when decoding, you get the raw image in 32-bit RGBA or 24-bit RGB +color, no matter what color type the PNG has. And by default when encoding, +LodePNG automatically picks the best color model for the output PNG, and expects +the input image to be 32-bit RGBA or 24-bit RGB. So, unless you want to control +the color format of the images yourself, you can skip this chapter. + +6.1. PNG color types +-------------------- + +A PNG image can have many color types, ranging from 1-bit color to 64-bit color, +as well as palettized color modes. After the zlib decompression and unfiltering +in the PNG image is done, the raw pixel data will have that color type and thus +a certain amount of bits per pixel. If you want the output raw image after +decoding to have another color type, a conversion is done by LodePNG. + +The PNG specification gives the following color types: + +0: grayscale, bit depths 1, 2, 4, 8, 16 +2: RGB, bit depths 8 and 16 +3: palette, bit depths 1, 2, 4 and 8 +4: grayscale with alpha, bit depths 8 and 16 +6: RGBA, bit depths 8 and 16 + +Bit depth is the amount of bits per pixel per color channel. So the total amount +of bits per pixel is: amount of channels * bitdepth. + +6.2. color conversions +---------------------- + +As explained in the sections about the encoder and decoder, you can specify +color types and bit depths in info_png and info_raw to change the default +behaviour. + +If, when decoding, you want the raw image to be something else than the default, +you need to set the color type and bit depth you want in the LodePNGColorMode, +or the parameters colortype and bitdepth of the simple decoding function. + +If, when encoding, you use another color type than the default in the raw input +image, you need to specify its color type and bit depth in the LodePNGColorMode +of the raw image, or use the parameters colortype and bitdepth of the simple +encoding function. + +If, when encoding, you don't want LodePNG to choose the output PNG color type +but control it yourself, you need to set auto_convert in the encoder settings +to false, and specify the color type you want in the LodePNGInfo of the +encoder (including palette: it can generate a palette if auto_convert is true, +otherwise not). + +If the input and output color type differ (whether user chosen or auto chosen), +LodePNG will do a color conversion, which follows the rules below, and may +sometimes result in an error. + +To avoid some confusion: +-the decoder converts from PNG to raw image +-the encoder converts from raw image to PNG +-the colortype and bitdepth in LodePNGColorMode info_raw, are those of the raw image +-the colortype and bitdepth in the color field of LodePNGInfo info_png, are those of the PNG +-when encoding, the color type in LodePNGInfo is ignored if auto_convert + is enabled, it is automatically generated instead +-when decoding, the color type in LodePNGInfo is set by the decoder to that of the original + PNG image, but it can be ignored since the raw image has the color type you requested instead +-if the color type of the LodePNGColorMode and PNG image aren't the same, a conversion + between the color types is done if the color types are supported. If it is not + supported, an error is returned. If the types are the same, no conversion is done. +-even though some conversions aren't supported, LodePNG supports loading PNGs from any + colortype and saving PNGs to any colortype, sometimes it just requires preparing + the raw image correctly before encoding. +-both encoder and decoder use the same color converter. + +The function lodepng_convert does the color conversion. It is available in the +interface but normally isn't needed since the encoder and decoder already call +it. + +Non supported color conversions: +-color to grayscale when non-gray pixels are present: no error is thrown, but +the result will look ugly because only the red channel is taken (it assumes all +three channels are the same in this case so ignores green and blue). The reason +no error is given is to allow converting from three-channel grayscale images to +one-channel even if there are numerical imprecisions. +-anything to palette when the palette does not have an exact match for a from-color +in it: in this case an error is thrown + +Supported color conversions: +-anything to 8-bit RGB, 8-bit RGBA, 16-bit RGB, 16-bit RGBA +-any gray or gray+alpha, to gray or gray+alpha +-anything to a palette, as long as the palette has the requested colors in it +-removing alpha channel +-higher to smaller bitdepth, and vice versa + +If you want no color conversion to be done (e.g. for speed or control): +-In the encoder, you can make it save a PNG with any color type by giving the +raw color mode and LodePNGInfo the same color mode, and setting auto_convert to +false. +-In the decoder, you can make it store the pixel data in the same color type +as the PNG has, by setting the color_convert setting to false. Settings in +info_raw are then ignored. + +6.3. padding bits +----------------- + +In the PNG file format, if a less than 8-bit per pixel color type is used and the scanlines +have a bit amount that isn't a multiple of 8, then padding bits are used so that each +scanline starts at a fresh byte. But that is NOT true for the LodePNG raw input and output. +The raw input image you give to the encoder, and the raw output image you get from the decoder +will NOT have these padding bits, e.g. in the case of a 1-bit image with a width +of 7 pixels, the first pixel of the second scanline will the 8th bit of the first byte, +not the first bit of a new byte. + +6.4. A note about 16-bits per channel and endianness +---------------------------------------------------- + +LodePNG uses unsigned char arrays for 16-bit per channel colors too, just like +for any other color format. The 16-bit values are stored in big endian (most +significant byte first) in these arrays. This is the opposite order of the +little endian used by x86 CPU's. + +LodePNG always uses big endian because the PNG file format does so internally. +Conversions to other formats than PNG uses internally are not supported by +LodePNG on purpose, there are myriads of formats, including endianness of 16-bit +colors, the order in which you store R, G, B and A, and so on. Supporting and +converting to/from all that is outside the scope of LodePNG. + +This may mean that, depending on your use case, you may want to convert the big +endian output of LodePNG to little endian with a for loop. This is certainly not +always needed, many applications and libraries support big endian 16-bit colors +anyway, but it means you cannot simply cast the unsigned char* buffer to an +unsigned short* buffer on x86 CPUs. + + +7. error values +--------------- + +All functions in LodePNG that return an error code, return 0 if everything went +OK, or a non-zero code if there was an error. + +The meaning of the LodePNG error values can be retrieved with the function +lodepng_error_text: given the numerical error code, it returns a description +of the error in English as a string. + +Check the implementation of lodepng_error_text to see the meaning of each code. + +It is not recommended to use the numerical values to programmatically make +different decisions based on error types as the numbers are not guaranteed to +stay backwards compatible. They are for human consumption only. Programmatically +only 0 or non-0 matter. + + +8. chunks and PNG editing +------------------------- + +If you want to add extra chunks to a PNG you encode, or use LodePNG for a PNG +editor that should follow the rules about handling of unknown chunks, or if your +program is able to read other types of chunks than the ones handled by LodePNG, +then that's possible with the chunk functions of LodePNG. + +A PNG chunk has the following layout: + +4 bytes length +4 bytes type name +length bytes data +4 bytes CRC + +8.1. iterating through chunks +----------------------------- + +If you have a buffer containing the PNG image data, then the first chunk (the +IHDR chunk) starts at byte number 8 of that buffer. The first 8 bytes are the +signature of the PNG and are not part of a chunk. But if you start at byte 8 +then you have a chunk, and can check the following things of it. + +NOTE: none of these functions check for memory buffer boundaries. To avoid +exploits, always make sure the buffer contains all the data of the chunks. +When using lodepng_chunk_next, make sure the returned value is within the +allocated memory. + +unsigned lodepng_chunk_length(const unsigned char* chunk): + +Get the length of the chunk's data. The total chunk length is this length + 12. + +void lodepng_chunk_type(char type[5], const unsigned char* chunk): +unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type): + +Get the type of the chunk or compare if it's a certain type + +unsigned char lodepng_chunk_critical(const unsigned char* chunk): +unsigned char lodepng_chunk_private(const unsigned char* chunk): +unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk): + +Check if the chunk is critical in the PNG standard (only IHDR, PLTE, IDAT and IEND are). +Check if the chunk is private (public chunks are part of the standard, private ones not). +Check if the chunk is safe to copy. If it's not, then, when modifying data in a critical +chunk, unsafe to copy chunks of the old image may NOT be saved in the new one if your +program doesn't handle that type of unknown chunk. + +unsigned char* lodepng_chunk_data(unsigned char* chunk): +const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk): + +Get a pointer to the start of the data of the chunk. + +unsigned lodepng_chunk_check_crc(const unsigned char* chunk): +void lodepng_chunk_generate_crc(unsigned char* chunk): + +Check if the crc is correct or generate a correct one. + +unsigned char* lodepng_chunk_next(unsigned char* chunk): +const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk): + +Iterate to the next chunk. This works if you have a buffer with consecutive chunks. Note that these +functions do no boundary checking of the allocated data whatsoever, so make sure there is enough +data available in the buffer to be able to go to the next chunk. + +unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk): +unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, + const char* type, const unsigned char* data): + +These functions are used to create new chunks that are appended to the data in *out that has +length *outsize. The append function appends an existing chunk to the new data. The create +function creates a new chunk with the given parameters and appends it. Type is the 4-letter +name of the chunk. + +8.2. chunks in info_png +----------------------- + +The LodePNGInfo struct contains fields with the unknown chunk in it. It has 3 +buffers (each with size) to contain 3 types of unknown chunks: +the ones that come before the PLTE chunk, the ones that come between the PLTE +and the IDAT chunks, and the ones that come after the IDAT chunks. +It's necessary to make the distinction between these 3 cases because the PNG +standard forces to keep the ordering of unknown chunks compared to the critical +chunks, but does not force any other ordering rules. + +info_png.unknown_chunks_data[0] is the chunks before PLTE +info_png.unknown_chunks_data[1] is the chunks after PLTE, before IDAT +info_png.unknown_chunks_data[2] is the chunks after IDAT + +The chunks in these 3 buffers can be iterated through and read by using the same +way described in the previous subchapter. + +When using the decoder to decode a PNG, you can make it store all unknown chunks +if you set the option settings.remember_unknown_chunks to 1. By default, this +option is off (0). + +The encoder will always encode unknown chunks that are stored in the info_png. +If you need it to add a particular chunk that isn't known by LodePNG, you can +use lodepng_chunk_append or lodepng_chunk_create to the chunk data in +info_png.unknown_chunks_data[x]. + +Chunks that are known by LodePNG should not be added in that way. E.g. to make +LodePNG add a bKGD chunk, set background_defined to true and add the correct +parameters there instead. + + +9. compiler support +------------------- + +No libraries other than the current standard C library are needed to compile +LodePNG. For the C++ version, only the standard C++ library is needed on top. +Add the files lodepng.c(pp) and lodepng.h to your project, include +lodepng.h where needed, and your program can read/write PNG files. + +It is compatible with C90 and up, and C++03 and up. + +If performance is important, use optimization when compiling! For both the +encoder and decoder, this makes a large difference. + +Make sure that LodePNG is compiled with the same compiler of the same version +and with the same settings as the rest of the program, or the interfaces with +std::vectors and std::strings in C++ can be incompatible. + +CHAR_BITS must be 8 or higher, because LodePNG uses unsigned chars for octets. + +*) gcc and g++ + +LodePNG is developed in gcc so this compiler is natively supported. It gives no +warnings with compiler options "-Wall -Wextra -pedantic -ansi", with gcc and g++ +version 4.7.1 on Linux, 32-bit and 64-bit. + +*) Clang + +Fully supported and warning-free. + +*) Mingw + +The Mingw compiler (a port of gcc for Windows) should be fully supported by +LodePNG. + +*) Visual Studio and Visual C++ Express Edition + +LodePNG should be warning-free with warning level W4. Two warnings were disabled +with pragmas though: warning 4244 about implicit conversions, and warning 4996 +where it wants to use a non-standard function fopen_s instead of the standard C +fopen. + +Visual Studio may want "stdafx.h" files to be included in each source file and +give an error "unexpected end of file while looking for precompiled header". +This is not standard C++ and will not be added to the stock LodePNG. You can +disable it for lodepng.cpp only by right clicking it, Properties, C/C++, +Precompiled Headers, and set it to Not Using Precompiled Headers there. + +NOTE: Modern versions of VS should be fully supported, but old versions, e.g. +VS6, are not guaranteed to work. + +*) Compilers on Macintosh + +LodePNG has been reported to work both with gcc and LLVM for Macintosh, both for +C and C++. + +*) Other Compilers + +If you encounter problems on any compilers, feel free to let me know and I may +try to fix it if the compiler is modern and standards compliant. + + +10. examples +------------ + +This decoder example shows the most basic usage of LodePNG. More complex +examples can be found on the LodePNG website. + +10.1. decoder C++ example +------------------------- + +#include "lodepng.h" +#include + +int main(int argc, char *argv[]) { + const char* filename = argc > 1 ? argv[1] : "test.png"; + + //load and decode + std::vector image; + unsigned width, height; + unsigned error = lodepng::decode(image, width, height, filename); + + //if there's an error, display it + if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; + + //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ... +} + +10.2. decoder C example +----------------------- + +#include "lodepng.h" + +int main(int argc, char *argv[]) { + unsigned error; + unsigned char* image; + size_t width, height; + const char* filename = argc > 1 ? argv[1] : "test.png"; + + error = lodepng_decode32_file(&image, &width, &height, filename); + + if(error) printf("decoder error %u: %s\n", error, lodepng_error_text(error)); + + / * use image here * / + + free(image); + return 0; +} + +11. state settings reference +---------------------------- + +A quick reference of some settings to set on the LodePNGState + +For decoding: + +state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksums +state.decoder.zlibsettings.custom_...: use custom inflate function +state.decoder.ignore_crc: ignore CRC checksums +state.decoder.ignore_critical: ignore unknown critical chunks +state.decoder.ignore_end: ignore missing IEND chunk. May fail if this corruption causes other errors +state.decoder.color_convert: convert internal PNG color to chosen one +state.decoder.read_text_chunks: whether to read in text metadata chunks +state.decoder.remember_unknown_chunks: whether to read in unknown chunks +state.info_raw.colortype: desired color type for decoded image +state.info_raw.bitdepth: desired bit depth for decoded image +state.info_raw....: more color settings, see struct LodePNGColorMode +state.info_png....: no settings for decoder but ouput, see struct LodePNGInfo + +For encoding: + +state.encoder.zlibsettings.btype: disable compression by setting it to 0 +state.encoder.zlibsettings.use_lz77: use LZ77 in compression +state.encoder.zlibsettings.windowsize: tweak LZ77 windowsize +state.encoder.zlibsettings.minmatch: tweak min LZ77 length to match +state.encoder.zlibsettings.nicematch: tweak LZ77 match where to stop searching +state.encoder.zlibsettings.lazymatching: try one more LZ77 matching +state.encoder.zlibsettings.custom_...: use custom deflate function +state.encoder.auto_convert: choose optimal PNG color type, if 0 uses info_png +state.encoder.filter_palette_zero: PNG filter strategy for palette +state.encoder.filter_strategy: PNG filter strategy to encode with +state.encoder.force_palette: add palette even if not encoding to one +state.encoder.add_id: add LodePNG identifier and version as a text chunk +state.encoder.text_compression: use compressed text chunks for metadata +state.info_raw.colortype: color type of raw input image you provide +state.info_raw.bitdepth: bit depth of raw input image you provide +state.info_raw: more color settings, see struct LodePNGColorMode +state.info_png.color.colortype: desired color type if auto_convert is false +state.info_png.color.bitdepth: desired bit depth if auto_convert is false +state.info_png.color....: more color settings, see struct LodePNGColorMode +state.info_png....: more PNG related settings, see struct LodePNGInfo + + +12. changes +----------- + +The version number of LodePNG is the date of the change given in the format +yyyymmdd. + +Some changes aren't backwards compatible. Those are indicated with a (!) +symbol. + +Not all changes are listed here, the commit history in github lists more: +https://github.com/lvandeve/lodepng + +*) 17 okt 2020: prevent decoding too large text/icc chunks by default. +*) 06 mar 2020: simplified some of the dynamic memory allocations. +*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct + overflow checks. +*) 14 aug 2019: around 25% faster decoding thanks to huffman lookup tables. +*) 15 jun 2019: (!) auto_choose_color API changed (for bugfix: don't use palette + if gray ICC profile) and non-ICC LodePNGColorProfile renamed to + LodePNGColorStats. +*) 30 dec 2018: code style changes only: removed newlines before opening braces. +*) 10 sep 2018: added way to inspect metadata chunks without full decoding. +*) 19 aug 2018: (!) fixed color mode bKGD is encoded with and made it use + palette index in case of palette. +*) 10 aug 2018: (!) added support for gAMA, cHRM, sRGB and iCCP chunks. This + change is backwards compatible unless you relied on unknown_chunks for those. +*) 11 jun 2018: less restrictive check for pixel size integer overflow +*) 14 jan 2018: allow optionally ignoring a few more recoverable errors +*) 17 sep 2017: fix memory leak for some encoder input error cases +*) 27 nov 2016: grey+alpha auto color model detection bugfix +*) 18 apr 2016: Changed qsort to custom stable sort (for platforms w/o qsort). +*) 09 apr 2016: Fixed colorkey usage detection, and better file loading (within + the limits of pure C90). +*) 08 dec 2015: Made load_file function return error if file can't be opened. +*) 24 okt 2015: Bugfix with decoding to palette output. +*) 18 apr 2015: Boundary PM instead of just package-merge for faster encoding. +*) 24 aug 2014: Moved to github +*) 23 aug 2014: Reduced needless memory usage of decoder. +*) 28 jun 2014: Removed fix_png setting, always support palette OOB for + simplicity. Made ColorProfile public. +*) 09 jun 2014: Faster encoder by fixing hash bug and more zeros optimization. +*) 22 dec 2013: Power of two windowsize required for optimization. +*) 15 apr 2013: Fixed bug with LAC_ALPHA and color key. +*) 25 mar 2013: Added an optional feature to ignore some PNG errors (fix_png). +*) 11 mar 2013: (!) Bugfix with custom free. Changed from "my" to "lodepng_" + prefix for the custom allocators and made it possible with a new #define to + use custom ones in your project without needing to change lodepng's code. +*) 28 jan 2013: Bugfix with color key. +*) 27 okt 2012: Tweaks in text chunk keyword length error handling. +*) 8 okt 2012: (!) Added new filter strategy (entropy) and new auto color mode. + (no palette). Better deflate tree encoding. New compression tweak settings. + Faster color conversions while decoding. Some internal cleanups. +*) 23 sep 2012: Reduced warnings in Visual Studio a little bit. +*) 1 sep 2012: (!) Removed #define's for giving custom (de)compression functions + and made it work with function pointers instead. +*) 23 jun 2012: Added more filter strategies. Made it easier to use custom alloc + and free functions and toggle #defines from compiler flags. Small fixes. +*) 6 may 2012: (!) Made plugging in custom zlib/deflate functions more flexible. +*) 22 apr 2012: (!) Made interface more consistent, renaming a lot. Removed + redundant C++ codec classes. Reduced amount of structs. Everything changed, + but it is cleaner now imho and functionality remains the same. Also fixed + several bugs and shrunk the implementation code. Made new samples. +*) 6 nov 2011: (!) By default, the encoder now automatically chooses the best + PNG color model and bit depth, based on the amount and type of colors of the + raw image. For this, autoLeaveOutAlphaChannel replaced by auto_choose_color. +*) 9 okt 2011: simpler hash chain implementation for the encoder. +*) 8 sep 2011: lz77 encoder lazy matching instead of greedy matching. +*) 23 aug 2011: tweaked the zlib compression parameters after benchmarking. + A bug with the PNG filtertype heuristic was fixed, so that it chooses much + better ones (it's quite significant). A setting to do an experimental, slow, + brute force search for PNG filter types is added. +*) 17 aug 2011: (!) changed some C zlib related function names. +*) 16 aug 2011: made the code less wide (max 120 characters per line). +*) 17 apr 2011: code cleanup. Bugfixes. Convert low to 16-bit per sample colors. +*) 21 feb 2011: fixed compiling for C90. Fixed compiling with sections disabled. +*) 11 dec 2010: encoding is made faster, based on suggestion by Peter Eastman + to optimize long sequences of zeros. +*) 13 nov 2010: added LodePNG_InfoColor_hasPaletteAlpha and + LodePNG_InfoColor_canHaveAlpha functions for convenience. +*) 7 nov 2010: added LodePNG_error_text function to get error code description. +*) 30 okt 2010: made decoding slightly faster +*) 26 okt 2010: (!) changed some C function and struct names (more consistent). + Reorganized the documentation and the declaration order in the header. +*) 08 aug 2010: only changed some comments and external samples. +*) 05 jul 2010: fixed bug thanks to warnings in the new gcc version. +*) 14 mar 2010: fixed bug where too much memory was allocated for char buffers. +*) 02 sep 2008: fixed bug where it could create empty tree that linux apps could + read by ignoring the problem but windows apps couldn't. +*) 06 jun 2008: added more error checks for out of memory cases. +*) 26 apr 2008: added a few more checks here and there to ensure more safety. +*) 06 mar 2008: crash with encoding of strings fixed +*) 02 feb 2008: support for international text chunks added (iTXt) +*) 23 jan 2008: small cleanups, and #defines to divide code in sections +*) 20 jan 2008: support for unknown chunks allowing using LodePNG for an editor. +*) 18 jan 2008: support for tIME and pHYs chunks added to encoder and decoder. +*) 17 jan 2008: ability to encode and decode compressed zTXt chunks added + Also various fixes, such as in the deflate and the padding bits code. +*) 13 jan 2008: Added ability to encode Adam7-interlaced images. Improved + filtering code of encoder. +*) 07 jan 2008: (!) changed LodePNG to use ISO C90 instead of C++. A + C++ wrapper around this provides an interface almost identical to before. + Having LodePNG be pure ISO C90 makes it more portable. The C and C++ code + are together in these files but it works both for C and C++ compilers. +*) 29 dec 2007: (!) changed most integer types to unsigned int + other tweaks +*) 30 aug 2007: bug fixed which makes this Borland C++ compatible +*) 09 aug 2007: some VS2005 warnings removed again +*) 21 jul 2007: deflate code placed in new namespace separate from zlib code +*) 08 jun 2007: fixed bug with 2- and 4-bit color, and small interlaced images +*) 04 jun 2007: improved support for Visual Studio 2005: crash with accessing + invalid std::vector element [0] fixed, and level 3 and 4 warnings removed +*) 02 jun 2007: made the encoder add a tag with version by default +*) 27 may 2007: zlib and png code separated (but still in the same file), + simple encoder/decoder functions added for more simple usage cases +*) 19 may 2007: minor fixes, some code cleaning, new error added (error 69), + moved some examples from here to lodepng_examples.cpp +*) 12 may 2007: palette decoding bug fixed +*) 24 apr 2007: changed the license from BSD to the zlib license +*) 11 mar 2007: very simple addition: ability to encode bKGD chunks. +*) 04 mar 2007: (!) tEXt chunk related fixes, and support for encoding + palettized PNG images. Plus little interface change with palette and texts. +*) 03 mar 2007: Made it encode dynamic Huffman shorter with repeat codes. + Fixed a bug where the end code of a block had length 0 in the Huffman tree. +*) 26 feb 2007: Huffman compression with dynamic trees (BTYPE 2) now implemented + and supported by the encoder, resulting in smaller PNGs at the output. +*) 27 jan 2007: Made the Adler-32 test faster so that a timewaste is gone. +*) 24 jan 2007: gave encoder an error interface. Added color conversion from any + greyscale type to 8-bit greyscale with or without alpha. +*) 21 jan 2007: (!) Totally changed the interface. It allows more color types + to convert to and is more uniform. See the manual for how it works now. +*) 07 jan 2007: Some cleanup & fixes, and a few changes over the last days: + encode/decode custom tEXt chunks, separate classes for zlib & deflate, and + at last made the decoder give errors for incorrect Adler32 or Crc. +*) 01 jan 2007: Fixed bug with encoding PNGs with less than 8 bits per channel. +*) 29 dec 2006: Added support for encoding images without alpha channel, and + cleaned out code as well as making certain parts faster. +*) 28 dec 2006: Added "Settings" to the encoder. +*) 26 dec 2006: The encoder now does LZ77 encoding and produces much smaller files now. + Removed some code duplication in the decoder. Fixed little bug in an example. +*) 09 dec 2006: (!) Placed output parameters of public functions as first parameter. + Fixed a bug of the decoder with 16-bit per color. +*) 15 okt 2006: Changed documentation structure +*) 09 okt 2006: Encoder class added. It encodes a valid PNG image from the + given image buffer, however for now it's not compressed. +*) 08 sep 2006: (!) Changed to interface with a Decoder class +*) 30 jul 2006: (!) LodePNG_InfoPng , width and height are now retrieved in different + way. Renamed decodePNG to decodePNGGeneric. +*) 29 jul 2006: (!) Changed the interface: image info is now returned as a + struct of type LodePNG::LodePNG_Info, instead of a vector, which was a bit clumsy. +*) 28 jul 2006: Cleaned the code and added new error checks. + Corrected terminology "deflate" into "inflate". +*) 23 jun 2006: Added SDL example in the documentation in the header, this + example allows easy debugging by displaying the PNG and its transparency. +*) 22 jun 2006: (!) Changed way to obtain error value. Added + loadFile function for convenience. Made decodePNG32 faster. +*) 21 jun 2006: (!) Changed type of info vector to unsigned. + Changed position of palette in info vector. Fixed an important bug that + happened on PNGs with an uncompressed block. +*) 16 jun 2006: Internally changed unsigned into unsigned where + needed, and performed some optimizations. +*) 07 jun 2006: (!) Renamed functions to decodePNG and placed them + in LodePNG namespace. Changed the order of the parameters. Rewrote the + documentation in the header. Renamed files to lodepng.cpp and lodepng.h +*) 22 apr 2006: Optimized and improved some code +*) 07 sep 2005: (!) Changed to std::vector interface +*) 12 aug 2005: Initial release (C++, decoder only) + + +13. contact information +----------------------- + +Feel free to contact me with suggestions, problems, comments, ... concerning +LodePNG. If you encounter a PNG image that doesn't work properly with this +decoder, feel free to send it and I'll use it to find and fix the problem. + +My email address is (puzzle the account and domain together with an @ symbol): +Domain: gmail dot com. +Account: lode dot vandevenne. + + +Copyright (c) 2005-2020 Lode Vandevenne +*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/png/lv_png.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/png/lv_png.h new file mode 100644 index 00000000..ef634540 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/png/lv_png.h @@ -0,0 +1,46 @@ +/** + * @file lv_png.h + * + */ + +#ifndef LV_PNG_H +#define LV_PNG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_PNG + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Register the PNG decoder functions in LVGL + */ +void lv_png_init(void); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_PNG*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_PNG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/qrcode/lv_qrcode.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/qrcode/lv_qrcode.h new file mode 100644 index 00000000..c8db4e5e --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/qrcode/lv_qrcode.h @@ -0,0 +1,69 @@ +/** + * @file lv_qrcode + * + */ + +#ifndef LV_QRCODE_H +#define LV_QRCODE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" +#if LV_USE_QRCODE + +/********************* + * DEFINES + *********************/ + +extern const lv_obj_class_t lv_qrcode_class; + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an empty QR code (an `lv_canvas`) object. + * @param parent point to an object where to create the QR code + * @param size width and height of the QR code + * @param dark_color dark color of the QR code + * @param light_color light color of the QR code + * @return pointer to the created QR code object + */ +lv_obj_t * lv_qrcode_create(lv_obj_t * parent, lv_coord_t size, lv_color_t dark_color, lv_color_t light_color); + +/** + * Set the data of a QR code object + * @param qrcode pointer to aQ code object + * @param data data to display + * @param data_len length of data in bytes + * @return LV_RES_OK: if no error; LV_RES_INV: on error + */ +lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_len); + +/** + * DEPRECATED: Use normal lv_obj_del instead + * Delete a QR code object + * @param qrcode pointer to a QR code object + */ +void lv_qrcode_delete(lv_obj_t * qrcode); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_QRCODE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_QRCODE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/qrcode/qrcodegen.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/qrcode/qrcodegen.h new file mode 100644 index 00000000..b484e917 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/qrcode/qrcodegen.h @@ -0,0 +1,319 @@ +/* + * QR Code generator library (C) + * + * Copyright (c) Project Nayuki. (MIT License) + * https://www.nayuki.io/page/qr-code-generator-library + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * - The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * - The Software is provided "as is", without warranty of any kind, express or + * implied, including but not limited to the warranties of merchantability, + * fitness for a particular purpose and noninfringement. In no event shall the + * authors or copyright holders be liable for any claim, damages or other + * liability, whether in an action of contract, tort or otherwise, arising from, + * out of or in connection with the Software or the use or other dealings in the + * Software. + */ + +#pragma once + +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * This library creates QR Code symbols, which is a type of two-dimension barcode. + * Invented by Denso Wave and described in the ISO/IEC 18004 standard. + * A QR Code structure is an immutable square grid of black and white cells. + * The library provides functions to create a QR Code from text or binary data. + * The library covers the QR Code Model 2 specification, supporting all versions (sizes) + * from 1 to 40, all 4 error correction levels, and 4 character encoding modes. + * + * Ways to create a QR Code object: + * - High level: Take the payload data and call qrcodegen_encodeText() or qrcodegen_encodeBinary(). + * - Low level: Custom-make the list of segments and call + * qrcodegen_encodeSegments() or qrcodegen_encodeSegmentsAdvanced(). + * (Note that all ways require supplying the desired error correction level and various byte buffers.) + */ + + +/*---- Enum and struct types----*/ + +/* + * The error correction level in a QR Code symbol. + */ +enum qrcodegen_Ecc { + // Must be declared in ascending order of error protection + // so that an internal qrcodegen function works properly + qrcodegen_Ecc_LOW = 0 , // The QR Code can tolerate about 7% erroneous codewords + qrcodegen_Ecc_MEDIUM , // The QR Code can tolerate about 15% erroneous codewords + qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords + qrcodegen_Ecc_HIGH , // The QR Code can tolerate about 30% erroneous codewords +}; + + +/* + * The mask pattern used in a QR Code symbol. + */ +enum qrcodegen_Mask { + // A special value to tell the QR Code encoder to + // automatically select an appropriate mask pattern + qrcodegen_Mask_AUTO = -1, + // The eight actual mask patterns + qrcodegen_Mask_0 = 0, + qrcodegen_Mask_1, + qrcodegen_Mask_2, + qrcodegen_Mask_3, + qrcodegen_Mask_4, + qrcodegen_Mask_5, + qrcodegen_Mask_6, + qrcodegen_Mask_7, +}; + + +/* + * Describes how a segment's data bits are interpreted. + */ +enum qrcodegen_Mode { + qrcodegen_Mode_NUMERIC = 0x1, + qrcodegen_Mode_ALPHANUMERIC = 0x2, + qrcodegen_Mode_BYTE = 0x4, + qrcodegen_Mode_KANJI = 0x8, + qrcodegen_Mode_ECI = 0x7, +}; + + +/* + * A segment of character/binary/control data in a QR Code symbol. + * The mid-level way to create a segment is to take the payload data + * and call a factory function such as qrcodegen_makeNumeric(). + * The low-level way to create a segment is to custom-make the bit buffer + * and initialize a qrcodegen_Segment struct with appropriate values. + * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. + * Any segment longer than this is meaningless for the purpose of generating QR Codes. + * Moreover, the maximum allowed bit length is 32767 because + * the largest QR Code (version 40) has 31329 modules. + */ +struct qrcodegen_Segment { + // The mode indicator of this segment. + enum qrcodegen_Mode mode; + + // The length of this segment's unencoded data. Measured in characters for + // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. + // Always zero or positive. Not the same as the data's bit length. + int numChars; + + // The data bits of this segment, packed in bitwise big endian. + // Can be null if the bit length is zero. + uint8_t *data; + + // The number of valid data bits used in the buffer. Requires + // 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8. + // The character count (numChars) must agree with the mode and the bit buffer length. + int bitLength; +}; + + + +/*---- Macro constants and functions ----*/ + +#define qrcodegen_VERSION_MIN 1 // The minimum version number supported in the QR Code Model 2 standard +#define qrcodegen_VERSION_MAX 40 // The maximum version number supported in the QR Code Model 2 standard + +// Calculates the number of bytes needed to store any QR Code up to and including the given version number, +// as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];' +// can store any single QR Code from version 1 to 25 (inclusive). The result fits in an int (or int16). +// Requires qrcodegen_VERSION_MIN <= n <= qrcodegen_VERSION_MAX. +#define qrcodegen_BUFFER_LEN_FOR_VERSION(n) ((((n) * 4 + 17) * ((n) * 4 + 17) + 7) / 8 + 1) + +// The worst-case number of bytes needed to store one QR Code, up to and including +// version 40. This value equals 3918, which is just under 4 kilobytes. +// Use this more convenient value to avoid calculating tighter memory bounds for buffers. +#define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX) + + + +/*---- Functions (high level) to generate QR Codes ----*/ + +/* + * Encodes the given text string to a QR Code, returning true if encoding succeeded. + * If the data is too long to fit in any version in the given range + * at the given ECC level, then false is returned. + * - The input text must be encoded in UTF-8 and contain no NULs. + * - The variables ecl and mask must correspond to enum constant values. + * - Requires 1 <= minVersion <= maxVersion <= 40. + * - The arrays tempBuffer and qrcode must each have a length + * of at least qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion). + * - After the function returns, tempBuffer contains no useful data. + * - If successful, the resulting QR Code may use numeric, + * alphanumeric, or byte mode to encode the text. + * - In the most optimistic case, a QR Code at version 40 with low ECC + * can hold any UTF-8 string up to 2953 bytes, or any alphanumeric string + * up to 4296 characters, or any digit string up to 7089 characters. + * These numbers represent the hard upper limit of the QR Code standard. + * - Please consult the QR Code specification for information on + * data capacities per version, ECC level, and text encoding mode. + */ +bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], + enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); + + +/* + * Encodes the given binary data to a QR Code, returning true if encoding succeeded. + * If the data is too long to fit in any version in the given range + * at the given ECC level, then false is returned. + * - The input array range dataAndTemp[0 : dataLen] should normally be + * valid UTF-8 text, but is not required by the QR Code standard. + * - The variables ecl and mask must correspond to enum constant values. + * - Requires 1 <= minVersion <= maxVersion <= 40. + * - The arrays dataAndTemp and qrcode must each have a length + * of at least qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion). + * - After the function returns, the contents of dataAndTemp may have changed, + * and does not represent useful data anymore. + * - If successful, the resulting QR Code will use byte mode to encode the data. + * - In the most optimistic case, a QR Code at version 40 with low ECC can hold any byte + * sequence up to length 2953. This is the hard upper limit of the QR Code standard. + * - Please consult the QR Code specification for information on + * data capacities per version, ECC level, and text encoding mode. + */ +bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[], + enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); + + +/*---- Functions (low level) to generate QR Codes ----*/ + +/* + * Renders a QR Code representing the given segments at the given error correction level. + * The smallest possible QR Code version is automatically chosen for the output. Returns true if + * QR Code creation succeeded, or false if the data is too long to fit in any version. The ECC level + * of the result may be higher than the ecl argument if it can be done without increasing the version. + * This function allows the user to create a custom sequence of segments that switches + * between modes (such as alphanumeric and byte) to encode text in less space. + * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary(). + * To save memory, the segments' data buffers can alias/overlap tempBuffer, and will + * result in them being clobbered, but the QR Code output will still be correct. + * But the qrcode array must not overlap tempBuffer or any segment's data buffer. + */ +bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len, + enum qrcodegen_Ecc ecl, uint8_t tempBuffer[], uint8_t qrcode[]); + + +/* + * Renders a QR Code representing the given segments with the given encoding parameters. + * Returns true if QR Code creation succeeded, or false if the data is too long to fit in the range of versions. + * The smallest possible QR Code version within the given range is automatically + * chosen for the output. Iff boostEcl is true, then the ECC level of the result + * may be higher than the ecl argument if it can be done without increasing the + * version. The mask number is either between 0 to 7 (inclusive) to force that + * mask, or -1 to automatically choose an appropriate mask (which may be slow). + * This function allows the user to create a custom sequence of segments that switches + * between modes (such as alphanumeric and byte) to encode text in less space. + * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary(). + * To save memory, the segments' data buffers can alias/overlap tempBuffer, and will + * result in them being clobbered, but the QR Code output will still be correct. + * But the qrcode array must not overlap tempBuffer or any segment's data buffer. + */ +bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl, + int minVersion, int maxVersion, int mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]); + + +/* + * Tests whether the given string can be encoded as a segment in alphanumeric mode. + * A string is encodable iff each character is in the following set: 0 to 9, A to Z + * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. + */ +bool qrcodegen_isAlphanumeric(const char *text); + + +/* + * Tests whether the given string can be encoded as a segment in numeric mode. + * A string is encodable iff each character is in the range 0 to 9. + */ +bool qrcodegen_isNumeric(const char *text); + + +/* + * Returns the number of bytes (uint8_t) needed for the data buffer of a segment + * containing the given number of characters using the given mode. Notes: + * - Returns SIZE_MAX on failure, i.e. numChars > INT16_MAX or + * the number of needed bits exceeds INT16_MAX (i.e. 32767). + * - Otherwise, all valid results are in the range [0, ceil(INT16_MAX / 8)], i.e. at most 4096. + * - It is okay for the user to allocate more bytes for the buffer than needed. + * - For byte mode, numChars measures the number of bytes, not Unicode code points. + * - For ECI mode, numChars must be 0, and the worst-case number of bytes is returned. + * An actual ECI segment can have shorter data. For non-ECI modes, the result is exact. + */ +size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars); + + +/* + * Returns a segment representing the given binary data encoded in + * byte mode. All input byte arrays are acceptable. Any text string + * can be converted to UTF-8 bytes and encoded as a byte mode segment. + */ +struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]); + + +/* + * Returns a segment representing the given string of decimal digits encoded in numeric mode. + */ +struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]); + + +/* + * Returns a segment representing the given text string encoded in alphanumeric mode. + * The characters allowed are: 0 to 9, A to Z (uppercase only), space, + * dollar, percent, asterisk, plus, hyphen, period, slash, colon. + */ +struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]); + + +/* + * Returns a segment representing an Extended Channel Interpretation + * (ECI) designator with the given assignment value. + */ +struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]); + + +/*---- Functions to extract raw data from QR Codes ----*/ + +/* + * Returns the side length of the given QR Code, assuming that encoding succeeded. + * The result is in the range [21, 177]. Note that the length of the array buffer + * is related to the side length - every 'uint8_t qrcode[]' must have length at least + * qrcodegen_BUFFER_LEN_FOR_VERSION(version), which equals ceil(size^2 / 8 + 1). + */ +int qrcodegen_getSize(const uint8_t qrcode[]); + + +/* + * Returns the color of the module (pixel) at the given coordinates, which is false + * for white or true for black. The top left corner has the coordinates (x=0, y=0). + * If the given coordinates are out of bounds, then false (white) is returned. + */ +bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y); + +/* + * Returns the qrcode size of the specified version. Returns -1 on failure + */ +int qrcodegen_version2size(int version); +/* + * Returns the min version of the data that can be stored. Returns -1 on failure + */ +int qrcodegen_getMinFitVersion(enum qrcodegen_Ecc ecl, size_t dataLen); + +#ifdef __cplusplus +} +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/rlottie/lv_rlottie.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/rlottie/lv_rlottie.h new file mode 100644 index 00000000..a8aca7bc --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/rlottie/lv_rlottie.h @@ -0,0 +1,75 @@ +/** + * @file lv_rlottie.h + * + */ + +#ifndef LV_RLOTTIE_H +#define LV_RLOTTIE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" +#if LV_USE_RLOTTIE + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef enum { + LV_RLOTTIE_CTRL_FORWARD = 0, + LV_RLOTTIE_CTRL_BACKWARD = 1, + LV_RLOTTIE_CTRL_PAUSE = 2, + LV_RLOTTIE_CTRL_PLAY = 0, /* Yes, play = 0 is the default mode */ + LV_RLOTTIE_CTRL_LOOP = 8, +} lv_rlottie_ctrl_t; + +/** definition in lottieanimation_capi.c */ +struct Lottie_Animation_S; +typedef struct { + lv_img_t img_ext; + struct Lottie_Animation_S * animation; + lv_timer_t * task; + lv_img_dsc_t imgdsc; + size_t total_frames; + size_t current_frame; + size_t framerate; + uint32_t * allocated_buf; + size_t allocated_buffer_size; + size_t scanline_width; + lv_rlottie_ctrl_t play_ctrl; + size_t dest_frame; +} lv_rlottie_t; + +extern const lv_obj_class_t lv_rlottie_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_rlottie_create_from_file(lv_obj_t * parent, lv_coord_t width, lv_coord_t height, const char * path); + +lv_obj_t * lv_rlottie_create_from_raw(lv_obj_t * parent, lv_coord_t width, lv_coord_t height, + const char * rlottie_desc); + +void lv_rlottie_set_play_mode(lv_obj_t * rlottie, const lv_rlottie_ctrl_t ctrl); +void lv_rlottie_set_current_frame(lv_obj_t * rlottie, const size_t goto_frame); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_RLOTTIE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_RLOTTIE_H*/ diff --git a/include/display/lv_hal/lv_hal.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/lv_sjpg.h similarity index 72% rename from include/display/lv_hal/lv_hal.h rename to EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/lv_sjpg.h index 5ab28f2a..d06e80de 100644 --- a/include/display/lv_hal/lv_hal.h +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/lv_sjpg.h @@ -1,10 +1,10 @@ /** - * @file hal.h + * @file lv_sjpg.h * */ -#ifndef HAL_H -#define HAL_H +#ifndef LV_SJPEG_H +#define LV_SJPEG_H #ifdef __cplusplus extern "C" { @@ -13,9 +13,8 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "lv_hal_disp.h" -#include "lv_hal_indev.h" -#include "lv_hal_tick.h" + +#if LV_USE_SJPG /********************* * DEFINES @@ -29,12 +28,16 @@ extern "C" { * GLOBAL PROTOTYPES **********************/ +void lv_split_jpeg_init(void); + /********************** * MACROS **********************/ +#endif /*LV_USE_SJPG*/ + #ifdef __cplusplus -} /* extern "C" */ +} #endif -#endif +#endif /* LV_SJPEG_H */ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/tjpgd.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/tjpgd.h new file mode 100644 index 00000000..866e6b32 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/tjpgd.h @@ -0,0 +1,93 @@ +/*----------------------------------------------------------------------------/ +/ TJpgDec - Tiny JPEG Decompressor R0.03 include file (C)ChaN, 2021 +/----------------------------------------------------------------------------*/ +#ifndef DEF_TJPGDEC +#define DEF_TJPGDEC + +#ifdef __cplusplus +extern "C" { +#endif + +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_SJPG + +#include "tjpgdcnf.h" +#include +#include + +#if JD_FASTDECODE >= 1 +typedef int16_t jd_yuv_t; +#else +typedef uint8_t jd_yuv_t; +#endif + + +/* Error code */ +typedef enum { + JDR_OK = 0, /* 0: Succeeded */ + JDR_INTR, /* 1: Interrupted by output function */ + JDR_INP, /* 2: Device error or wrong termination of input stream */ + JDR_MEM1, /* 3: Insufficient memory pool for the image */ + JDR_MEM2, /* 4: Insufficient stream input buffer */ + JDR_PAR, /* 5: Parameter error */ + JDR_FMT1, /* 6: Data format error (may be broken data) */ + JDR_FMT2, /* 7: Right format but not supported */ + JDR_FMT3 /* 8: Not supported JPEG standard */ +} JRESULT; + +/* Rectangular region in the output image */ +typedef struct { + uint16_t left; /* Left end */ + uint16_t right; /* Right end */ + uint16_t top; /* Top end */ + uint16_t bottom; /* Bottom end */ +} JRECT; + +/* Decompressor object structure */ +typedef struct JDEC JDEC; +struct JDEC { + size_t dctr; /* Number of bytes available in the input buffer */ + uint8_t* dptr; /* Current data read ptr */ + uint8_t* inbuf; /* Bit stream input buffer */ + uint8_t dbit; /* Number of bits availavble in wreg or reading bit mask */ + uint8_t scale; /* Output scaling ratio */ + uint8_t msx, msy; /* MCU size in unit of block (width, height) */ + uint8_t qtid[3]; /* Quantization table ID of each component, Y, Cb, Cr */ + uint8_t ncomp; /* Number of color components 1:grayscale, 3:color */ + int16_t dcv[3]; /* Previous DC element of each component */ + uint16_t nrst; /* Restart inverval */ + uint16_t width, height; /* Size of the input image (pixel) */ + uint8_t* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */ + uint16_t* huffcode[2][2]; /* Huffman code word tables [id][dcac] */ + uint8_t* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */ + int32_t* qttbl[4]; /* Dequantizer tables [id] */ +#if JD_FASTDECODE >= 1 + uint32_t wreg; /* Working shift register */ + uint8_t marker; /* Detected marker (0:None) */ +#if JD_FASTDECODE == 2 + uint8_t longofs[2][2]; /* Table offset of long code [id][dcac] */ + uint16_t* hufflut_ac[2]; /* Fast huffman decode tables for AC short code [id] */ + uint8_t* hufflut_dc[2]; /* Fast huffman decode tables for DC short code [id] */ +#endif +#endif + void* workbuf; /* Working buffer for IDCT and RGB output */ + jd_yuv_t* mcubuf; /* Working buffer for the MCU */ + void* pool; /* Pointer to available memory pool */ + size_t sz_pool; /* Size of momory pool (bytes available) */ + size_t (*infunc)(JDEC*, uint8_t*, size_t); /* Pointer to jpeg stream input function */ + void* device; /* Pointer to I/O device identifiler for the session */ +}; + + + +/* TJpgDec API functions */ +JRESULT jd_prepare (JDEC* jd, size_t (*infunc)(JDEC*,uint8_t*,size_t), void* pool, size_t sz_pool, void* dev); +JRESULT jd_decomp (JDEC* jd, int (*outfunc)(JDEC*,void*,JRECT*), uint8_t scale); + +#endif /*LV_USE_SJPG*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _TJPGDEC */ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/tjpgdcnf.h b/EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/tjpgdcnf.h new file mode 100644 index 00000000..6d425e6f --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/libs/sjpg/tjpgdcnf.h @@ -0,0 +1,33 @@ +/*----------------------------------------------*/ +/* TJpgDec System Configurations R0.03 */ +/*----------------------------------------------*/ + +#define JD_SZBUF 512 +/* Specifies size of stream input buffer */ + +#define JD_FORMAT 0 +/* Specifies output pixel format. +/ 0: RGB888 (24-bit/pix) +/ 1: RGB565 (16-bit/pix) +/ 2: Grayscale (8-bit/pix) +*/ + +#define JD_USE_SCALE 1 +/* Switches output descaling feature. +/ 0: Disable +/ 1: Enable +*/ + +#define JD_TBLCLIP 1 +/* Use table conversion for saturation arithmetic. A bit faster, but increases 1 KB of code size. +/ 0: Disable +/ 1: Enable +*/ + +#define JD_FASTDECODE 0 +/* Optimization level +/ 0: Basic optimization. Suitable for 8/16-bit MCUs. +/ 1: + 32-bit barrel shifter. Suitable for 32-bit MCUs. +/ 2: + Table conversion for huffman decoding (wants 6 << HUFF_BIT bytes of RAM) +*/ + diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/lv_extra.h b/EZ-Template-Example-Project/include/liblvgl/extra/lv_extra.h new file mode 100644 index 00000000..c0306a98 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/lv_extra.h @@ -0,0 +1,48 @@ +/** + * @file lv_extra.h + * + */ + +#ifndef LV_EXTRA_H +#define LV_EXTRA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "layouts/lv_layouts.h" +#include "libs/lv_libs.h" +#include "others/lv_others.h" +#include "themes/lv_themes.h" +#include "widgets/lv_widgets.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the extra components + */ +void lv_extra_init(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_EXTRA_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/others/fragment/lv_fragment.h b/EZ-Template-Example-Project/include/liblvgl/extra/others/fragment/lv_fragment.h new file mode 100644 index 00000000..9b7312f8 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/others/fragment/lv_fragment.h @@ -0,0 +1,339 @@ +/** + * Public header for Fragment + * @file lv_fragment.h + */ + +#ifndef LV_FRAGMENT_H +#define LV_FRAGMENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_FRAGMENT + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct _lv_fragment_manager_t lv_fragment_manager_t; + +typedef struct _lv_fragment_t lv_fragment_t; +typedef struct _lv_fragment_class_t lv_fragment_class_t; +typedef struct _lv_fragment_managed_states_t lv_fragment_managed_states_t; + +struct _lv_fragment_t { + /** + * Class of this fragment + */ + const lv_fragment_class_t * cls; + /** + * Managed fragment states. If not null, then this fragment is managed. + * + * @warning Don't modify values inside this struct! + */ + lv_fragment_managed_states_t * managed; + /** + * Child fragment manager + */ + lv_fragment_manager_t * child_manager; + /** + * lv_obj returned by create_obj_cb + */ + lv_obj_t * obj; + +}; + +struct _lv_fragment_class_t { + /** + * Constructor function for fragment class + * @param self Fragment instance + * @param args Arguments assigned by fragment manager + */ + void (*constructor_cb)(lv_fragment_t * self, void * args); + + /** + * Destructor function for fragment class + * @param self Fragment instance, will be freed after this call + */ + void (*destructor_cb)(lv_fragment_t * self); + + /** + * Fragment attached to manager + * @param self Fragment instance + */ + void (*attached_cb)(lv_fragment_t * self); + + /** + * Fragment detached from manager + * @param self Fragment instance + */ + void (*detached_cb)(lv_fragment_t * self); + + /** + * Create objects + * @param self Fragment instance + * @param container Container of the objects should be created upon + * @return Created object, NULL if multiple objects has been created + */ + lv_obj_t * (*create_obj_cb)(lv_fragment_t * self, lv_obj_t * container); + + /** + * + * @param self Fragment instance + * @param obj lv_obj returned by create_obj_cb + */ + void (*obj_created_cb)(lv_fragment_t * self, lv_obj_t * obj); + + /** + * Called before objects in the fragment will be deleted. + * + * @param self Fragment instance + * @param obj object with this fragment + */ + void (*obj_will_delete_cb)(lv_fragment_t * self, lv_obj_t * obj); + + /** + * Called when the object created by fragment received `LV_EVENT_DELETE` event + * @param self Fragment instance + * @param obj object with this fragment + */ + void (*obj_deleted_cb)(lv_fragment_t * self, lv_obj_t * obj); + + /** + * Handle event + * @param self Fragment instance + * @param which User-defined ID of event + * @param data1 User-defined data + * @param data2 User-defined data + */ + bool (*event_cb)(lv_fragment_t * self, int code, void * userdata); + + /** + * *REQUIRED*: Allocation size of fragment + */ + size_t instance_size; +}; + +/** + * Fragment states + */ +typedef struct _lv_fragment_managed_states_t { + /** + * Class of the fragment + */ + const lv_fragment_class_t * cls; + /** + * Manager the fragment attached to + */ + lv_fragment_manager_t * manager; + /** + * Container object the fragment adding view to + */ + lv_obj_t * const * container; + /** + * Fragment instance + */ + lv_fragment_t * instance; + /** + * true between `create_obj_cb` and `obj_deleted_cb` + */ + bool obj_created; + /** + * true before `lv_fragment_del_obj` is called. Don't touch any object if this is true + */ + bool destroying_obj; + /** + * true if this fragment is in navigation stack that can be popped + */ + bool in_stack; +} lv_fragment_managed_states_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create fragment manager instance + * @param parent Parent fragment if this manager is placed inside another fragment, can be null. + * @return Fragment manager instance + */ +lv_fragment_manager_t * lv_fragment_manager_create(lv_fragment_t * parent); + +/** + * Destroy fragment manager instance + * @param manager Fragment manager instance + */ +void lv_fragment_manager_del(lv_fragment_manager_t * manager); + +/** + * Create object of all fragments managed by this manager. + * @param manager Fragment manager instance + */ +void lv_fragment_manager_create_obj(lv_fragment_manager_t * manager); + +/** + * Delete object created by all fragments managed by this manager. Instance of fragments will not be deleted. + * @param manager Fragment manager instance + */ +void lv_fragment_manager_del_obj(lv_fragment_manager_t * manager); + +/** + * Attach fragment to manager, and add to container. + * @param manager Fragment manager instance + * @param fragment Fragment instance + * @param container Pointer to container object for manager to add objects to + */ +void lv_fragment_manager_add(lv_fragment_manager_t * manager, lv_fragment_t * fragment, lv_obj_t * const * container); + +/** + * Detach and destroy fragment. If fragment is in navigation stack, remove from it. + * @param manager Fragment manager instance + * @param fragment Fragment instance + */ +void lv_fragment_manager_remove(lv_fragment_manager_t * manager, lv_fragment_t * fragment); + +/** + * Attach fragment to manager and add to navigation stack. + * @param manager Fragment manager instance + * @param fragment Fragment instance + * @param container Pointer to container object for manager to add objects to + */ +void lv_fragment_manager_push(lv_fragment_manager_t * manager, lv_fragment_t * fragment, lv_obj_t * const * container); + +/** + * Remove the top-most fragment for stack + * @param manager Fragment manager instance + * @return true if there is fragment to pop + */ +bool lv_fragment_manager_pop(lv_fragment_manager_t * manager); + +/** + * Replace fragment. Old item in the stack will be removed. + * @param manager Fragment manager instance + * @param fragment Fragment instance + * @param container Pointer to container object for manager to add objects to + */ +void lv_fragment_manager_replace(lv_fragment_manager_t * manager, lv_fragment_t * fragment, + lv_obj_t * const * container); + +/** + * Send event to top-most fragment + * @param manager Fragment manager instance + * @param code User-defined ID of event + * @param userdata User-defined data + * @return true if fragment returned true + */ +bool lv_fragment_manager_send_event(lv_fragment_manager_t * manager, int code, void * userdata); + +/** + * Get stack size of this fragment manager + * @param manager Fragment manager instance + * @return Stack size of this fragment manager + */ +size_t lv_fragment_manager_get_stack_size(lv_fragment_manager_t * manager); + +/** + * Get top most fragment instance + * @param manager Fragment manager instance + * @return Top most fragment instance + */ +lv_fragment_t * lv_fragment_manager_get_top(lv_fragment_manager_t * manager); + +/** + * Find first fragment instance in the container + * @param manager Fragment manager instance + * @param container Container which target fragment added to + * @return First fragment instance in the container + */ +lv_fragment_t * lv_fragment_manager_find_by_container(lv_fragment_manager_t * manager, const lv_obj_t * container); + +/** + * Get parent fragment + * @param manager Fragment manager instance + * @return Parent fragment instance + */ +lv_fragment_t * lv_fragment_manager_get_parent_fragment(lv_fragment_manager_t * manager); + + +/** + * Create a fragment instance. + * + * @param cls Fragment class. This fragment must return non null object. + * @param args Arguments assigned by fragment manager + * @return Fragment instance + */ +lv_fragment_t * lv_fragment_create(const lv_fragment_class_t * cls, void * args); + +/** + * Destroy a fragment. + * @param fragment Fragment instance. + */ +void lv_fragment_del(lv_fragment_t * fragment); + +/** + * Get associated manager of this fragment + * @param fragment Fragment instance + * @return Fragment manager instance + */ +lv_fragment_manager_t * lv_fragment_get_manager(lv_fragment_t * fragment); + +/** + * Get container object of this fragment + * @param fragment Fragment instance + * @return Reference to container object + */ +lv_obj_t * const * lv_fragment_get_container(lv_fragment_t * fragment); + +/** + * Get parent fragment of this fragment + * @param fragment Fragment instance + * @return Parent fragment + */ +lv_fragment_t * lv_fragment_get_parent(lv_fragment_t * fragment); + +/** + * Create object by fragment. + * + * @param fragment Fragment instance. + * @param container Container of the objects should be created upon. + * @return Created object + */ +lv_obj_t * lv_fragment_create_obj(lv_fragment_t * fragment, lv_obj_t * container); + +/** + * Delete created object of a fragment + * + * @param fragment Fragment instance. + */ +void lv_fragment_del_obj(lv_fragment_t * fragment); + +/** + * Destroy obj in fragment, and recreate them. + * @param fragment Fragment instance + */ +void lv_fragment_recreate_obj(lv_fragment_t * fragment); + + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_FRAGMENT*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FRAGMENT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/others/gridnav/lv_gridnav.h b/EZ-Template-Example-Project/include/liblvgl/extra/others/gridnav/lv_gridnav.h new file mode 100644 index 00000000..89391208 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/others/gridnav/lv_gridnav.h @@ -0,0 +1,123 @@ +/** + * @file lv_templ.c + * + */ + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*This typedef exists purely to keep -Wpedantic happy when the file is empty.*/ +/*It can be removed.*/ +typedef int _keep_pedantic_happy; + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/********************** + * STATIC FUNCTIONS + **********************/ +/** + * @file lv_gridnav.h + * + */ + +#ifndef LV_GRIDFOCUS_H +#define LV_GRIDFOCUS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_GRIDNAV + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef enum { + LV_GRIDNAV_CTRL_NONE = 0x0, + + /** + * If there is no next/previous object in a direction, + * the focus goes to the object in the next/previous row (on left/right keys) + * or first/last row (on up/down keys) + */ + LV_GRIDNAV_CTRL_ROLLOVER = 0x1, + + /** + * If an arrow is pressed and the focused object can be scrolled in that direction + * then it will be scrolled instead of going to the next/previous object. + * If there is no more room for scrolling the next/previous object will be focused normally */ + LV_GRIDNAV_CTRL_SCROLL_FIRST = 0x2, + +} lv_gridnav_ctrl_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Add grid navigation feature to an object. It expects the children to be arranged + * into a grid-like layout. Although it's not required to have pixel perfect alignment. + * This feature makes possible to use keys to navigate among the children and focus them. + * The keys other than arrows and press/release related events + * are forwarded to the focused child. + * @param obj pointer to an object on which navigation should be applied. + * @param ctrl control flags from `lv_gridnav_ctrl_t`. + */ +void lv_gridnav_add(lv_obj_t * obj, lv_gridnav_ctrl_t ctrl); + +/** + * Remove the grid navigation support from an object + * @param obj pointer to an object + */ +void lv_gridnav_remove(lv_obj_t * obj); + +/** + * Manually focus an object on gridnav container + * @param cont pointer to a gridnav container + * @param to_focus pointer to an object to focus + * @param anim_en LV_ANIM_ON/OFF + */ +void lv_gridnav_set_focused(lv_obj_t * cont, lv_obj_t * to_focus, lv_anim_enable_t anim_en); + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_GRIDNAV*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GRIDFOCUS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/others/ime/lv_ime_pinyin.h b/EZ-Template-Example-Project/include/liblvgl/extra/others/ime/lv_ime_pinyin.h new file mode 100644 index 00000000..2d70d293 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/others/ime/lv_ime_pinyin.h @@ -0,0 +1,145 @@ +/** + * @file lv_ime_pinyin.h + * + */ +#ifndef LV_IME_PINYIN_H +#define LV_IME_PINYIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_IME_PINYIN != 0 + +/********************* + * DEFINES + *********************/ +#define LV_IME_PINYIN_K9_MAX_INPUT 7 + +/********************** + * TYPEDEFS + **********************/ + +typedef enum { + LV_IME_PINYIN_MODE_K26, + LV_IME_PINYIN_MODE_K9, +} lv_ime_pinyin_mode_t; + +/*Data of pinyin_dict*/ +typedef struct { + const char * const py; + const char * const py_mb; +} lv_pinyin_dict_t; + +/*Data of 9-key input(k9) mode*/ +typedef struct { + char py_str[7]; +} ime_pinyin_k9_py_str_t; + +/*Data of lv_ime_pinyin*/ +typedef struct { + lv_obj_t obj; + lv_obj_t * kb; + lv_obj_t * cand_panel; + lv_pinyin_dict_t * dict; + lv_ll_t k9_legal_py_ll; + char * cand_str; /* Candidate string */ + char input_char[16]; /* Input box character */ +#if LV_IME_PINYIN_USE_K9_MODE + char k9_input_str[LV_IME_PINYIN_K9_MAX_INPUT]; /* 9-key input(k9) mode input string */ + uint16_t k9_py_ll_pos; /* Current pinyin map pages(k9) */ + uint16_t k9_legal_py_count; /* Count of legal Pinyin numbers(k9) */ + uint16_t k9_input_str_len; /* 9-key input(k9) mode input string max len */ +#endif + uint16_t ta_count; /* The number of characters entered in the text box this time */ + uint16_t cand_num; /* Number of candidates */ + uint16_t py_page; /* Current pinyin map pages(k26) */ + uint16_t py_num[26]; /* Number and length of Pinyin */ + uint16_t py_pos[26]; /* Pinyin position */ + uint8_t mode : 1; /* Set mode, 1: 26-key input(k26), 0: 9-key input(k9). Default: 1. */ +} lv_ime_pinyin_t; + +/*********************** + * GLOBAL VARIABLES + ***********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +lv_obj_t * lv_ime_pinyin_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the keyboard of Pinyin input method. + * @param obj pointer to a Pinyin input method object + * @param dict pointer to a Pinyin input method keyboard + */ +void lv_ime_pinyin_set_keyboard(lv_obj_t * obj, lv_obj_t * kb); + +/** + * Set the dictionary of Pinyin input method. + * @param obj pointer to a Pinyin input method object + * @param dict pointer to a Pinyin input method dictionary + */ +void lv_ime_pinyin_set_dict(lv_obj_t * obj, lv_pinyin_dict_t * dict); + +/** + * Set mode, 26-key input(k26) or 9-key input(k9). + * @param obj pointer to a Pinyin input method object + * @param mode the mode from 'lv_ime_pinyin_mode_t' + */ +void lv_ime_pinyin_set_mode(lv_obj_t * obj, lv_ime_pinyin_mode_t mode); + + +/*===================== + * Getter functions + *====================*/ + +/** + * Set the dictionary of Pinyin input method. + * @param obj pointer to a Pinyin IME object + * @return pointer to the Pinyin IME keyboard + */ +lv_obj_t * lv_ime_pinyin_get_kb(lv_obj_t * obj); + + +/** + * Set the dictionary of Pinyin input method. + * @param obj pointer to a Pinyin input method object + * @return pointer to the Pinyin input method candidate panel + */ +lv_obj_t * lv_ime_pinyin_get_cand_panel(lv_obj_t * obj); + + +/** + * Set the dictionary of Pinyin input method. + * @param obj pointer to a Pinyin input method object + * @return pointer to the Pinyin input method dictionary + */ +lv_pinyin_dict_t * lv_ime_pinyin_get_dict(lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_IME_PINYIN*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_USE_IME_PINYIN*/ + + diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/others/imgfont/lv_imgfont.h b/EZ-Template-Example-Project/include/liblvgl/extra/others/imgfont/lv_imgfont.h new file mode 100644 index 00000000..4fb6f78b --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/others/imgfont/lv_imgfont.h @@ -0,0 +1,60 @@ +/** + * @file lv_imgfont.h + * + */ + +#ifndef LV_IMGFONT_H +#define LV_IMGFONT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_IMGFONT + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/* gets the image path name of this character */ +typedef bool (*lv_get_imgfont_path_cb_t)(const lv_font_t * font, void * img_src, + uint16_t len, uint32_t unicode, uint32_t unicode_next); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Creates a image font with info parameter specified. + * @param height font size + * @param path_cb a function to get the image path name of character. + * @return pointer to the new imgfont or NULL if create error. + */ +lv_font_t * lv_imgfont_create(uint16_t height, lv_get_imgfont_path_cb_t path_cb); + +/** + * Destroy a image font that has been created. + * @param font pointer to image font handle. + */ +void lv_imgfont_destroy(lv_font_t * font); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_IMGFONT*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /* LV_IMGFONT_H */ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/others/lv_others.h b/EZ-Template-Example-Project/include/liblvgl/extra/others/lv_others.h new file mode 100644 index 00000000..106d85e4 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/others/lv_others.h @@ -0,0 +1,44 @@ +/** + * @file lv_others.h + * + */ + +#ifndef LV_OTHERS_H +#define LV_OTHERS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "snapshot/lv_snapshot.h" +#include "monkey/lv_monkey.h" +#include "gridnav/lv_gridnav.h" +#include "fragment/lv_fragment.h" +#include "imgfont/lv_imgfont.h" +#include "msg/lv_msg.h" +#include "ime/lv_ime_pinyin.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OTHERS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/others/monkey/lv_monkey.h b/EZ-Template-Example-Project/include/liblvgl/extra/others/monkey/lv_monkey.h new file mode 100644 index 00000000..589daf1d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/others/monkey/lv_monkey.h @@ -0,0 +1,118 @@ +/** + * @file lv_monkey.h + * + */ +#ifndef LV_MONKEY_H +#define LV_MONKEY_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_MONKEY != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct _lv_monkey; +typedef struct _lv_monkey lv_monkey_t; + +typedef struct { + /**< Input device type*/ + lv_indev_type_t type; + + /**< Monkey execution period*/ + struct { + uint32_t min; + uint32_t max; + } period_range; + + /**< The range of input value*/ + struct { + int32_t min; + int32_t max; + } input_range; +} lv_monkey_config_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize a monkey config with default values + * @param config pointer to 'lv_monkey_config_t' variable to initialize + */ +void lv_monkey_config_init(lv_monkey_config_t * config); + +/** + * Create monkey for test + * @param config pointer to 'lv_monkey_config_t' variable + * @return pointer to the created monkey + */ +lv_monkey_t * lv_monkey_create(const lv_monkey_config_t * config); + +/** + * Get monkey input device + * @param monkey pointer to a monkey + * @return pointer to the input device + */ +lv_indev_t * lv_monkey_get_indev(lv_monkey_t * monkey); + +/** + * Enable monkey + * @param monkey pointer to a monkey + * @param en set to true to enable + */ +void lv_monkey_set_enable(lv_monkey_t * monkey, bool en); + +/** + * Get whether monkey is enabled + * @param monkey pointer to a monkey + * @return return true if monkey enabled + */ +bool lv_monkey_get_enable(lv_monkey_t * monkey); + +#if LV_USE_USER_DATA + +/** + * Set the user_data field of the monkey + * @param monkey pointer to a monkey + * @param user_data pointer to the new user_data. + */ +void lv_monkey_set_user_data(lv_monkey_t * monkey, void * user_data); + +/** + * Get the user_data field of the monkey + * @param monkey pointer to a monkey + * @return the pointer to the user_data of the monkey + */ +void * lv_monkey_get_user_data(lv_monkey_t * monkey); + +#endif/*LV_USE_USER_DATA*/ + +/** + * Delete monkey + * @param monkey pointer to monkey + */ +void lv_monkey_del(lv_monkey_t * monkey); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_MONKEY*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MONKEY_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/others/msg/lv_msg.h b/EZ-Template-Example-Project/include/liblvgl/extra/others/msg/lv_msg.h new file mode 100644 index 00000000..64dc0d45 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/others/msg/lv_msg.h @@ -0,0 +1,124 @@ +/** + * @file lv_msg.h + * + */ + +#ifndef LV_MSG_H +#define LV_MSG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_MSG + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + uint32_t id; /*Identifier of the message*/ + void * user_data; /*Set the the user_data set in `lv_msg_subscribe`*/ + void * _priv_data; /*Used internally*/ + const void * payload; /*Pointer to the data of the message*/ +} lv_msg_t; + +typedef void (*lv_msg_subscribe_cb_t)(void * s, lv_msg_t * msg); + +typedef void (*lv_msg_request_cb_t)(void * r, uint32_t msg_id); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Called internally to initialize the message module + */ +void lv_msg_init(void); + +/** + * Subscribe to an `msg_id` + * @param msg_id the message ID to listen to + * @param cb callback to call if a message with `msg_id` was sent + * @param user_data arbitrary data which will be available in `cb` too + * @return pointer to a "subscribe object". It can be used the unsubscribe. + */ +void * lv_msg_subsribe(uint32_t msg_id, lv_msg_subscribe_cb_t cb, void * user_data); + +/** + * Subscribe an `lv_obj` to a message. + * `LV_EVENT_MSG_RECEIVED` will be triggered if a message with matching ID was sent + * @param msg_id the message ID to listen to + * @param obj pointer to an `lv_obj` + * @param user_data arbitrary data which will be available in `cb` too + * @return pointer to a "subscribe object". It can be used the unsubscribe. + */ +void * lv_msg_subsribe_obj(uint32_t msg_id, lv_obj_t * obj, void * user_data); + +/** + * Cancel a previous subscription + * @param s pointer to a "subscibe object". + * Return value of `lv_msg_subsribe` or `lv_msg_subsribe_obj` + */ +void lv_msg_unsubscribe(void * s); + +/** + * Send a message with a given ID and payload + * @param msg_id ID of the message to send + * @param data pointer to the data to send + */ +void lv_msg_send(uint32_t msg_id, const void * payload); + +/** + * Get the ID of a message object. Typically used in the subscriber callback. + * @param m pointer to a message object + * @return the ID of the message + */ +uint32_t lv_msg_get_id(lv_msg_t * m); + +/** + * Get the payload of a message object. Typically used in the subscriber callback. + * @param m pointer to a message object + * @return the payload of the message + */ +const void * lv_msg_get_payload(lv_msg_t * m); + +/** + * Get the user data of a message object. Typically used in the subscriber callback. + * @param m pointer to a message object + * @return the user data of the message + */ +void * lv_msg_get_user_data(lv_msg_t * m); + +/** + * Get the message object from an event object. Can be used in `LV_EVENT_MSG_RECEIVED` events. + * @param e pointer to an event object + * @return the message object or NULL if called with unrelated event code. + */ +lv_msg_t * lv_event_get_msg(lv_event_t * e); + +/********************** + * GLOBAL VARIABLES + **********************/ + +extern lv_event_code_t LV_EVENT_MSG_RECEIVED; + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_MSG*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MSG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/others/snapshot/lv_snapshot.h b/EZ-Template-Example-Project/include/liblvgl/extra/others/snapshot/lv_snapshot.h new file mode 100644 index 00000000..33d97412 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/others/snapshot/lv_snapshot.h @@ -0,0 +1,84 @@ +/** + * @file lv_snapshot.h + * + */ + +#ifndef LV_SNAPSHOT_H +#define LV_SNAPSHOT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include + +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +#if LV_USE_SNAPSHOT +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** Take snapshot for object with its children. + * + * @param obj The object to generate snapshot. + * @param cf color format for generated image. + * + * @return a pointer to an image descriptor, or NULL if failed. + */ +lv_img_dsc_t * lv_snapshot_take(lv_obj_t * obj, lv_img_cf_t cf); + +/** Free the snapshot image returned by @ref lv_snapshot_take + * + * It will firstly free the data image takes, then the image descriptor. + * + * @param dsc The image descriptor generated by lv_snapshot_take. + * + */ +void lv_snapshot_free(lv_img_dsc_t * dsc); + +/** Get the buffer needed for object snapshot image. + * + * @param obj The object to generate snapshot. + * @param cf color format for generated image. + * + * @return the buffer size needed in bytes + */ +uint32_t lv_snapshot_buf_size_needed(lv_obj_t * obj, lv_img_cf_t cf); + +/** Take snapshot for object with its children, save image info to provided buffer. + * + * @param obj The object to generate snapshot. + * @param cf color format for generated image. + * @param dsc image descriptor to store the image result. + * @param buff the buffer to store image data. + * @param buff_size provided buffer size in bytes. + * + * @return LV_RES_OK on success, LV_RES_INV on error. + */ +lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t * dsc, void * buf, uint32_t buff_size); + + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_SNAPSHOT*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/themes/basic/lv_theme_basic.h b/EZ-Template-Example-Project/include/liblvgl/extra/themes/basic/lv_theme_basic.h new file mode 100644 index 00000000..06d6828b --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/themes/basic/lv_theme_basic.h @@ -0,0 +1,55 @@ +/** + * @file lv_theme_basic.h + * + */ + +#ifndef LV_THEME_BASIC_H +#define LV_THEME_BASIC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_THEME_BASIC + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the theme + * @param disp pointer to display to attach the theme + * @return a pointer to reference this theme later + */ +lv_theme_t * lv_theme_basic_init(lv_disp_t * disp); + +/** +* Check if the theme is initialized +* @return true if default theme is initialized, false otherwise +*/ +bool lv_theme_basic_is_inited(void); + +/********************** + * MACROS + **********************/ + +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_THEME_BASIC_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/themes/default/lv_theme_default.h b/EZ-Template-Example-Project/include/liblvgl/extra/themes/default/lv_theme_default.h new file mode 100644 index 00000000..7fab5be4 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/themes/default/lv_theme_default.h @@ -0,0 +1,64 @@ +/** + * @file lv_theme_default.h + * + */ + +#ifndef LV_THEME_DEFAULT_H +#define LV_THEME_DEFAULT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_THEME_DEFAULT + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the theme + * @param color_primary the primary color of the theme + * @param color_secondary the secondary color for the theme + * @param font pointer to a font to use. + * @return a pointer to reference this theme later + */ +lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark, + const lv_font_t * font); + +/** + * Get default theme + * @return a pointer to default theme, or NULL if this is not initialized + */ +lv_theme_t * lv_theme_default_get(void); + +/** + * Check if default theme is initialized + * @return true if default theme is initialized, false otherwise + */ +bool lv_theme_default_is_inited(void); + +/********************** + * MACROS + **********************/ + +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_THEME_DEFAULT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/themes/lv_themes.h b/EZ-Template-Example-Project/include/liblvgl/extra/themes/lv_themes.h new file mode 100644 index 00000000..372f6260 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/themes/lv_themes.h @@ -0,0 +1,40 @@ +/** + * @file lv_themes.h + * + */ + +#ifndef LV_THEMES_H +#define LV_THEMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "default/lv_theme_default.h" +#include "mono/lv_theme_mono.h" +#include "basic/lv_theme_basic.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_THEMES_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/themes/mono/lv_theme_mono.h b/EZ-Template-Example-Project/include/liblvgl/extra/themes/mono/lv_theme_mono.h new file mode 100644 index 00000000..3d907fff --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/themes/mono/lv_theme_mono.h @@ -0,0 +1,57 @@ +/** + * @file lv_theme_mono.h + * + */ + +#ifndef LV_USE_THEME_MONO_H +#define LV_USE_THEME_MONO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_THEME_MONO + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the theme + * @param color_primary the primary color of the theme + * @param color_secondary the secondary color for the theme + * @param font pointer to a font to use. + * @return a pointer to reference this theme later + */ +lv_theme_t * lv_theme_mono_init(lv_disp_t * disp, bool dark_bg, const lv_font_t * font); + +/** +* Check if the theme is initialized +* @return true if default theme is initialized, false otherwise +*/ +bool lv_theme_mono_is_inited(void); + +/********************** + * MACROS + **********************/ + +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_USE_THEME_MONO_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/animimg/lv_animimg.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/animimg/lv_animimg.h new file mode 100644 index 00000000..9ffe6217 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/animimg/lv_animimg.h @@ -0,0 +1,103 @@ +/** + * @file lv_animimg.h + * + */ + +#ifndef LV_ANIM_IMG_H +#define LV_ANIM_IMG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_ANIMIMG != 0 + +/*Testing of dependencies*/ +#if LV_USE_IMG == 0 +#error "lv_animimg: lv_img is required. Enable it in lv_conf.h (LV_USE_IMG 1)" +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +extern const lv_obj_class_t lv_animimg_class; + +/*Data of image*/ +typedef struct { + lv_img_t img; + lv_anim_t anim; + /*picture sequence */ + lv_img_dsc_t ** dsc; + int8_t pic_count; +} lv_animimg_t; + + +/*Image parts*/ +enum { + LV_ANIM_IMG_PART_MAIN, +}; +typedef uint8_t lv_animimg_part_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an animation image objects + * @param parent pointer to an object, it will be the parent of the new button + * @return pointer to the created animation image object + */ +lv_obj_t * lv_animimg_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the image animation images source. + * @param img pointer to an animation image object + * @param dsc pointer to a series images + * @param num images' number + */ +void lv_animimg_set_src(lv_obj_t * img, lv_img_dsc_t * dsc[], uint8_t num); + +/** + * Startup the image animation. + * @param obj pointer to an animation image object + */ +void lv_animimg_start(lv_obj_t * obj); + +/** + * Set the image animation duration time. unit:ms + * @param img pointer to an animation image object + */ +void lv_animimg_set_duration(lv_obj_t * img, uint32_t duration); + +/** + * Set the image animation reapeatly play times. + * @param img pointer to an animation image object + * @param count the number of times to repeat the animation + */ +void lv_animimg_set_repeat_count(lv_obj_t * img, uint16_t count); + +/*===================== + * Getter functions + *====================*/ + +#endif /*LV_USE_ANIMIMG*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_ANIM_IMG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar.h new file mode 100644 index 00000000..ad157bf6 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar.h @@ -0,0 +1,164 @@ +/** + * @file lv_calendar.h + * + */ + +#ifndef LV_CALENDAR_H +#define LV_CALENDAR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/widgets/lv_btnmatrix.h" + +#if LV_USE_CALENDAR + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Represents a date on the calendar object (platform-agnostic). + */ +typedef struct { + uint16_t year; + int8_t month; /** 1..12*/ + int8_t day; /** 1..31*/ +} lv_calendar_date_t; + +/*Data of calendar*/ +typedef struct { + lv_obj_t obj; + lv_obj_t * btnm; + /*New data for this type*/ + lv_calendar_date_t today; /*Date of today*/ + lv_calendar_date_t showed_date; /*Currently visible month (day is ignored)*/ + lv_calendar_date_t * + highlighted_dates; /*Apply different style on these days (pointer to an array defined by the user)*/ + uint16_t highlighted_dates_num; /*Number of elements in `highlighted_days`*/ + const char * map[8 * 7]; + char nums [7 * 6][4]; +} lv_calendar_t; + +extern const lv_obj_class_t lv_calendar_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_calendar_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the today's date + * @param obj pointer to a calendar object + * @param year today's year + * @param month today's month [1..12] + * @param day today's day [1..31] + */ +void lv_calendar_set_today_date(lv_obj_t * obj, uint32_t year, uint32_t month, uint32_t day); + +/** + * Set the currently showed + * @param obj pointer to a calendar object + * @param year today's year + * @param month today's month [1..12] + */ +void lv_calendar_set_showed_date(lv_obj_t * obj, uint32_t year, uint32_t month); + +/** + * Set the highlighted dates + * @param obj pointer to a calendar object + * @param highlighted pointer to an `lv_calendar_date_t` array containing the dates. + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + * @param date_num number of dates in the array + */ +void lv_calendar_set_highlighted_dates(lv_obj_t * obj, lv_calendar_date_t highlighted[], uint16_t date_num); + +/** + * Set the name of the days + * @param obj pointer to a calendar object + * @param day_names pointer to an array with the names. + * E.g. `const char * days[7] = {"Sun", "Mon", ...}` + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + */ +void lv_calendar_set_day_names(lv_obj_t * obj, const char ** day_names); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the button matrix object of the calendar. + * It shows the dates and day names. + * @param obj pointer to a calendar object + * @return pointer to a the button matrix + */ +lv_obj_t * lv_calendar_get_btnmatrix(const lv_obj_t * obj); + +/** + * Get the today's date + * @param calendar pointer to a calendar object + * @return return pointer to an `lv_calendar_date_t` variable containing the date of today. + */ +const lv_calendar_date_t * lv_calendar_get_today_date(const lv_obj_t * calendar); + +/** + * Get the currently showed + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` variable containing the date is being shown. + */ +const lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar); + +/** + * Get the highlighted dates + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` array containing the dates. + */ +lv_calendar_date_t * lv_calendar_get_highlighted_dates(const lv_obj_t * calendar); + +/** + * Get the number of the highlighted dates + * @param calendar pointer to a calendar object + * @return number of highlighted days + */ +uint16_t lv_calendar_get_highlighted_dates_num(const lv_obj_t * calendar); + +/** + * Get the currently pressed day + * @param calendar pointer to a calendar object + * @param date store the pressed date here + * @return LV_RES_OK: there is a valid pressed date; LV_RES_INV: there is no pressed data + */ +lv_res_t lv_calendar_get_pressed_date(const lv_obj_t * calendar, lv_calendar_date_t * date); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CALENDAR*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CALENDAR_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar_header_arrow.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar_header_arrow.h new file mode 100644 index 00000000..30639e85 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar_header_arrow.h @@ -0,0 +1,49 @@ +/** + * @file lv_calendar_header_arrow.h + * + */ + +#ifndef LV_CALENDAR_HEADER_ARROW_H +#define LV_CALENDAR_HEADER_ARROW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_CALENDAR_HEADER_ARROW + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +extern const lv_obj_class_t lv_calendar_header_arrow_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a calendar header with drop-drowns to select the year and month + * @param parent pointer to a calendar object. + * @return the created header + */ +lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CALENDAR_HEADER_ARROW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CALENDAR_HEADER_ARROW_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar_header_dropdown.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar_header_dropdown.h new file mode 100644 index 00000000..ba926a0b --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/calendar/lv_calendar_header_dropdown.h @@ -0,0 +1,49 @@ +/** + * @file lv_calendar_header_dropdown.h + * + */ + +#ifndef LV_CALENDAR_HEADER_DROPDOWN_H +#define LV_CALENDAR_HEADER_DROPDOWN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_CALENDAR_HEADER_DROPDOWN + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +extern const lv_obj_class_t lv_calendar_header_dropdown_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a calendar header with drop-drowns to select the year and month + * @param parent pointer to a calendar object. + * @return the created header + */ +lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CALENDAR_HEADER_ARROW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CALENDAR_HEADER_DROPDOWN_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/chart/lv_chart.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/chart/lv_chart.h new file mode 100644 index 00000000..14d70b9a --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/chart/lv_chart.h @@ -0,0 +1,460 @@ +/** + * @file lv_chart.h + * + */ + +#ifndef LV_CHART_H +#define LV_CHART_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_CHART != 0 + +/********************* + * DEFINES + *********************/ + +/**Default value of points. Can be used to not draw a point*/ +#if LV_USE_LARGE_COORD +#define LV_CHART_POINT_NONE (INT32_MAX) +#else +#define LV_CHART_POINT_NONE (INT16_MAX) +#endif +LV_EXPORT_CONST_INT(LV_CHART_POINT_NONE); + +/********************** + * TYPEDEFS + **********************/ + +/** + * Chart types + */ +enum { + LV_CHART_TYPE_NONE, /**< Don't draw the series*/ + LV_CHART_TYPE_LINE, /**< Connect the points with lines*/ + LV_CHART_TYPE_BAR, /**< Draw columns*/ + LV_CHART_TYPE_SCATTER, /**< Draw points and lines in 2D (x,y coordinates)*/ +}; +typedef uint8_t lv_chart_type_t; + +/** + * Chart update mode for `lv_chart_set_next` + */ +enum { + LV_CHART_UPDATE_MODE_SHIFT, /**< Shift old data to the left and add the new one the right*/ + LV_CHART_UPDATE_MODE_CIRCULAR, /**< Add the new data in a circular way*/ +}; +typedef uint8_t lv_chart_update_mode_t; + +/** + * Enumeration of the axis' + */ +enum { + LV_CHART_AXIS_PRIMARY_Y = 0x00, + LV_CHART_AXIS_SECONDARY_Y = 0x01, + LV_CHART_AXIS_PRIMARY_X = 0x02, + LV_CHART_AXIS_SECONDARY_X = 0x04, + _LV_CHART_AXIS_LAST +}; +typedef uint8_t lv_chart_axis_t; + +/** + * Descriptor a chart series + */ +typedef struct { + lv_coord_t * x_points; + lv_coord_t * y_points; + lv_color_t color; + uint16_t start_point; + uint8_t hidden : 1; + uint8_t x_ext_buf_assigned : 1; + uint8_t y_ext_buf_assigned : 1; + uint8_t x_axis_sec : 1; + uint8_t y_axis_sec : 1; +} lv_chart_series_t; + +typedef struct { + lv_point_t pos; + lv_coord_t point_id; + lv_color_t color; + lv_chart_series_t * ser; + lv_dir_t dir; + uint8_t pos_set: 1; /*1: pos is set; 0: point_id is set*/ +} lv_chart_cursor_t; + +typedef struct { + lv_coord_t major_len; + lv_coord_t minor_len; + lv_coord_t draw_size; + uint32_t minor_cnt : 15; + uint32_t major_cnt : 15; + uint32_t label_en : 1; +} lv_chart_tick_dsc_t; + + +typedef struct { + lv_obj_t obj; + lv_ll_t series_ll; /**< Linked list for the series (stores lv_chart_series_t)*/ + lv_ll_t cursor_ll; /**< Linked list for the cursors (stores lv_chart_cursor_t)*/ + lv_chart_tick_dsc_t tick[4]; + lv_coord_t ymin[2]; + lv_coord_t ymax[2]; + lv_coord_t xmin[2]; + lv_coord_t xmax[2]; + lv_coord_t pressed_point_id; + uint16_t hdiv_cnt; /**< Number of horizontal division lines*/ + uint16_t vdiv_cnt; /**< Number of vertical division lines*/ + uint16_t point_cnt; /**< Point number in a data line*/ + uint16_t zoom_x; + uint16_t zoom_y; + lv_chart_type_t type : 3; /**< Line or column chart*/ + lv_chart_update_mode_t update_mode : 1; +} lv_chart_t; + +extern const lv_obj_class_t lv_chart_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_chart_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_CHART_DRAW_PART_DIV_LINE_INIT, /**< Used before/after drawn the div lines*/ + LV_CHART_DRAW_PART_DIV_LINE_HOR, /**< Used for each horizontal division lines*/ + LV_CHART_DRAW_PART_DIV_LINE_VER, /**< Used for each vertical division lines*/ + LV_CHART_DRAW_PART_LINE_AND_POINT, /**< Used on line and scatter charts for lines and points*/ + LV_CHART_DRAW_PART_BAR, /**< Used on bar charts for the rectangles*/ + LV_CHART_DRAW_PART_CURSOR, /**< Used on cursor lines and points*/ + LV_CHART_DRAW_PART_TICK_LABEL, /**< Used on tick lines and labels*/ +} lv_chart_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a chart object + * @param parent pointer to an object, it will be the parent of the new chart + * @return pointer to the created chart + */ +lv_obj_t * lv_chart_create(lv_obj_t * parent); + +/** + * Set a new type for a chart + * @param obj pointer to a chart object + * @param type new type of the chart (from 'lv_chart_type_t' enum) + */ +void lv_chart_set_type(lv_obj_t * obj, lv_chart_type_t type); +/** + * Set the number of points on a data line on a chart + * @param obj pointer to a chart object + * @param cnt new number of points on the data lines + */ +void lv_chart_set_point_count(lv_obj_t * obj, uint16_t cnt); + +/** + * Set the minimal and maximal y values on an axis + * @param obj pointer to a chart object + * @param axis `LV_CHART_AXIS_PRIMARY_Y` or `LV_CHART_AXIS_SECONDARY_Y` + * @param min minimum value of the y axis + * @param max maximum value of the y axis + */ +void lv_chart_set_range(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t min, lv_coord_t max); + +/** + * Set update mode of the chart object. Affects + * @param obj pointer to a chart object + * @param mode the update mode + */ +void lv_chart_set_update_mode(lv_obj_t * obj, lv_chart_update_mode_t update_mode); + +/** + * Set the number of horizontal and vertical division lines + * @param obj pointer to a chart object + * @param hdiv number of horizontal division lines + * @param vdiv number of vertical division lines + */ +void lv_chart_set_div_line_count(lv_obj_t * obj, uint8_t hdiv, uint8_t vdiv); + +/** + * Zoom into the chart in X direction + * @param obj pointer to a chart object + * @param zoom_x zoom in x direction. LV_ZOOM_NONE or 256 for no zoom, 512 double zoom + */ +void lv_chart_set_zoom_x(lv_obj_t * obj, uint16_t zoom_x); + +/** + * Zoom into the chart in Y direction + * @param obj pointer to a chart object + * @param zoom_y zoom in y direction. LV_ZOOM_NONE or 256 for no zoom, 512 double zoom + */ +void lv_chart_set_zoom_y(lv_obj_t * obj, uint16_t zoom_y); + +/** + * Get X zoom of a chart + * @param obj pointer to a chart object + * @return the X zoom value + */ +uint16_t lv_chart_get_zoom_x(const lv_obj_t * obj); + +/** + * Get Y zoom of a chart + * @param obj pointer to a chart object + * @return the Y zoom value + */ +uint16_t lv_chart_get_zoom_y(const lv_obj_t * obj); + +/** + * Set the number of tick lines on an axis + * @param obj pointer to a chart object + * @param axis an axis which ticks count should be set + * @param major_len length of major ticks + * @param minor_len length of minor ticks + * @param major_cnt number of major ticks on the axis + * @param minor_cnt number of minor ticks between two major ticks + * @param label_en true: enable label drawing on major ticks + * @param draw_size extra size required to draw the tick and labels + * (start with 20 px and increase if the ticks/labels are clipped) + */ +void lv_chart_set_axis_tick(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t major_len, lv_coord_t minor_len, + lv_coord_t major_cnt, lv_coord_t minor_cnt, bool label_en, lv_coord_t draw_size); + +/** + * Get the type of a chart + * @param obj pointer to chart object + * @return type of the chart (from 'lv_chart_t' enum) + */ +lv_chart_type_t lv_chart_get_type(const lv_obj_t * obj); + +/** + * Get the data point number per data line on chart + * @param chart pointer to chart object + * @return point number on each data line + */ +uint16_t lv_chart_get_point_count(const lv_obj_t * obj); + +/** + * Get the current index of the x-axis start point in the data array + * @param chart pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @return the index of the current x start point in the data array + */ +uint16_t lv_chart_get_x_start_point(const lv_obj_t * obj, lv_chart_series_t * ser); + +/** + * Get the position of a point to the chart. + * @param chart pointer to a chart object + * @param ser pointer to series + * @param id the index. + * @param p_out store the result position here + */ +void lv_chart_get_point_pos_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_point_t * p_out); + +/** + * Refresh a chart if its data line has changed + * @param chart pointer to chart object + */ +void lv_chart_refresh(lv_obj_t * obj); + +/*====================== + * Series + *=====================*/ + +/** + * Allocate and add a data series to the chart + * @param obj pointer to a chart object + * @param color color of the data series + * @param axis the y axis to which the series should be attached (::LV_CHART_AXIS_PRIMARY_Y or ::LV_CHART_AXIS_SECONDARY_Y) + * @return pointer to the allocated data series + */ +lv_chart_series_t * lv_chart_add_series(lv_obj_t * obj, lv_color_t color, lv_chart_axis_t axis); + +/** + * Deallocate and remove a data series from a chart + * @param chart pointer to a chart object + * @param series pointer to a data series on 'chart' + */ +void lv_chart_remove_series(lv_obj_t * obj, lv_chart_series_t * series); + +/** + * Hide/Unhide a single series of a chart. + * @param obj pointer to a chart object. + * @param series pointer to a series object + * @param hide true: hide the series + */ +void lv_chart_hide_series(lv_obj_t * chart, lv_chart_series_t * series, bool hide); + +/** + * Change the color of a series + * @param obj pointer to a chart object. + * @param series pointer to a series object + * @param color the new color of the series + */ +void lv_chart_set_series_color(lv_obj_t * chart, lv_chart_series_t * series, lv_color_t color); + +/** + * Set the index of the x-axis start point in the data array. + * This point will be considers the first (left) point and the other points will be drawn after it. + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @param id the index of the x point in the data array + */ +void lv_chart_set_x_start_point(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id); + +/** + * Get the next series. + * @param chart pointer to a chart + * @param ser the previous series or NULL to get the first + * @return the next series or NULL if there is no more. + */ +lv_chart_series_t * lv_chart_get_series_next(const lv_obj_t * chart, const lv_chart_series_t * ser); + + + +/*===================== + * Cursor + *====================*/ + +/** + * Add a cursor with a given color + * @param obj pointer to chart object + * @param color color of the cursor + * @param dir direction of the cursor. `LV_DIR_RIGHT/LEFT/TOP/DOWN/HOR/VER/ALL`. OR-ed values are possible + * @return pointer to the created cursor + */ +lv_chart_cursor_t * lv_chart_add_cursor(lv_obj_t * obj, lv_color_t color, lv_dir_t dir); + +/** + * Set the coordinate of the cursor with respect to the paddings + * @param obj pointer to a chart object + * @param cursor pointer to the cursor + * @param pos the new coordinate of cursor relative to the chart + */ +void lv_chart_set_cursor_pos(lv_obj_t * chart, lv_chart_cursor_t * cursor, lv_point_t * pos); + +/** + * Stick the cursor to a point + * @param obj pointer to a chart object + * @param cursor pointer to the cursor + * @param ser pointer to a series + * @param point_id the point's index or `LV_CHART_POINT_NONE` to not assign to any points. + */ +void lv_chart_set_cursor_point(lv_obj_t * chart, lv_chart_cursor_t * cursor, lv_chart_series_t * ser, + uint16_t point_id); + +/** + * Get the coordinate of the cursor with respect to the paddings + * @param obj pointer to a chart object + * @param cursor pointer to cursor + * @return coordinate of the cursor as lv_point_t + */ +lv_point_t lv_chart_get_cursor_point(lv_obj_t * chart, lv_chart_cursor_t * cursor); + +/*===================== + * Set/Get value(s) + *====================*/ + +/** + * Initialize all data points of a series with a value + * @param obj pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param value the new value for all points. `LV_CHART_POINT_NONE` can be used to hide the points. + */ +void lv_chart_set_all_value(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t value); + +/** + * Set the next point's Y value according to the update mode policy. + * @param obj pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param value the new value of the next data + */ +void lv_chart_set_next_value(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t value); + +/** + * Set the next point's X and Y value according to the update mode policy. + * @param obj pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param x_value the new X value of the next data + * @param y_value the new Y value of the next data + */ +void lv_chart_set_next_value2(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t x_value, lv_coord_t y_value); + +/** + * Set an individual point's y value of a chart's series directly based on its index + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @param id the index of the x point in the array + * @param value value to assign to array point + */ +void lv_chart_set_value_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_coord_t value); + +/** + * Set an individual point's x and y value of a chart's series directly based on its index + * Can be used only with `LV_CHART_TYPE_SCATTER`. + * @param obj pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param id the index of the x point in the array + * @param x_value the new X value of the next data + * @param y_value the new Y value of the next data + */ +void lv_chart_set_value_by_id2(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_coord_t x_value, + lv_coord_t y_value); + +/** + * Set an external array for the y data points to use for the chart + * NOTE: It is the users responsibility to make sure the `point_cnt` matches the external array size. + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @param array external array of points for chart + */ +void lv_chart_set_ext_y_array(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t array[]); + +/** + * Set an external array for the x data points to use for the chart + * NOTE: It is the users responsibility to make sure the `point_cnt` matches the external array size. + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @param array external array of points for chart + */ +void lv_chart_set_ext_x_array(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t array[]); + +/** + * Get the array of y values of a series + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @return the array of values with 'point_count' elements + */ +lv_coord_t * lv_chart_get_y_array(const lv_obj_t * obj, lv_chart_series_t * ser); + +/** + * Get the array of x values of a series + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @return the array of values with 'point_count' elements + */ +lv_coord_t * lv_chart_get_x_array(const lv_obj_t * obj, lv_chart_series_t * ser); + +/** + * Get the index of the currently pressed point. It's the same for every series. + * @param obj pointer to a chart object + * @return the index of the point [0 .. point count] or LV_CHART_POINT_ID_NONE if no point is being pressed + */ +uint32_t lv_chart_get_pressed_point(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CHART*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CHART_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/colorwheel/lv_colorwheel.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/colorwheel/lv_colorwheel.h new file mode 100644 index 00000000..38266d01 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/colorwheel/lv_colorwheel.h @@ -0,0 +1,142 @@ +/** + * @file lv_colorwheel.h + * + */ + +#ifndef LV_COLORWHEEL_H +#define LV_COLORWHEEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_COLORWHEEL + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_COLORWHEEL_MODE_HUE, + LV_COLORWHEEL_MODE_SATURATION, + LV_COLORWHEEL_MODE_VALUE +}; +typedef uint8_t lv_colorwheel_mode_t; + + +/*Data of color picker*/ +typedef struct { + lv_obj_t obj; + lv_color_hsv_t hsv; + struct { + lv_point_t pos; + uint8_t recolor : 1; + } knob; + uint32_t last_click_time; + uint32_t last_change_time; + lv_point_t last_press_point; + lv_colorwheel_mode_t mode : 2; + uint8_t mode_fixed : 1; +} lv_colorwheel_t; + +extern const lv_obj_class_t lv_colorwheel_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a color picker object with disc shape + * @param parent pointer to an object, it will be the parent of the new color picker + * @param knob_recolor true: set the knob's color to the current color + * @return pointer to the created color picker + */ +lv_obj_t * lv_colorwheel_create(lv_obj_t * parent, bool knob_recolor); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the current hsv of a color wheel. + * @param colorwheel pointer to color wheel object + * @param color current selected hsv + * @return true if changed, otherwise false + */ +bool lv_colorwheel_set_hsv(lv_obj_t * obj, lv_color_hsv_t hsv); + +/** + * Set the current color of a color wheel. + * @param colorwheel pointer to color wheel object + * @param color current selected color + * @return true if changed, otherwise false + */ +bool lv_colorwheel_set_rgb(lv_obj_t * obj, lv_color_t color); + +/** + * Set the current color mode. + * @param colorwheel pointer to color wheel object + * @param mode color mode (hue/sat/val) + */ +void lv_colorwheel_set_mode(lv_obj_t * obj, lv_colorwheel_mode_t mode); + +/** + * Set if the color mode is changed on long press on center + * @param colorwheel pointer to color wheel object + * @param fixed color mode cannot be changed on long press + */ +void lv_colorwheel_set_mode_fixed(lv_obj_t * obj, bool fixed); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current selected hsv of a color wheel. + * @param colorwheel pointer to color wheel object + * @return current selected hsv + */ +lv_color_hsv_t lv_colorwheel_get_hsv(lv_obj_t * obj); + +/** + * Get the current selected color of a color wheel. + * @param colorwheel pointer to color wheel object + * @return color current selected color + */ +lv_color_t lv_colorwheel_get_rgb(lv_obj_t * obj); + +/** + * Get the current color mode. + * @param colorwheel pointer to color wheel object + * @return color mode (hue/sat/val) + */ +lv_colorwheel_mode_t lv_colorwheel_get_color_mode(lv_obj_t * obj); + +/** + * Get if the color mode is changed on long press on center + * @param colorwheel pointer to color wheel object + * @return mode cannot be changed on long press + */ +bool lv_colorwheel_get_color_mode_fixed(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_COLORWHEEL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_COLORWHEEL_H*/ + diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/imgbtn/lv_imgbtn.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/imgbtn/lv_imgbtn.h new file mode 100644 index 00000000..38bcc033 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/imgbtn/lv_imgbtn.h @@ -0,0 +1,131 @@ +/** + * @file lv_imgbtn.h + * + */ + +#ifndef LV_IMGBTN_H +#define LV_IMGBTN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_IMGBTN != 0 + +/********************* + * DEFINES + *********************/ +typedef enum { + LV_IMGBTN_STATE_RELEASED, + LV_IMGBTN_STATE_PRESSED, + LV_IMGBTN_STATE_DISABLED, + LV_IMGBTN_STATE_CHECKED_RELEASED, + LV_IMGBTN_STATE_CHECKED_PRESSED, + LV_IMGBTN_STATE_CHECKED_DISABLED, + _LV_IMGBTN_STATE_NUM, +} lv_imgbtn_state_t; + +/********************** + * TYPEDEFS + **********************/ +/*Data of image button*/ +typedef struct { + lv_obj_t obj; + const void * img_src_mid[_LV_IMGBTN_STATE_NUM]; /*Store center images to each state*/ + const void * img_src_left[_LV_IMGBTN_STATE_NUM]; /*Store left side images to each state*/ + const void * img_src_right[_LV_IMGBTN_STATE_NUM]; /*Store right side images to each state*/ + lv_img_cf_t act_cf; /*Color format of the currently active image*/ +} lv_imgbtn_t; + +extern const lv_obj_class_t lv_imgbtn_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an image button object + * @param parent pointer to an object, it will be the parent of the new image button + * @return pointer to the created image button + */ +lv_obj_t * lv_imgbtn_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/** + * Set images for a state of the image button + * @param imgbtn pointer to an image button object + * @param state for which state set the new image + * @param src_left pointer to an image source for the left side of the button (a C array or path to + * a file) + * @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C + * array or path to a file) + * @param src_right pointer to an image source for the right side of the button (a C array or path + * to a file) + */ +void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_imgbtn_state_t state, const void * src_left, const void * src_mid, + const void * src_right); + + +/** + * Use this function instead of `lv_obj_add/clear_state` to set a state manually + * @param imgbtn pointer to an image button object + * @param state the new state + */ +void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_imgbtn_state_t state); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the left image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the left image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_imgbtn_state_t state); + +/** + * Get the middle image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the middle image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_imgbtn_state_t state); + +/** + * Get the right image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the left image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_imgbtn_state_t state); + + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_IMGBTN*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMGBTN_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/keyboard/lv_keyboard.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/keyboard/lv_keyboard.h new file mode 100644 index 00000000..64356a33 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/keyboard/lv_keyboard.h @@ -0,0 +1,187 @@ +/** + * @file lv_keyboard.h + * + */ + +#ifndef LV_KEYBOARD_H +#define LV_KEYBOARD_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/widgets/lv_btnmatrix.h" + +#if LV_USE_KEYBOARD + +/*Testing of dependencies*/ +#if LV_USE_BTNMATRIX == 0 +#error "lv_kb: lv_btnm is required. Enable it in lv_conf.h (LV_USE_BTNMATRIX 1) " +#endif + +#if LV_USE_TEXTAREA == 0 +#error "lv_kb: lv_ta is required. Enable it in lv_conf.h (LV_USE_TEXTAREA 1) " +#endif + +/********************* + * DEFINES + *********************/ +#define LV_KEYBOARD_CTRL_BTN_FLAGS (LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_CHECKED) + +/********************** + * TYPEDEFS + **********************/ + +/** Current keyboard mode.*/ +enum { + LV_KEYBOARD_MODE_TEXT_LOWER, + LV_KEYBOARD_MODE_TEXT_UPPER, + LV_KEYBOARD_MODE_SPECIAL, + LV_KEYBOARD_MODE_NUMBER, + LV_KEYBOARD_MODE_USER_1, + LV_KEYBOARD_MODE_USER_2, + LV_KEYBOARD_MODE_USER_3, + LV_KEYBOARD_MODE_USER_4, +}; +typedef uint8_t lv_keyboard_mode_t; + +/*Data of keyboard*/ +typedef struct { + lv_btnmatrix_t btnm; + lv_obj_t * ta; /*Pointer to the assigned text area*/ + lv_keyboard_mode_t mode; /*Key map type*/ + uint8_t popovers : 1; /*Show button titles in popovers on press*/ +} lv_keyboard_t; + +extern const lv_obj_class_t lv_keyboard_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Keyboard object + * @param parent pointer to an object, it will be the parent of the new keyboard + * @return pointer to the created keyboard + */ +lv_obj_t * lv_keyboard_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @param ta pointer to a Text Area object to write there + */ +void lv_keyboard_set_textarea(lv_obj_t * kb, lv_obj_t * ta); + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @param mode the mode from 'lv_keyboard_mode_t' + */ +void lv_keyboard_set_mode(lv_obj_t * kb, lv_keyboard_mode_t mode); + +/** + * Show the button title in a popover when pressed. + * @param kb pointer to a Keyboard object + * @param en whether "popovers" mode is enabled + */ +void lv_keyboard_set_popovers(lv_obj_t * kb, bool en); + +/** + * Set a new map for the keyboard + * @param kb pointer to a Keyboard object + * @param mode keyboard map to alter 'lv_keyboard_mode_t' + * @param map pointer to a string array to describe the map. + * See 'lv_btnmatrix_set_map()' for more info. + */ +void lv_keyboard_set_map(lv_obj_t * kb, lv_keyboard_mode_t mode, const char * map[], + const lv_btnmatrix_ctrl_t ctrl_map[]); + +/*===================== + * Getter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @return pointer to the assigned Text Area object + */ +lv_obj_t * lv_keyboard_get_textarea(const lv_obj_t * kb); + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @return the current mode from 'lv_keyboard_mode_t' + */ +lv_keyboard_mode_t lv_keyboard_get_mode(const lv_obj_t * kb); + +/** + * Tell whether "popovers" mode is enabled or not. + * @param kb pointer to a Keyboard object + * @return true: "popovers" mode is enabled; false: disabled + */ +bool lv_btnmatrix_get_popovers(const lv_obj_t * obj); + +/** + * Get the current map of a keyboard + * @param kb pointer to a keyboard object + * @return the current map + */ +static inline const char ** lv_keyboard_get_map_array(const lv_obj_t * kb) +{ + return lv_btnmatrix_get_map(kb); +} + +/** + * Get the index of the lastly "activated" button by the user (pressed, released, focused etc) + * Useful in the `event_cb` to get the text of the button, check if hidden etc. + * @param obj pointer to button matrix object + * @return index of the last released button (LV_BTNMATRIX_BTN_NONE: if unset) + */ +static inline uint16_t lv_keyboard_get_selected_btn(const lv_obj_t * obj) +{ + return lv_btnmatrix_get_selected_btn(obj); +} + +/** + * Get the button's text + * @param obj pointer to button matrix object + * @param btn_id the index a button not counting new line characters. + * @return text of btn_index` button + */ +static inline const char * lv_keyboard_get_btn_text(const lv_obj_t * obj, uint16_t btn_id) +{ + return lv_btnmatrix_get_btn_text(obj, btn_id); +} + +/*===================== + * Other functions + *====================*/ + +/** + * Default keyboard event to add characters to the Text area and change the map. + * If a custom `event_cb` is added to the keyboard this function can be called from it to handle the + * button clicks + * @param kb pointer to a keyboard + * @param event the triggering event + */ +void lv_keyboard_def_event_cb(lv_event_t * e); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_KEYBOARD*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_KEYBOARD_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/led/lv_led.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/led/lv_led.h new file mode 100644 index 00000000..f188b8e9 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/led/lv_led.h @@ -0,0 +1,116 @@ +/** + * @file lv_led.h + * + */ + +#ifndef LV_LED_H +#define LV_LED_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_LED + + +/********************* + * DEFINES + *********************/ +/** Brightness when the LED if OFF */ +#ifndef LV_LED_BRIGHT_MIN +# define LV_LED_BRIGHT_MIN 80 +#endif + +/** Brightness when the LED if ON */ +#ifndef LV_LED_BRIGHT_MAX +# define LV_LED_BRIGHT_MAX 255 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/*Data of led*/ +typedef struct { + lv_obj_t obj; + lv_color_t color; + uint8_t bright; /**< Current brightness of the LED (0..255)*/ +} lv_led_t; + +extern const lv_obj_class_t lv_led_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_led_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_LED_DRAW_PART_RECTANGLE, /**< The main rectangle*/ +} lv_led_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a led object + * @param parent pointer to an object, it will be the parent of the new led + * @return pointer to the created led + */ +lv_obj_t * lv_led_create(lv_obj_t * parent); + +/** + * Set the color of the LED + * @param led pointer to a LED object + * @param color the color of the LED + */ +void lv_led_set_color(lv_obj_t * led, lv_color_t color); + +/** + * Set the brightness of a LED object + * @param led pointer to a LED object + * @param bright LV_LED_BRIGHT_MIN (max. dark) ... LV_LED_BRIGHT_MAX (max. light) + */ +void lv_led_set_brightness(lv_obj_t * led, uint8_t bright); + +/** + * Light on a LED + * @param led pointer to a LED object + */ +void lv_led_on(lv_obj_t * led); + +/** + * Light off a LED + * @param led pointer to a LED object + */ +void lv_led_off(lv_obj_t * led); + +/** + * Toggle the state of a LED + * @param led pointer to a LED object + */ +void lv_led_toggle(lv_obj_t * led); + +/** + * Get the brightness of a LEd object + * @param led pointer to LED object + * @return bright 0 (max. dark) ... 255 (max. light) + */ +uint8_t lv_led_get_brightness(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_LED*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + + +#endif /*LV_LED_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/list/lv_list.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/list/lv_list.h new file mode 100644 index 00000000..e9bb6266 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/list/lv_list.h @@ -0,0 +1,54 @@ +/** + * @file lv_win.h + * + */ + +#ifndef LV_LIST_H +#define LV_LIST_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/extra/layouts/flex/lv_flex.h" + +#if LV_USE_LIST + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +extern const lv_obj_class_t lv_list_class; +extern const lv_obj_class_t lv_list_text_class; +extern const lv_obj_class_t lv_list_btn_class; +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_list_create(lv_obj_t * parent); + +lv_obj_t * lv_list_add_text(lv_obj_t * list, const char * txt); + +lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * icon, const char * txt); + +const char * lv_list_get_btn_text(lv_obj_t * list, lv_obj_t * btn); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_LIST*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LIST_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/lv_widgets.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/lv_widgets.h new file mode 100644 index 00000000..11418102 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/lv_widgets.h @@ -0,0 +1,56 @@ +/** + * @file lv_widgets.h + * + */ + +#ifndef LV_WIDGETS_H +#define LV_WIDGETS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "animimg/lv_animimg.h" +#include "calendar/lv_calendar.h" +#include "calendar/lv_calendar_header_arrow.h" +#include "calendar/lv_calendar_header_dropdown.h" +#include "chart/lv_chart.h" +#include "keyboard/lv_keyboard.h" +#include "list/lv_list.h" +#include "menu/lv_menu.h" +#include "msgbox/lv_msgbox.h" +#include "meter/lv_meter.h" +#include "spinbox/lv_spinbox.h" +#include "spinner/lv_spinner.h" +#include "tabview/lv_tabview.h" +#include "tileview/lv_tileview.h" +#include "win/lv_win.h" +#include "colorwheel/lv_colorwheel.h" +#include "led/lv_led.h" +#include "imgbtn/lv_imgbtn.h" +#include "span/lv_span.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_WIDGETS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/menu/lv_menu.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/menu/lv_menu.h new file mode 100644 index 00000000..42099792 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/menu/lv_menu.h @@ -0,0 +1,233 @@ +/** + * @file lv_menu.h + * + */ + +#ifndef LV_MENU_H +#define LV_MENU_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_MENU + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_MENU_HEADER_TOP_FIXED, /* Header is positioned at the top */ + LV_MENU_HEADER_TOP_UNFIXED, /* Header is positioned at the top and can be scrolled out of view*/ + LV_MENU_HEADER_BOTTOM_FIXED /* Header is positioned at the bottom */ +}; +typedef uint8_t lv_menu_mode_header_t; + +enum { + LV_MENU_ROOT_BACK_BTN_DISABLED, + LV_MENU_ROOT_BACK_BTN_ENABLED +}; +typedef uint8_t lv_menu_mode_root_back_btn_t; + +typedef struct lv_menu_load_page_event_data_t { + lv_obj_t * menu; + lv_obj_t * page; +} lv_menu_load_page_event_data_t; + +typedef struct { + lv_obj_t * page; +} lv_menu_history_t; + +typedef struct { + lv_obj_t obj; + lv_obj_t * storage; /* a pointer to obj that is the parent of all pages not displayed */ + lv_obj_t * main; + lv_obj_t * main_page; + lv_obj_t * main_header; + lv_obj_t * + main_header_back_btn; /* a pointer to obj that on click triggers back btn event handler, can be same as 'main_header' */ + lv_obj_t * main_header_title; + lv_obj_t * sidebar; + lv_obj_t * sidebar_page; + lv_obj_t * sidebar_header; + lv_obj_t * + sidebar_header_back_btn; /* a pointer to obj that on click triggers back btn event handler, can be same as 'sidebar_header' */ + lv_obj_t * sidebar_header_title; + lv_obj_t * selected_tab; + lv_ll_t history_ll; + uint8_t cur_depth; + uint8_t prev_depth; + uint8_t sidebar_generated : 1; + lv_menu_mode_header_t mode_header : 2; + lv_menu_mode_root_back_btn_t mode_root_back_btn : 1; +} lv_menu_t; + +typedef struct { + lv_obj_t obj; + char * title; +} lv_menu_page_t; + +extern const lv_obj_class_t lv_menu_class; +extern const lv_obj_class_t lv_menu_page_class; +extern const lv_obj_class_t lv_menu_cont_class; +extern const lv_obj_class_t lv_menu_section_class; +extern const lv_obj_class_t lv_menu_separator_class; +extern const lv_obj_class_t lv_menu_sidebar_cont_class; +extern const lv_obj_class_t lv_menu_main_cont_class; +extern const lv_obj_class_t lv_menu_sidebar_header_cont_class; +extern const lv_obj_class_t lv_menu_main_header_cont_class; +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a menu object + * @param parent pointer to an object, it will be the parent of the new menu + * @return pointer to the created menu + */ +lv_obj_t * lv_menu_create(lv_obj_t * parent); + +/** + * Create a menu page object + * @param parent pointer to menu object + * @param title pointer to text for title in header (NULL to not display title) + * @return pointer to the created menu page + */ +lv_obj_t * lv_menu_page_create(lv_obj_t * parent, char * title); + +/** + * Create a menu cont object + * @param parent pointer to an object, it will be the parent of the new menu cont object + * @return pointer to the created menu cont + */ +lv_obj_t * lv_menu_cont_create(lv_obj_t * parent); + +/** + * Create a menu section object + * @param parent pointer to an object, it will be the parent of the new menu section object + * @return pointer to the created menu section + */ +lv_obj_t * lv_menu_section_create(lv_obj_t * parent); + +/** + * Create a menu separator object + * @param parent pointer to an object, it will be the parent of the new menu separator object + * @return pointer to the created menu separator + */ +lv_obj_t * lv_menu_separator_create(lv_obj_t * parent); +/*===================== + * Setter functions + *====================*/ +/** + * Set menu page to display in main + * @param obj pointer to the menu + * @param page pointer to the menu page to set (NULL to clear main and clear menu history) + */ +void lv_menu_set_page(lv_obj_t * obj, lv_obj_t * page); + +/** + * Set menu page to display in sidebar + * @param obj pointer to the menu + * @param page pointer to the menu page to set (NULL to clear sidebar) + */ +void lv_menu_set_sidebar_page(lv_obj_t * obj, lv_obj_t * page); + +/** + * Set the how the header should behave and its position + * @param obj pointer to a menu + * @param mode_header + */ +void lv_menu_set_mode_header(lv_obj_t * obj, lv_menu_mode_header_t mode_header); + +/** + * Set whether back button should appear at root + * @param obj pointer to a menu + * @param mode_root_back_btn + */ +void lv_menu_set_mode_root_back_btn(lv_obj_t * obj, lv_menu_mode_root_back_btn_t mode_root_back_btn); + +/** + * Add menu to the menu item + * @param menu pointer to the menu + * @param obj pointer to the obj + * @param page pointer to the page to load when obj is clicked + */ +void lv_menu_set_load_page_event(lv_obj_t * menu, lv_obj_t * obj, lv_obj_t * page); + +/*===================== + * Getter functions + *====================*/ +/** +* Get a pointer to menu page that is currently displayed in main +* @param obj pointer to the menu +* @return pointer to current page +*/ +lv_obj_t * lv_menu_get_cur_main_page(lv_obj_t * obj); + +/** +* Get a pointer to menu page that is currently displayed in sidebar +* @param obj pointer to the menu +* @return pointer to current page +*/ +lv_obj_t * lv_menu_get_cur_sidebar_page(lv_obj_t * obj); + +/** +* Get a pointer to main header obj +* @param obj pointer to the menu +* @return pointer to main header obj +*/ +lv_obj_t * lv_menu_get_main_header(lv_obj_t * obj); + +/** +* Get a pointer to main header back btn obj +* @param obj pointer to the menu +* @return pointer to main header back btn obj +*/ +lv_obj_t * lv_menu_get_main_header_back_btn(lv_obj_t * obj); + +/** +* Get a pointer to sidebar header obj +* @param obj pointer to the menu +* @return pointer to sidebar header obj +*/ +lv_obj_t * lv_menu_get_sidebar_header(lv_obj_t * obj); + +/** +* Get a pointer to sidebar header obj +* @param obj pointer to the menu +* @return pointer to sidebar header back btn obj +*/ +lv_obj_t * lv_menu_get_sidebar_header_back_btn(lv_obj_t * obj); + +/** + * Check if an obj is a root back btn + * @param menu pointer to the menu + * @return true if it is a root back btn + */ +bool lv_menu_back_btn_is_root(lv_obj_t * menu, lv_obj_t * obj); + +/** + * Clear menu history + * @param obj pointer to the menu + */ +void lv_menu_clear_history(lv_obj_t * obj); +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_MENU*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MENU_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/meter/lv_meter.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/meter/lv_meter.h new file mode 100644 index 00000000..d64ad0d5 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/meter/lv_meter.h @@ -0,0 +1,267 @@ +/** + * @file lv_meter.h + * + */ + +#ifndef LV_METER_H +#define LV_METER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_METER != 0 + +/*Testing of dependencies*/ +#if LV_DRAW_COMPLEX == 0 +#error "lv_meter: Complex drawing is required. Enable it in lv_conf.h (LV_DRAW_COMPLEX 1)" +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_color_t tick_color; + uint16_t tick_cnt; + uint16_t tick_length; + uint16_t tick_width; + + lv_color_t tick_major_color; + uint16_t tick_major_nth; + uint16_t tick_major_length; + uint16_t tick_major_width; + + int16_t label_gap; + int16_t label_color; + + int32_t min; + int32_t max; + int16_t r_mod; + uint16_t angle_range; + int16_t rotation; +} lv_meter_scale_t; + +enum { + LV_METER_INDICATOR_TYPE_NEEDLE_IMG, + LV_METER_INDICATOR_TYPE_NEEDLE_LINE, + LV_METER_INDICATOR_TYPE_SCALE_LINES, + LV_METER_INDICATOR_TYPE_ARC, +}; +typedef uint8_t lv_meter_indicator_type_t; + +typedef struct { + lv_meter_scale_t * scale; + lv_meter_indicator_type_t type; + lv_opa_t opa; + int32_t start_value; + int32_t end_value; + union { + struct { + const void * src; + lv_point_t pivot; + } needle_img; + struct { + uint16_t width; + int16_t r_mod; + lv_color_t color; + } needle_line; + struct { + uint16_t width; + const void * src; + lv_color_t color; + int16_t r_mod; + } arc; + struct { + int16_t width_mod; + lv_color_t color_start; + lv_color_t color_end; + uint8_t local_grad : 1; + } scale_lines; + } type_data; +} lv_meter_indicator_t; + +/*Data of line meter*/ +typedef struct { + lv_obj_t obj; + lv_ll_t scale_ll; + lv_ll_t indicator_ll; +} lv_meter_t; + +extern const lv_obj_class_t lv_meter_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_meter_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_METER_DRAW_PART_ARC, /**< The arc indicator*/ + LV_METER_DRAW_PART_NEEDLE_LINE, /**< The needle lines*/ + LV_METER_DRAW_PART_NEEDLE_IMG, /**< The needle images*/ + LV_METER_DRAW_PART_TICK, /**< The tick lines and labels*/ +} lv_meter_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Meter object + * @param parent pointer to an object, it will be the parent of the new bar. + * @return pointer to the created meter + */ +lv_obj_t * lv_meter_create(lv_obj_t * parent); + +/*===================== + * Add scale + *====================*/ + +/** + * Add a new scale to the meter. + * @param obj pointer to a meter object + * @return the new scale + * @note Indicators can be attached to scales. + */ +lv_meter_scale_t * lv_meter_add_scale(lv_obj_t * obj); + +/** + * Set the properties of the ticks of a scale + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param cnt number of tick lines + * @param width width of tick lines + * @param len length of tick lines + * @param color color of tick lines + */ +void lv_meter_set_scale_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t cnt, uint16_t width, uint16_t len, + lv_color_t color); + +/** + * Make some "normal" ticks major ticks and set their attributes. + * Texts with the current value are also added to the major ticks. + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param nth make every Nth normal tick major tick. (start from the first on the left) + * @param width width of the major ticks + * @param len length of the major ticks + * @param color color of the major ticks + * @param label_gap gap between the major ticks and the labels + */ +void lv_meter_set_scale_major_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t nth, uint16_t width, + uint16_t len, lv_color_t color, int16_t label_gap); + +/** + * Set the value and angular range of a scale. + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param min the minimum value + * @param max the maximal value + * @param angle_range the angular range of the scale + * @param rotation the angular offset from the 3 o'clock position (clock-wise) + */ +void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t min, int32_t max, uint32_t angle_range, + uint32_t rotation); + +/*===================== + * Add indicator + *====================*/ + +/** + * Add a needle line indicator the scale + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param width width of the line + * @param color color of the line + * @param r_mod the radius modifier (added to the scale's radius) to get the lines length + * @return the new indicator + */ +lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, + lv_color_t color, int16_t r_mod); + +/** + * Add a needle image indicator the scale + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param src the image source of the indicator. path or pointer to ::lv_img_dsc_t + * @param pivot_x the X pivot point of the needle + * @param pivot_y the Y pivot point of the needle + * @return the new indicator + * @note the needle image should point to the right, like -O-----> + */ +lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t * scale, const void * src, + lv_coord_t pivot_x, lv_coord_t pivot_y); + +/** + * Add an arc indicator the scale + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param width width of the arc + * @param color color of the arc + * @param r_mod the radius modifier (added to the scale's radius) to get the outer radius of the arc + * @return the new indicator + */ +lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, + int16_t r_mod); + + +/** + * Add a scale line indicator the scale. It will modify the ticks. + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param color_start the start color + * @param color_end the end color + * @param local tell how to map start and end color. true: the indicator's start and end_value; false: the scale's min max value + * @param width_mod add this the affected tick's width + * @return the new indicator + */ +lv_meter_indicator_t * lv_meter_add_scale_lines(lv_obj_t * obj, lv_meter_scale_t * scale, lv_color_t color_start, + lv_color_t color_end, bool local, int16_t width_mod); + +/*===================== + * Set indicator value + *====================*/ + +/** + * Set the value of the indicator. It will set start and and value to the same value + * @param obj pointer to a meter object + * @param indic pointer to an indicator + * @param value the new value + */ +void lv_meter_set_indicator_value(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value); + +/** + * Set the start value of the indicator. + * @param obj pointer to a meter object + * @param indic pointer to an indicator + * @param value the new value + */ +void lv_meter_set_indicator_start_value(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value); + +/** + * Set the start value of the indicator. + * @param obj pointer to a meter object + * @param indic pointer to an indicator + * @param value the new value + */ +void lv_meter_set_indicator_end_value(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_METER*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_METER_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/msgbox/lv_msgbox.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/msgbox/lv_msgbox.h new file mode 100644 index 00000000..6b8ccd61 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/msgbox/lv_msgbox.h @@ -0,0 +1,99 @@ +/** + * @file lv_mbox.h + * + */ + +#ifndef LV_MSGBOX_H +#define LV_MSGBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_MSGBOX + +/*Testing of dependencies*/ +#if LV_USE_BTNMATRIX == 0 +#error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (LV_USE_BTNMATRIX 1) " +#endif + +#if LV_USE_LABEL == 0 +#error "lv_mbox: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) " +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + lv_obj_t * title; + lv_obj_t * close_btn; + lv_obj_t * content; + lv_obj_t * text; + lv_obj_t * btns; +} lv_msgbox_t; + +extern const lv_obj_class_t lv_msgbox_class; +extern const lv_obj_class_t lv_msgbox_content_class; +extern const lv_obj_class_t lv_msgbox_backdrop_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a message box object + * @param parent pointer to parent or NULL to create a full screen modal message box + * @param title the title of the message box + * @param txt the text of the message box + * @param btn_txts the buttons as an array of texts terminated by an "" element. E.g. {"btn1", "btn2", ""} + * @param add_close_btn true: add a close button + * @return pointer to the message box object + */ +lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char * txt, const char * btn_txts[], + bool add_close_btn); + +lv_obj_t * lv_msgbox_get_title(lv_obj_t * obj); + +lv_obj_t * lv_msgbox_get_close_btn(lv_obj_t * obj); + +lv_obj_t * lv_msgbox_get_text(lv_obj_t * obj); + +lv_obj_t * lv_msgbox_get_content(lv_obj_t * obj); + +lv_obj_t * lv_msgbox_get_btns(lv_obj_t * obj); + +/** + * Get the index of the selected button + * @param mbox message box object + * @return index of the button (LV_BTNMATRIX_BTN_NONE: if unset) + */ +uint16_t lv_msgbox_get_active_btn(lv_obj_t * mbox); + +const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox); + +void lv_msgbox_close(lv_obj_t * mbox); + +void lv_msgbox_close_async(lv_obj_t * mbox); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_MSGBOX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MSGBOX_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/span/lv_span.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/span/lv_span.h new file mode 100644 index 00000000..bbf65acb --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/span/lv_span.h @@ -0,0 +1,245 @@ +/** + * @file lv_span.h + * + */ + +#ifndef LV_SPAN_H +#define LV_SPAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_SPAN != 0 + +/********************* + * DEFINES + *********************/ +#ifndef LV_SPAN_SNIPPET_STACK_SIZE +#define LV_SPAN_SNIPPET_STACK_SIZE 64 +#endif + +/********************** + * TYPEDEFS + **********************/ +enum { + LV_SPAN_OVERFLOW_CLIP, + LV_SPAN_OVERFLOW_ELLIPSIS, +}; +typedef uint8_t lv_span_overflow_t; + +enum { + LV_SPAN_MODE_FIXED, /**< fixed the obj size*/ + LV_SPAN_MODE_EXPAND, /**< Expand the object size to the text size*/ + LV_SPAN_MODE_BREAK, /**< Keep width, break the too long lines and expand height*/ +}; +typedef uint8_t lv_span_mode_t; + +typedef struct { + char * txt; /* a pointer to display text */ + lv_obj_t * spangroup; /* a pointer to spangroup */ + lv_style_t style; /* display text style */ + uint8_t static_flag : 1;/* the text is static flag */ +} lv_span_t; + +/** Data of label*/ +typedef struct { + lv_obj_t obj; + int32_t lines; + lv_coord_t indent; /* first line indent */ + lv_coord_t cache_w; /* the cache automatically calculates the width */ + lv_coord_t cache_h; /* similar cache_w */ + lv_ll_t child_ll; + uint8_t mode : 2; /* details see lv_span_mode_t */ + uint8_t overflow : 1; /* details see lv_span_overflow_t */ + uint8_t refresh : 1; /* the spangroup need refresh cache_w and cache_h */ +} lv_spangroup_t; + +extern const lv_obj_class_t lv_spangroup_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a spangroup object + * @param par pointer to an object, it will be the parent of the new spangroup + * @return pointer to the created spangroup + */ +lv_obj_t * lv_spangroup_create(lv_obj_t * par); + +/** + * Create a span string descriptor and add to spangroup. + * @param obj pointer to a spangroup object. + * @return pointer to the created span. + */ +lv_span_t * lv_spangroup_new_span(lv_obj_t * obj); + +/** + * Remove the span from the spangroup and free memory. + * @param obj pointer to a spangroup object. + * @param span pointer to a span. + */ +void lv_spangroup_del_span(lv_obj_t * obj, lv_span_t * span); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new text for a span. Memory will be allocated to store the text by the span. + * @param span pointer to a span. + * @param text pointer to a text. + */ +void lv_span_set_text(lv_span_t * span, const char * text); + +/** + * Set a static text. It will not be saved by the span so the 'text' variable + * has to be 'alive' while the span exist. + * @param span pointer to a span. + * @param text pointer to a text. + */ +void lv_span_set_text_static(lv_span_t * span, const char * text); + +/** + * Set the align of the spangroup. + * @param obj pointer to a spangroup object. + * @param align see lv_text_align_t for details. + */ +void lv_spangroup_set_align(lv_obj_t * obj, lv_text_align_t align); + +/** + * Set the overflow of the spangroup. + * @param obj pointer to a spangroup object. + * @param overflow see lv_span_overflow_t for details. + */ +void lv_spangroup_set_overflow(lv_obj_t * obj, lv_span_overflow_t overflow); + +/** + * Set the indent of the spangroup. + * @param obj pointer to a spangroup object. + * @param indent The first line indentation + */ +void lv_spangroup_set_indent(lv_obj_t * obj, lv_coord_t indent); + +/** + * Set the mode of the spangroup. + * @param obj pointer to a spangroup object. + * @param mode see lv_span_mode_t for details. + */ +void lv_spangroup_set_mode(lv_obj_t * obj, lv_span_mode_t mode); + +/** + * Set lines of the spangroup. + * @param obj pointer to a spangroup object. + * @param lines max lines that can be displayed in LV_SPAN_MODE_BREAK mode. < 0 means no limit. + */ +void lv_spangroup_set_lines(lv_obj_t * obj, int32_t lines); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get a spangroup child by its index. + * + * @param obj The spangroup object + * @param id the index of the child. + * 0: the oldest (firstly created) child + * 1: the second oldest + * child count-1: the youngest + * -1: the youngest + * -2: the second youngest + * @return The child span at index `id`, or NULL if the ID does not exist + */ +lv_span_t * lv_spangroup_get_child(const lv_obj_t * obj, int32_t id); + +/** + * + * @param obj The spangroup object to get the child count of. + * @return The span count of the spangroup. + */ +uint32_t lv_spangroup_get_child_cnt(const lv_obj_t * obj); + +/** + * get the align of the spangroup. + * @param obj pointer to a spangroup object. + * @return the align value. + */ +lv_text_align_t lv_spangroup_get_align(lv_obj_t * obj); + +/** + * get the overflow of the spangroup. + * @param obj pointer to a spangroup object. + * @return the overflow value. + */ +lv_span_overflow_t lv_spangroup_get_overflow(lv_obj_t * obj); + +/** + * get the indent of the spangroup. + * @param obj pointer to a spangroup object. + * @return the indent value. + */ +lv_coord_t lv_spangroup_get_indent(lv_obj_t * obj); + +/** + * get the mode of the spangroup. + * @param obj pointer to a spangroup object. + */ +lv_span_mode_t lv_spangroup_get_mode(lv_obj_t * obj); + +/** + * get lines of the spangroup. + * @param obj pointer to a spangroup object. + * @return the lines value. + */ +int32_t lv_spangroup_get_lines(lv_obj_t * obj); + +/** + * get max line height of all span in the spangroup. + * @param obj pointer to a spangroup object. + */ +lv_coord_t lv_spangroup_get_max_line_h(lv_obj_t * obj); + +/** + * get the text content width when all span of spangroup on a line. + * @param obj pointer to a spangroup object. + * @param max_width if text content width >= max_width, return max_width + * to reduce computation, if max_width == 0, returns the text content width. + * @return text content width or max_width. + */ +uint32_t lv_spangroup_get_expand_width(lv_obj_t * obj, uint32_t max_width); + +/** + * get the text content height with width fixed. + * @param obj pointer to a spangroup object. + */ +lv_coord_t lv_spangroup_get_expand_height(lv_obj_t * obj, lv_coord_t width); + + +/*===================== + * Other functions + *====================*/ + +/** + * update the mode of the spangroup. + * @param obj pointer to a spangroup object. + */ +void lv_spangroup_refr_mode(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_SPAN*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_SPAN_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/spinbox/lv_spinbox.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/spinbox/lv_spinbox.h new file mode 100644 index 00000000..830178fa --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/spinbox/lv_spinbox.h @@ -0,0 +1,182 @@ +/** + * @file lv_spinbox.h + * + */ + +#ifndef LV_SPINBOX_H +#define LV_SPINBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_SPINBOX + +/*Testing of dependencies*/ +#if LV_USE_TEXTAREA == 0 +#error "lv_spinbox: lv_ta is required. Enable it in lv_conf.h (LV_USE_TEXTAREA 1) " +#endif + +/********************* + * DEFINES + *********************/ +#define LV_SPINBOX_MAX_DIGIT_COUNT 10 + +/********************** + * TYPEDEFS + **********************/ + +/*Data of spinbox*/ +typedef struct { + lv_textarea_t ta; /*Ext. of ancestor*/ + /*New data for this type*/ + int32_t value; + int32_t range_max; + int32_t range_min; + int32_t step; + uint16_t digit_count : 4; + uint16_t dec_point_pos : 4; /*if 0, there is no separator and the number is an integer*/ + uint16_t rollover : 1; // Set to true for rollover functionality + uint16_t digit_step_dir : 2; // the direction the digit will step on encoder button press when editing +} lv_spinbox_t; + +extern const lv_obj_class_t lv_spinbox_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Spinbox object + * @param parent pointer to an object, it will be the parent of the new spinbox + * @return pointer to the created spinbox + */ +lv_obj_t * lv_spinbox_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set spinbox value + * @param obj pointer to spinbox + * @param i value to be set + */ +void lv_spinbox_set_value(lv_obj_t * obj, int32_t i); + +/** + * Set spinbox rollover function + * @param obj pointer to spinbox + * @param b true or false to enable or disable (default) + */ +void lv_spinbox_set_rollover(lv_obj_t * obj, bool b); + +/** + * Set spinbox digit format (digit count and decimal format) + * @param obj pointer to spinbox + * @param digit_count number of digit excluding the decimal separator and the sign + * @param separator_position number of digit before the decimal point. If 0, decimal point is not + * shown + */ +void lv_spinbox_set_digit_format(lv_obj_t * obj, uint8_t digit_count, uint8_t separator_position); + +/** + * Set spinbox step + * @param obj pointer to spinbox + * @param step steps on increment/decrement. Can be 1, 10, 100, 1000, etc the digit that will change. + */ +void lv_spinbox_set_step(lv_obj_t * obj, uint32_t step); + +/** + * Set spinbox value range + * @param obj pointer to spinbox + * @param range_min maximum value, inclusive + * @param range_max minimum value, inclusive + */ +void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max); + +/** + * Set cursor position to a specific digit for edition + * @param obj pointer to spinbox + * @param pos selected position in spinbox + */ +void lv_spinbox_set_cursor_pos(lv_obj_t * obj, uint8_t pos); + +/** + * Set direction of digit step when clicking an encoder button while in editing mode + * @param obj pointer to spinbox + * @param direction the direction (LV_DIR_RIGHT or LV_DIR_LEFT) + */ +void lv_spinbox_set_digit_step_direction(lv_obj_t * obj, lv_dir_t direction); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get spinbox rollover function status + * @param obj pointer to spinbox + */ +bool lv_spinbox_get_rollover(lv_obj_t * obj); + +/** + * Get the spinbox numeral value (user has to convert to float according to its digit format) + * @param obj pointer to spinbox + * @return value integer value of the spinbox + */ +int32_t lv_spinbox_get_value(lv_obj_t * obj); + +/** + * Get the spinbox step value (user has to convert to float according to its digit format) + * @param obj pointer to spinbox + * @return value integer step value of the spinbox + */ +int32_t lv_spinbox_get_step(lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Select next lower digit for edition by dividing the step by 10 + * @param obj pointer to spinbox + */ +void lv_spinbox_step_next(lv_obj_t * obj); + +/** + * Select next higher digit for edition by multiplying the step by 10 + * @param obj pointer to spinbox + */ +void lv_spinbox_step_prev(lv_obj_t * obj); + +/** + * Increment spinbox value by one step + * @param obj pointer to spinbox + */ +void lv_spinbox_increment(lv_obj_t * obj); + +/** + * Decrement spinbox value by one step + * @param obj pointer to spinbox + */ +void lv_spinbox_decrement(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +/* It was ambiguous in MicroPython. See https://github.com/lvgl/lvgl/issues/3301 + * TODO remove in v9*/ +#define lv_spinbox_set_pos lv_spinbox_set_cursor_pos + +#endif /*LV_USE_SPINBOX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif +#endif /*LV_SPINBOX_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/spinner/lv_spinner.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/spinner/lv_spinner.h new file mode 100644 index 00000000..794f7363 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/spinner/lv_spinner.h @@ -0,0 +1,50 @@ +/** + * @file lv_spinner.h + * + */ + +#ifndef LV_SPINNER_H +#define LV_SPINNER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_SPINNER + +/*Testing of dependencies*/ +#if LV_USE_ARC == 0 +#error "lv_spinner: lv_arc is required. Enable it in lv_conf.h (LV_USE_ARC 1) " +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +extern const lv_obj_class_t lv_spinner_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_spinner_create(lv_obj_t * parent, uint32_t time, uint32_t arc_length); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_SPINNER*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_SPINNER_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/tabview/lv_tabview.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/tabview/lv_tabview.h new file mode 100644 index 00000000..bcee5a13 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/tabview/lv_tabview.h @@ -0,0 +1,65 @@ +/** + * @file lv_templ.h + * + */ + +#ifndef LV_TABVIEW_H +#define LV_TABVIEW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_TABVIEW + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + char ** map; + uint16_t tab_cnt; + uint16_t tab_cur; + lv_dir_t tab_pos; +} lv_tabview_t; + +extern const lv_obj_class_t lv_tabview_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ +lv_obj_t * lv_tabview_create(lv_obj_t * parent, lv_dir_t tab_pos, lv_coord_t tab_size); + +lv_obj_t * lv_tabview_add_tab(lv_obj_t * tv, const char * name); + +void lv_tabview_rename_tab(lv_obj_t * obj, uint32_t tab_id, const char * new_name); + +lv_obj_t * lv_tabview_get_content(lv_obj_t * tv); + +lv_obj_t * lv_tabview_get_tab_btns(lv_obj_t * tv); + +void lv_tabview_set_act(lv_obj_t * obj, uint32_t id, lv_anim_enable_t anim_en); + +uint16_t lv_tabview_get_tab_act(lv_obj_t * tv); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TABVIEW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TABVIEW_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/tileview/lv_tileview.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/tileview/lv_tileview.h new file mode 100644 index 00000000..34a1bf18 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/tileview/lv_tileview.h @@ -0,0 +1,72 @@ +/** + * @file lv_tileview.h + * + */ + +#ifndef LV_TILEVIEW_H +#define LV_TILEVIEW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_TILEVIEW + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_obj_t obj; + lv_obj_t * tile_act; +} lv_tileview_t; + +typedef struct { + lv_obj_t obj; + lv_dir_t dir; +} lv_tileview_tile_t; + +extern const lv_obj_class_t lv_tileview_class; +extern const lv_obj_class_t lv_tileview_tile_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Tileview object + * @param parent pointer to an object, it will be the parent of the new tileview + * @return pointer to the created tileview + */ +lv_obj_t * lv_tileview_create(lv_obj_t * parent); + +lv_obj_t * lv_tileview_add_tile(lv_obj_t * tv, uint8_t col_id, uint8_t row_id, lv_dir_t dir); + +void lv_obj_set_tile(lv_obj_t * tv, lv_obj_t * tile_obj, lv_anim_enable_t anim_en); +void lv_obj_set_tile_id(lv_obj_t * tv, uint32_t col_id, uint32_t row_id, lv_anim_enable_t anim_en); + +lv_obj_t * lv_tileview_get_tile_act(lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TILEVIEW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TILEVIEW_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/extra/widgets/win/lv_win.h b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/win/lv_win.h new file mode 100644 index 00000000..2ea907d3 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/extra/widgets/win/lv_win.h @@ -0,0 +1,51 @@ +/** + * @file lv_win.h + * + */ + +#ifndef LV_WIN_H +#define LV_WIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_obj_t obj; +} lv_win_t; + +extern const lv_obj_class_t lv_win_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_win_create(lv_obj_t * parent, lv_coord_t header_height); + + +lv_obj_t * lv_win_add_title(lv_obj_t * win, const char * txt); +lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w); + +lv_obj_t * lv_win_get_header(lv_obj_t * win); +lv_obj_t * lv_win_get_content(lv_obj_t * win); +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_WIN_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/font/lv_font.h b/EZ-Template-Example-Project/include/liblvgl/font/lv_font.h new file mode 100644 index 00000000..3c0a689e --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/font/lv_font.h @@ -0,0 +1,287 @@ +/** + * @file lv_font.h + * + */ + +#ifndef LV_FONT_H +#define LV_FONT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include +#include +#include + +#include "lv_symbol_def.h" +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/* imgfont identifier */ +#define LV_IMGFONT_BPP 9 + +/********************** + * TYPEDEFS + **********************/ + +/*------------------ + * General types + *-----------------*/ + +struct _lv_font_t; +/** Describes the properties of a glyph.*/ +typedef struct { + const struct _lv_font_t * + resolved_font; /**< Pointer to a font where the glyph was actually found after handling fallbacks*/ + uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width.*/ + uint16_t box_w; /**< Width of the glyph's bounding box*/ + uint16_t box_h; /**< Height of the glyph's bounding box*/ + int16_t ofs_x; /**< x offset of the bounding box*/ + int16_t ofs_y; /**< y offset of the bounding box*/ + uint8_t bpp: 4; /**< Bit-per-pixel: 1, 2, 4, 8*/ + uint8_t is_placeholder: 1; /** Glyph is missing. But placeholder will still be displayed */ +} lv_font_glyph_dsc_t; + +/** The bitmaps might be upscaled by 3 to achieve subpixel rendering.*/ +enum { + LV_FONT_SUBPX_NONE, + LV_FONT_SUBPX_HOR, + LV_FONT_SUBPX_VER, + LV_FONT_SUBPX_BOTH, +}; + +typedef uint8_t lv_font_subpx_t; + +/** Describe the properties of a font*/ +typedef struct _lv_font_t { + /** Get a glyph's descriptor from a font*/ + bool (*get_glyph_dsc)(const struct _lv_font_t *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next); + + /** Get a glyph's bitmap from a font*/ + const uint8_t * (*get_glyph_bitmap)(const struct _lv_font_t *, uint32_t); + + /*Pointer to the font in a font pack (must have the same line height)*/ + lv_coord_t line_height; /**< The real line height where any text fits*/ + lv_coord_t base_line; /**< Base line measured from the top of the line_height*/ + uint8_t subpx : 2; /**< An element of `lv_font_subpx_t`*/ + + int8_t underline_position; /**< Distance between the top of the underline and base line (< 0 means below the base line)*/ + int8_t underline_thickness; /**< Thickness of the underline*/ + + const void * dsc; /**< Store implementation specific or run_time data or caching here*/ + const struct _lv_font_t * fallback; /**< Fallback font for missing glyph. Resolved recursively */ +#if LV_USE_USER_DATA + void * user_data; /**< Custom user data for font.*/ +#endif +} lv_font_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Return with the bitmap of a font. + * @param font_p pointer to a font + * @param letter a UNICODE character code + * @return pointer to the bitmap of the letter + */ +const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter); + +/** + * Get the descriptor of a glyph + * @param font_p pointer to font + * @param dsc_out store the result descriptor here + * @param letter a UNICODE letter code + * @param letter_next the next letter after `letter`. Used for kerning + * @return true: descriptor is successfully loaded into `dsc_out`. + * false: the letter was not found, no data is loaded to `dsc_out` + */ +bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, + uint32_t letter_next); + +/** + * Get the width of a glyph with kerning + * @param font pointer to a font + * @param letter a UNICODE letter + * @param letter_next the next letter after `letter`. Used for kerning + * @return the width of the glyph + */ +uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next); + +/** + * Get the line height of a font. All characters fit into this height + * @param font_p pointer to a font + * @return the height of a font + */ +static inline lv_coord_t lv_font_get_line_height(const lv_font_t * font_p) +{ + return font_p->line_height; +} + +/********************** + * MACROS + **********************/ + +#define LV_FONT_DECLARE(font_name) extern const lv_font_t font_name; + +#if LV_FONT_MONTSERRAT_8 +LV_FONT_DECLARE(lv_font_montserrat_8) +#endif + +#if LV_FONT_MONTSERRAT_10 +LV_FONT_DECLARE(lv_font_montserrat_10) +#endif + +#if LV_FONT_MONTSERRAT_12 +LV_FONT_DECLARE(lv_font_montserrat_12) +#endif + +#if LV_FONT_MONTSERRAT_14 +LV_FONT_DECLARE(lv_font_montserrat_14) +#endif + +#if LV_FONT_MONTSERRAT_16 +LV_FONT_DECLARE(lv_font_montserrat_16) +#endif + +#if LV_FONT_MONTSERRAT_18 +LV_FONT_DECLARE(lv_font_montserrat_18) +#endif + +#if LV_FONT_MONTSERRAT_20 +LV_FONT_DECLARE(lv_font_montserrat_20) +#endif + +#if LV_FONT_MONTSERRAT_22 +LV_FONT_DECLARE(lv_font_montserrat_22) +#endif + +#if LV_FONT_MONTSERRAT_24 +LV_FONT_DECLARE(lv_font_montserrat_24) +#endif + +#if LV_FONT_MONTSERRAT_26 +LV_FONT_DECLARE(lv_font_montserrat_26) +#endif + +#if LV_FONT_MONTSERRAT_28 +LV_FONT_DECLARE(lv_font_montserrat_28) +#endif + +#if LV_FONT_MONTSERRAT_30 +LV_FONT_DECLARE(lv_font_montserrat_30) +#endif + +#if LV_FONT_MONTSERRAT_32 +LV_FONT_DECLARE(lv_font_montserrat_32) +#endif + +#if LV_FONT_MONTSERRAT_34 +LV_FONT_DECLARE(lv_font_montserrat_34) +#endif + +#if LV_FONT_MONTSERRAT_36 +LV_FONT_DECLARE(lv_font_montserrat_36) +#endif + +#if LV_FONT_MONTSERRAT_38 +LV_FONT_DECLARE(lv_font_montserrat_38) +#endif + +#if LV_FONT_MONTSERRAT_40 +LV_FONT_DECLARE(lv_font_montserrat_40) +#endif + +#if LV_FONT_MONTSERRAT_42 +LV_FONT_DECLARE(lv_font_montserrat_42) +#endif + +#if LV_FONT_MONTSERRAT_44 +LV_FONT_DECLARE(lv_font_montserrat_44) +#endif + +#if LV_FONT_MONTSERRAT_46 +LV_FONT_DECLARE(lv_font_montserrat_46) +#endif + +#if LV_FONT_MONTSERRAT_48 +LV_FONT_DECLARE(lv_font_montserrat_48) +#endif + +#if LV_FONT_MONTSERRAT_12_SUBPX +LV_FONT_DECLARE(lv_font_montserrat_12_subpx) +#endif + +#if LV_FONT_MONTSERRAT_28_COMPRESSED +LV_FONT_DECLARE(lv_font_montserrat_28_compressed) +#endif + +#if LV_FONT_DEJAVU_16_PERSIAN_HEBREW +LV_FONT_DECLARE(lv_font_dejavu_16_persian_hebrew) +#endif + +#if LV_FONT_SIMSUN_16_CJK +LV_FONT_DECLARE(lv_font_simsun_16_cjk) +#endif + +#if LV_FONT_UNSCII_8 +LV_FONT_DECLARE(lv_font_unscii_8) +#endif + +#if LV_FONT_UNSCII_16 +LV_FONT_DECLARE(lv_font_unscii_16) +#endif + +// TODO: reimplement some of the '_LATIN_SUP' fonts as custom fonts + +/*Declare the custom (user defined) fonts*/ +#ifdef LV_FONT_CUSTOM_DECLARE +LV_FONT_CUSTOM_DECLARE +#endif +#if USE_PROS_FONT_DEJAVU_MONO_10 +LV_FONT_DECLARE(pros_font_dejavu_mono_10); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_10_LATIN_SUP +LV_FONT_DECLARE(pros_font_dejavu_mono_10_latin_sup); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_18 +LV_FONT_DECLARE(pros_font_dejavu_mono_18); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_18_LATIN_SUP +LV_FONT_DECLARE(pros_font_dejavu_mono_18_latin_sup); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_30 +LV_FONT_DECLARE(pros_font_dejavu_mono_30); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_30_LATIN_SUP +LV_FONT_DECLARE(pros_font_dejavu_mono_30_latin_sup); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_40 +LV_FONT_DECLARE(pros_font_dejavu_mono_40); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_40_LATIN_SUP +LV_FONT_DECLARE(pros_font_dejavu_mono_40_latin_sup); +#endif + +/** + * Just a wrapper around LV_FONT_DEFAULT because it might be more convenient to use a function in some cases + * @return pointer to LV_FONT_DEFAULT + */ +static inline const lv_font_t * lv_font_default(void) +{ + return LV_FONT_DEFAULT; +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*USE_FONT*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/font/lv_font_fmt_txt.h b/EZ-Template-Example-Project/include/liblvgl/font/lv_font_fmt_txt.h new file mode 100644 index 00000000..86546a35 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/font/lv_font_fmt_txt.h @@ -0,0 +1,240 @@ +/** + * @file lv_font_fmt_txt.h + * + */ + +#ifndef LV_FONT_FMT_TXT_H +#define LV_FONT_FMT_TXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include +#include +#include "lv_font.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** This describes a glyph.*/ +typedef struct { +#if LV_FONT_FMT_TXT_LARGE == 0 + uint32_t bitmap_index : 20; /**< Start index of the bitmap. A font can be max 1 MB.*/ + uint32_t adv_w : 12; /**< Draw the next glyph after this width. 8.4 format (real_value * 16 is stored).*/ + uint8_t box_w; /**< Width of the glyph's bounding box*/ + uint8_t box_h; /**< Height of the glyph's bounding box*/ + int8_t ofs_x; /**< x offset of the bounding box*/ + int8_t ofs_y; /**< y offset of the bounding box. Measured from the top of the line*/ +#else + uint32_t bitmap_index; /**< Start index of the bitmap. A font can be max 4 GB.*/ + uint32_t adv_w; /**< Draw the next glyph after this width. 28.4 format (real_value * 16 is stored).*/ + uint16_t box_w; /**< Width of the glyph's bounding box*/ + uint16_t box_h; /**< Height of the glyph's bounding box*/ + int16_t ofs_x; /**< x offset of the bounding box*/ + int16_t ofs_y; /**< y offset of the bounding box. Measured from the top of the line*/ +#endif +} lv_font_fmt_txt_glyph_dsc_t; + +/** Format of font character map.*/ +enum { + LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL, + LV_FONT_FMT_TXT_CMAP_SPARSE_FULL, + LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY, + LV_FONT_FMT_TXT_CMAP_SPARSE_TINY, +}; + +typedef uint8_t lv_font_fmt_txt_cmap_type_t; + +/** + * Map codepoints to a `glyph_dsc`s + * Several formats are supported to optimize memory usage + * See https://github.com/lvgl/lv_font_conv/blob/master/doc/font_spec.md + */ +typedef struct { + /** First Unicode character for this range*/ + uint32_t range_start; + + /** Number of Unicode characters related to this range. + * Last Unicode character = range_start + range_length - 1*/ + uint16_t range_length; + + /** First glyph ID (array index of `glyph_dsc`) for this range*/ + uint16_t glyph_id_start; + + /* + According the specification there are 4 formats: + https://github.com/lvgl/lv_font_conv/blob/master/doc/font_spec.md + + For simplicity introduce "relative code point": + rcp = codepoint - range_start + + and a search function: + search a "value" in an "array" and returns the index of "value". + + Format 0 tiny + unicode_list == NULL && glyph_id_ofs_list == NULL + glyph_id = glyph_id_start + rcp + + Format 0 full + unicode_list == NULL && glyph_id_ofs_list != NULL + glyph_id = glyph_id_start + glyph_id_ofs_list[rcp] + + Sparse tiny + unicode_list != NULL && glyph_id_ofs_list == NULL + glyph_id = glyph_id_start + search(unicode_list, rcp) + + Sparse full + unicode_list != NULL && glyph_id_ofs_list != NULL + glyph_id = glyph_id_start + glyph_id_ofs_list[search(unicode_list, rcp)] + */ + + const uint16_t * unicode_list; + + /** if(type == LV_FONT_FMT_TXT_CMAP_FORMAT0_...) it's `uint8_t *` + * if(type == LV_FONT_FMT_TXT_CMAP_SPARSE_...) it's `uint16_t *` + */ + const void * glyph_id_ofs_list; + + /** Length of `unicode_list` and/or `glyph_id_ofs_list`*/ + uint16_t list_length; + + /** Type of this character map*/ + lv_font_fmt_txt_cmap_type_t type; +} lv_font_fmt_txt_cmap_t; + +/** A simple mapping of kern values from pairs*/ +typedef struct { + /*To get a kern value of two code points: + 1. Get the `glyph_id_left` and `glyph_id_right` from `lv_font_fmt_txt_cmap_t + 2. for(i = 0; i < pair_cnt * 2; i += 2) + if(gylph_ids[i] == glyph_id_left && + gylph_ids[i+1] == glyph_id_right) + return values[i / 2]; + */ + const void * glyph_ids; + const int8_t * values; + uint32_t pair_cnt : 30; + uint32_t glyph_ids_size : 2; /*0: `glyph_ids` is stored as `uint8_t`; 1: as `uint16_t`*/ +} lv_font_fmt_txt_kern_pair_t; + +/** More complex but more optimal class based kern value storage*/ +typedef struct { + /*To get a kern value of two code points: + 1. Get the `glyph_id_left` and `glyph_id_right` from `lv_font_fmt_txt_cmap_t + 2. Get the class of the left and right glyphs as `left_class` and `right_class` + left_class = left_class_mapping[glyph_id_left]; + right_class = right_class_mapping[glyph_id_right]; + 3. value = class_pair_values[(left_class-1)*right_class_cnt + (right_class-1)] + */ + + const int8_t * class_pair_values; /*left_class_cnt * right_class_cnt value*/ + const uint8_t * left_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/ + const uint8_t * right_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/ + uint8_t left_class_cnt; + uint8_t right_class_cnt; +} lv_font_fmt_txt_kern_classes_t; + +/** Bitmap formats*/ +typedef enum { + LV_FONT_FMT_TXT_PLAIN = 0, + LV_FONT_FMT_TXT_COMPRESSED = 1, + LV_FONT_FMT_TXT_COMPRESSED_NO_PREFILTER = 1, +} lv_font_fmt_txt_bitmap_format_t; + +typedef struct { + uint32_t last_letter; + uint32_t last_glyph_id; +} lv_font_fmt_txt_glyph_cache_t; + +/*Describe store additional data for fonts*/ +typedef struct { + /*The bitmaps of all glyphs*/ + const uint8_t * glyph_bitmap; + + /*Describe the glyphs*/ + const lv_font_fmt_txt_glyph_dsc_t * glyph_dsc; + + /*Map the glyphs to Unicode characters. + *Array of `lv_font_cmap_fmt_txt_t` variables*/ + const lv_font_fmt_txt_cmap_t * cmaps; + + /** + * Store kerning values. + * Can be `lv_font_fmt_txt_kern_pair_t * or `lv_font_kern_classes_fmt_txt_t *` + * depending on `kern_classes` + */ + const void * kern_dsc; + + /*Scale kern values in 12.4 format*/ + uint16_t kern_scale; + + /*Number of cmap tables*/ + uint16_t cmap_num : 9; + + /*Bit per pixel: 1, 2, 3, 4, 8*/ + uint16_t bpp : 4; + + /*Type of `kern_dsc`*/ + uint16_t kern_classes : 1; + + /* + * storage format of the bitmap + * from `lv_font_fmt_txt_bitmap_format_t` + */ + uint16_t bitmap_format : 2; + + /*Cache the last letter and is glyph id*/ + lv_font_fmt_txt_glyph_cache_t * cache; +} lv_font_fmt_txt_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Used as `get_glyph_bitmap` callback in LittelvGL's native font format if the font is uncompressed. + * @param font pointer to font + * @param unicode_letter a unicode letter which bitmap should be get + * @return pointer to the bitmap or NULL if not found + */ +const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t letter); + +/** + * Used as `get_glyph_dsc` callback in LittelvGL's native font format if the font is uncompressed. + * @param font_p pointer to font + * @param dsc_out store the result descriptor here + * @param letter a UNICODE letter code + * @return true: descriptor is successfully loaded into `dsc_out`. + * false: the letter was not found, no data is loaded to `dsc_out` + */ +bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, + uint32_t unicode_letter_next); + +/** + * Free the allocated memories. + */ +void _lv_font_clean_up_fmt_txt(void); + +/********************** + * MACROS + **********************/ + +/********************** + * ADD BUILT IN FONTS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FONT_FMT_TXT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/font/lv_font_loader.h b/EZ-Template-Example-Project/include/liblvgl/font/lv_font_loader.h new file mode 100644 index 00000000..783cb2e7 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/font/lv_font_loader.h @@ -0,0 +1,40 @@ +/** + * @file lv_font_loader.h + * + */ + +#ifndef LV_FONT_LOADER_H +#define LV_FONT_LOADER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_font_t * lv_font_load(const char * fontName); +void lv_font_free(lv_font_t * font); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FONT_LOADER_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/font/lv_symbol_def.h b/EZ-Template-Example-Project/include/liblvgl/font/lv_symbol_def.h new file mode 100644 index 00000000..1055392d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/font/lv_symbol_def.h @@ -0,0 +1,353 @@ +#ifndef LV_SYMBOL_DEF_H +#define LV_SYMBOL_DEF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "liblvgl/lv_conf_internal.h" + +/*------------------------------- + * Symbols from "normal" font + *-----------------------------*/ +#if !defined LV_SYMBOL_BULLET +#define LV_SYMBOL_BULLET "\xE2\x80\xA2" /*20042, 0x2022*/ +#endif + +/*------------------------------- + * Symbols from FontAwesome font + *-----------------------------*/ + +/*In the font converter use this list as range: + 61441, 61448, 61451, 61452, 61453, 61457, 61459, 61461, 61465, 61468, + 61473, 61478, 61479, 61480, 61502, 61507, 61512, 61515, 61516, 61517, + 61521, 61522, 61523, 61524, 61543, 61544, 61550, 61552, 61553, 61556, + 61559, 61560, 61561, 61563, 61587, 61589, 61636, 61637, 61639, 61641, + 61664, 61671, 61674, 61683, 61724, 61732, 61787, 61931, 62016, 62017, + 62018, 62019, 62020, 62087, 62099, 62189, 62212, 62810, 63426, 63650 +*/ + +/* These symbols can be prefined in the lv_conf.h file. + * If they are not predefined, they will use the following values + */ + + +#if !defined LV_SYMBOL_AUDIO +#define LV_SYMBOL_AUDIO "\xEF\x80\x81" /*61441, 0xF001*/ +#endif + +#if !defined LV_SYMBOL_VIDEO +#define LV_SYMBOL_VIDEO "\xEF\x80\x88" /*61448, 0xF008*/ +#endif + +#if !defined LV_SYMBOL_LIST +#define LV_SYMBOL_LIST "\xEF\x80\x8B" /*61451, 0xF00B*/ +#endif + +#if !defined LV_SYMBOL_OK +#define LV_SYMBOL_OK "\xEF\x80\x8C" /*61452, 0xF00C*/ +#endif + +#if !defined LV_SYMBOL_CLOSE +#define LV_SYMBOL_CLOSE "\xEF\x80\x8D" /*61453, 0xF00D*/ +#endif + +#if !defined LV_SYMBOL_POWER +#define LV_SYMBOL_POWER "\xEF\x80\x91" /*61457, 0xF011*/ +#endif + +#if !defined LV_SYMBOL_SETTINGS +#define LV_SYMBOL_SETTINGS "\xEF\x80\x93" /*61459, 0xF013*/ +#endif + +#if !defined LV_SYMBOL_HOME +#define LV_SYMBOL_HOME "\xEF\x80\x95" /*61461, 0xF015*/ +#endif + +#if !defined LV_SYMBOL_DOWNLOAD +#define LV_SYMBOL_DOWNLOAD "\xEF\x80\x99" /*61465, 0xF019*/ +#endif + +#if !defined LV_SYMBOL_DRIVE +#define LV_SYMBOL_DRIVE "\xEF\x80\x9C" /*61468, 0xF01C*/ +#endif + +#if !defined LV_SYMBOL_REFRESH +#define LV_SYMBOL_REFRESH "\xEF\x80\xA1" /*61473, 0xF021*/ +#endif + +#if !defined LV_SYMBOL_MUTE +#define LV_SYMBOL_MUTE "\xEF\x80\xA6" /*61478, 0xF026*/ +#endif + +#if !defined LV_SYMBOL_VOLUME_MID +#define LV_SYMBOL_VOLUME_MID "\xEF\x80\xA7" /*61479, 0xF027*/ +#endif + +#if !defined LV_SYMBOL_VOLUME_MAX +#define LV_SYMBOL_VOLUME_MAX "\xEF\x80\xA8" /*61480, 0xF028*/ +#endif + +#if !defined LV_SYMBOL_IMAGE +#define LV_SYMBOL_IMAGE "\xEF\x80\xBE" /*61502, 0xF03E*/ +#endif + +#if !defined LV_SYMBOL_TINT +#define LV_SYMBOL_TINT "\xEF\x81\x83" /*61507, 0xF043*/ +#endif + +#if !defined LV_SYMBOL_PREV +#define LV_SYMBOL_PREV "\xEF\x81\x88" /*61512, 0xF048*/ +#endif + +#if !defined LV_SYMBOL_PLAY +#define LV_SYMBOL_PLAY "\xEF\x81\x8B" /*61515, 0xF04B*/ +#endif + +#if !defined LV_SYMBOL_PAUSE +#define LV_SYMBOL_PAUSE "\xEF\x81\x8C" /*61516, 0xF04C*/ +#endif + +#if !defined LV_SYMBOL_STOP +#define LV_SYMBOL_STOP "\xEF\x81\x8D" /*61517, 0xF04D*/ +#endif + +#if !defined LV_SYMBOL_NEXT +#define LV_SYMBOL_NEXT "\xEF\x81\x91" /*61521, 0xF051*/ +#endif + +#if !defined LV_SYMBOL_EJECT +#define LV_SYMBOL_EJECT "\xEF\x81\x92" /*61522, 0xF052*/ +#endif + +#if !defined LV_SYMBOL_LEFT +#define LV_SYMBOL_LEFT "\xEF\x81\x93" /*61523, 0xF053*/ +#endif + +#if !defined LV_SYMBOL_RIGHT +#define LV_SYMBOL_RIGHT "\xEF\x81\x94" /*61524, 0xF054*/ +#endif + +#if !defined LV_SYMBOL_PLUS +#define LV_SYMBOL_PLUS "\xEF\x81\xA7" /*61543, 0xF067*/ +#endif + +#if !defined LV_SYMBOL_MINUS +#define LV_SYMBOL_MINUS "\xEF\x81\xA8" /*61544, 0xF068*/ +#endif + +#if !defined LV_SYMBOL_EYE_OPEN +#define LV_SYMBOL_EYE_OPEN "\xEF\x81\xAE" /*61550, 0xF06E*/ +#endif + +#if !defined LV_SYMBOL_EYE_CLOSE +#define LV_SYMBOL_EYE_CLOSE "\xEF\x81\xB0" /*61552, 0xF070*/ +#endif + +#if !defined LV_SYMBOL_WARNING +#define LV_SYMBOL_WARNING "\xEF\x81\xB1" /*61553, 0xF071*/ +#endif + +#if !defined LV_SYMBOL_SHUFFLE +#define LV_SYMBOL_SHUFFLE "\xEF\x81\xB4" /*61556, 0xF074*/ +#endif + +#if !defined LV_SYMBOL_UP +#define LV_SYMBOL_UP "\xEF\x81\xB7" /*61559, 0xF077*/ +#endif + +#if !defined LV_SYMBOL_DOWN +#define LV_SYMBOL_DOWN "\xEF\x81\xB8" /*61560, 0xF078*/ +#endif + +#if !defined LV_SYMBOL_LOOP +#define LV_SYMBOL_LOOP "\xEF\x81\xB9" /*61561, 0xF079*/ +#endif + +#if !defined LV_SYMBOL_DIRECTORY +#define LV_SYMBOL_DIRECTORY "\xEF\x81\xBB" /*61563, 0xF07B*/ +#endif + +#if !defined LV_SYMBOL_UPLOAD +#define LV_SYMBOL_UPLOAD "\xEF\x82\x93" /*61587, 0xF093*/ +#endif + +#if !defined LV_SYMBOL_CALL +#define LV_SYMBOL_CALL "\xEF\x82\x95" /*61589, 0xF095*/ +#endif + +#if !defined LV_SYMBOL_CUT +#define LV_SYMBOL_CUT "\xEF\x83\x84" /*61636, 0xF0C4*/ +#endif + +#if !defined LV_SYMBOL_COPY +#define LV_SYMBOL_COPY "\xEF\x83\x85" /*61637, 0xF0C5*/ +#endif + +#if !defined LV_SYMBOL_SAVE +#define LV_SYMBOL_SAVE "\xEF\x83\x87" /*61639, 0xF0C7*/ +#endif + +#if !defined LV_SYMBOL_BARS +#define LV_SYMBOL_BARS "\xEF\x83\x89" /*61641, 0xF0C9*/ +#endif + +#if !defined LV_SYMBOL_ENVELOPE +#define LV_SYMBOL_ENVELOPE "\xEF\x83\xA0" /*61664, 0xF0E0*/ +#endif + +#if !defined LV_SYMBOL_CHARGE +#define LV_SYMBOL_CHARGE "\xEF\x83\xA7" /*61671, 0xF0E7*/ +#endif + +#if !defined LV_SYMBOL_PASTE +#define LV_SYMBOL_PASTE "\xEF\x83\xAA" /*61674, 0xF0EA*/ +#endif + +#if !defined LV_SYMBOL_BELL +#define LV_SYMBOL_BELL "\xEF\x83\xB3" /*61683, 0xF0F3*/ +#endif + +#if !defined LV_SYMBOL_KEYBOARD +#define LV_SYMBOL_KEYBOARD "\xEF\x84\x9C" /*61724, 0xF11C*/ +#endif + +#if !defined LV_SYMBOL_GPS +#define LV_SYMBOL_GPS "\xEF\x84\xA4" /*61732, 0xF124*/ +#endif + +#if !defined LV_SYMBOL_FILE +#define LV_SYMBOL_FILE "\xEF\x85\x9B" /*61787, 0xF158*/ +#endif + +#if !defined LV_SYMBOL_WIFI +#define LV_SYMBOL_WIFI "\xEF\x87\xAB" /*61931, 0xF1EB*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_FULL +#define LV_SYMBOL_BATTERY_FULL "\xEF\x89\x80" /*62016, 0xF240*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_3 +#define LV_SYMBOL_BATTERY_3 "\xEF\x89\x81" /*62017, 0xF241*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_2 +#define LV_SYMBOL_BATTERY_2 "\xEF\x89\x82" /*62018, 0xF242*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_1 +#define LV_SYMBOL_BATTERY_1 "\xEF\x89\x83" /*62019, 0xF243*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_EMPTY +#define LV_SYMBOL_BATTERY_EMPTY "\xEF\x89\x84" /*62020, 0xF244*/ +#endif + +#if !defined LV_SYMBOL_USB +#define LV_SYMBOL_USB "\xEF\x8a\x87" /*62087, 0xF287*/ +#endif + +#if !defined LV_SYMBOL_BLUETOOTH +#define LV_SYMBOL_BLUETOOTH "\xEF\x8a\x93" /*62099, 0xF293*/ +#endif + +#if !defined LV_SYMBOL_TRASH +#define LV_SYMBOL_TRASH "\xEF\x8B\xAD" /*62189, 0xF2ED*/ +#endif + +#if !defined LV_SYMBOL_EDIT +#define LV_SYMBOL_EDIT "\xEF\x8C\x84" /*62212, 0xF304*/ +#endif + +#if !defined LV_SYMBOL_BACKSPACE +#define LV_SYMBOL_BACKSPACE "\xEF\x95\x9A" /*62810, 0xF55A*/ +#endif + +#if !defined LV_SYMBOL_SD_CARD +#define LV_SYMBOL_SD_CARD "\xEF\x9F\x82" /*63426, 0xF7C2*/ +#endif + +#if !defined LV_SYMBOL_NEW_LINE +#define LV_SYMBOL_NEW_LINE "\xEF\xA2\xA2" /*63650, 0xF8A2*/ +#endif + +#if !defined LV_SYMBOL_DUMMY +/** Invalid symbol at (U+F8FF). If written before a string then `lv_img` will show it as a label*/ +#define LV_SYMBOL_DUMMY "\xEF\xA3\xBF" +#endif + +/* + * The following list is generated using + * cat src/font/lv_symbol_def.h | sed -E -n 's/^#define\s+LV_(SYMBOL_\w+).*".*$/ _LV_STR_\1,/p' + */ +enum { + _LV_STR_SYMBOL_BULLET, + _LV_STR_SYMBOL_AUDIO, + _LV_STR_SYMBOL_VIDEO, + _LV_STR_SYMBOL_LIST, + _LV_STR_SYMBOL_OK, + _LV_STR_SYMBOL_CLOSE, + _LV_STR_SYMBOL_POWER, + _LV_STR_SYMBOL_SETTINGS, + _LV_STR_SYMBOL_HOME, + _LV_STR_SYMBOL_DOWNLOAD, + _LV_STR_SYMBOL_DRIVE, + _LV_STR_SYMBOL_REFRESH, + _LV_STR_SYMBOL_MUTE, + _LV_STR_SYMBOL_VOLUME_MID, + _LV_STR_SYMBOL_VOLUME_MAX, + _LV_STR_SYMBOL_IMAGE, + _LV_STR_SYMBOL_TINT, + _LV_STR_SYMBOL_PREV, + _LV_STR_SYMBOL_PLAY, + _LV_STR_SYMBOL_PAUSE, + _LV_STR_SYMBOL_STOP, + _LV_STR_SYMBOL_NEXT, + _LV_STR_SYMBOL_EJECT, + _LV_STR_SYMBOL_LEFT, + _LV_STR_SYMBOL_RIGHT, + _LV_STR_SYMBOL_PLUS, + _LV_STR_SYMBOL_MINUS, + _LV_STR_SYMBOL_EYE_OPEN, + _LV_STR_SYMBOL_EYE_CLOSE, + _LV_STR_SYMBOL_WARNING, + _LV_STR_SYMBOL_SHUFFLE, + _LV_STR_SYMBOL_UP, + _LV_STR_SYMBOL_DOWN, + _LV_STR_SYMBOL_LOOP, + _LV_STR_SYMBOL_DIRECTORY, + _LV_STR_SYMBOL_UPLOAD, + _LV_STR_SYMBOL_CALL, + _LV_STR_SYMBOL_CUT, + _LV_STR_SYMBOL_COPY, + _LV_STR_SYMBOL_SAVE, + _LV_STR_SYMBOL_BARS, + _LV_STR_SYMBOL_ENVELOPE, + _LV_STR_SYMBOL_CHARGE, + _LV_STR_SYMBOL_PASTE, + _LV_STR_SYMBOL_BELL, + _LV_STR_SYMBOL_KEYBOARD, + _LV_STR_SYMBOL_GPS, + _LV_STR_SYMBOL_FILE, + _LV_STR_SYMBOL_WIFI, + _LV_STR_SYMBOL_BATTERY_FULL, + _LV_STR_SYMBOL_BATTERY_3, + _LV_STR_SYMBOL_BATTERY_2, + _LV_STR_SYMBOL_BATTERY_1, + _LV_STR_SYMBOL_BATTERY_EMPTY, + _LV_STR_SYMBOL_USB, + _LV_STR_SYMBOL_BLUETOOTH, + _LV_STR_SYMBOL_TRASH, + _LV_STR_SYMBOL_EDIT, + _LV_STR_SYMBOL_BACKSPACE, + _LV_STR_SYMBOL_SD_CARD, + _LV_STR_SYMBOL_NEW_LINE, + _LV_STR_SYMBOL_DUMMY, +}; + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_SYMBOL_DEF_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal.h b/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal.h new file mode 100644 index 00000000..167da1f4 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal.h @@ -0,0 +1,48 @@ +/** + * @file lv_hal.h + * + */ + +#ifndef LV_HAL_H +#define LV_HAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_hal_disp.h" +#include "lv_hal_indev.h" +#include "lv_hal_tick.h" + +/********************* + * DEFINES + *********************/ +/** + * Same as Android's DIP. (Different name is chosen to avoid mistype between LV_DPI and LV_DIP) + * 1 dip is 1 px on a 160 DPI screen + * 1 dip is 2 px on a 320 DPI screen + * https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dip-dp-and-sp + */ +#define _LV_DPX_CALC(dpi, n) ((n) == 0 ? 0 :LV_MAX((( (dpi) * (n) + 80) / 160), 1)) /*+80 for rounding*/ +#define LV_DPX(n) _LV_DPX_CALC(lv_disp_get_dpi(NULL), n) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_disp.h b/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_disp.h new file mode 100644 index 00000000..5b36916c --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_disp.h @@ -0,0 +1,371 @@ +/** + * @file lv_hal_disp.h + * + * @description Display Driver HAL interface header file + * + */ + +#ifndef LV_HAL_DISP_H +#define LV_HAL_DISP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include +#include "lv_hal.h" +#include "liblvgl/draw/lv_draw.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_ll.h" +#include "liblvgl/misc/lv_timer.h" + +/********************* + * DEFINES + *********************/ +#ifndef LV_INV_BUF_SIZE +#define LV_INV_BUF_SIZE 32 /*Buffer size for invalid areas*/ +#endif + +#ifndef LV_ATTRIBUTE_FLUSH_READY +#define LV_ATTRIBUTE_FLUSH_READY +#endif + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_disp_t; +struct _lv_disp_drv_t; +struct _lv_theme_t; + +/** + * Structure for holding display buffer information. + */ +typedef struct _lv_disp_draw_buf_t { + void * buf1; /**< First display buffer.*/ + void * buf2; /**< Second display buffer.*/ + + /*Internal, used by the library*/ + void * buf_act; + uint32_t size; /*In pixel count*/ + /*1: flushing is in progress. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ + volatile int flushing; + /*1: It was the last chunk to flush. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ + volatile int flushing_last; + volatile uint32_t last_area : 1; /*1: the last area is being rendered*/ + volatile uint32_t last_part : 1; /*1: the last part of the current area is being rendered*/ +} lv_disp_draw_buf_t; + +typedef enum { + LV_DISP_ROT_NONE = 0, + LV_DISP_ROT_90, + LV_DISP_ROT_180, + LV_DISP_ROT_270 +} lv_disp_rot_t; + +/** + * Display Driver structure to be registered by HAL. + * Only its pointer will be saved in `lv_disp_t` so it should be declared as + * `static lv_disp_drv_t my_drv` or allocated dynamically. + */ +typedef struct _lv_disp_drv_t { + + lv_coord_t hor_res; /**< Horizontal resolution.*/ + lv_coord_t ver_res; /**< Vertical resolution.*/ + + lv_coord_t + physical_hor_res; /**< Horizontal resolution of the full / physical display. Set to -1 for fullscreen mode.*/ + lv_coord_t + physical_ver_res; /**< Vertical resolution of the full / physical display. Set to -1 for fullscreen mode.*/ + lv_coord_t + offset_x; /**< Horizontal offset from the full / physical display. Set to 0 for fullscreen mode.*/ + lv_coord_t offset_y; /**< Vertical offset from the full / physical display. Set to 0 for fullscreen mode.*/ + + /** Pointer to a buffer initialized with `lv_disp_draw_buf_init()`. + * LVGL will use this buffer(s) to draw the screens contents*/ + lv_disp_draw_buf_t * draw_buf; + + uint32_t direct_mode : 1; /**< 1: Use screen-sized buffers and draw to absolute coordinates*/ + uint32_t full_refresh : 1; /**< 1: Always make the whole screen redrawn*/ + uint32_t sw_rotate : 1; /**< 1: use software rotation (slower)*/ + uint32_t antialiasing : 1; /**< 1: anti-aliasing is enabled on this display.*/ + uint32_t rotated : 2; /**< 1: turn the display by 90 degree. @warning Does not update coordinates for you!*/ + uint32_t screen_transp : 1; /**Handle if the screen doesn't have a solid (opa == LV_OPA_COVER) background. + * Use only if required because it's slower.*/ + + uint32_t dpi : 10; /** DPI (dot per inch) of the display. Default value is `LV_DPI_DEF`.*/ + + /** MANDATORY: Write the internal buffer (draw_buf) to the display. 'lv_disp_flush_ready()' has to be + * called when finished*/ + void (*flush_cb)(struct _lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); + + /** OPTIONAL: Extend the invalidated areas to match with the display drivers requirements + * E.g. round `y` to, 8, 16 ..) on a monochrome display*/ + void (*rounder_cb)(struct _lv_disp_drv_t * disp_drv, lv_area_t * area); + + /** OPTIONAL: Set a pixel in a buffer according to the special requirements of the display + * Can be used for color format not supported in LittelvGL. E.g. 2 bit -> 4 gray scales + * @note Much slower then drawing with supported color formats.*/ + void (*set_px_cb)(struct _lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, + lv_color_t color, lv_opa_t opa); + + void (*clear_cb)(struct _lv_disp_drv_t * disp_drv, uint8_t * buf, uint32_t size); + + + /** OPTIONAL: Called after every refresh cycle to tell the rendering and flushing time + the + * number of flushed pixels*/ + void (*monitor_cb)(struct _lv_disp_drv_t * disp_drv, uint32_t time, uint32_t px); + + /** OPTIONAL: Called periodically while lvgl waits for operation to be completed. + * For example flushing or GPU + * User can execute very simple tasks here or yield the task*/ + void (*wait_cb)(struct _lv_disp_drv_t * disp_drv); + + /** OPTIONAL: Called when lvgl needs any CPU cache that affects rendering to be cleaned*/ + void (*clean_dcache_cb)(struct _lv_disp_drv_t * disp_drv); + + /** OPTIONAL: called when driver parameters are updated */ + void (*drv_update_cb)(struct _lv_disp_drv_t * disp_drv); + + /** OPTIONAL: called when start rendering */ + void (*render_start_cb)(struct _lv_disp_drv_t * disp_drv); + + /** On CHROMA_KEYED images this color will be transparent. + * `LV_COLOR_CHROMA_KEY` by default. (lv_conf.h)*/ + lv_color_t color_chroma_key; + + lv_draw_ctx_t * draw_ctx; + void (*draw_ctx_init)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); + void (*draw_ctx_deinit)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); + size_t draw_ctx_size; + +#if LV_USE_USER_DATA + void * user_data; /**< Custom display driver user data*/ +#endif + +} lv_disp_drv_t; + +/** + * Display structure. + * @note `lv_disp_drv_t` should be the first member of the structure. + */ +typedef struct _lv_disp_t { + /**< Driver to the display*/ + struct _lv_disp_drv_t * driver; + + /**< A timer which periodically checks the dirty areas and refreshes them*/ + lv_timer_t * refr_timer; + + /**< The theme assigned to the screen*/ + struct _lv_theme_t * theme; + + /** Screens of the display*/ + struct _lv_obj_t ** screens; /**< Array of screen objects.*/ + struct _lv_obj_t * act_scr; /**< Currently active screen on this display*/ + struct _lv_obj_t * prev_scr; /**< Previous screen. Used during screen animations*/ + struct _lv_obj_t * scr_to_load; /**< The screen prepared to load in lv_scr_load_anim*/ + struct _lv_obj_t * top_layer; /**< @see lv_disp_get_layer_top*/ + struct _lv_obj_t * sys_layer; /**< @see lv_disp_get_layer_sys*/ + uint32_t screen_cnt; +uint8_t draw_prev_over_act : + 1; /**< 1: Draw previous screen over active screen*/ +uint8_t del_prev : + 1; /**< 1: Automatically delete the previous screen when the screen load animation is ready*/ + uint8_t rendering_in_progress : 1; /**< 1: The current screen rendering is in progress*/ + + lv_opa_t bg_opa; /**flush` you should use DMA or similar hardware to send + * the image to the display in the background. + * It lets LVGL to render next frame into the other buffer while previous is being + * sent. Set to `NULL` if unused. + * @param size_in_px_cnt size of the `buf1` and `buf2` in pixel count. + */ +void lv_disp_draw_buf_init(lv_disp_draw_buf_t * draw_buf, void * buf1, void * buf2, uint32_t size_in_px_cnt); + +/** + * Register an initialized display driver. + * Automatically set the first display as active. + * @param driver pointer to an initialized 'lv_disp_drv_t' variable. Only its pointer is saved! + * @return pointer to the new display or NULL on error + */ +lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver); + +/** + * Update the driver in run time. + * @param disp pointer to a display. (return value of `lv_disp_drv_register`) + * @param new_drv pointer to the new driver + */ +void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv); + +/** + * Remove a display + * @param disp pointer to display + */ +void lv_disp_remove(lv_disp_t * disp); + +/** + * Set a default display. The new screens will be created on it by default. + * @param disp pointer to a display + */ +void lv_disp_set_default(lv_disp_t * disp); + +/** + * Get the default display + * @return pointer to the default display + */ +lv_disp_t * lv_disp_get_default(void); + +/** + * Get the horizontal resolution of a display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal resolution of the display + */ +lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp); + +/** + * Get the vertical resolution of a display + * @param disp pointer to a display (NULL to use the default display) + * @return the vertical resolution of the display + */ +lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp); + +/** + * Get the full / physical horizontal resolution of a display + * @param disp pointer to a display (NULL to use the default display) + * @return the full / physical horizontal resolution of the display + */ +lv_coord_t lv_disp_get_physical_hor_res(lv_disp_t * disp); + +/** + * Get the full / physical vertical resolution of a display + * @param disp pointer to a display (NULL to use the default display) + * @return the full / physical vertical resolution of the display + */ +lv_coord_t lv_disp_get_physical_ver_res(lv_disp_t * disp); + +/** + * Get the horizontal offset from the full / physical display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal offset from the full / physical display + */ +lv_coord_t lv_disp_get_offset_x(lv_disp_t * disp); + +/** + * Get the vertical offset from the full / physical display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal offset from the full / physical display + */ +lv_coord_t lv_disp_get_offset_y(lv_disp_t * disp); + +/** + * Get if anti-aliasing is enabled for a display or not + * @param disp pointer to a display (NULL to use the default display) + * @return true: anti-aliasing is enabled; false: disabled + */ +bool lv_disp_get_antialiasing(lv_disp_t * disp); + +/** + * Get the DPI of the display + * @param disp pointer to a display (NULL to use the default display) + * @return dpi of the display + */ +lv_coord_t lv_disp_get_dpi(const lv_disp_t * disp); + + +/** + * Set the rotation of this display. + * @param disp pointer to a display (NULL to use the default display) + * @param rotation rotation angle + */ +void lv_disp_set_rotation(lv_disp_t * disp, lv_disp_rot_t rotation); + +/** + * Get the current rotation of this display. + * @param disp pointer to a display (NULL to use the default display) + * @return rotation angle + */ +lv_disp_rot_t lv_disp_get_rotation(lv_disp_t * disp); + +//! @cond Doxygen_Suppress + +/** + * Call in the display driver's `flush_cb` function when the flushing is finished + * @param disp_drv pointer to display driver in `flush_cb` where this function is called + */ +LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv); + +/** + * Tell if it's the last area of the refreshing process. + * Can be called from `flush_cb` to execute some special display refreshing if needed when all areas area flushed. + * @param disp_drv pointer to display driver + * @return true: it's the last area to flush; false: there are other areas too which will be refreshed soon + */ +LV_ATTRIBUTE_FLUSH_READY bool lv_disp_flush_is_last(lv_disp_drv_t * disp_drv); + +//! @endcond + +/** + * Get the next display. + * @param disp pointer to the current display. NULL to initialize. + * @return the next display or NULL if no more. Give the first display when the parameter is NULL + */ +lv_disp_t * lv_disp_get_next(lv_disp_t * disp); + +/** + * Get the internal buffer of a display + * @param disp pointer to a display + * @return pointer to the internal buffers + */ +lv_disp_draw_buf_t * lv_disp_get_draw_buf(lv_disp_t * disp); + +void lv_disp_drv_use_generic_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_indev.h b/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_indev.h new file mode 100644 index 00000000..630d471a --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_indev.h @@ -0,0 +1,239 @@ +/** + * @file lv_hal_indev.h + * + * @description Input Device HAL interface layer header file + * + */ + +#ifndef LV_HAL_INDEV_H +#define LV_HAL_INDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_timer.h" + +/********************* + * DEFINES + *********************/ + +/*Drag threshold in pixels*/ +#define LV_INDEV_DEF_SCROLL_LIMIT 10 + +/*Drag throw slow-down in [%]. Greater value -> faster slow-down*/ +#define LV_INDEV_DEF_SCROLL_THROW 10 + +/*Long press time in milliseconds. + *Time to send `LV_EVENT_LONG_PRESSSED`)*/ +#define LV_INDEV_DEF_LONG_PRESS_TIME 400 + +/*Repeated trigger period in long press [ms] + *Time between `LV_EVENT_LONG_PRESSED_REPEAT*/ +#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100 + + +/*Gesture threshold in pixels*/ +#define LV_INDEV_DEF_GESTURE_LIMIT 50 + +/*Gesture min velocity at release before swipe (pixels)*/ +#define LV_INDEV_DEF_GESTURE_MIN_VELOCITY 3 + + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_disp_t; +struct _lv_group_t; +struct _lv_indev_t; +struct _lv_indev_drv_t; + +/** Possible input device types*/ +typedef enum { + LV_INDEV_TYPE_NONE, /**< Uninitialized state*/ + LV_INDEV_TYPE_POINTER, /**< Touch pad, mouse, external button*/ + LV_INDEV_TYPE_KEYPAD, /**< Keypad or keyboard*/ + LV_INDEV_TYPE_BUTTON, /**< External (hardware button) which is assigned to a specific point of the screen*/ + LV_INDEV_TYPE_ENCODER, /**< Encoder with only Left, Right turn and a Button*/ +} lv_indev_type_t; + +/** States for input devices*/ +typedef enum { + LV_INDEV_STATE_RELEASED = 0, + LV_INDEV_STATE_PRESSED +} lv_indev_state_t; + +/** Data structure passed to an input driver to fill*/ +typedef struct { + lv_point_t point; /**< For LV_INDEV_TYPE_POINTER the currently pressed point*/ + uint32_t key; /**< For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ + uint32_t btn_id; /**< For LV_INDEV_TYPE_BUTTON the currently pressed button*/ + int16_t enc_diff; /**< For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/ + + lv_indev_state_t state; /**< LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ + bool continue_reading; /**< If set to true, the read callback is invoked again*/ +} lv_indev_data_t; + +/** Initialized by the user and registered by 'lv_indev_add()'*/ +typedef struct _lv_indev_drv_t { + + /**< Input device type*/ + lv_indev_type_t type; + + /**< Function pointer to read input device data.*/ + void (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data); + + /** Called when an action happened on the input device. + * The second parameter is the event from `lv_event_t`*/ + void (*feedback_cb)(struct _lv_indev_drv_t *, uint8_t); + +#if LV_USE_USER_DATA + void * user_data; +#endif + + /**< Pointer to the assigned display*/ + struct _lv_disp_t * disp; + + /**< Timer to periodically read the input device*/ + lv_timer_t * read_timer; + + /**< Number of pixels to slide before actually drag the object*/ + uint8_t scroll_limit; + + /**< Drag throw slow-down in [%]. Greater value means faster slow-down*/ + uint8_t scroll_throw; + + /**< At least this difference should be between two points to evaluate as gesture*/ + uint8_t gesture_min_velocity; + + /**< At least this difference should be to send a gesture*/ + uint8_t gesture_limit; + + /**< Long press time in milliseconds*/ + uint16_t long_press_time; + + /**< Repeated trigger period in long press [ms]*/ + uint16_t long_press_repeat_time; +} lv_indev_drv_t; + +/** Run time data of input devices + * Internally used by the library, you should not need to touch it. + */ +typedef struct _lv_indev_proc_t { + lv_indev_state_t state; /**< Current state of the input device.*/ + /*Flags*/ + uint8_t long_pr_sent : 1; + uint8_t reset_query : 1; + uint8_t disabled : 1; + uint8_t wait_until_release : 1; + + union { + struct { + /*Pointer and button data*/ + lv_point_t act_point; /**< Current point of input device.*/ + lv_point_t last_point; /**< Last point of input device.*/ + lv_point_t last_raw_point; /**< Last point read from read_cb. */ + lv_point_t vect; /**< Difference between `act_point` and `last_point`.*/ + lv_point_t scroll_sum; /*Count the dragged pixels to check LV_INDEV_DEF_SCROLL_LIMIT*/ + lv_point_t scroll_throw_vect; + lv_point_t scroll_throw_vect_ori; + struct _lv_obj_t * act_obj; /*The object being pressed*/ + struct _lv_obj_t * last_obj; /*The last object which was pressed*/ + struct _lv_obj_t * scroll_obj; /*The object being scrolled*/ + struct _lv_obj_t * last_pressed; /*The lastly pressed object*/ + lv_area_t scroll_area; + + lv_point_t gesture_sum; /*Count the gesture pixels to check LV_INDEV_DEF_GESTURE_LIMIT*/ + /*Flags*/ + lv_dir_t scroll_dir : 4; + lv_dir_t gesture_dir : 4; + uint8_t gesture_sent : 1; + } pointer; + struct { + /*Keypad data*/ + lv_indev_state_t last_state; + uint32_t last_key; + } keypad; + } types; + + uint32_t pr_timestamp; /**< Pressed time stamp*/ + uint32_t longpr_rep_timestamp; /**< Long press repeat time stamp*/ +} _lv_indev_proc_t; + +/** The main input device descriptor with driver, runtime data ('proc') and some additional + * information*/ +typedef struct _lv_indev_t { + struct _lv_indev_drv_t * driver; + _lv_indev_proc_t proc; + struct _lv_obj_t * cursor; /**< Cursor for LV_INPUT_TYPE_POINTER*/ + struct _lv_group_t * group; /**< Keypad destination group*/ + const lv_point_t * btn_points; /**< Array points assigned to the button ()screen will be pressed + here by the buttons*/ +} lv_indev_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize an input device driver with default values. + * It is used to surely have known values in the fields and not memory junk. + * After it you can set the fields. + * @param driver pointer to driver variable to initialize + */ +void lv_indev_drv_init(struct _lv_indev_drv_t * driver); + +/** + * Register an initialized input device driver. + * @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable) + * @return pointer to the new input device or NULL on error + */ +lv_indev_t * lv_indev_drv_register(struct _lv_indev_drv_t * driver); + +/** + * Update the driver in run time. + * @param indev pointer to an input device. (return value of `lv_indev_drv_register`) + * @param new_drv pointer to the new driver + */ +void lv_indev_drv_update(lv_indev_t * indev, struct _lv_indev_drv_t * new_drv); + +/** +* Remove the provided input device. Make sure not to use the provided input device afterwards anymore. +* @param indev pointer to delete +*/ +void lv_indev_delete(lv_indev_t * indev); + +/** + * Get the next input device. + * @param indev pointer to the current input device. NULL to initialize. + * @return the next input device or NULL if there are no more. Provide the first input device when + * the parameter is NULL + */ +lv_indev_t * lv_indev_get_next(lv_indev_t * indev); + +/** + * Read data from an input device. + * @param indev pointer to an input device + * @param data input device will write its data here + */ +void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/display/lv_hal/lv_hal_tick.h b/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_tick.h similarity index 84% rename from include/display/lv_hal/lv_hal_tick.h rename to EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_tick.h index c59ed0b2..407fa427 100644 --- a/include/display/lv_hal/lv_hal_tick.h +++ b/EZ-Template-Example-Project/include/liblvgl/hal/lv_hal_tick.h @@ -13,11 +13,8 @@ extern "C" { /********************* * INCLUDES *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif +#include "liblvgl/lv_conf_internal.h" + #include #include @@ -36,11 +33,17 @@ extern "C" { * GLOBAL PROTOTYPES **********************/ +//! @cond Doxygen_Suppress + +#if !LV_TICK_CUSTOM /** * You have to call this function periodically * @param tick_period the call period of this function in milliseconds */ LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period); +#endif + +//! @endcond /** * Get the elapsed milliseconds since start up @@ -50,7 +53,7 @@ uint32_t lv_tick_get(void); /** * Get the elapsed milliseconds since a previous time stamp - * @param prev_tick a previous time stamp (return value of systick_get() ) + * @param prev_tick a previous time stamp (return value of lv_tick_get() ) * @return the elapsed milliseconds since 'prev_tick' */ uint32_t lv_tick_elaps(uint32_t prev_tick); @@ -60,7 +63,7 @@ uint32_t lv_tick_elaps(uint32_t prev_tick); **********************/ #ifdef __cplusplus -} /* extern "C" */ +} /*extern "C"*/ #endif -#endif /*LV_HAL_TICK_H*/ +#endif /*LV_HAL_TICK_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/llemu.h b/EZ-Template-Example-Project/include/liblvgl/llemu.h new file mode 100644 index 00000000..c3c4e6dc --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/llemu.h @@ -0,0 +1,438 @@ +/** + * \file liblvgl/llemu.h + * \ingroup c-llemu + * + * Legacy LCD Emulator + * + * \details This file defines a high-level API for emulating the three-button, UART-based + * VEX LCD, containing a set of functions that facilitate the use of a software- + * emulated version of the classic VEX LCD module. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-llemu LLEMU C API + * @{ + * LLEMU - Legacy Lcd EMUlator + * + * \image html llemu/llemu-3.8.png + * + * LLEMU provides a virtual 40x8 LCD screen with 3 buttons. The user can set the + * text of the screen and set create functions that are run when the buttons are + * pressed. + * + * LLEMU is a emulation of the UART-based LCD screens that were available with + * VEX's cortex product line. + * @} + */ + +#ifndef _LIBLVGL_LLEMU_H_ +#define _LIBLVGL_LLEMU_H_ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#include "liblvgl/lvgl.h" +#pragma GCC diagnostic pop + +#ifdef __cplusplus +extern "C" { +namespace pros { +#endif + +typedef void (*lcd_btn_cb_fn_t)(void); + +#define LCD_BTN_LEFT 4 +#define LCD_BTN_CENTER 2 +#define LCD_BTN_RIGHT 1 + +typedef struct lcd_s { + lv_obj_t* frame; + lv_obj_t* screen; + lv_obj_t* lcd_text[8]; + lv_obj_t* btn_container; + lv_obj_t* btns[3]; // < 0 => left; 1 => center; 2 => right + lcd_btn_cb_fn_t callbacks[3]; // < 0 => left; 1 => center; 2 => right + volatile uint8_t touch_bits; // < 4 => left; 2 => center; 1 => right (no + // multitouch support) +} lcd_s_t; + +/** + * \ingroup c-llemu + */ + +/** + * \addtogroup c-llemu + * @{ + */ + +/** + * \enum lcd_text_align_e + * + * @brief Represents how to align the text in the LCD + */ +typedef enum lcd_text_align_e { + /// Align the text to the left side of LCD line + LCD_TEXT_ALIGN_LEFT = 0, + /// Align the text to the center of the LCD line + LCD_TEXT_ALIGN_CENTER = 1, + /// Align the text to the right side of the LCD line + LCD_TEXT_ALIGN_RIGHT = 2 +} text_align_e_t; + +/// @} + +#ifdef __cplusplus + +/** + * \ingroup c-llemu + */ +namespace c { +#endif + +/** + * \ingroup c-llemu + */ + +/** + * \addtogroup c-llemu + * @{ + */ + +/** + * Checks whether the emulated three-button LCD has already been initialized. + * + * \return True if the LCD has been initialized or false if not. + * + * \b Example + * \code + * if (pros::c::lcd_is_initialized()) { + * pros::c::lcd_print("LLEMU!"); + * } + * else { + * printf("Error: LLEMU is not initialized\n"); + * } + * \endcode + */ +bool lcd_is_initialized(void); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * if (pros::c::lcd_initialize()) { + * pros::c::lcd_print("LLEMU!"); + * } + * else { + * printf("Error: LLEMU could not initailize\n"); + * } + * } + * \endcode + */ +bool lcd_initialize(void); + +/** + * Turns 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 lcd_initialize. + * + * 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. + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void disabled() { + * pros::c::lcd_shutdown(); + * } + * \endcode + */ +bool lcd_shutdown(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. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_print(0, "My formatted text: %d!", 2); + * } + * \endcode + */ +bool lcd_print(int16_t line, const char* fmt, ...); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_set_text(0, "My custom LLEMU text!"); + * } + * \endcode + */ +bool lcd_set_text(int16_t line, const char* text); + +/** + * Clears the contents 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] + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_clear(); // Clear the LCD screen + * } + * \endcode + */ +bool lcd_clear(void); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_clear_line(0); // Clear line 0 + * } + * \endcode + */ +bool lcd_clear_line(int16_t line); + +/** + * Registers 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. + * + * 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void left_callback() { + * static int i = 0; + * + * i++; + * pros::c::lcd_print(0, "Left button pressed %i times", i); + * } + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_register_btn0_cb(); + * } + * \endcode + */ +bool lcd_register_btn0_cb(lcd_btn_cb_fn_t cb); + +/** + * Registers 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. + * + * 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void center_callback() { + * static int i = 0; + * + * i++; + * pros::c::lcd_print(0, "Center button pressed %i times", i); + * } + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_register_btn1_cb(); + * } + * \endcode + */ +bool lcd_register_btn1_cb(lcd_btn_cb_fn_t cb); + +/** + * 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. + * + * 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void right_callback() { + * static int i = 0; + * + * i++; + * pros::c::lcd_print(0, "Right button pressed %i times", i); + * } + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_register_btn2_cb(); + * } + * \endcode + */ +bool lcd_register_btn2_cb(lcd_btn_cb_fn_t cb); + +/** + * 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 + */ +uint8_t lcd_read_buttons(void); + +/** + * Changes the alignment of text on the LCD background + * + * \param alignment + * An enum specifying the alignment. Available alignments are: + * TEXT_ALIGN_LEFT + * TEXT_ALIGN_RIGHT + * TEXT_ALIGN_CENTER + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_set_alignment(pros::c::lcd_Text_Align::LEFT); + * pros::c::lcd_print(0, "Left Aligned Text"); + * pros::c::lcd_set_alignment(pros::c::lcd_Text_Align::CENTER); + * pros::c::lcd_print(1, "Center Aligned Text"); + * pros::c::lcd_set_alignment(pros::c::lcd_Text_Align::RIGHT); + * pros::c::lcd_print(2, "Right Aligned Text"); + * } + * \endcode + */ +void lcd_set_text_align(text_align_e_t alignment); + + +///@} + +#ifdef __cplusplus +} // namespace c +} // namespace pros +} // extern "C" +#endif +#endif // _LIBLVGL_LLEMU_H_ diff --git a/EZ-Template-Example-Project/include/liblvgl/llemu.hpp b/EZ-Template-Example-Project/include/liblvgl/llemu.hpp new file mode 100644 index 00000000..78d31934 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/llemu.hpp @@ -0,0 +1,373 @@ +/** + * \file liblvgl/llemu.hpp + * + * \ingroup cpp-llemu + * + * Legacy LCD Emulator + * + * \details This file defines a high-level API for emulating the three-button, UART-based + * VEX LCD, containing a set of functions that facilitate the use of a software- + * emulated version of the classic VEX LCD module. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-llemu LLEMU C++ API + * @{ + * LLEMU - Legacy Lcd EMUlator + * + * \image html llemu/llemu-3.8.png + * + * LLEMU provides a virtual 40x8 LCD screen with 3 buttons. The user can set the + * text of the screen and set create functions that are run when the buttons are + * pressed. + * + * LLEMU is a emulation of the UART-based LCD screens that were available with + * VEX's cortex product line. + * @} + */ + +#ifndef _LIBLVGL_LLEMU_HPP_ +#define _LIBLVGL_LLEMU_HPP_ + +#include +#include + +#include "liblvgl/llemu.h" + +namespace pros { + +/** + * \ingroup cpp-llemu + */ +namespace lcd { + +/** + * \ingroup cpp-llemu + */ + +/** + * \addtogroup cpp-llemu + * @{ + */ + +/** + * \enum Text_Align + * + * @brief Represents how to align the text in the LCD + */ +enum class Text_Align { + /// Align the text to the left side of LCD line + LEFT = 0, + /// Align the text to the center of the LCD line + CENTER = 1, + /// Align the text to the right side of the LCD line + RIGHT = 2 +}; + +/** + * Checks whether the emulated three-button LCD has already been initialized. + * + * \return True if the LCD has been initialized or false if not. + * + * \b Example + * \code + * if (pros::lcd::is_initialized()) { + * pros::lcd::print("LLEMU!"); + * } + * else { + * printf("Error: LLEMU is not initialized\n"); + * } + * \endcode + */ +bool is_initialized(void); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * if (pros::lcd::initialize()) { + * pros::lcd::print("LLEMU!"); + * } + * else { + * printf("Error: LLEMU could not initailize\n"); + * } + * } + * \endcode + */ +bool initialize(void); + +/** + * Turns 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 lcd_initialize. + * + * 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. + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void disabled() { + * pros::lcd::shutdown(); + * } + * \endcode + */ +bool shutdown(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. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::set_text(0, "My custom LLEMU text!"); + * } + * \endcode + */ +bool set_text(std::int16_t line, std::string text); + +/** + * Clears the contents 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] + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::clear(); // Clear the LCD screen + * } + * \endcode + */ +bool clear(void); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::clear_line(0); // Clear line 0 + * } + * \endcode + */ +bool clear_line(std::int16_t line); + +using lcd_btn_cb_fn_t = void (*)(void); + +/** + * Registers 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t(void (*cb)(void)) + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void left_callback() { + * static int i = 0; + * + * pros::lcd::print(0, "Left button pressed %i times", i); + * i++ + * } + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::register_btn0_cb(); + * } + * \endcode + */ +void register_btn0_cb(lcd_btn_cb_fn_t cb); + +/** + * Registers 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t(void (*cb)(void)) + * + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void center_callback() { + * static int i = 0; + * + * pros::lcd::print(0, "Center button pressed %i times", i); + * i++ + * } + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::register_btn1_cb(); + * } + * \endcode + */ +void register_btn1_cb(lcd_btn_cb_fn_t cb); + +/** + * 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)) + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void right_callback() { + * static int i = 0; + * + * pros::lcd::print(0, "Right button pressed %i times", i); + * i++ + * } + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::register_btn2_cb(); + * } + * \endcode + */ +void register_btn2_cb(lcd_btn_cb_fn_t cb); + +/** + * Sets the alignment to use for subsequent calls that print text to a line. + * + * \param alignment + * An enum specifying the alignment. Available alignments are: + * TEXT_ALIGN_LEFT + * TEXT_ALIGN_RIGHT + * TEXT_ALIGN_CENTER + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::set_alignment(pros::lcd::Text_Align::LEFT); + * pros::lcd::print(0, "Left Aligned Text"); + * pros::lcd::set_alignment(pros::lcd::Text_Align::CENTER); + * pros::lcd::print(1, "Center Aligned Text"); + * pros::lcd::set_alignment(pros::lcd::Text_Align::RIGHT); + * pros::lcd::print(2, "Right Aligned Text"); + * } + * \endcode + */ +void set_text_align(Text_Align alignment); + +/** + * 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 + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * } + * + * void opcontrol() { + * while(true) { + * std::uint8_t state = pros::lcd::read_buttons(); + * pros::lcd::print(0, "%d %d %d", + * (state & LCD_BTN_LEFT) >> 2 + * (state & LCD_BTN_CENTER) >> 1, + * (state & LCD_BTN_RIGHT) >> 0 + * ); + * + * pros::delay(10); + * } + * } + * \endcode + */ +std::uint8_t read_buttons(void); + +///@} + +} // namespace lcd +} // namespace pros + + +#endif // _LIBLVGL_LLEMU_HPP_ diff --git a/EZ-Template-Example-Project/include/liblvgl/lv_api_map.h b/EZ-Template-Example-Project/include/liblvgl/lv_api_map.h new file mode 100644 index 00000000..c1b9e8d8 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/lv_api_map.h @@ -0,0 +1,88 @@ +/** + * @file lv_api_map.h + * + */ + +#ifndef LV_API_MAP_H +#define LV_API_MAP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +/********************* + * DEFINES + *********************/ + +#define LV_NO_TASK_READY LV_NO_TIMER_READY +#define LV_INDEV_STATE_REL LV_INDEV_STATE_RELEASED +#define LV_INDEV_STATE_PR LV_INDEV_STATE_PRESSED +#define LV_OBJ_FLAG_SNAPABLE LV_OBJ_FLAG_SNAPPABLE /*Fixed typo*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_task_handler(void) +{ + return lv_timer_handler(); +} + +/********************** + * MACROS + **********************/ + + +/********************** + * INLINE FUNCTIONS + **********************/ + +/** + * Move the object to the foreground. + * It will look like if it was created as the last child of its parent. + * It also means it can cover any of the siblings. + * @param obj pointer to an object + */ +static inline void lv_obj_move_foreground(lv_obj_t * obj) +{ + lv_obj_t * parent = lv_obj_get_parent(obj); + lv_obj_move_to_index(obj, lv_obj_get_child_cnt(parent) - 1); +} + +/** + * Move the object to the background. + * It will look like if it was created as the first child of its parent. + * It also means any of the siblings can cover the object. + * @param obj pointer to an object + */ +static inline void lv_obj_move_background(lv_obj_t * obj) +{ + lv_obj_move_to_index(obj, 0); +} + + + +/********************** + * DEPRECATED FUNCTIONS + **********************/ + +static inline uint32_t lv_obj_get_child_id(const struct _lv_obj_t * obj) +{ + LV_LOG_WARN("lv_obj_get_child_id(obj) is deprecated, please use lv_obj_get_index(obj)."); + return lv_obj_get_index(obj); +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_API_MAP_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/lv_conf.h b/EZ-Template-Example-Project/include/liblvgl/lv_conf.h new file mode 100644 index 00000000..a7b8bf08 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/lv_conf.h @@ -0,0 +1,777 @@ +/** + * @file lv_conf.h + * Configuration file for v7.11.0 + */ + +/* + * COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER + */ + +#if 1 /*Set it to "1" to enable content*/ + +#ifndef LV_CONF_H +#define LV_CONF_H +/* clang-format off */ + +#include + +/*==================== + Graphical settings + *====================*/ + +/* Maximal horizontal and vertical resolution to support by the library.*/ +#define LV_HOR_RES_MAX (480) +#define LV_VER_RES_MAX (240) + +/* Color depth: + * - 1: 1 byte per pixel + * - 8: RGB332 + * - 16: RGB565 + * - 32: ARGB8888 + */ +#define LV_COLOR_DEPTH 32 + +/* Swap the 2 bytes of RGB565 color. + * Useful if the display has a 8 bit interface (e.g. SPI)*/ +#define LV_COLOR_16_SWAP 0 + +/* 1: Enable screen transparency. + * Useful for OSD or other overlapping GUIs. + * Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/ +#define LV_COLOR_SCREEN_TRANSP 0 + +/*Images pixels with this color will not be drawn (with chroma keying)*/ +#define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/ + +/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ +#define LV_ANTIALIAS 1 + +/* Default display refresh period. + * Can be changed in the display driver (`lv_disp_drv_t`).*/ +#define LV_DISP_DEF_REFR_PERIOD 40 /*[ms]*/ + +/* Dot Per Inch: used to initialize default sizes. + * E.g. a button with width = LV_DPI / 2 -> half inch wide + * (Not so important, you can adjust it to modify default sizes and spaces)*/ +#define LV_DPI 126 /*[px]*/ + +/* The the real width of the display changes some default values: + * default object sizes, layout of examples, etc. + * According to the width of the display (hor. res. / dpi) + * the displays fall in 4 categories. + * The 4th is extra large which has no upper limit so not listed here + * The upper limit of the categories are set below in 0.1 inch unit. + */ +#define LV_DISP_SMALL_LIMIT 30 +#define LV_DISP_MEDIUM_LIMIT 50 +#define LV_DISP_LARGE_LIMIT 70 + +/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */ +typedef int16_t lv_coord_t; + +/* Maximum buffer size to allocate for rotation. Only used if software rotation is enabled. */ +#define LV_DISP_ROT_MAX_BUF (10U * 1024U) + +/*========================= + Memory manager settings + *=========================*/ + +/* LittelvGL's internal memory manager's settings. + * The graphical objects and other related data are stored here. */ + +/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */ +#define LV_MEM_CUSTOM 0 +#if LV_MEM_CUSTOM == 0 +/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ +# define LV_MEM_SIZE (32U * 1024U) + +/* Compiler prefix for a big array declaration */ +# define LV_MEM_ATTR + +/* Set an address for the memory pool instead of allocating it as an array. + * Can be in external SRAM too. */ +# define LV_MEM_ADR 0 + +/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */ +# define LV_MEM_AUTO_DEFRAG 1 +#else /*LV_MEM_CUSTOM*/ +# define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ +# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ +# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ +#endif /*LV_MEM_CUSTOM*/ + +/* Use the standard memcpy and memset instead of LVGL's own functions. + * The standard functions might or might not be faster depending on their implementation. */ +#define LV_MEMCPY_MEMSET_STD 0 + +/* Garbage Collector settings + * Used if lvgl is binded to higher level language and the memory is managed by that language */ +#define LV_ENABLE_GC 0 +#if LV_ENABLE_GC != 0 +# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ +# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/ +# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/ +#endif /* LV_ENABLE_GC */ + +/*======================= + Input device settings + *=======================*/ + +/* Input device default settings. + * Can be changed in the Input device driver (`lv_indev_drv_t`)*/ + +/* Input device read period in milliseconds */ +#define LV_INDEV_DEF_READ_PERIOD 50 + +/* Drag threshold in pixels */ +#define LV_INDEV_DEF_DRAG_LIMIT 10 + +/* Drag throw slow-down in [%]. Greater value -> faster slow-down */ +#define LV_INDEV_DEF_DRAG_THROW 20 + +/* Long press time in milliseconds. + * Time to send `LV_EVENT_LONG_PRESSED`) */ +#define LV_INDEV_DEF_LONG_PRESS_TIME 400 + +/* Repeated trigger period in long press [ms] + * Time between `LV_EVENT_LONG_PRESSED_REPEAT */ +#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100 + +/* Gesture threshold in pixels */ +#define LV_INDEV_DEF_GESTURE_LIMIT 50 + +/* Gesture min velocity at release before swipe (pixels)*/ +#define LV_INDEV_DEF_GESTURE_MIN_VELOCITY 3 + +/*================== + * Feature usage + *==================*/ + +/*1: Enable the Animations */ +#define LV_USE_ANIMATION 1 +#if LV_USE_ANIMATION + +/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_anim_user_data_t; + +#endif + +/* 1: Enable shadow drawing on rectangles*/ +#define LV_USE_SHADOW 1 +#if LV_USE_SHADOW +/* Allow buffering some shadow calculation + * LV_SHADOW_CACHE_SIZE is the max. shadow size to buffer, + * where shadow size is `shadow_width + radius` + * Caching has LV_SHADOW_CACHE_SIZE^2 RAM cost*/ +#define LV_SHADOW_CACHE_SIZE 0 +#endif + +/*1: enable outline drawing on rectangles*/ +#define LV_USE_OUTLINE 1 + +/*1: enable pattern drawing on rectangles*/ +#define LV_USE_PATTERN 1 + +/*1: enable value string drawing on rectangles*/ +#define LV_USE_VALUE_STR 1 + +/* 1: Use other blend modes than normal (`LV_BLEND_MODE_...`)*/ +#define LV_USE_BLEND_MODES 1 + +/* 1: Use the `opa_scale` style property to set the opacity of an object and its children at once*/ +#define LV_USE_OPA_SCALE 1 + +/* 1: Use image zoom and rotation*/ +#define LV_USE_IMG_TRANSFORM 1 + +/* 1: Enable object groups (for keyboard/encoder navigation) */ +#define LV_USE_GROUP 1 +#if LV_USE_GROUP +typedef void * lv_group_user_data_t; +#endif /*LV_USE_GROUP*/ + +/* 1: Enable GPU interface*/ +#define LV_USE_GPU 0 /*Only enables `gpu_fill_cb` and `gpu_blend_cb` in the disp. drv- */ +#define LV_USE_GPU_STM32_DMA2D 0 +/*If enabling LV_USE_GPU_STM32_DMA2D, LV_GPU_DMA2D_CMSIS_INCLUDE must be defined to include path of CMSIS header of target processor +e.g. "stm32f769xx.h" or "stm32f429xx.h" */ +#define LV_GPU_DMA2D_CMSIS_INCLUDE + +/*1: Use PXP for CPU off-load on NXP RTxxx platforms */ +#define LV_USE_GPU_NXP_PXP 0 + +/*1: Add default bare metal and FreeRTOS interrupt handling routines for PXP (lv_gpu_nxp_pxp_osa.c) + * and call lv_gpu_nxp_pxp_init() automatically during lv_init(). Note that symbol FSL_RTOS_FREE_RTOS + * has to be defined in order to use FreeRTOS OSA, otherwise bare-metal implementation is selected. + *0: lv_gpu_nxp_pxp_init() has to be called manually before lv_init() + * */ +#define LV_USE_GPU_NXP_PXP_AUTO_INIT 0 + +/*1: Use VG-Lite for CPU offload on NXP RTxxx platforms */ +#define LV_USE_GPU_NXP_VG_LITE 0 + +/* 1: Enable file system (might be required for images */ +#define LV_USE_FILESYSTEM 1 +#if LV_USE_FILESYSTEM +/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_fs_drv_user_data_t; +#endif + +/*1: Add a `user_data` to drivers and objects*/ +#define LV_USE_USER_DATA 1 + +/*1: Show CPU usage and FPS count in the right bottom corner*/ +#define LV_USE_PERF_MONITOR 0 + +/*1: Use the functions and types from the older API if possible */ +#define LV_USE_API_EXTENSION_V6 1 +#define LV_USE_API_EXTENSION_V7 1 + +/*======================== + * Image decoder and cache + *========================*/ + +/* 1: Enable indexed (palette) images */ +#define LV_IMG_CF_INDEXED 1 + +/* 1: Enable alpha indexed images */ +#define LV_IMG_CF_ALPHA 1 + +/* Default image cache size. Image caching keeps the images opened. + * If only the built-in image formats are used there is no real advantage of caching. + * (I.e. no new image decoder is added) + * With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images. + * However the opened images might consume additional RAM. + * Set it to 0 to disable caching */ +#define LV_IMG_CACHE_DEF_SIZE 1 + +/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_img_decoder_user_data_t; + +/*===================== + * Compiler settings + *====================*/ + +/* For big endian systems set to 1 */ +#define LV_BIG_ENDIAN_SYSTEM 0 + +/* Define a custom attribute to `lv_tick_inc` function */ +#define LV_ATTRIBUTE_TICK_INC + +/* Define a custom attribute to `lv_task_handler` function */ +#define LV_ATTRIBUTE_TASK_HANDLER + +/* Define a custom attribute to `lv_disp_flush_ready` function */ +#define LV_ATTRIBUTE_FLUSH_READY + +/* Required alignment size for buffers */ +#define LV_ATTRIBUTE_MEM_ALIGN_SIZE + +/* With size optimization (-Os) the compiler might not align data to + * 4 or 8 byte boundary. Some HW may need even 32 or 64 bytes. + * This alignment will be explicitly applied where needed. + * LV_ATTRIBUTE_MEM_ALIGN_SIZE should be used to specify required align size. + * E.g. __attribute__((aligned(LV_ATTRIBUTE_MEM_ALIGN_SIZE))) */ +#define LV_ATTRIBUTE_MEM_ALIGN + +/* Attribute to mark large constant arrays for example + * font's bitmaps */ +#define LV_ATTRIBUTE_LARGE_CONST + +/* Prefix performance critical functions to place them into a faster memory (e.g RAM) + * Uses 15-20 kB extra memory */ +#define LV_ATTRIBUTE_FAST_MEM + +/* Export integer constant to binding. + * This macro is used with constants in the form of LV_ that + * should also appear on lvgl binding API such as Micropython + * + * The default value just prevents a GCC warning. + */ +#define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning + +/* Prefix variables that are used in GPU accelerated operations, often these need to be + * placed in RAM sections that are DMA accessible */ +#define LV_ATTRIBUTE_DMA + +/*=================== + * HAL settings + *==================*/ + +/* 1: use a custom tick source. + * It removes the need to manually update the tick with `lv_tick_inc`) */ +#define LV_TICK_CUSTOM 0 +#if LV_TICK_CUSTOM == 1 +#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ +#endif /*LV_TICK_CUSTOM*/ + +typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ +typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/ + +/*================ + * Log settings + *===============*/ + +/*1: Enable the log module*/ +#define LV_USE_LOG 0 +#if LV_USE_LOG +/* How important log should be added: + * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information + * LV_LOG_LEVEL_INFO Log important events + * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem + * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail + * LV_LOG_LEVEL_NONE Do not log anything + */ +# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN + +/* 1: Print the log with 'printf'; + * 0: user need to register a callback with `lv_log_register_print_cb`*/ +# define LV_LOG_PRINTF 0 +#endif /*LV_USE_LOG*/ + +/*================= + * Debug settings + *================*/ + +/* If Debug is enabled LittelvGL validates the parameters of the functions. + * If an invalid parameter is found an error log message is printed and + * the MCU halts at the error. (`LV_USE_LOG` should be enabled) + * If you are debugging the MCU you can pause + * the debugger to see exactly where the issue is. + * + * The behavior of asserts can be overwritten by redefining them here. + * E.g. #define LV_ASSERT_MEM(p) + */ +#define LV_USE_DEBUG 1 +#if LV_USE_DEBUG + +/*Check if the parameter is NULL. (Quite fast) */ +#define LV_USE_ASSERT_NULL 1 + +/*Checks is the memory is successfully allocated or no. (Quite fast)*/ +#define LV_USE_ASSERT_MEM 1 + +/*Check the integrity of `lv_mem` after critical operations. (Slow)*/ +#define LV_USE_ASSERT_MEM_INTEGRITY 0 + +/* Check the strings. + * Search for NULL, very long strings, invalid characters, and unnatural repetitions. (Slow) + * If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) */ +#define LV_USE_ASSERT_STR 0 + +/* Check NULL, the object's type and existence (e.g. not deleted). (Quite slow) + * If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) */ +#define LV_USE_ASSERT_OBJ 0 + +/*Check if the styles are properly initialized. (Fast)*/ +#define LV_USE_ASSERT_STYLE 0 + +#endif /*LV_USE_DEBUG*/ + +/*================== + * FONT USAGE + *===================*/ + +/* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel. + * The symbols are available via `LV_SYMBOL_...` defines + * More info about fonts: https://docs.lvgl.io/v7/en/html/overview/font.html + * To create a new font go to: https://lvgl.com/ttf-font-to-c-array + */ + +/* Montserrat fonts with bpp = 4 + * https://fonts.google.com/specimen/Montserrat */ +#define LV_FONT_MONTSERRAT_8 0 +#define LV_FONT_MONTSERRAT_10 1 +#define LV_FONT_MONTSERRAT_12 1 +#define LV_FONT_MONTSERRAT_14 1 +#define LV_FONT_MONTSERRAT_16 1 +#define LV_FONT_MONTSERRAT_18 1 +#define LV_FONT_MONTSERRAT_20 1 +#define LV_FONT_MONTSERRAT_22 0 +#define LV_FONT_MONTSERRAT_24 1 +#define LV_FONT_MONTSERRAT_26 0 +#define LV_FONT_MONTSERRAT_28 0 +#define LV_FONT_MONTSERRAT_30 1 +#define LV_FONT_MONTSERRAT_32 0 +#define LV_FONT_MONTSERRAT_34 0 +#define LV_FONT_MONTSERRAT_36 1 +#define LV_FONT_MONTSERRAT_38 0 +#define LV_FONT_MONTSERRAT_40 1 +#define LV_FONT_MONTSERRAT_42 1 +#define LV_FONT_MONTSERRAT_44 0 +#define LV_FONT_MONTSERRAT_46 0 +#define LV_FONT_MONTSERRAT_48 1 + +/* Demonstrate special features */ +#define LV_FONT_MONTSERRAT_12_SUBPX 0 +#define LV_FONT_MONTSERRAT_28_COMPRESSED 0 /*bpp = 3*/ +#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0 /*Hebrew, Arabic, PErisan letters and all their forms*/ +#define LV_FONT_SIMSUN_16_CJK 0 /*1000 most common CJK radicals*/ + +/*Pixel perfect monospace font + * http://pelulamu.net/unscii/ */ +#define LV_FONT_UNSCII_8 1 +#define LV_FONT_UNSCII_16 1 + +/* Optionally declare your custom fonts here. + * You can use these fonts as default font too + * and they will be available globally. E.g. + * #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \ + * LV_FONT_DECLARE(my_font_2) + */ +#define LV_FONT_CUSTOM_DECLARE + +/* Enable it if you have fonts with a lot of characters. + * The limit depends on the font size, font face and bpp + * but with > 10,000 characters if you see issues probably you need to enable it.*/ +#define LV_FONT_FMT_TXT_LARGE 0 + +/* Enables/disables support for compressed fonts. If it's disabled, compressed + * glyphs cannot be processed by the library and won't be rendered. + */ +#define LV_USE_FONT_COMPRESSED 1 + +/* Enable subpixel rendering */ +#define LV_USE_FONT_SUBPX 1 +#if LV_USE_FONT_SUBPX +/* Set the pixel order of the display. + * Important only if "subpx fonts" are used. + * With "normal" font it doesn't matter. + */ +#define LV_FONT_SUBPX_BGR 0 + +/* PROS adds the mono variant of DejaVu sans */ +#define USE_PROS_FONT_DEJAVU_MONO_10 1 + +#define USE_PROS_FONT_DEJAVU_MONO_18 1 // llemu font + +#define USE_PROS_FONT_DEJAVU_MONO_30 0 + +#define USE_PROS_FONT_DEJAVU_MONO_40 0 + +#endif + +/*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_font_user_data_t; + +/*================ + * THEME USAGE + *================*/ + +/*Always enable at least on theme*/ + +/* No theme, you can apply your styles as you need + * No flags. Set LV_THEME_DEFAULT_FLAG 0 */ +#define LV_USE_THEME_EMPTY 1 + +/*Simple to the create your theme based on it + * No flags. Set LV_THEME_DEFAULT_FLAG 0 */ +#define LV_USE_THEME_TEMPLATE 1 + +/* A fast and impressive theme. + * Flags: + * LV_THEME_MATERIAL_FLAG_LIGHT: light theme + * LV_THEME_MATERIAL_FLAG_DARK: dark theme + * LV_THEME_MATERIAL_FLAG_NO_TRANSITION: disable transitions (state change animations) + * LV_THEME_MATERIAL_FLAG_NO_FOCUS: disable indication of focused state) + * */ +#define LV_USE_THEME_MATERIAL 1 + +/* Mono-color theme for monochrome displays. + * If LV_THEME_DEFAULT_COLOR_PRIMARY is LV_COLOR_BLACK the + * texts and borders will be black and the background will be + * white. Else the colors are inverted. + * No flags. Set LV_THEME_DEFAULT_FLAG 0 */ +#define LV_USE_THEME_MONO 1 + +#define LV_THEME_DEFAULT_INCLUDE /*Include a header for the init. function*/ +#define LV_THEME_DEFAULT_INIT lv_theme_material_init +#define LV_THEME_DEFAULT_COLOR_PRIMARY lv_color_hex(0x01a2b1) +#define LV_THEME_DEFAULT_COLOR_SECONDARY lv_color_hex(0x44d1b6) +#define LV_THEME_DEFAULT_FLAG LV_THEME_MATERIAL_FLAG_DARK +#define LV_THEME_DEFAULT_FONT_SMALL &lv_font_montserrat_10 +#define LV_THEME_DEFAULT_FONT_NORMAL &lv_font_montserrat_20 +#define LV_THEME_DEFAULT_FONT_SUBTITLE &lv_font_montserrat_10 +#define LV_THEME_DEFAULT_FONT_TITLE &lv_font_montserrat_30 + +#define CONFIG_LV_THEME_DEFAULT_DARK 1 + +/*================= + * Text settings + *=================*/ + +/* Select a character encoding for strings. + * Your IDE or editor should have the same character encoding + * - LV_TXT_ENC_UTF8 + * - LV_TXT_ENC_ASCII + * */ +#define LV_TXT_ENC LV_TXT_ENC_UTF8 + + /*Can break (wrap) texts on these chars*/ +#define LV_TXT_BREAK_CHARS " ,.;:-_" + +/* If a word is at least this long, will break wherever "prettiest" + * To disable, set to a value <= 0 */ +#define LV_TXT_LINE_BREAK_LONG_LEN 0 + +/* Minimum number of characters in a long word to put on a line before a break. + * Depends on LV_TXT_LINE_BREAK_LONG_LEN. */ +#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 + +/* Minimum number of characters in a long word to put on a line after a break. + * Depends on LV_TXT_LINE_BREAK_LONG_LEN. */ +#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3 + +/* The control character to use for signalling text recoloring. */ +#define LV_TXT_COLOR_CMD "#" + +/* Support bidirectional texts. + * Allows mixing Left-to-Right and Right-to-Left texts. + * The direction will be processed according to the Unicode Bidirectional Algorithm: + * https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/ +#define LV_USE_BIDI 0 +#if LV_USE_BIDI +/* Set the default direction. Supported values: + * `LV_BIDI_DIR_LTR` Left-to-Right + * `LV_BIDI_DIR_RTL` Right-to-Left + * `LV_BIDI_DIR_AUTO` detect texts base direction */ +#define LV_BIDI_BASE_DIR_DEF LV_BIDI_DIR_AUTO +#endif + +/* Enable Arabic/Persian processing + * In these languages characters should be replaced with + * an other form based on their position in the text */ +#define LV_USE_ARABIC_PERSIAN_CHARS 0 + +/*Change the built in (v)snprintf functions*/ +#define LV_SPRINTF_CUSTOM 0 +#if LV_SPRINTF_CUSTOM +# define LV_SPRINTF_INCLUDE +# define lv_snprintf snprintf +# define lv_vsnprintf vsnprintf +#else /*!LV_SPRINTF_CUSTOM*/ +# define LV_SPRINTF_DISABLE_FLOAT 1 +#endif /*LV_SPRINTF_CUSTOM*/ + +/*=================== + * LV_OBJ SETTINGS + *==================*/ + +#if LV_USE_USER_DATA +/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_obj_user_data_t; +/*Provide a function to free user data*/ +#define LV_USE_USER_DATA_FREE 0 +#if LV_USE_USER_DATA_FREE +# define LV_USER_DATA_FREE_INCLUDE "something.h" /*Header for user data free function*/ +/* Function prototype : void user_data_free(lv_obj_t * obj); */ +# define LV_USER_DATA_FREE (user_data_free) /*Invoking for user data free function*/ +#endif +#endif + +/*1: enable `lv_obj_realign()` based on `lv_obj_align()` parameters*/ +#define LV_USE_OBJ_REALIGN 1 + +/* Enable to make the object clickable on a larger area. + * LV_EXT_CLICK_AREA_OFF or 0: Disable this feature + * LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px) + * LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px) + */ +#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_TINY + +/*================== + * LV OBJ X USAGE + *================*/ +/* + * Documentation of the object types: https://docs.lvgl.com/#Object-types + */ + +/*Arc (dependencies: -)*/ +#define LV_USE_ARC 1 + +/*Bar (dependencies: -)*/ +#define LV_USE_BAR 1 + +/*Button (dependencies: lv_cont*/ +#define LV_USE_BTN 1 + +/*Button matrix (dependencies: -)*/ +#define LV_USE_BTNMATRIX 1 + +/*Calendar (dependencies: -)*/ +#define LV_USE_CALENDAR 1 +#if LV_USE_CALENDAR +# define LV_CALENDAR_WEEK_STARTS_MONDAY 0 +#endif + +/*Canvas (dependencies: lv_img)*/ +#define LV_USE_CANVAS 1 + +/*Check box (dependencies: lv_btn, lv_label)*/ +#define LV_USE_CHECKBOX 1 + +/*Chart (dependencies: -)*/ +#define LV_USE_CHART 1 +#if LV_USE_CHART +# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 256 +#endif + +/*Container (dependencies: -*/ +#define LV_USE_CONT 1 + +/*Color picker (dependencies: -*/ +#define LV_USE_CPICKER 1 + +/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ +#define LV_USE_DROPDOWN 1 +#if LV_USE_DROPDOWN != 0 +/*Open and close default animation time [ms] (0: no animation)*/ +# define LV_DROPDOWN_DEF_ANIM_TIME 200 +#endif + +/*Gauge (dependencies:lv_bar, lv_linemeter)*/ +#define LV_USE_GAUGE 1 + +/*Image (dependencies: lv_label*/ +#define LV_USE_IMG 1 + +/*Image Button (dependencies: lv_btn*/ +#define LV_USE_IMGBTN 1 +#if LV_USE_IMGBTN +/*1: The imgbtn requires left, mid and right parts and the width can be set freely*/ +# define LV_IMGBTN_TILED 0 +#endif + +/*Keyboard (dependencies: lv_btnm)*/ +#define LV_USE_KEYBOARD 1 + +/*Label (dependencies: -*/ +#define LV_USE_LABEL 1 +#if LV_USE_LABEL != 0 +/*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/ +# define LV_LABEL_DEF_SCROLL_SPEED 25 + +/* Waiting period at beginning/end of animation cycle */ +# define LV_LABEL_WAIT_CHAR_COUNT 3 + +/*Enable selecting text of the label */ +# define LV_LABEL_TEXT_SEL 0 + +/*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/ +# define LV_LABEL_LONG_TXT_HINT 0 +#endif + +/*LED (dependencies: -)*/ +#define LV_USE_LED 1 +#if LV_USE_LED +# define LV_LED_BRIGHT_MIN 120 /*Minimal brightness*/ +# define LV_LED_BRIGHT_MAX 255 /*Maximal brightness*/ +#endif + +/*Line (dependencies: -*/ +#define LV_USE_LINE 1 + +/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ +#define LV_USE_LIST 1 +#if LV_USE_LIST != 0 +/*Default animation time of focusing to a list element [ms] (0: no animation) */ +# define LV_LIST_DEF_ANIM_TIME 100 +#endif + +/*Line meter (dependencies: *;)*/ +#define LV_USE_LINEMETER 1 +#if LV_USE_LINEMETER +/* Draw line more precisely at cost of performance. + * Useful if there are lot of lines any minor are visible + * 0: No extra precision + * 1: Some extra precision + * 2: Best precision + */ +# define LV_LINEMETER_PRECISE 1 +#endif + +/*Mask (dependencies: -)*/ +#define LV_USE_OBJMASK 1 + +/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ +#define LV_USE_MSGBOX 1 + +/*Page (dependencies: lv_cont)*/ +#define LV_USE_PAGE 1 +#if LV_USE_PAGE != 0 +/*Focus default animation time [ms] (0: no animation)*/ +# define LV_PAGE_DEF_ANIM_TIME 400 +#endif + +/*Preload (dependencies: lv_arc, lv_anim)*/ +#define LV_USE_SPINNER 1 +#if LV_USE_SPINNER != 0 +# define LV_SPINNER_DEF_ARC_LENGTH 60 /*[deg]*/ +# define LV_SPINNER_DEF_SPIN_TIME 1000 /*[ms]*/ +# define LV_SPINNER_DEF_ANIM LV_SPINNER_TYPE_SPINNING_ARC +#endif + +/*Roller (dependencies: lv_ddlist)*/ +#define LV_USE_ROLLER 1 +#if LV_USE_ROLLER != 0 +/*Focus animation time [ms] (0: no animation)*/ +# define LV_ROLLER_DEF_ANIM_TIME 200 + +/*Number of extra "pages" when the roller is infinite*/ +# define LV_ROLLER_INF_PAGES 7 +#endif + +/*Slider (dependencies: lv_bar)*/ +#define LV_USE_SLIDER 1 + +/*Spinbox (dependencies: lv_ta)*/ +#define LV_USE_SPINBOX 1 + +/*Switch (dependencies: lv_slider)*/ +#define LV_USE_SWITCH 1 + +/*Text area (dependencies: lv_label, lv_page)*/ +#define LV_USE_TEXTAREA 1 +#if LV_USE_TEXTAREA != 0 +# define LV_TEXTAREA_DEF_CURSOR_BLINK_TIME 400 /*ms*/ +# define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/ +#endif + +/*Table (dependencies: lv_label)*/ +#define LV_USE_TABLE 1 +#if LV_USE_TABLE +# define LV_TABLE_COL_MAX 12 +# define LV_TABLE_CELL_STYLE_CNT 4 +#endif + +/*Tab (dependencies: lv_page, lv_btnm)*/ +#define LV_USE_TABVIEW 1 +# if LV_USE_TABVIEW != 0 +/*Time of slide animation [ms] (0: no animation)*/ +# define LV_TABVIEW_DEF_ANIM_TIME 300 +#endif + +/*Tileview (dependencies: lv_page) */ +#define LV_USE_TILEVIEW 1 +#if LV_USE_TILEVIEW +/*Time of slide animation [ms] (0: no animation)*/ +# define LV_TILEVIEW_DEF_ANIM_TIME 300 +#endif + +/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ +#define LV_USE_WIN 1 + +/*================== + * Non-user section + *==================*/ + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ +# define _CRT_SECURE_NO_WARNINGS +#endif + +/*--END OF LV_CONF_H--*/ + +#endif /*LV_CONF_H*/ + +#endif /*End of "Content enable"*/ diff --git a/EZ-Template-Example-Project/include/display/lv_conf.h b/EZ-Template-Example-Project/include/liblvgl/lv_conf.old.h similarity index 98% rename from EZ-Template-Example-Project/include/display/lv_conf.h rename to EZ-Template-Example-Project/include/liblvgl/lv_conf.old.h index 0b1a1626..16deedde 100644 --- a/EZ-Template-Example-Project/include/display/lv_conf.h +++ b/EZ-Template-Example-Project/include/liblvgl/lv_conf.old.h @@ -13,7 +13,7 @@ /* Memory size which will be used by the library * to store the graphical objects and other data */ #define LV_MEM_CUSTOM \ - 1 /*1: use custom malloc/free, 0: use the built-in \ + 0 /*1: use custom malloc/free, 0: use the built-in \ lv_mem_alloc/lv_mem_free*/ #if LV_MEM_CUSTOM == 0 #define LV_MEM_SIZE \ @@ -22,7 +22,7 @@ #define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/ #else /*LV_MEM_CUSTOM*/ #define LV_MEM_CUSTOM_INCLUDE \ - "kapi.h" /*Header for the dynamic memory function*/ + /*Header for the dynamic memory function*/ #define LV_MEM_CUSTOM_ALLOC kmalloc /*Wrapper to malloc*/ #define LV_MEM_CUSTOM_FREE kfree /*Wrapper to free*/ #endif /*LV_MEM_CUSTOM*/ @@ -337,5 +337,5 @@ #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) # define _CRT_SECURE_NO_WARNINGS #endif -#include "display/lv_conf_checker.h" +#include "liblvgl/lv_conf_checker.h" #endif /*LV_CONF_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_conf_checker.h b/EZ-Template-Example-Project/include/liblvgl/lv_conf_checker.h similarity index 100% rename from EZ-Template-Example-Project/include/display/lv_conf_checker.h rename to EZ-Template-Example-Project/include/liblvgl/lv_conf_checker.h diff --git a/EZ-Template-Example-Project/include/liblvgl/lv_conf_internal.h b/EZ-Template-Example-Project/include/liblvgl/lv_conf_internal.h new file mode 100644 index 00000000..97807fe3 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/lv_conf_internal.h @@ -0,0 +1,2469 @@ +/** + * GENERATED FILE, DO NOT EDIT IT! + * @file lv_conf_internal.h + * Make sure all the defines of lv_conf.h have a default value +**/ + +#ifndef LV_CONF_INTERNAL_H +#define LV_CONF_INTERNAL_H +/* clang-format off */ + +#include + +/* Handle special Kconfig options */ +#ifndef LV_KCONFIG_IGNORE + #include "lv_conf_kconfig.h" + #ifdef CONFIG_LV_CONF_SKIP + #define LV_CONF_SKIP + #endif +#endif + +/*If "lv_conf.h" is available from here try to use it later.*/ +#ifdef __has_include + #if __has_include("lv_conf.h") + #ifndef LV_CONF_INCLUDE_SIMPLE + #define LV_CONF_INCLUDE_SIMPLE + #endif + #endif +#endif + +/*If lv_conf.h is not skipped include it*/ +#ifndef LV_CONF_SKIP + #ifdef LV_CONF_PATH /*If there is a path defined for lv_conf.h use it*/ + #define __LV_TO_STR_AUX(x) #x + #define __LV_TO_STR(x) __LV_TO_STR_AUX(x) + #include __LV_TO_STR(LV_CONF_PATH) + #undef __LV_TO_STR_AUX + #undef __LV_TO_STR + #elif defined(LV_CONF_INCLUDE_SIMPLE) /*Or simply include lv_conf.h is enabled*/ + #include "lv_conf.h" + #else + #include "../../lv_conf.h" /*Else assume lv_conf.h is next to the lvgl folder*/ + #endif + #if !defined(LV_CONF_H) && !defined(LV_CONF_SUPPRESS_DEFINE_CHECK) + /* #include will sometimes silently fail when __has_include is used */ + /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80753 */ + #pragma message("Possible failure to include lv_conf.h, please read the comment in this file if you get errors") + #endif +#endif + +#ifdef CONFIG_LV_COLOR_DEPTH + #define _LV_KCONFIG_PRESENT +#endif + +/*---------------------------------- + * Start parsing lv_conf_template.h + -----------------------------------*/ + +#include + +/*==================== + COLOR SETTINGS + *====================*/ + +/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/ +#ifndef LV_COLOR_DEPTH + #ifdef CONFIG_LV_COLOR_DEPTH + #define LV_COLOR_DEPTH CONFIG_LV_COLOR_DEPTH + #else + #define LV_COLOR_DEPTH 16 + #endif +#endif + +/*Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)*/ +#ifndef LV_COLOR_16_SWAP + #ifdef CONFIG_LV_COLOR_16_SWAP + #define LV_COLOR_16_SWAP CONFIG_LV_COLOR_16_SWAP + #else + #define LV_COLOR_16_SWAP 0 + #endif +#endif + +/*Enable features to draw on transparent background. + *It's required if opa, and transform_* style properties are used. + *Can be also used if the UI is above another layer, e.g. an OSD menu or video player.*/ +#ifndef LV_COLOR_SCREEN_TRANSP + #ifdef CONFIG_LV_COLOR_SCREEN_TRANSP + #define LV_COLOR_SCREEN_TRANSP CONFIG_LV_COLOR_SCREEN_TRANSP + #else + #define LV_COLOR_SCREEN_TRANSP 0 + #endif +#endif + +/* Adjust color mix functions rounding. GPUs might calculate color mix (blending) differently. + * 0: round down, 64: round up from x.75, 128: round up from half, 192: round up from x.25, 254: round up */ +#ifndef LV_COLOR_MIX_ROUND_OFS + #ifdef CONFIG_LV_COLOR_MIX_ROUND_OFS + #define LV_COLOR_MIX_ROUND_OFS CONFIG_LV_COLOR_MIX_ROUND_OFS + #else + #define LV_COLOR_MIX_ROUND_OFS 0 + #endif +#endif + +/*Images pixels with this color will not be drawn if they are chroma keyed)*/ +#ifndef LV_COLOR_CHROMA_KEY + #ifdef CONFIG_LV_COLOR_CHROMA_KEY + #define LV_COLOR_CHROMA_KEY CONFIG_LV_COLOR_CHROMA_KEY + #else + #define LV_COLOR_CHROMA_KEY lv_color_hex(0x00ff00) /*pure green*/ + #endif +#endif + +/*========================= + MEMORY SETTINGS + *=========================*/ + +/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/ +#ifndef LV_MEM_CUSTOM + #ifdef CONFIG_LV_MEM_CUSTOM + #define LV_MEM_CUSTOM CONFIG_LV_MEM_CUSTOM + #else + #define LV_MEM_CUSTOM 0 + #endif +#endif +#if LV_MEM_CUSTOM == 0 + /*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/ + #ifndef LV_MEM_SIZE + #ifdef CONFIG_LV_MEM_SIZE + #define LV_MEM_SIZE CONFIG_LV_MEM_SIZE + #else + #define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/ + #endif + #endif + + /*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/ + #ifndef LV_MEM_ADR + #ifdef CONFIG_LV_MEM_ADR + #define LV_MEM_ADR CONFIG_LV_MEM_ADR + #else + #define LV_MEM_ADR 0 /*0: unused*/ + #endif + #endif + /*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/ + #if LV_MEM_ADR == 0 + #ifndef LV_MEM_POOL_INCLUDE + #ifdef CONFIG_LV_MEM_POOL_INCLUDE + #define LV_MEM_POOL_INCLUDE CONFIG_LV_MEM_POOL_INCLUDE + #else + #undef LV_MEM_POOL_INCLUDE + #endif + #endif + #ifndef LV_MEM_POOL_ALLOC + #ifdef CONFIG_LV_MEM_POOL_ALLOC + #define LV_MEM_POOL_ALLOC CONFIG_LV_MEM_POOL_ALLOC + #else + #undef LV_MEM_POOL_ALLOC + #endif + #endif + #endif + +#else /*LV_MEM_CUSTOM*/ + #ifndef LV_MEM_CUSTOM_INCLUDE + #ifdef CONFIG_LV_MEM_CUSTOM_INCLUDE + #define LV_MEM_CUSTOM_INCLUDE CONFIG_LV_MEM_CUSTOM_INCLUDE + #else + #define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ + #endif + #endif + #ifndef LV_MEM_CUSTOM_ALLOC + #ifdef CONFIG_LV_MEM_CUSTOM_ALLOC + #define LV_MEM_CUSTOM_ALLOC CONFIG_LV_MEM_CUSTOM_ALLOC + #else + #define LV_MEM_CUSTOM_ALLOC malloc + #endif + #endif + #ifndef LV_MEM_CUSTOM_FREE + #ifdef CONFIG_LV_MEM_CUSTOM_FREE + #define LV_MEM_CUSTOM_FREE CONFIG_LV_MEM_CUSTOM_FREE + #else + #define LV_MEM_CUSTOM_FREE free + #endif + #endif + #ifndef LV_MEM_CUSTOM_REALLOC + #ifdef CONFIG_LV_MEM_CUSTOM_REALLOC + #define LV_MEM_CUSTOM_REALLOC CONFIG_LV_MEM_CUSTOM_REALLOC + #else + #define LV_MEM_CUSTOM_REALLOC realloc + #endif + #endif +#endif /*LV_MEM_CUSTOM*/ + +/*Number of the intermediate memory buffer used during rendering and other internal processing mechanisms. + *You will see an error log message if there wasn't enough buffers. */ +#ifndef LV_MEM_BUF_MAX_NUM + #ifdef CONFIG_LV_MEM_BUF_MAX_NUM + #define LV_MEM_BUF_MAX_NUM CONFIG_LV_MEM_BUF_MAX_NUM + #else + #define LV_MEM_BUF_MAX_NUM 16 + #endif +#endif + +/*Use the standard `memcpy` and `memset` instead of LVGL's own functions. (Might or might not be faster).*/ +#ifndef LV_MEMCPY_MEMSET_STD + #ifdef CONFIG_LV_MEMCPY_MEMSET_STD + #define LV_MEMCPY_MEMSET_STD CONFIG_LV_MEMCPY_MEMSET_STD + #else + #define LV_MEMCPY_MEMSET_STD 0 + #endif +#endif + +/*==================== + HAL SETTINGS + *====================*/ + +/*Default display refresh period. LVG will redraw changed areas with this period time*/ +#ifndef LV_DISP_DEF_REFR_PERIOD + #ifdef CONFIG_LV_DISP_DEF_REFR_PERIOD + #define LV_DISP_DEF_REFR_PERIOD CONFIG_LV_DISP_DEF_REFR_PERIOD + #else + #define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/ + #endif +#endif + +/*Input device read period in milliseconds*/ +#ifndef LV_INDEV_DEF_READ_PERIOD + #ifdef CONFIG_LV_INDEV_DEF_READ_PERIOD + #define LV_INDEV_DEF_READ_PERIOD CONFIG_LV_INDEV_DEF_READ_PERIOD + #else + #define LV_INDEV_DEF_READ_PERIOD 30 /*[ms]*/ + #endif +#endif + +/*Use a custom tick source that tells the elapsed time in milliseconds. + *It removes the need to manually update the tick with `lv_tick_inc()`)*/ +#ifndef LV_TICK_CUSTOM + #ifdef CONFIG_LV_TICK_CUSTOM + #define LV_TICK_CUSTOM CONFIG_LV_TICK_CUSTOM + #else + #define LV_TICK_CUSTOM 0 + #endif +#endif +#if LV_TICK_CUSTOM + #ifndef LV_TICK_CUSTOM_INCLUDE + #ifdef CONFIG_LV_TICK_CUSTOM_INCLUDE + #define LV_TICK_CUSTOM_INCLUDE CONFIG_LV_TICK_CUSTOM_INCLUDE + #else + #define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ + #endif + #endif + #ifndef LV_TICK_CUSTOM_SYS_TIME_EXPR + #ifdef CONFIG_LV_TICK_CUSTOM_SYS_TIME_EXPR + #define LV_TICK_CUSTOM_SYS_TIME_EXPR CONFIG_LV_TICK_CUSTOM_SYS_TIME_EXPR + #else + #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ + #endif + #endif +#endif /*LV_TICK_CUSTOM*/ + +/*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings. + *(Not so important, you can adjust it to modify default sizes and spaces)*/ +#ifndef LV_DPI_DEF + #ifdef CONFIG_LV_DPI_DEF + #define LV_DPI_DEF CONFIG_LV_DPI_DEF + #else + #define LV_DPI_DEF 130 /*[px/inch]*/ + #endif +#endif + +/*======================= + * FEATURE CONFIGURATION + *=======================*/ + +/*------------- + * Drawing + *-----------*/ + +/*Enable complex draw engine. + *Required to draw shadow, gradient, rounded corners, circles, arc, skew lines, image transformations or any masks*/ +#ifndef LV_DRAW_COMPLEX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_DRAW_COMPLEX + #define LV_DRAW_COMPLEX CONFIG_LV_DRAW_COMPLEX + #else + #define LV_DRAW_COMPLEX 0 + #endif + #else + #define LV_DRAW_COMPLEX 1 + #endif +#endif +#if LV_DRAW_COMPLEX != 0 + + /*Allow buffering some shadow calculation. + *LV_SHADOW_CACHE_SIZE is the max. shadow size to buffer, where shadow size is `shadow_width + radius` + *Caching has LV_SHADOW_CACHE_SIZE^2 RAM cost*/ + #ifndef LV_SHADOW_CACHE_SIZE + #ifdef CONFIG_LV_SHADOW_CACHE_SIZE + #define LV_SHADOW_CACHE_SIZE CONFIG_LV_SHADOW_CACHE_SIZE + #else + #define LV_SHADOW_CACHE_SIZE 0 + #endif + #endif + + /* Set number of maximally cached circle data. + * The circumference of 1/4 circle are saved for anti-aliasing + * radius * 4 bytes are used per circle (the most often used radiuses are saved) + * 0: to disable caching */ + #ifndef LV_CIRCLE_CACHE_SIZE + #ifdef CONFIG_LV_CIRCLE_CACHE_SIZE + #define LV_CIRCLE_CACHE_SIZE CONFIG_LV_CIRCLE_CACHE_SIZE + #else + #define LV_CIRCLE_CACHE_SIZE 4 + #endif + #endif +#endif /*LV_DRAW_COMPLEX*/ + +/** + * "Simple layers" are used when a widget has `style_opa < 255` to buffer the widget into a layer + * and blend it as an image with the given opacity. + * Note that `bg_opa`, `text_opa` etc don't require buffering into layer) + * The widget can be buffered in smaller chunks to avoid using large buffers. + * + * - LV_LAYER_SIMPLE_BUF_SIZE: [bytes] the optimal target buffer size. LVGL will try to allocate it + * - LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE: [bytes] used if `LV_LAYER_SIMPLE_BUF_SIZE` couldn't be allocated. + * + * Both buffer sizes are in bytes. + * "Transformed layers" (where transform_angle/zoom properties are used) use larger buffers + * and can't be drawn in chunks. So these settings affects only widgets with opacity. + */ +#ifndef LV_LAYER_SIMPLE_BUF_SIZE + #ifdef CONFIG_LV_LAYER_SIMPLE_BUF_SIZE + #define LV_LAYER_SIMPLE_BUF_SIZE CONFIG_LV_LAYER_SIMPLE_BUF_SIZE + #else + #define LV_LAYER_SIMPLE_BUF_SIZE (24 * 1024) + #endif +#endif +#ifndef LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE + #ifdef CONFIG_LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE + #define LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE CONFIG_LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE + #else + #define LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE (3 * 1024) + #endif +#endif + +/*Default image cache size. Image caching keeps the images opened. + *If only the built-in image formats are used there is no real advantage of caching. (I.e. if no new image decoder is added) + *With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images. + *However the opened images might consume additional RAM. + *0: to disable caching*/ +#ifndef LV_IMG_CACHE_DEF_SIZE + #ifdef CONFIG_LV_IMG_CACHE_DEF_SIZE + #define LV_IMG_CACHE_DEF_SIZE CONFIG_LV_IMG_CACHE_DEF_SIZE + #else + #define LV_IMG_CACHE_DEF_SIZE 0 + #endif +#endif + +/*Number of stops allowed per gradient. Increase this to allow more stops. + *This adds (sizeof(lv_color_t) + 1) bytes per additional stop*/ +#ifndef LV_GRADIENT_MAX_STOPS + #ifdef CONFIG_LV_GRADIENT_MAX_STOPS + #define LV_GRADIENT_MAX_STOPS CONFIG_LV_GRADIENT_MAX_STOPS + #else + #define LV_GRADIENT_MAX_STOPS 2 + #endif +#endif + +/*Default gradient buffer size. + *When LVGL calculates the gradient "maps" it can save them into a cache to avoid calculating them again. + *LV_GRAD_CACHE_DEF_SIZE sets the size of this cache in bytes. + *If the cache is too small the map will be allocated only while it's required for the drawing. + *0 mean no caching.*/ +#ifndef LV_GRAD_CACHE_DEF_SIZE + #ifdef CONFIG_LV_GRAD_CACHE_DEF_SIZE + #define LV_GRAD_CACHE_DEF_SIZE CONFIG_LV_GRAD_CACHE_DEF_SIZE + #else + #define LV_GRAD_CACHE_DEF_SIZE 0 + #endif +#endif + +/*Allow dithering the gradients (to achieve visual smooth color gradients on limited color depth display) + *LV_DITHER_GRADIENT implies allocating one or two more lines of the object's rendering surface + *The increase in memory consumption is (32 bits * object width) plus 24 bits * object width if using error diffusion */ +#ifndef LV_DITHER_GRADIENT + #ifdef CONFIG_LV_DITHER_GRADIENT + #define LV_DITHER_GRADIENT CONFIG_LV_DITHER_GRADIENT + #else + #define LV_DITHER_GRADIENT 0 + #endif +#endif +#if LV_DITHER_GRADIENT + /*Add support for error diffusion dithering. + *Error diffusion dithering gets a much better visual result, but implies more CPU consumption and memory when drawing. + *The increase in memory consumption is (24 bits * object's width)*/ + #ifndef LV_DITHER_ERROR_DIFFUSION + #ifdef CONFIG_LV_DITHER_ERROR_DIFFUSION + #define LV_DITHER_ERROR_DIFFUSION CONFIG_LV_DITHER_ERROR_DIFFUSION + #else + #define LV_DITHER_ERROR_DIFFUSION 0 + #endif + #endif +#endif + +/*Maximum buffer size to allocate for rotation. + *Only used if software rotation is enabled in the display driver.*/ +#ifndef LV_DISP_ROT_MAX_BUF + #ifdef CONFIG_LV_DISP_ROT_MAX_BUF + #define LV_DISP_ROT_MAX_BUF CONFIG_LV_DISP_ROT_MAX_BUF + #else + #define LV_DISP_ROT_MAX_BUF (10*1024) + #endif +#endif + +/*------------- + * GPU + *-----------*/ + +/*Use Arm's 2D acceleration library Arm-2D */ +#ifndef LV_USE_GPU_ARM2D + #ifdef CONFIG_LV_USE_GPU_ARM2D + #define LV_USE_GPU_ARM2D CONFIG_LV_USE_GPU_ARM2D + #else + #define LV_USE_GPU_ARM2D 0 + #endif +#endif + +/*Use STM32's DMA2D (aka Chrom Art) GPU*/ +#ifndef LV_USE_GPU_STM32_DMA2D + #ifdef CONFIG_LV_USE_GPU_STM32_DMA2D + #define LV_USE_GPU_STM32_DMA2D CONFIG_LV_USE_GPU_STM32_DMA2D + #else + #define LV_USE_GPU_STM32_DMA2D 0 + #endif +#endif +#if LV_USE_GPU_STM32_DMA2D + /*Must be defined to include path of CMSIS header of target processor + e.g. "stm32f769xx.h" or "stm32f429xx.h"*/ + #ifndef LV_GPU_DMA2D_CMSIS_INCLUDE + #ifdef CONFIG_LV_GPU_DMA2D_CMSIS_INCLUDE + #define LV_GPU_DMA2D_CMSIS_INCLUDE CONFIG_LV_GPU_DMA2D_CMSIS_INCLUDE + #else + #define LV_GPU_DMA2D_CMSIS_INCLUDE + #endif + #endif +#endif + +/*Use SWM341's DMA2D GPU*/ +#ifndef LV_USE_GPU_SWM341_DMA2D + #ifdef CONFIG_LV_USE_GPU_SWM341_DMA2D + #define LV_USE_GPU_SWM341_DMA2D CONFIG_LV_USE_GPU_SWM341_DMA2D + #else + #define LV_USE_GPU_SWM341_DMA2D 0 + #endif +#endif +#if LV_USE_GPU_SWM341_DMA2D + #ifndef LV_GPU_SWM341_DMA2D_INCLUDE + #ifdef CONFIG_LV_GPU_SWM341_DMA2D_INCLUDE + #define LV_GPU_SWM341_DMA2D_INCLUDE CONFIG_LV_GPU_SWM341_DMA2D_INCLUDE + #else + #define LV_GPU_SWM341_DMA2D_INCLUDE "SWM341.h" + #endif + #endif +#endif + +/*Use NXP's PXP GPU iMX RTxxx platforms*/ +#ifndef LV_USE_GPU_NXP_PXP + #ifdef CONFIG_LV_USE_GPU_NXP_PXP + #define LV_USE_GPU_NXP_PXP CONFIG_LV_USE_GPU_NXP_PXP + #else + #define LV_USE_GPU_NXP_PXP 0 + #endif +#endif +#if LV_USE_GPU_NXP_PXP + /*1: Add default bare metal and FreeRTOS interrupt handling routines for PXP (lv_gpu_nxp_pxp_osa.c) + * and call lv_gpu_nxp_pxp_init() automatically during lv_init(). Note that symbol SDK_OS_FREE_RTOS + * has to be defined in order to use FreeRTOS OSA, otherwise bare-metal implementation is selected. + *0: lv_gpu_nxp_pxp_init() has to be called manually before lv_init() + */ + #ifndef LV_USE_GPU_NXP_PXP_AUTO_INIT + #ifdef CONFIG_LV_USE_GPU_NXP_PXP_AUTO_INIT + #define LV_USE_GPU_NXP_PXP_AUTO_INIT CONFIG_LV_USE_GPU_NXP_PXP_AUTO_INIT + #else + #define LV_USE_GPU_NXP_PXP_AUTO_INIT 0 + #endif + #endif +#endif + +/*Use NXP's VG-Lite GPU iMX RTxxx platforms*/ +#ifndef LV_USE_GPU_NXP_VG_LITE + #ifdef CONFIG_LV_USE_GPU_NXP_VG_LITE + #define LV_USE_GPU_NXP_VG_LITE CONFIG_LV_USE_GPU_NXP_VG_LITE + #else + #define LV_USE_GPU_NXP_VG_LITE 0 + #endif +#endif + +/*Use SDL renderer API*/ +#ifndef LV_USE_GPU_SDL + #ifdef CONFIG_LV_USE_GPU_SDL + #define LV_USE_GPU_SDL CONFIG_LV_USE_GPU_SDL + #else + #define LV_USE_GPU_SDL 0 + #endif +#endif +#if LV_USE_GPU_SDL + #ifndef LV_GPU_SDL_INCLUDE_PATH + #ifdef CONFIG_LV_GPU_SDL_INCLUDE_PATH + #define LV_GPU_SDL_INCLUDE_PATH CONFIG_LV_GPU_SDL_INCLUDE_PATH + #else + #define LV_GPU_SDL_INCLUDE_PATH + #endif + #endif + /*Texture cache size, 8MB by default*/ + #ifndef LV_GPU_SDL_LRU_SIZE + #ifdef CONFIG_LV_GPU_SDL_LRU_SIZE + #define LV_GPU_SDL_LRU_SIZE CONFIG_LV_GPU_SDL_LRU_SIZE + #else + #define LV_GPU_SDL_LRU_SIZE (1024 * 1024 * 8) + #endif + #endif + /*Custom blend mode for mask drawing, disable if you need to link with older SDL2 lib*/ + #ifndef LV_GPU_SDL_CUSTOM_BLEND_MODE + #ifdef CONFIG_LV_GPU_SDL_CUSTOM_BLEND_MODE + #define LV_GPU_SDL_CUSTOM_BLEND_MODE CONFIG_LV_GPU_SDL_CUSTOM_BLEND_MODE + #else + #define LV_GPU_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6)) + #endif + #endif +#endif + +/*------------- + * Logging + *-----------*/ + +/*Enable the log module*/ +#ifndef LV_USE_LOG + #ifdef CONFIG_LV_USE_LOG + #define LV_USE_LOG CONFIG_LV_USE_LOG + #else + #define LV_USE_LOG 0 + #endif +#endif +#if LV_USE_LOG + + /*How important log should be added: + *LV_LOG_LEVEL_TRACE A lot of logs to give detailed information + *LV_LOG_LEVEL_INFO Log important events + *LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem + *LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail + *LV_LOG_LEVEL_USER Only logs added by the user + *LV_LOG_LEVEL_NONE Do not log anything*/ + #ifndef LV_LOG_LEVEL + #ifdef CONFIG_LV_LOG_LEVEL + #define LV_LOG_LEVEL CONFIG_LV_LOG_LEVEL + #else + #define LV_LOG_LEVEL LV_LOG_LEVEL_WARN + #endif + #endif + + /*1: Print the log with 'printf'; + *0: User need to register a callback with `lv_log_register_print_cb()`*/ + #ifndef LV_LOG_PRINTF + #ifdef CONFIG_LV_LOG_PRINTF + #define LV_LOG_PRINTF CONFIG_LV_LOG_PRINTF + #else + #define LV_LOG_PRINTF 0 + #endif + #endif + + /*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/ + #ifndef LV_LOG_TRACE_MEM + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_MEM + #define LV_LOG_TRACE_MEM CONFIG_LV_LOG_TRACE_MEM + #else + #define LV_LOG_TRACE_MEM 0 + #endif + #else + #define LV_LOG_TRACE_MEM 1 + #endif + #endif + #ifndef LV_LOG_TRACE_TIMER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_TIMER + #define LV_LOG_TRACE_TIMER CONFIG_LV_LOG_TRACE_TIMER + #else + #define LV_LOG_TRACE_TIMER 0 + #endif + #else + #define LV_LOG_TRACE_TIMER 1 + #endif + #endif + #ifndef LV_LOG_TRACE_INDEV + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_INDEV + #define LV_LOG_TRACE_INDEV CONFIG_LV_LOG_TRACE_INDEV + #else + #define LV_LOG_TRACE_INDEV 0 + #endif + #else + #define LV_LOG_TRACE_INDEV 1 + #endif + #endif + #ifndef LV_LOG_TRACE_DISP_REFR + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_DISP_REFR + #define LV_LOG_TRACE_DISP_REFR CONFIG_LV_LOG_TRACE_DISP_REFR + #else + #define LV_LOG_TRACE_DISP_REFR 0 + #endif + #else + #define LV_LOG_TRACE_DISP_REFR 1 + #endif + #endif + #ifndef LV_LOG_TRACE_EVENT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_EVENT + #define LV_LOG_TRACE_EVENT CONFIG_LV_LOG_TRACE_EVENT + #else + #define LV_LOG_TRACE_EVENT 0 + #endif + #else + #define LV_LOG_TRACE_EVENT 1 + #endif + #endif + #ifndef LV_LOG_TRACE_OBJ_CREATE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_OBJ_CREATE + #define LV_LOG_TRACE_OBJ_CREATE CONFIG_LV_LOG_TRACE_OBJ_CREATE + #else + #define LV_LOG_TRACE_OBJ_CREATE 0 + #endif + #else + #define LV_LOG_TRACE_OBJ_CREATE 1 + #endif + #endif + #ifndef LV_LOG_TRACE_LAYOUT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_LAYOUT + #define LV_LOG_TRACE_LAYOUT CONFIG_LV_LOG_TRACE_LAYOUT + #else + #define LV_LOG_TRACE_LAYOUT 0 + #endif + #else + #define LV_LOG_TRACE_LAYOUT 1 + #endif + #endif + #ifndef LV_LOG_TRACE_ANIM + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_ANIM + #define LV_LOG_TRACE_ANIM CONFIG_LV_LOG_TRACE_ANIM + #else + #define LV_LOG_TRACE_ANIM 0 + #endif + #else + #define LV_LOG_TRACE_ANIM 1 + #endif + #endif + +#endif /*LV_USE_LOG*/ + +/*------------- + * Asserts + *-----------*/ + +/*Enable asserts if an operation is failed or an invalid data is found. + *If LV_USE_LOG is enabled an error message will be printed on failure*/ +#ifndef LV_USE_ASSERT_NULL + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ASSERT_NULL + #define LV_USE_ASSERT_NULL CONFIG_LV_USE_ASSERT_NULL + #else + #define LV_USE_ASSERT_NULL 0 + #endif + #else + #define LV_USE_ASSERT_NULL 1 /*Check if the parameter is NULL. (Very fast, recommended)*/ + #endif +#endif +#ifndef LV_USE_ASSERT_MALLOC + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ASSERT_MALLOC + #define LV_USE_ASSERT_MALLOC CONFIG_LV_USE_ASSERT_MALLOC + #else + #define LV_USE_ASSERT_MALLOC 0 + #endif + #else + #define LV_USE_ASSERT_MALLOC 1 /*Checks is the memory is successfully allocated or no. (Very fast, recommended)*/ + #endif +#endif +#ifndef LV_USE_ASSERT_STYLE + #ifdef CONFIG_LV_USE_ASSERT_STYLE + #define LV_USE_ASSERT_STYLE CONFIG_LV_USE_ASSERT_STYLE + #else + #define LV_USE_ASSERT_STYLE 0 /*Check if the styles are properly initialized. (Very fast, recommended)*/ + #endif +#endif +#ifndef LV_USE_ASSERT_MEM_INTEGRITY + #ifdef CONFIG_LV_USE_ASSERT_MEM_INTEGRITY + #define LV_USE_ASSERT_MEM_INTEGRITY CONFIG_LV_USE_ASSERT_MEM_INTEGRITY + #else + #define LV_USE_ASSERT_MEM_INTEGRITY 0 /*Check the integrity of `lv_mem` after critical operations. (Slow)*/ + #endif +#endif +#ifndef LV_USE_ASSERT_OBJ + #ifdef CONFIG_LV_USE_ASSERT_OBJ + #define LV_USE_ASSERT_OBJ CONFIG_LV_USE_ASSERT_OBJ + #else + #define LV_USE_ASSERT_OBJ 0 /*Check the object's type and existence (e.g. not deleted). (Slow)*/ + #endif +#endif + +/*Add a custom handler when assert happens e.g. to restart the MCU*/ +#ifndef LV_ASSERT_HANDLER_INCLUDE + #ifdef CONFIG_LV_ASSERT_HANDLER_INCLUDE + #define LV_ASSERT_HANDLER_INCLUDE CONFIG_LV_ASSERT_HANDLER_INCLUDE + #else + #define LV_ASSERT_HANDLER_INCLUDE + #endif +#endif +#ifndef LV_ASSERT_HANDLER + #ifdef CONFIG_LV_ASSERT_HANDLER + #define LV_ASSERT_HANDLER CONFIG_LV_ASSERT_HANDLER + #else + #define LV_ASSERT_HANDLER while(1); /*Halt by default*/ + #endif +#endif + +/*------------- + * Others + *-----------*/ + +/*1: Show CPU usage and FPS count*/ +#ifndef LV_USE_PERF_MONITOR + #ifdef CONFIG_LV_USE_PERF_MONITOR + #define LV_USE_PERF_MONITOR CONFIG_LV_USE_PERF_MONITOR + #else + #define LV_USE_PERF_MONITOR 0 + #endif +#endif +#if LV_USE_PERF_MONITOR + #ifndef LV_USE_PERF_MONITOR_POS + #ifdef CONFIG_LV_USE_PERF_MONITOR_POS + #define LV_USE_PERF_MONITOR_POS CONFIG_LV_USE_PERF_MONITOR_POS + #else + #define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT + #endif + #endif +#endif + +/*1: Show the used memory and the memory fragmentation + * Requires LV_MEM_CUSTOM = 0*/ +#ifndef LV_USE_MEM_MONITOR + #ifdef CONFIG_LV_USE_MEM_MONITOR + #define LV_USE_MEM_MONITOR CONFIG_LV_USE_MEM_MONITOR + #else + #define LV_USE_MEM_MONITOR 0 + #endif +#endif +#if LV_USE_MEM_MONITOR + #ifndef LV_USE_MEM_MONITOR_POS + #ifdef CONFIG_LV_USE_MEM_MONITOR_POS + #define LV_USE_MEM_MONITOR_POS CONFIG_LV_USE_MEM_MONITOR_POS + #else + #define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT + #endif + #endif +#endif + +/*1: Draw random colored rectangles over the redrawn areas*/ +#ifndef LV_USE_REFR_DEBUG + #ifdef CONFIG_LV_USE_REFR_DEBUG + #define LV_USE_REFR_DEBUG CONFIG_LV_USE_REFR_DEBUG + #else + #define LV_USE_REFR_DEBUG 0 + #endif +#endif + +/*Change the built in (v)snprintf functions*/ +#ifndef LV_SPRINTF_CUSTOM + #ifdef CONFIG_LV_SPRINTF_CUSTOM + #define LV_SPRINTF_CUSTOM CONFIG_LV_SPRINTF_CUSTOM + #else + #define LV_SPRINTF_CUSTOM 0 + #endif +#endif +#if LV_SPRINTF_CUSTOM + #ifndef LV_SPRINTF_INCLUDE + #ifdef CONFIG_LV_SPRINTF_INCLUDE + #define LV_SPRINTF_INCLUDE CONFIG_LV_SPRINTF_INCLUDE + #else + #define LV_SPRINTF_INCLUDE + #endif + #endif + #ifndef lv_snprintf + #ifdef CONFIG_LV_SNPRINTF + #define lv_snprintf CONFIG_LV_SNPRINTF + #else + #define lv_snprintf snprintf + #endif + #endif + #ifndef lv_vsnprintf + #ifdef CONFIG_LV_VSNPRINTF + #define lv_vsnprintf CONFIG_LV_VSNPRINTF + #else + #define lv_vsnprintf vsnprintf + #endif + #endif +#else /*LV_SPRINTF_CUSTOM*/ + #ifndef LV_SPRINTF_USE_FLOAT + #ifdef CONFIG_LV_SPRINTF_USE_FLOAT + #define LV_SPRINTF_USE_FLOAT CONFIG_LV_SPRINTF_USE_FLOAT + #else + #define LV_SPRINTF_USE_FLOAT 0 + #endif + #endif +#endif /*LV_SPRINTF_CUSTOM*/ + +#ifndef LV_USE_USER_DATA + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_USER_DATA + #define LV_USE_USER_DATA CONFIG_LV_USE_USER_DATA + #else + #define LV_USE_USER_DATA 0 + #endif + #else + #define LV_USE_USER_DATA 1 + #endif +#endif + +/*Garbage Collector settings + *Used if lvgl is bound to higher level language and the memory is managed by that language*/ +#ifndef LV_ENABLE_GC + #ifdef CONFIG_LV_ENABLE_GC + #define LV_ENABLE_GC CONFIG_LV_ENABLE_GC + #else + #define LV_ENABLE_GC 0 + #endif +#endif +#if LV_ENABLE_GC != 0 + #ifndef LV_GC_INCLUDE + #ifdef CONFIG_LV_GC_INCLUDE + #define LV_GC_INCLUDE CONFIG_LV_GC_INCLUDE + #else + #define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ + #endif + #endif +#endif /*LV_ENABLE_GC*/ + +/*===================== + * COMPILER SETTINGS + *====================*/ + +/*For big endian systems set to 1*/ +#ifndef LV_BIG_ENDIAN_SYSTEM + #ifdef CONFIG_LV_BIG_ENDIAN_SYSTEM + #define LV_BIG_ENDIAN_SYSTEM CONFIG_LV_BIG_ENDIAN_SYSTEM + #else + #define LV_BIG_ENDIAN_SYSTEM 0 + #endif +#endif + +/*Define a custom attribute to `lv_tick_inc` function*/ +#ifndef LV_ATTRIBUTE_TICK_INC + #ifdef CONFIG_LV_ATTRIBUTE_TICK_INC + #define LV_ATTRIBUTE_TICK_INC CONFIG_LV_ATTRIBUTE_TICK_INC + #else + #define LV_ATTRIBUTE_TICK_INC + #endif +#endif + +/*Define a custom attribute to `lv_timer_handler` function*/ +#ifndef LV_ATTRIBUTE_TIMER_HANDLER + #ifdef CONFIG_LV_ATTRIBUTE_TIMER_HANDLER + #define LV_ATTRIBUTE_TIMER_HANDLER CONFIG_LV_ATTRIBUTE_TIMER_HANDLER + #else + #define LV_ATTRIBUTE_TIMER_HANDLER + #endif +#endif + +/*Define a custom attribute to `lv_disp_flush_ready` function*/ +#ifndef LV_ATTRIBUTE_FLUSH_READY + #ifdef CONFIG_LV_ATTRIBUTE_FLUSH_READY + #define LV_ATTRIBUTE_FLUSH_READY CONFIG_LV_ATTRIBUTE_FLUSH_READY + #else + #define LV_ATTRIBUTE_FLUSH_READY + #endif +#endif + +/*Required alignment size for buffers*/ +#ifndef LV_ATTRIBUTE_MEM_ALIGN_SIZE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_ATTRIBUTE_MEM_ALIGN_SIZE + #define LV_ATTRIBUTE_MEM_ALIGN_SIZE CONFIG_LV_ATTRIBUTE_MEM_ALIGN_SIZE + #else + #define LV_ATTRIBUTE_MEM_ALIGN_SIZE 0 + #endif + #else + #define LV_ATTRIBUTE_MEM_ALIGN_SIZE 1 + #endif +#endif + +/*Will be added where memories needs to be aligned (with -Os data might not be aligned to boundary by default). + * E.g. __attribute__((aligned(4)))*/ +#ifndef LV_ATTRIBUTE_MEM_ALIGN + #ifdef CONFIG_LV_ATTRIBUTE_MEM_ALIGN + #define LV_ATTRIBUTE_MEM_ALIGN CONFIG_LV_ATTRIBUTE_MEM_ALIGN + #else + #define LV_ATTRIBUTE_MEM_ALIGN + #endif +#endif + +/*Attribute to mark large constant arrays for example font's bitmaps*/ +#ifndef LV_ATTRIBUTE_LARGE_CONST + #ifdef CONFIG_LV_ATTRIBUTE_LARGE_CONST + #define LV_ATTRIBUTE_LARGE_CONST CONFIG_LV_ATTRIBUTE_LARGE_CONST + #else + #define LV_ATTRIBUTE_LARGE_CONST + #endif +#endif + +/*Compiler prefix for a big array declaration in RAM*/ +#ifndef LV_ATTRIBUTE_LARGE_RAM_ARRAY + #ifdef CONFIG_LV_ATTRIBUTE_LARGE_RAM_ARRAY + #define LV_ATTRIBUTE_LARGE_RAM_ARRAY CONFIG_LV_ATTRIBUTE_LARGE_RAM_ARRAY + #else + #define LV_ATTRIBUTE_LARGE_RAM_ARRAY + #endif +#endif + +/*Place performance critical functions into a faster memory (e.g RAM)*/ +#ifndef LV_ATTRIBUTE_FAST_MEM + #ifdef CONFIG_LV_ATTRIBUTE_FAST_MEM + #define LV_ATTRIBUTE_FAST_MEM CONFIG_LV_ATTRIBUTE_FAST_MEM + #else + #define LV_ATTRIBUTE_FAST_MEM + #endif +#endif + +/*Prefix variables that are used in GPU accelerated operations, often these need to be placed in RAM sections that are DMA accessible*/ +#ifndef LV_ATTRIBUTE_DMA + #ifdef CONFIG_LV_ATTRIBUTE_DMA + #define LV_ATTRIBUTE_DMA CONFIG_LV_ATTRIBUTE_DMA + #else + #define LV_ATTRIBUTE_DMA + #endif +#endif + +/*Export integer constant to binding. This macro is used with constants in the form of LV_ that + *should also appear on LVGL binding API such as Micropython.*/ +#ifndef LV_EXPORT_CONST_INT + #ifdef CONFIG_LV_EXPORT_CONST_INT + #define LV_EXPORT_CONST_INT CONFIG_LV_EXPORT_CONST_INT + #else + #define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning /*The default value just prevents GCC warning*/ + #endif +#endif + +/*Extend the default -32k..32k coordinate range to -4M..4M by using int32_t for coordinates instead of int16_t*/ +#ifndef LV_USE_LARGE_COORD + #ifdef CONFIG_LV_USE_LARGE_COORD + #define LV_USE_LARGE_COORD CONFIG_LV_USE_LARGE_COORD + #else + #define LV_USE_LARGE_COORD 0 + #endif +#endif + +/*================== + * FONT USAGE + *===================*/ + +/*Montserrat fonts with ASCII range and some symbols using bpp = 4 + *https://fonts.google.com/specimen/Montserrat*/ +#ifndef LV_FONT_MONTSERRAT_8 + #ifdef CONFIG_LV_FONT_MONTSERRAT_8 + #define LV_FONT_MONTSERRAT_8 CONFIG_LV_FONT_MONTSERRAT_8 + #else + #define LV_FONT_MONTSERRAT_8 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_10 + #ifdef CONFIG_LV_FONT_MONTSERRAT_10 + #define LV_FONT_MONTSERRAT_10 CONFIG_LV_FONT_MONTSERRAT_10 + #else + #define LV_FONT_MONTSERRAT_10 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_12 + #ifdef CONFIG_LV_FONT_MONTSERRAT_12 + #define LV_FONT_MONTSERRAT_12 CONFIG_LV_FONT_MONTSERRAT_12 + #else + #define LV_FONT_MONTSERRAT_12 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_14 + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_FONT_MONTSERRAT_14 + #define LV_FONT_MONTSERRAT_14 CONFIG_LV_FONT_MONTSERRAT_14 + #else + #define LV_FONT_MONTSERRAT_14 0 + #endif + #else + #define LV_FONT_MONTSERRAT_14 1 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_16 + #ifdef CONFIG_LV_FONT_MONTSERRAT_16 + #define LV_FONT_MONTSERRAT_16 CONFIG_LV_FONT_MONTSERRAT_16 + #else + #define LV_FONT_MONTSERRAT_16 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_18 + #ifdef CONFIG_LV_FONT_MONTSERRAT_18 + #define LV_FONT_MONTSERRAT_18 CONFIG_LV_FONT_MONTSERRAT_18 + #else + #define LV_FONT_MONTSERRAT_18 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_20 + #ifdef CONFIG_LV_FONT_MONTSERRAT_20 + #define LV_FONT_MONTSERRAT_20 CONFIG_LV_FONT_MONTSERRAT_20 + #else + #define LV_FONT_MONTSERRAT_20 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_22 + #ifdef CONFIG_LV_FONT_MONTSERRAT_22 + #define LV_FONT_MONTSERRAT_22 CONFIG_LV_FONT_MONTSERRAT_22 + #else + #define LV_FONT_MONTSERRAT_22 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_24 + #ifdef CONFIG_LV_FONT_MONTSERRAT_24 + #define LV_FONT_MONTSERRAT_24 CONFIG_LV_FONT_MONTSERRAT_24 + #else + #define LV_FONT_MONTSERRAT_24 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_26 + #ifdef CONFIG_LV_FONT_MONTSERRAT_26 + #define LV_FONT_MONTSERRAT_26 CONFIG_LV_FONT_MONTSERRAT_26 + #else + #define LV_FONT_MONTSERRAT_26 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_28 + #ifdef CONFIG_LV_FONT_MONTSERRAT_28 + #define LV_FONT_MONTSERRAT_28 CONFIG_LV_FONT_MONTSERRAT_28 + #else + #define LV_FONT_MONTSERRAT_28 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_30 + #ifdef CONFIG_LV_FONT_MONTSERRAT_30 + #define LV_FONT_MONTSERRAT_30 CONFIG_LV_FONT_MONTSERRAT_30 + #else + #define LV_FONT_MONTSERRAT_30 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_32 + #ifdef CONFIG_LV_FONT_MONTSERRAT_32 + #define LV_FONT_MONTSERRAT_32 CONFIG_LV_FONT_MONTSERRAT_32 + #else + #define LV_FONT_MONTSERRAT_32 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_34 + #ifdef CONFIG_LV_FONT_MONTSERRAT_34 + #define LV_FONT_MONTSERRAT_34 CONFIG_LV_FONT_MONTSERRAT_34 + #else + #define LV_FONT_MONTSERRAT_34 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_36 + #ifdef CONFIG_LV_FONT_MONTSERRAT_36 + #define LV_FONT_MONTSERRAT_36 CONFIG_LV_FONT_MONTSERRAT_36 + #else + #define LV_FONT_MONTSERRAT_36 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_38 + #ifdef CONFIG_LV_FONT_MONTSERRAT_38 + #define LV_FONT_MONTSERRAT_38 CONFIG_LV_FONT_MONTSERRAT_38 + #else + #define LV_FONT_MONTSERRAT_38 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_40 + #ifdef CONFIG_LV_FONT_MONTSERRAT_40 + #define LV_FONT_MONTSERRAT_40 CONFIG_LV_FONT_MONTSERRAT_40 + #else + #define LV_FONT_MONTSERRAT_40 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_42 + #ifdef CONFIG_LV_FONT_MONTSERRAT_42 + #define LV_FONT_MONTSERRAT_42 CONFIG_LV_FONT_MONTSERRAT_42 + #else + #define LV_FONT_MONTSERRAT_42 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_44 + #ifdef CONFIG_LV_FONT_MONTSERRAT_44 + #define LV_FONT_MONTSERRAT_44 CONFIG_LV_FONT_MONTSERRAT_44 + #else + #define LV_FONT_MONTSERRAT_44 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_46 + #ifdef CONFIG_LV_FONT_MONTSERRAT_46 + #define LV_FONT_MONTSERRAT_46 CONFIG_LV_FONT_MONTSERRAT_46 + #else + #define LV_FONT_MONTSERRAT_46 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_48 + #ifdef CONFIG_LV_FONT_MONTSERRAT_48 + #define LV_FONT_MONTSERRAT_48 CONFIG_LV_FONT_MONTSERRAT_48 + #else + #define LV_FONT_MONTSERRAT_48 0 + #endif +#endif + +/*Demonstrate special features*/ +#ifndef LV_FONT_MONTSERRAT_12_SUBPX + #ifdef CONFIG_LV_FONT_MONTSERRAT_12_SUBPX + #define LV_FONT_MONTSERRAT_12_SUBPX CONFIG_LV_FONT_MONTSERRAT_12_SUBPX + #else + #define LV_FONT_MONTSERRAT_12_SUBPX 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_28_COMPRESSED + #ifdef CONFIG_LV_FONT_MONTSERRAT_28_COMPRESSED + #define LV_FONT_MONTSERRAT_28_COMPRESSED CONFIG_LV_FONT_MONTSERRAT_28_COMPRESSED + #else + #define LV_FONT_MONTSERRAT_28_COMPRESSED 0 /*bpp = 3*/ + #endif +#endif +#ifndef LV_FONT_DEJAVU_16_PERSIAN_HEBREW + #ifdef CONFIG_LV_FONT_DEJAVU_16_PERSIAN_HEBREW + #define LV_FONT_DEJAVU_16_PERSIAN_HEBREW CONFIG_LV_FONT_DEJAVU_16_PERSIAN_HEBREW + #else + #define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0 /*Hebrew, Arabic, Persian letters and all their forms*/ + #endif +#endif +#ifndef LV_FONT_SIMSUN_16_CJK + #ifdef CONFIG_LV_FONT_SIMSUN_16_CJK + #define LV_FONT_SIMSUN_16_CJK CONFIG_LV_FONT_SIMSUN_16_CJK + #else + #define LV_FONT_SIMSUN_16_CJK 0 /*1000 most common CJK radicals*/ + #endif +#endif + +/*Pixel perfect monospace fonts*/ +#ifndef LV_FONT_UNSCII_8 + #ifdef CONFIG_LV_FONT_UNSCII_8 + #define LV_FONT_UNSCII_8 CONFIG_LV_FONT_UNSCII_8 + #else + #define LV_FONT_UNSCII_8 0 + #endif +#endif +#ifndef LV_FONT_UNSCII_16 + #ifdef CONFIG_LV_FONT_UNSCII_16 + #define LV_FONT_UNSCII_16 CONFIG_LV_FONT_UNSCII_16 + #else + #define LV_FONT_UNSCII_16 0 + #endif +#endif + +/*Optionally declare custom fonts here. + *You can use these fonts as default font too and they will be available globally. + *E.g. #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) LV_FONT_DECLARE(my_font_2)*/ +#ifndef LV_FONT_CUSTOM_DECLARE + #ifdef CONFIG_LV_FONT_CUSTOM_DECLARE + #define LV_FONT_CUSTOM_DECLARE CONFIG_LV_FONT_CUSTOM_DECLARE + #else + #define LV_FONT_CUSTOM_DECLARE + #endif +#endif + +/*Always set a default font*/ +#ifndef LV_FONT_DEFAULT + #ifdef CONFIG_LV_FONT_DEFAULT + #define LV_FONT_DEFAULT CONFIG_LV_FONT_DEFAULT + #else + #define LV_FONT_DEFAULT &lv_font_montserrat_14 + #endif +#endif + +/*Enable handling large font and/or fonts with a lot of characters. + *The limit depends on the font size, font face and bpp. + *Compiler error will be triggered if a font needs it.*/ +#ifndef LV_FONT_FMT_TXT_LARGE + #ifdef CONFIG_LV_FONT_FMT_TXT_LARGE + #define LV_FONT_FMT_TXT_LARGE CONFIG_LV_FONT_FMT_TXT_LARGE + #else + #define LV_FONT_FMT_TXT_LARGE 0 + #endif +#endif + +/*Enables/disables support for compressed fonts.*/ +#ifndef LV_USE_FONT_COMPRESSED + #ifdef CONFIG_LV_USE_FONT_COMPRESSED + #define LV_USE_FONT_COMPRESSED CONFIG_LV_USE_FONT_COMPRESSED + #else + #define LV_USE_FONT_COMPRESSED 0 + #endif +#endif + +/*Enable subpixel rendering*/ +#ifndef LV_USE_FONT_SUBPX + #ifdef CONFIG_LV_USE_FONT_SUBPX + #define LV_USE_FONT_SUBPX CONFIG_LV_USE_FONT_SUBPX + #else + #define LV_USE_FONT_SUBPX 0 + #endif +#endif +#if LV_USE_FONT_SUBPX + /*Set the pixel order of the display. Physical order of RGB channels. Doesn't matter with "normal" fonts.*/ + #ifndef LV_FONT_SUBPX_BGR + #ifdef CONFIG_LV_FONT_SUBPX_BGR + #define LV_FONT_SUBPX_BGR CONFIG_LV_FONT_SUBPX_BGR + #else + #define LV_FONT_SUBPX_BGR 0 /*0: RGB; 1:BGR order*/ + #endif + #endif +#endif + +/*Enable drawing placeholders when glyph dsc is not found*/ +#ifndef LV_USE_FONT_PLACEHOLDER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_FONT_PLACEHOLDER + #define LV_USE_FONT_PLACEHOLDER CONFIG_LV_USE_FONT_PLACEHOLDER + #else + #define LV_USE_FONT_PLACEHOLDER 0 + #endif + #else + #define LV_USE_FONT_PLACEHOLDER 1 + #endif +#endif + +/*================= + * TEXT SETTINGS + *=================*/ + +/** + * Select a character encoding for strings. + * Your IDE or editor should have the same character encoding + * - LV_TXT_ENC_UTF8 + * - LV_TXT_ENC_ASCII + */ +#ifndef LV_TXT_ENC + #ifdef CONFIG_LV_TXT_ENC + #define LV_TXT_ENC CONFIG_LV_TXT_ENC + #else + #define LV_TXT_ENC LV_TXT_ENC_UTF8 + #endif +#endif + +/*Can break (wrap) texts on these chars*/ +#ifndef LV_TXT_BREAK_CHARS + #ifdef CONFIG_LV_TXT_BREAK_CHARS + #define LV_TXT_BREAK_CHARS CONFIG_LV_TXT_BREAK_CHARS + #else + #define LV_TXT_BREAK_CHARS " ,.;:-_" + #endif +#endif + +/*If a word is at least this long, will break wherever "prettiest" + *To disable, set to a value <= 0*/ +#ifndef LV_TXT_LINE_BREAK_LONG_LEN + #ifdef CONFIG_LV_TXT_LINE_BREAK_LONG_LEN + #define LV_TXT_LINE_BREAK_LONG_LEN CONFIG_LV_TXT_LINE_BREAK_LONG_LEN + #else + #define LV_TXT_LINE_BREAK_LONG_LEN 0 + #endif +#endif + +/*Minimum number of characters in a long word to put on a line before a break. + *Depends on LV_TXT_LINE_BREAK_LONG_LEN.*/ +#ifndef LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN + #ifdef CONFIG_LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN + #define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN CONFIG_LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN + #else + #define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 + #endif +#endif + +/*Minimum number of characters in a long word to put on a line after a break. + *Depends on LV_TXT_LINE_BREAK_LONG_LEN.*/ +#ifndef LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN + #ifdef CONFIG_LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN + #define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN CONFIG_LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN + #else + #define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3 + #endif +#endif + +/*The control character to use for signalling text recoloring.*/ +#ifndef LV_TXT_COLOR_CMD + #ifdef CONFIG_LV_TXT_COLOR_CMD + #define LV_TXT_COLOR_CMD CONFIG_LV_TXT_COLOR_CMD + #else + #define LV_TXT_COLOR_CMD "#" + #endif +#endif + +/*Support bidirectional texts. Allows mixing Left-to-Right and Right-to-Left texts. + *The direction will be processed according to the Unicode Bidirectional Algorithm: + *https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/ +#ifndef LV_USE_BIDI + #ifdef CONFIG_LV_USE_BIDI + #define LV_USE_BIDI CONFIG_LV_USE_BIDI + #else + #define LV_USE_BIDI 0 + #endif +#endif +#if LV_USE_BIDI + /*Set the default direction. Supported values: + *`LV_BASE_DIR_LTR` Left-to-Right + *`LV_BASE_DIR_RTL` Right-to-Left + *`LV_BASE_DIR_AUTO` detect texts base direction*/ + #ifndef LV_BIDI_BASE_DIR_DEF + #ifdef CONFIG_LV_BIDI_BASE_DIR_DEF + #define LV_BIDI_BASE_DIR_DEF CONFIG_LV_BIDI_BASE_DIR_DEF + #else + #define LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_AUTO + #endif + #endif +#endif + +/*Enable Arabic/Persian processing + *In these languages characters should be replaced with an other form based on their position in the text*/ +#ifndef LV_USE_ARABIC_PERSIAN_CHARS + #ifdef CONFIG_LV_USE_ARABIC_PERSIAN_CHARS + #define LV_USE_ARABIC_PERSIAN_CHARS CONFIG_LV_USE_ARABIC_PERSIAN_CHARS + #else + #define LV_USE_ARABIC_PERSIAN_CHARS 0 + #endif +#endif + +/*================== + * WIDGET USAGE + *================*/ + +/*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/ + +#ifndef LV_USE_ARC + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ARC + #define LV_USE_ARC CONFIG_LV_USE_ARC + #else + #define LV_USE_ARC 0 + #endif + #else + #define LV_USE_ARC 1 + #endif +#endif + +#ifndef LV_USE_BAR + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_BAR + #define LV_USE_BAR CONFIG_LV_USE_BAR + #else + #define LV_USE_BAR 0 + #endif + #else + #define LV_USE_BAR 1 + #endif +#endif + +#ifndef LV_USE_BTN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_BTN + #define LV_USE_BTN CONFIG_LV_USE_BTN + #else + #define LV_USE_BTN 0 + #endif + #else + #define LV_USE_BTN 1 + #endif +#endif + +#ifndef LV_USE_BTNMATRIX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_BTNMATRIX + #define LV_USE_BTNMATRIX CONFIG_LV_USE_BTNMATRIX + #else + #define LV_USE_BTNMATRIX 0 + #endif + #else + #define LV_USE_BTNMATRIX 1 + #endif +#endif + +#ifndef LV_USE_CANVAS + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CANVAS + #define LV_USE_CANVAS CONFIG_LV_USE_CANVAS + #else + #define LV_USE_CANVAS 0 + #endif + #else + #define LV_USE_CANVAS 1 + #endif +#endif + +#ifndef LV_USE_CHECKBOX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CHECKBOX + #define LV_USE_CHECKBOX CONFIG_LV_USE_CHECKBOX + #else + #define LV_USE_CHECKBOX 0 + #endif + #else + #define LV_USE_CHECKBOX 1 + #endif +#endif + +#ifndef LV_USE_DROPDOWN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_DROPDOWN + #define LV_USE_DROPDOWN CONFIG_LV_USE_DROPDOWN + #else + #define LV_USE_DROPDOWN 0 + #endif + #else + #define LV_USE_DROPDOWN 1 /*Requires: lv_label*/ + #endif +#endif + +#ifndef LV_USE_IMG + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_IMG + #define LV_USE_IMG CONFIG_LV_USE_IMG + #else + #define LV_USE_IMG 0 + #endif + #else + #define LV_USE_IMG 1 /*Requires: lv_label*/ + #endif +#endif + +#ifndef LV_USE_LABEL + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_LABEL + #define LV_USE_LABEL CONFIG_LV_USE_LABEL + #else + #define LV_USE_LABEL 0 + #endif + #else + #define LV_USE_LABEL 1 + #endif +#endif +#if LV_USE_LABEL + #ifndef LV_LABEL_TEXT_SELECTION + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LABEL_TEXT_SELECTION + #define LV_LABEL_TEXT_SELECTION CONFIG_LV_LABEL_TEXT_SELECTION + #else + #define LV_LABEL_TEXT_SELECTION 0 + #endif + #else + #define LV_LABEL_TEXT_SELECTION 1 /*Enable selecting text of the label*/ + #endif + #endif + #ifndef LV_LABEL_LONG_TXT_HINT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LABEL_LONG_TXT_HINT + #define LV_LABEL_LONG_TXT_HINT CONFIG_LV_LABEL_LONG_TXT_HINT + #else + #define LV_LABEL_LONG_TXT_HINT 0 + #endif + #else + #define LV_LABEL_LONG_TXT_HINT 1 /*Store some extra info in labels to speed up drawing of very long texts*/ + #endif + #endif +#endif + +#ifndef LV_USE_LINE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_LINE + #define LV_USE_LINE CONFIG_LV_USE_LINE + #else + #define LV_USE_LINE 0 + #endif + #else + #define LV_USE_LINE 1 + #endif +#endif + +#ifndef LV_USE_ROLLER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ROLLER + #define LV_USE_ROLLER CONFIG_LV_USE_ROLLER + #else + #define LV_USE_ROLLER 0 + #endif + #else + #define LV_USE_ROLLER 1 /*Requires: lv_label*/ + #endif +#endif +#if LV_USE_ROLLER + #ifndef LV_ROLLER_INF_PAGES + #ifdef CONFIG_LV_ROLLER_INF_PAGES + #define LV_ROLLER_INF_PAGES CONFIG_LV_ROLLER_INF_PAGES + #else + #define LV_ROLLER_INF_PAGES 7 /*Number of extra "pages" when the roller is infinite*/ + #endif + #endif +#endif + +#ifndef LV_USE_SLIDER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SLIDER + #define LV_USE_SLIDER CONFIG_LV_USE_SLIDER + #else + #define LV_USE_SLIDER 0 + #endif + #else + #define LV_USE_SLIDER 1 /*Requires: lv_bar*/ + #endif +#endif + +#ifndef LV_USE_SWITCH + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SWITCH + #define LV_USE_SWITCH CONFIG_LV_USE_SWITCH + #else + #define LV_USE_SWITCH 0 + #endif + #else + #define LV_USE_SWITCH 1 + #endif +#endif + +#ifndef LV_USE_TEXTAREA + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_TEXTAREA + #define LV_USE_TEXTAREA CONFIG_LV_USE_TEXTAREA + #else + #define LV_USE_TEXTAREA 0 + #endif + #else + #define LV_USE_TEXTAREA 1 /*Requires: lv_label*/ + #endif +#endif +#if LV_USE_TEXTAREA != 0 + #ifndef LV_TEXTAREA_DEF_PWD_SHOW_TIME + #ifdef CONFIG_LV_TEXTAREA_DEF_PWD_SHOW_TIME + #define LV_TEXTAREA_DEF_PWD_SHOW_TIME CONFIG_LV_TEXTAREA_DEF_PWD_SHOW_TIME + #else + #define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/ + #endif + #endif +#endif + +#ifndef LV_USE_TABLE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_TABLE + #define LV_USE_TABLE CONFIG_LV_USE_TABLE + #else + #define LV_USE_TABLE 0 + #endif + #else + #define LV_USE_TABLE 1 + #endif +#endif + +/*================== + * EXTRA COMPONENTS + *==================*/ + +/*----------- + * Widgets + *----------*/ +#ifndef LV_USE_ANIMIMG + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ANIMIMG + #define LV_USE_ANIMIMG CONFIG_LV_USE_ANIMIMG + #else + #define LV_USE_ANIMIMG 0 + #endif + #else + #define LV_USE_ANIMIMG 1 + #endif +#endif + +#ifndef LV_USE_CALENDAR + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CALENDAR + #define LV_USE_CALENDAR CONFIG_LV_USE_CALENDAR + #else + #define LV_USE_CALENDAR 0 + #endif + #else + #define LV_USE_CALENDAR 1 + #endif +#endif +#if LV_USE_CALENDAR + #ifndef LV_CALENDAR_WEEK_STARTS_MONDAY + #ifdef CONFIG_LV_CALENDAR_WEEK_STARTS_MONDAY + #define LV_CALENDAR_WEEK_STARTS_MONDAY CONFIG_LV_CALENDAR_WEEK_STARTS_MONDAY + #else + #define LV_CALENDAR_WEEK_STARTS_MONDAY 0 + #endif + #endif + #if LV_CALENDAR_WEEK_STARTS_MONDAY + #ifndef LV_CALENDAR_DEFAULT_DAY_NAMES + #ifdef CONFIG_LV_CALENDAR_DEFAULT_DAY_NAMES + #define LV_CALENDAR_DEFAULT_DAY_NAMES CONFIG_LV_CALENDAR_DEFAULT_DAY_NAMES + #else + #define LV_CALENDAR_DEFAULT_DAY_NAMES {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"} + #endif + #endif + #else + #ifndef LV_CALENDAR_DEFAULT_DAY_NAMES + #ifdef CONFIG_LV_CALENDAR_DEFAULT_DAY_NAMES + #define LV_CALENDAR_DEFAULT_DAY_NAMES CONFIG_LV_CALENDAR_DEFAULT_DAY_NAMES + #else + #define LV_CALENDAR_DEFAULT_DAY_NAMES {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"} + #endif + #endif + #endif + + #ifndef LV_CALENDAR_DEFAULT_MONTH_NAMES + #ifdef CONFIG_LV_CALENDAR_DEFAULT_MONTH_NAMES + #define LV_CALENDAR_DEFAULT_MONTH_NAMES CONFIG_LV_CALENDAR_DEFAULT_MONTH_NAMES + #else + #define LV_CALENDAR_DEFAULT_MONTH_NAMES {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} + #endif + #endif + #ifndef LV_USE_CALENDAR_HEADER_ARROW + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CALENDAR_HEADER_ARROW + #define LV_USE_CALENDAR_HEADER_ARROW CONFIG_LV_USE_CALENDAR_HEADER_ARROW + #else + #define LV_USE_CALENDAR_HEADER_ARROW 0 + #endif + #else + #define LV_USE_CALENDAR_HEADER_ARROW 1 + #endif + #endif + #ifndef LV_USE_CALENDAR_HEADER_DROPDOWN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CALENDAR_HEADER_DROPDOWN + #define LV_USE_CALENDAR_HEADER_DROPDOWN CONFIG_LV_USE_CALENDAR_HEADER_DROPDOWN + #else + #define LV_USE_CALENDAR_HEADER_DROPDOWN 0 + #endif + #else + #define LV_USE_CALENDAR_HEADER_DROPDOWN 1 + #endif + #endif +#endif /*LV_USE_CALENDAR*/ + +#ifndef LV_USE_CHART + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CHART + #define LV_USE_CHART CONFIG_LV_USE_CHART + #else + #define LV_USE_CHART 0 + #endif + #else + #define LV_USE_CHART 1 + #endif +#endif + +#ifndef LV_USE_COLORWHEEL + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_COLORWHEEL + #define LV_USE_COLORWHEEL CONFIG_LV_USE_COLORWHEEL + #else + #define LV_USE_COLORWHEEL 0 + #endif + #else + #define LV_USE_COLORWHEEL 1 + #endif +#endif + +#ifndef LV_USE_IMGBTN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_IMGBTN + #define LV_USE_IMGBTN CONFIG_LV_USE_IMGBTN + #else + #define LV_USE_IMGBTN 0 + #endif + #else + #define LV_USE_IMGBTN 1 + #endif +#endif + +#ifndef LV_USE_KEYBOARD + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_KEYBOARD + #define LV_USE_KEYBOARD CONFIG_LV_USE_KEYBOARD + #else + #define LV_USE_KEYBOARD 0 + #endif + #else + #define LV_USE_KEYBOARD 1 + #endif +#endif + +#ifndef LV_USE_LED + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_LED + #define LV_USE_LED CONFIG_LV_USE_LED + #else + #define LV_USE_LED 0 + #endif + #else + #define LV_USE_LED 1 + #endif +#endif + +#ifndef LV_USE_LIST + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_LIST + #define LV_USE_LIST CONFIG_LV_USE_LIST + #else + #define LV_USE_LIST 0 + #endif + #else + #define LV_USE_LIST 1 + #endif +#endif + +#ifndef LV_USE_MENU + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_MENU + #define LV_USE_MENU CONFIG_LV_USE_MENU + #else + #define LV_USE_MENU 0 + #endif + #else + #define LV_USE_MENU 1 + #endif +#endif + +#ifndef LV_USE_METER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_METER + #define LV_USE_METER CONFIG_LV_USE_METER + #else + #define LV_USE_METER 0 + #endif + #else + #define LV_USE_METER 1 + #endif +#endif + +#ifndef LV_USE_MSGBOX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_MSGBOX + #define LV_USE_MSGBOX CONFIG_LV_USE_MSGBOX + #else + #define LV_USE_MSGBOX 0 + #endif + #else + #define LV_USE_MSGBOX 1 + #endif +#endif + +#ifndef LV_USE_SPAN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SPAN + #define LV_USE_SPAN CONFIG_LV_USE_SPAN + #else + #define LV_USE_SPAN 0 + #endif + #else + #define LV_USE_SPAN 1 + #endif +#endif +#if LV_USE_SPAN + /*A line text can contain maximum num of span descriptor */ + #ifndef LV_SPAN_SNIPPET_STACK_SIZE + #ifdef CONFIG_LV_SPAN_SNIPPET_STACK_SIZE + #define LV_SPAN_SNIPPET_STACK_SIZE CONFIG_LV_SPAN_SNIPPET_STACK_SIZE + #else + #define LV_SPAN_SNIPPET_STACK_SIZE 64 + #endif + #endif +#endif + +#ifndef LV_USE_SPINBOX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SPINBOX + #define LV_USE_SPINBOX CONFIG_LV_USE_SPINBOX + #else + #define LV_USE_SPINBOX 0 + #endif + #else + #define LV_USE_SPINBOX 1 + #endif +#endif + +#ifndef LV_USE_SPINNER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SPINNER + #define LV_USE_SPINNER CONFIG_LV_USE_SPINNER + #else + #define LV_USE_SPINNER 0 + #endif + #else + #define LV_USE_SPINNER 1 + #endif +#endif + +#ifndef LV_USE_TABVIEW + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_TABVIEW + #define LV_USE_TABVIEW CONFIG_LV_USE_TABVIEW + #else + #define LV_USE_TABVIEW 0 + #endif + #else + #define LV_USE_TABVIEW 1 + #endif +#endif + +#ifndef LV_USE_TILEVIEW + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_TILEVIEW + #define LV_USE_TILEVIEW CONFIG_LV_USE_TILEVIEW + #else + #define LV_USE_TILEVIEW 0 + #endif + #else + #define LV_USE_TILEVIEW 1 + #endif +#endif + +#ifndef LV_USE_WIN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_WIN + #define LV_USE_WIN CONFIG_LV_USE_WIN + #else + #define LV_USE_WIN 0 + #endif + #else + #define LV_USE_WIN 1 + #endif +#endif + +/*----------- + * Themes + *----------*/ + +/*A simple, impressive and very complete theme*/ +#ifndef LV_USE_THEME_DEFAULT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_THEME_DEFAULT + #define LV_USE_THEME_DEFAULT CONFIG_LV_USE_THEME_DEFAULT + #else + #define LV_USE_THEME_DEFAULT 0 + #endif + #else + #define LV_USE_THEME_DEFAULT 1 + #endif +#endif +#if LV_USE_THEME_DEFAULT + + /*0: Light mode; 1: Dark mode*/ + #ifndef LV_THEME_DEFAULT_DARK + #ifdef CONFIG_LV_THEME_DEFAULT_DARK + #define LV_THEME_DEFAULT_DARK CONFIG_LV_THEME_DEFAULT_DARK + #else + #define LV_THEME_DEFAULT_DARK 0 + #endif + #endif + + /*1: Enable grow on press*/ + #ifndef LV_THEME_DEFAULT_GROW + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_THEME_DEFAULT_GROW + #define LV_THEME_DEFAULT_GROW CONFIG_LV_THEME_DEFAULT_GROW + #else + #define LV_THEME_DEFAULT_GROW 0 + #endif + #else + #define LV_THEME_DEFAULT_GROW 1 + #endif + #endif + + /*Default transition time in [ms]*/ + #ifndef LV_THEME_DEFAULT_TRANSITION_TIME + #ifdef CONFIG_LV_THEME_DEFAULT_TRANSITION_TIME + #define LV_THEME_DEFAULT_TRANSITION_TIME CONFIG_LV_THEME_DEFAULT_TRANSITION_TIME + #else + #define LV_THEME_DEFAULT_TRANSITION_TIME 80 + #endif + #endif +#endif /*LV_USE_THEME_DEFAULT*/ + +/*A very simple theme that is a good starting point for a custom theme*/ +#ifndef LV_USE_THEME_BASIC + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_THEME_BASIC + #define LV_USE_THEME_BASIC CONFIG_LV_USE_THEME_BASIC + #else + #define LV_USE_THEME_BASIC 0 + #endif + #else + #define LV_USE_THEME_BASIC 1 + #endif +#endif + +/*A theme designed for monochrome displays*/ +#ifndef LV_USE_THEME_MONO + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_THEME_MONO + #define LV_USE_THEME_MONO CONFIG_LV_USE_THEME_MONO + #else + #define LV_USE_THEME_MONO 0 + #endif + #else + #define LV_USE_THEME_MONO 1 + #endif +#endif + +/*----------- + * Layouts + *----------*/ + +/*A layout similar to Flexbox in CSS.*/ +#ifndef LV_USE_FLEX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_FLEX + #define LV_USE_FLEX CONFIG_LV_USE_FLEX + #else + #define LV_USE_FLEX 0 + #endif + #else + #define LV_USE_FLEX 1 + #endif +#endif + +/*A layout similar to Grid in CSS.*/ +#ifndef LV_USE_GRID + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_GRID + #define LV_USE_GRID CONFIG_LV_USE_GRID + #else + #define LV_USE_GRID 0 + #endif + #else + #define LV_USE_GRID 1 + #endif +#endif + +/*--------------------- + * 3rd party libraries + *--------------------*/ + +/*File system interfaces for common APIs */ + +/*API for fopen, fread, etc*/ +#ifndef LV_USE_FS_STDIO + #ifdef CONFIG_LV_USE_FS_STDIO + #define LV_USE_FS_STDIO CONFIG_LV_USE_FS_STDIO + #else + #define LV_USE_FS_STDIO 0 + #endif +#endif +#if LV_USE_FS_STDIO + #ifndef LV_FS_STDIO_LETTER + #ifdef CONFIG_LV_FS_STDIO_LETTER + #define LV_FS_STDIO_LETTER CONFIG_LV_FS_STDIO_LETTER + #else + #define LV_FS_STDIO_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #endif + #endif + #ifndef LV_FS_STDIO_PATH + #ifdef CONFIG_LV_FS_STDIO_PATH + #define LV_FS_STDIO_PATH CONFIG_LV_FS_STDIO_PATH + #else + #define LV_FS_STDIO_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #endif + #endif + #ifndef LV_FS_STDIO_CACHE_SIZE + #ifdef CONFIG_LV_FS_STDIO_CACHE_SIZE + #define LV_FS_STDIO_CACHE_SIZE CONFIG_LV_FS_STDIO_CACHE_SIZE + #else + #define LV_FS_STDIO_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ + #endif + #endif +#endif + +/*API for open, read, etc*/ +#ifndef LV_USE_FS_POSIX + #ifdef CONFIG_LV_USE_FS_POSIX + #define LV_USE_FS_POSIX CONFIG_LV_USE_FS_POSIX + #else + #define LV_USE_FS_POSIX 0 + #endif +#endif +#if LV_USE_FS_POSIX + #ifndef LV_FS_POSIX_LETTER + #ifdef CONFIG_LV_FS_POSIX_LETTER + #define LV_FS_POSIX_LETTER CONFIG_LV_FS_POSIX_LETTER + #else + #define LV_FS_POSIX_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #endif + #endif + #ifndef LV_FS_POSIX_PATH + #ifdef CONFIG_LV_FS_POSIX_PATH + #define LV_FS_POSIX_PATH CONFIG_LV_FS_POSIX_PATH + #else + #define LV_FS_POSIX_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #endif + #endif + #ifndef LV_FS_POSIX_CACHE_SIZE + #ifdef CONFIG_LV_FS_POSIX_CACHE_SIZE + #define LV_FS_POSIX_CACHE_SIZE CONFIG_LV_FS_POSIX_CACHE_SIZE + #else + #define LV_FS_POSIX_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ + #endif + #endif +#endif + +/*API for CreateFile, ReadFile, etc*/ +#ifndef LV_USE_FS_WIN32 + #ifdef CONFIG_LV_USE_FS_WIN32 + #define LV_USE_FS_WIN32 CONFIG_LV_USE_FS_WIN32 + #else + #define LV_USE_FS_WIN32 0 + #endif +#endif +#if LV_USE_FS_WIN32 + #ifndef LV_FS_WIN32_LETTER + #ifdef CONFIG_LV_FS_WIN32_LETTER + #define LV_FS_WIN32_LETTER CONFIG_LV_FS_WIN32_LETTER + #else + #define LV_FS_WIN32_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #endif + #endif + #ifndef LV_FS_WIN32_PATH + #ifdef CONFIG_LV_FS_WIN32_PATH + #define LV_FS_WIN32_PATH CONFIG_LV_FS_WIN32_PATH + #else + #define LV_FS_WIN32_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #endif + #endif + #ifndef LV_FS_WIN32_CACHE_SIZE + #ifdef CONFIG_LV_FS_WIN32_CACHE_SIZE + #define LV_FS_WIN32_CACHE_SIZE CONFIG_LV_FS_WIN32_CACHE_SIZE + #else + #define LV_FS_WIN32_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ + #endif + #endif +#endif + +/*API for FATFS (needs to be added separately). Uses f_open, f_read, etc*/ +#ifndef LV_USE_FS_FATFS + #ifdef CONFIG_LV_USE_FS_FATFS + #define LV_USE_FS_FATFS CONFIG_LV_USE_FS_FATFS + #else + #define LV_USE_FS_FATFS 0 + #endif +#endif +#if LV_USE_FS_FATFS + #ifndef LV_FS_FATFS_LETTER + #ifdef CONFIG_LV_FS_FATFS_LETTER + #define LV_FS_FATFS_LETTER CONFIG_LV_FS_FATFS_LETTER + #else + #define LV_FS_FATFS_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #endif + #endif + #ifndef LV_FS_FATFS_CACHE_SIZE + #ifdef CONFIG_LV_FS_FATFS_CACHE_SIZE + #define LV_FS_FATFS_CACHE_SIZE CONFIG_LV_FS_FATFS_CACHE_SIZE + #else + #define LV_FS_FATFS_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ + #endif + #endif +#endif + +/*PNG decoder library*/ +#ifndef LV_USE_PNG + #ifdef CONFIG_LV_USE_PNG + #define LV_USE_PNG CONFIG_LV_USE_PNG + #else + #define LV_USE_PNG 0 + #endif +#endif + +/*BMP decoder library*/ +#ifndef LV_USE_BMP + #ifdef CONFIG_LV_USE_BMP + #define LV_USE_BMP CONFIG_LV_USE_BMP + #else + #define LV_USE_BMP 0 + #endif +#endif + +/* JPG + split JPG decoder library. + * Split JPG is a custom format optimized for embedded systems. */ +#ifndef LV_USE_SJPG + #ifdef CONFIG_LV_USE_SJPG + #define LV_USE_SJPG CONFIG_LV_USE_SJPG + #else + #define LV_USE_SJPG 0 + #endif +#endif + +/*GIF decoder library*/ +#ifndef LV_USE_GIF + #ifdef CONFIG_LV_USE_GIF + #define LV_USE_GIF CONFIG_LV_USE_GIF + #else + #define LV_USE_GIF 0 + #endif +#endif + +/*QR code library*/ +#ifndef LV_USE_QRCODE + #ifdef CONFIG_LV_USE_QRCODE + #define LV_USE_QRCODE CONFIG_LV_USE_QRCODE + #else + #define LV_USE_QRCODE 0 + #endif +#endif + +/*FreeType library*/ +#ifndef LV_USE_FREETYPE + #ifdef CONFIG_LV_USE_FREETYPE + #define LV_USE_FREETYPE CONFIG_LV_USE_FREETYPE + #else + #define LV_USE_FREETYPE 0 + #endif +#endif +#if LV_USE_FREETYPE + /*Memory used by FreeType to cache characters [bytes] (-1: no caching)*/ + #ifndef LV_FREETYPE_CACHE_SIZE + #ifdef CONFIG_LV_FREETYPE_CACHE_SIZE + #define LV_FREETYPE_CACHE_SIZE CONFIG_LV_FREETYPE_CACHE_SIZE + #else + #define LV_FREETYPE_CACHE_SIZE (16 * 1024) + #endif + #endif + #if LV_FREETYPE_CACHE_SIZE >= 0 + /* 1: bitmap cache use the sbit cache, 0:bitmap cache use the image cache. */ + /* sbit cache:it is much more memory efficient for small bitmaps(font size < 256) */ + /* if font size >= 256, must be configured as image cache */ + #ifndef LV_FREETYPE_SBIT_CACHE + #ifdef CONFIG_LV_FREETYPE_SBIT_CACHE + #define LV_FREETYPE_SBIT_CACHE CONFIG_LV_FREETYPE_SBIT_CACHE + #else + #define LV_FREETYPE_SBIT_CACHE 0 + #endif + #endif + /* Maximum number of opened FT_Face/FT_Size objects managed by this cache instance. */ + /* (0:use system defaults) */ + #ifndef LV_FREETYPE_CACHE_FT_FACES + #ifdef CONFIG_LV_FREETYPE_CACHE_FT_FACES + #define LV_FREETYPE_CACHE_FT_FACES CONFIG_LV_FREETYPE_CACHE_FT_FACES + #else + #define LV_FREETYPE_CACHE_FT_FACES 0 + #endif + #endif + #ifndef LV_FREETYPE_CACHE_FT_SIZES + #ifdef CONFIG_LV_FREETYPE_CACHE_FT_SIZES + #define LV_FREETYPE_CACHE_FT_SIZES CONFIG_LV_FREETYPE_CACHE_FT_SIZES + #else + #define LV_FREETYPE_CACHE_FT_SIZES 0 + #endif + #endif + #endif +#endif + +/*Rlottie library*/ +#ifndef LV_USE_RLOTTIE + #ifdef CONFIG_LV_USE_RLOTTIE + #define LV_USE_RLOTTIE CONFIG_LV_USE_RLOTTIE + #else + #define LV_USE_RLOTTIE 0 + #endif +#endif + +/*FFmpeg library for image decoding and playing videos + *Supports all major image formats so do not enable other image decoder with it*/ +#ifndef LV_USE_FFMPEG + #ifdef CONFIG_LV_USE_FFMPEG + #define LV_USE_FFMPEG CONFIG_LV_USE_FFMPEG + #else + #define LV_USE_FFMPEG 0 + #endif +#endif +#if LV_USE_FFMPEG + /*Dump input information to stderr*/ + #ifndef LV_FFMPEG_DUMP_FORMAT + #ifdef CONFIG_LV_FFMPEG_DUMP_FORMAT + #define LV_FFMPEG_DUMP_FORMAT CONFIG_LV_FFMPEG_DUMP_FORMAT + #else + #define LV_FFMPEG_DUMP_FORMAT 0 + #endif + #endif +#endif + +/*----------- + * Others + *----------*/ + +/*1: Enable API to take snapshot for object*/ +#ifndef LV_USE_SNAPSHOT + #ifdef CONFIG_LV_USE_SNAPSHOT + #define LV_USE_SNAPSHOT CONFIG_LV_USE_SNAPSHOT + #else + #define LV_USE_SNAPSHOT 0 + #endif +#endif + +/*1: Enable Monkey test*/ +#ifndef LV_USE_MONKEY + #ifdef CONFIG_LV_USE_MONKEY + #define LV_USE_MONKEY CONFIG_LV_USE_MONKEY + #else + #define LV_USE_MONKEY 0 + #endif +#endif + +/*1: Enable grid navigation*/ +#ifndef LV_USE_GRIDNAV + #ifdef CONFIG_LV_USE_GRIDNAV + #define LV_USE_GRIDNAV CONFIG_LV_USE_GRIDNAV + #else + #define LV_USE_GRIDNAV 0 + #endif +#endif + +/*1: Enable lv_obj fragment*/ +#ifndef LV_USE_FRAGMENT + #ifdef CONFIG_LV_USE_FRAGMENT + #define LV_USE_FRAGMENT CONFIG_LV_USE_FRAGMENT + #else + #define LV_USE_FRAGMENT 0 + #endif +#endif + +/*1: Support using images as font in label or span widgets */ +#ifndef LV_USE_IMGFONT + #ifdef CONFIG_LV_USE_IMGFONT + #define LV_USE_IMGFONT CONFIG_LV_USE_IMGFONT + #else + #define LV_USE_IMGFONT 0 + #endif +#endif + +/*1: Enable a published subscriber based messaging system */ +#ifndef LV_USE_MSG + #ifdef CONFIG_LV_USE_MSG + #define LV_USE_MSG CONFIG_LV_USE_MSG + #else + #define LV_USE_MSG 0 + #endif +#endif + +/*1: Enable Pinyin input method*/ +/*Requires: lv_keyboard*/ +#ifndef LV_USE_IME_PINYIN + #ifdef CONFIG_LV_USE_IME_PINYIN + #define LV_USE_IME_PINYIN CONFIG_LV_USE_IME_PINYIN + #else + #define LV_USE_IME_PINYIN 0 + #endif +#endif +#if LV_USE_IME_PINYIN + /*1: Use default thesaurus*/ + /*If you do not use the default thesaurus, be sure to use `lv_ime_pinyin` after setting the thesauruss*/ + #ifndef LV_IME_PINYIN_USE_DEFAULT_DICT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_IME_PINYIN_USE_DEFAULT_DICT + #define LV_IME_PINYIN_USE_DEFAULT_DICT CONFIG_LV_IME_PINYIN_USE_DEFAULT_DICT + #else + #define LV_IME_PINYIN_USE_DEFAULT_DICT 0 + #endif + #else + #define LV_IME_PINYIN_USE_DEFAULT_DICT 1 + #endif + #endif + /*Set the maximum number of candidate panels that can be displayed*/ + /*This needs to be adjusted according to the size of the screen*/ + #ifndef LV_IME_PINYIN_CAND_TEXT_NUM + #ifdef CONFIG_LV_IME_PINYIN_CAND_TEXT_NUM + #define LV_IME_PINYIN_CAND_TEXT_NUM CONFIG_LV_IME_PINYIN_CAND_TEXT_NUM + #else + #define LV_IME_PINYIN_CAND_TEXT_NUM 6 + #endif + #endif + + /*Use 9 key input(k9)*/ + #ifndef LV_IME_PINYIN_USE_K9_MODE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_IME_PINYIN_USE_K9_MODE + #define LV_IME_PINYIN_USE_K9_MODE CONFIG_LV_IME_PINYIN_USE_K9_MODE + #else + #define LV_IME_PINYIN_USE_K9_MODE 0 + #endif + #else + #define LV_IME_PINYIN_USE_K9_MODE 1 + #endif + #endif + #if LV_IME_PINYIN_USE_K9_MODE == 1 + #ifndef LV_IME_PINYIN_K9_CAND_TEXT_NUM + #ifdef CONFIG_LV_IME_PINYIN_K9_CAND_TEXT_NUM + #define LV_IME_PINYIN_K9_CAND_TEXT_NUM CONFIG_LV_IME_PINYIN_K9_CAND_TEXT_NUM + #else + #define LV_IME_PINYIN_K9_CAND_TEXT_NUM 3 + #endif + #endif + #endif // LV_IME_PINYIN_USE_K9_MODE +#endif + +/*================== +* EXAMPLES +*==================*/ + +/*Enable the examples to be built with the library*/ +#ifndef LV_BUILD_EXAMPLES + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_BUILD_EXAMPLES + #define LV_BUILD_EXAMPLES CONFIG_LV_BUILD_EXAMPLES + #else + #define LV_BUILD_EXAMPLES 0 + #endif + #else + #define LV_BUILD_EXAMPLES 1 + #endif +#endif + +/*=================== + * DEMO USAGE + ====================*/ + +/*Show some widget. It might be required to increase `LV_MEM_SIZE` */ +#ifndef LV_USE_DEMO_WIDGETS + #ifdef CONFIG_LV_USE_DEMO_WIDGETS + #define LV_USE_DEMO_WIDGETS CONFIG_LV_USE_DEMO_WIDGETS + #else + #define LV_USE_DEMO_WIDGETS 0 + #endif +#endif +#if LV_USE_DEMO_WIDGETS +#ifndef LV_DEMO_WIDGETS_SLIDESHOW + #ifdef CONFIG_LV_DEMO_WIDGETS_SLIDESHOW + #define LV_DEMO_WIDGETS_SLIDESHOW CONFIG_LV_DEMO_WIDGETS_SLIDESHOW + #else + #define LV_DEMO_WIDGETS_SLIDESHOW 0 + #endif +#endif +#endif + +/*Demonstrate the usage of encoder and keyboard*/ +#ifndef LV_USE_DEMO_KEYPAD_AND_ENCODER + #ifdef CONFIG_LV_USE_DEMO_KEYPAD_AND_ENCODER + #define LV_USE_DEMO_KEYPAD_AND_ENCODER CONFIG_LV_USE_DEMO_KEYPAD_AND_ENCODER + #else + #define LV_USE_DEMO_KEYPAD_AND_ENCODER 0 + #endif +#endif + +/*Benchmark your system*/ +#ifndef LV_USE_DEMO_BENCHMARK + #ifdef CONFIG_LV_USE_DEMO_BENCHMARK + #define LV_USE_DEMO_BENCHMARK CONFIG_LV_USE_DEMO_BENCHMARK + #else + #define LV_USE_DEMO_BENCHMARK 0 + #endif +#endif +#if LV_USE_DEMO_BENCHMARK +/*Use RGB565A8 images with 16 bit color depth instead of ARGB8565*/ +#ifndef LV_DEMO_BENCHMARK_RGB565A8 + #ifdef CONFIG_LV_DEMO_BENCHMARK_RGB565A8 + #define LV_DEMO_BENCHMARK_RGB565A8 CONFIG_LV_DEMO_BENCHMARK_RGB565A8 + #else + #define LV_DEMO_BENCHMARK_RGB565A8 0 + #endif +#endif +#endif + +/*Stress test for LVGL*/ +#ifndef LV_USE_DEMO_STRESS + #ifdef CONFIG_LV_USE_DEMO_STRESS + #define LV_USE_DEMO_STRESS CONFIG_LV_USE_DEMO_STRESS + #else + #define LV_USE_DEMO_STRESS 0 + #endif +#endif + +/*Music player demo*/ +#ifndef LV_USE_DEMO_MUSIC + #ifdef CONFIG_LV_USE_DEMO_MUSIC + #define LV_USE_DEMO_MUSIC CONFIG_LV_USE_DEMO_MUSIC + #else + #define LV_USE_DEMO_MUSIC 0 + #endif +#endif +#if LV_USE_DEMO_MUSIC + #ifndef LV_DEMO_MUSIC_SQUARE + #ifdef CONFIG_LV_DEMO_MUSIC_SQUARE + #define LV_DEMO_MUSIC_SQUARE CONFIG_LV_DEMO_MUSIC_SQUARE + #else + #define LV_DEMO_MUSIC_SQUARE 0 + #endif + #endif + #ifndef LV_DEMO_MUSIC_LANDSCAPE + #ifdef CONFIG_LV_DEMO_MUSIC_LANDSCAPE + #define LV_DEMO_MUSIC_LANDSCAPE CONFIG_LV_DEMO_MUSIC_LANDSCAPE + #else + #define LV_DEMO_MUSIC_LANDSCAPE 0 + #endif + #endif + #ifndef LV_DEMO_MUSIC_ROUND + #ifdef CONFIG_LV_DEMO_MUSIC_ROUND + #define LV_DEMO_MUSIC_ROUND CONFIG_LV_DEMO_MUSIC_ROUND + #else + #define LV_DEMO_MUSIC_ROUND 0 + #endif + #endif + #ifndef LV_DEMO_MUSIC_LARGE + #ifdef CONFIG_LV_DEMO_MUSIC_LARGE + #define LV_DEMO_MUSIC_LARGE CONFIG_LV_DEMO_MUSIC_LARGE + #else + #define LV_DEMO_MUSIC_LARGE 0 + #endif + #endif + #ifndef LV_DEMO_MUSIC_AUTO_PLAY + #ifdef CONFIG_LV_DEMO_MUSIC_AUTO_PLAY + #define LV_DEMO_MUSIC_AUTO_PLAY CONFIG_LV_DEMO_MUSIC_AUTO_PLAY + #else + #define LV_DEMO_MUSIC_AUTO_PLAY 0 + #endif + #endif +#endif + + + +/*---------------------------------- + * End of parsing lv_conf_template.h + -----------------------------------*/ + +LV_EXPORT_CONST_INT(LV_DPI_DEF); + +#undef _LV_KCONFIG_PRESENT + + +/*Set some defines if a dependency is disabled*/ +#if LV_USE_LOG == 0 + #define LV_LOG_LEVEL LV_LOG_LEVEL_NONE + #define LV_LOG_TRACE_MEM 0 + #define LV_LOG_TRACE_TIMER 0 + #define LV_LOG_TRACE_INDEV 0 + #define LV_LOG_TRACE_DISP_REFR 0 + #define LV_LOG_TRACE_EVENT 0 + #define LV_LOG_TRACE_OBJ_CREATE 0 + #define LV_LOG_TRACE_LAYOUT 0 + #define LV_LOG_TRACE_ANIM 0 +#endif /*LV_USE_LOG*/ + + +/*If running without lv_conf.h add typedefs with default value*/ +#ifdef LV_CONF_SKIP + #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /*Disable warnings for Visual Studio*/ + #define _CRT_SECURE_NO_WARNINGS + #endif +#endif /*defined(LV_CONF_SKIP)*/ + +#endif /*LV_CONF_INTERNAL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/lv_conf_kconfig.h b/EZ-Template-Example-Project/include/liblvgl/lv_conf_kconfig.h new file mode 100644 index 00000000..7742fe77 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/lv_conf_kconfig.h @@ -0,0 +1,182 @@ +/** * @file lv_conf_kconfig.h * Configs that need special handling when LVGL is used with Kconfig */ + +#ifndef LV_CONF_KCONFIG_H +#define LV_CONF_KCONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef LV_CONF_KCONFIG_EXTERNAL_INCLUDE +# include LV_CONF_KCONFIG_EXTERNAL_INCLUDE +#else + +# ifdef ESP_PLATFORM +# include "sdkconfig.h" +# include "esp_attr.h" +# endif + +# ifdef __NuttX__ +# include +# elif defined(__RTTHREAD__) +# define LV_CONF_INCLUDE_SIMPLE +# include +# endif + +#endif /*LV_CONF_KCONFIG_EXTERNAL_INCLUDE*/ + +/******************* + * LV COLOR CHROMA KEY + *******************/ + +#ifdef CONFIG_LV_COLOR_CHROMA_KEY_HEX +# define CONFIG_LV_COLOR_CHROMA_KEY lv_color_hex(CONFIG_LV_COLOR_CHROMA_KEY_HEX) +#endif + +/******************* + * LV_MEM_SIZE + *******************/ + +#ifdef CONFIG_LV_MEM_SIZE_KILOBYTES +# define CONFIG_LV_MEM_SIZE (CONFIG_LV_MEM_SIZE_KILOBYTES * 1024U) +#endif + +/*------------------ + * MONITOR POSITION + *-----------------*/ + +#ifdef CONFIG_LV_PERF_MONITOR_ALIGN_TOP_LEFT +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_LEFT +#elif defined(CONFIG_LV_USE_PERF_MONITOR_ALIGN_TOP_MID) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_MID +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_TOP_RIGHT) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_RIGHT +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_BOTTOM_LEFT) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_LEFT +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_BOTTOM_MID) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_MID +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_BOTTOM_RIGHT) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_LEFT_MID) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_LEFT_MID +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_RIGHT_MID) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_RIGHT_MID +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_CENTER) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_CENTER +#endif + +#ifdef CONFIG_LV_MEM_MONITOR_ALIGN_TOP_LEFT +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_TOP_LEFT +#elif defined(CONFIG_LV_USE_MEM_MONITOR_ALIGN_TOP_MID) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_TOP_MID +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_TOP_RIGHT) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_TOP_RIGHT +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_BOTTOM_LEFT) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_BOTTOM_MID) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_MID +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_BOTTOM_RIGHT) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_LEFT_MID) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_LEFT_MID +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_RIGHT_MID) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_RIGHT_MID +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_CENTER) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_CENTER +#endif + +/******************** + * FONT SELECTION + *******************/ + +/** + * NOTE: In Kconfig instead of `LV_DEFAULT_FONT` + * `CONFIG_LV_FONT_DEFAULT_` is defined + * hence the large selection with if-s + */ + +/*------------------ + * DEFAULT FONT + *-----------------*/ +#ifdef CONFIG_LV_FONT_DEFAULT_MONTSERRAT_8 +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_8 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_10) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_10 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_12) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_12 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_14) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_14 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_16) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_16 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_18) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_18 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_20) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_20 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_22) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_22 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_24) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_24 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_26) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_26 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_28) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_28 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_30) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_30 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_32 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_34) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_34 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_36) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_36 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_38) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_38 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_40) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_40 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_42) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_42 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_44) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_44 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_46) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_46 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_48) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_48 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_12_SUBPX) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_12_subpx +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_28_COMPRESSED) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_28_compressed +#elif defined(CONFIG_LV_FONT_DEFAULT_DEJAVU_16_PERSIAN_HEBREW) +# define CONFIG_LV_FONT_DEFAULT &lv_font_dejavu_16_persian_hebrew +#elif defined(CONFIG_LV_FONT_DEFAULT_SIMSUN_16_CJK) +# define CONFIG_LV_FONT_DEFAULT &lv_font_simsun_16_cjk +#elif defined(CONFIG_LV_FONT_DEFAULT_UNSCII_8) +# define CONFIG_LV_FONT_DEFAULT &lv_font_unscii_8 +#elif defined(CONFIG_LV_FONT_DEFAULT_UNSCII_16) +# define CONFIG_LV_FONT_DEFAULT &lv_font_unscii_16 +#endif + +/*------------------ + * TEXT ENCODING + *-----------------*/ +#ifdef CONFIG_LV_TXT_ENC_UTF8 +# define CONFIG_LV_TXT_ENC LV_TXT_ENC_UTF8 +#elif defined(CONFIG_LV_TXT_ENC_ASCII) +# define CONFIG_LV_TXT_ENC LV_TXT_ENC_ASCII +#endif + +/*------------------ + * BIDI DIRECTION + *-----------------*/ + +#ifdef CONFIG_LV_BASE_DIR_LTR +# define CONFIG_LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_LTR +#elif defined(CONFIG_LV_BASE_DIR_RTL) +# define CONFIG_LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_RTL +#elif defined(CONFIG_LV_BASE_DIR_AUTO) +# define CONFIG_LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_AUTO +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CONF_KCONFIG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/lvgl.h b/EZ-Template-Example-Project/include/liblvgl/lvgl.h new file mode 100644 index 00000000..60d29f5d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/lvgl.h @@ -0,0 +1,138 @@ +/** + * @file lvgl.h + * Include all LVGL related headers + */ + +#ifndef LVGL_H +#define LVGL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************** + * CURRENT VERSION OF LVGL + ***************************/ +#define LVGL_VERSION_MAJOR 8 +#define LVGL_VERSION_MINOR 3 +#define LVGL_VERSION_PATCH 4 +#define LVGL_VERSION_INFO "dev" + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/misc/lv_log.h" +#include "liblvgl/misc/lv_timer.h" +#include "liblvgl/misc/lv_math.h" +#include "liblvgl/misc/lv_mem.h" +#include "liblvgl/misc/lv_async.h" +#include "liblvgl/misc/lv_anim_timeline.h" +#include "liblvgl/misc/lv_printf.h" + +#include "liblvgl/hal/lv_hal.h" + +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/core/lv_group.h" +#include "liblvgl/core/lv_indev.h" +#include "liblvgl/core/lv_refr.h" +#include "liblvgl/core/lv_disp.h" +#include "liblvgl/core/lv_theme.h" + +#include "liblvgl/font/lv_font.h" +#include "liblvgl/font/lv_font_loader.h" +#include "liblvgl/font/lv_font_fmt_txt.h" + +#include "liblvgl/widgets/lv_arc.h" +#include "liblvgl/widgets/lv_btn.h" +#include "liblvgl/widgets/lv_img.h" +#include "liblvgl/widgets/lv_label.h" +#include "liblvgl/widgets/lv_line.h" +#include "liblvgl/widgets/lv_table.h" +#include "liblvgl/widgets/lv_checkbox.h" +#include "liblvgl/widgets/lv_bar.h" +#include "liblvgl/widgets/lv_slider.h" +#include "liblvgl/widgets/lv_btnmatrix.h" +#include "liblvgl/widgets/lv_dropdown.h" +#include "liblvgl/widgets/lv_roller.h" +#include "liblvgl/widgets/lv_textarea.h" +#include "liblvgl/widgets/lv_canvas.h" +#include "liblvgl/widgets/lv_switch.h" + +#include "liblvgl/draw/lv_draw.h" + +#include "liblvgl/lv_api_map.h" + +/*----------------- + * EXTRAS + *----------------*/ +#include "liblvgl/extra/lv_extra.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +/** Gives 1 if the x.y.z version is supported in the current version + * Usage: + * + * - Require v6 + * #if LV_VERSION_CHECK(6,0,0) + * new_func_in_v6(); + * #endif + * + * + * - Require at least v5.3 + * #if LV_VERSION_CHECK(5,3,0) + * new_feature_from_v5_3(); + * #endif + * + * + * - Require v5.3.2 bugfixes + * #if LV_VERSION_CHECK(5,3,2) + * bugfix_in_v5_3_2(); + * #endif + * + */ +#define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) + +/** + * Wrapper functions for VERSION macros + */ + +static inline int lv_version_major(void) +{ + return LVGL_VERSION_MAJOR; +} + +static inline int lv_version_minor(void) +{ + return LVGL_VERSION_MINOR; +} + +static inline int lv_version_patch(void) +{ + return LVGL_VERSION_PATCH; +} + +static inline const char *lv_version_info(void) +{ + return LVGL_VERSION_INFO; +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LVGL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_anim.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_anim.h new file mode 100644 index 00000000..cb460ab8 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_anim.h @@ -0,0 +1,484 @@ +/** + * @file lv_anim.h + * + */ + +#ifndef LV_ANIM_H +#define LV_ANIM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include + +/********************* + * DEFINES + *********************/ + +#define LV_ANIM_REPEAT_INFINITE 0xFFFF +#define LV_ANIM_PLAYTIME_INFINITE 0xFFFFFFFF + +LV_EXPORT_CONST_INT(LV_ANIM_REPEAT_INFINITE); +LV_EXPORT_CONST_INT(LV_ANIM_PLAYTIME_INFINITE); + +/********************** + * TYPEDEFS + **********************/ + +/** Can be used to indicate if animations are enabled or disabled in a case*/ +typedef enum { + LV_ANIM_OFF, + LV_ANIM_ON, +} lv_anim_enable_t; + +struct _lv_anim_t; +struct _lv_timer_t; + +/** Get the current value during an animation*/ +typedef int32_t (*lv_anim_path_cb_t)(const struct _lv_anim_t *); + +/** Generic prototype of "animator" functions. + * First parameter is the variable to animate. + * Second parameter is the value to set. + * Compatible with `lv_xxx_set_yyy(obj, value)` functions + * The `x` in `_xcb_t` means it's not a fully generic prototype because + * it doesn't receive `lv_anim_t *` as its first argument*/ +typedef void (*lv_anim_exec_xcb_t)(void *, int32_t); + +/** Same as `lv_anim_exec_xcb_t` but receives `lv_anim_t *` as the first parameter. + * It's more consistent but less convenient. Might be used by binding generator functions.*/ +typedef void (*lv_anim_custom_exec_cb_t)(struct _lv_anim_t *, int32_t); + +/** Callback to call when the animation is ready*/ +typedef void (*lv_anim_ready_cb_t)(struct _lv_anim_t *); + +/** Callback to call when the animation really stars (considering `delay`)*/ +typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *); + +/** Callback used when the animation values are relative to get the current value*/ +typedef int32_t (*lv_anim_get_value_cb_t)(struct _lv_anim_t *); + +/** Callback used when the animation is deleted*/ +typedef void (*lv_anim_deleted_cb_t)(struct _lv_anim_t *); + +/** Describes an animation*/ +typedef struct _lv_anim_t { + void * var; /**var = var; +} + +/** + * Set a function to animate `var` + * @param a pointer to an initialized `lv_anim_t` variable + * @param exec_cb a function to execute during animation + * LVGL's built-in functions can be used. + * E.g. lv_obj_set_x + */ +static inline void lv_anim_set_exec_cb(lv_anim_t * a, lv_anim_exec_xcb_t exec_cb) +{ + a->exec_cb = exec_cb; +} + +/** + * Set the duration of an animation + * @param a pointer to an initialized `lv_anim_t` variable + * @param duration duration of the animation in milliseconds + */ +static inline void lv_anim_set_time(lv_anim_t * a, uint32_t duration) +{ + a->time = duration; +} + +/** + * Set a delay before starting the animation + * @param a pointer to an initialized `lv_anim_t` variable + * @param delay delay before the animation in milliseconds + */ +static inline void lv_anim_set_delay(lv_anim_t * a, uint32_t delay) +{ + a->act_time = -(int32_t)(delay); +} + +/** + * Set the start and end values of an animation + * @param a pointer to an initialized `lv_anim_t` variable + * @param start the start value + * @param end the end value + */ +static inline void lv_anim_set_values(lv_anim_t * a, int32_t start, int32_t end) +{ + a->start_value = start; + a->current_value = start; + a->end_value = end; +} + +/** + * Similar to `lv_anim_set_exec_cb` but `lv_anim_custom_exec_cb_t` receives + * `lv_anim_t * ` as its first parameter instead of `void *`. + * This function might be used when LVGL is bound to other languages because + * it's more consistent to have `lv_anim_t *` as first parameter. + * The variable to animate can be stored in the animation's `user_data` + * @param a pointer to an initialized `lv_anim_t` variable + * @param exec_cb a function to execute. + */ +static inline void lv_anim_set_custom_exec_cb(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb) +{ + a->var = a; + a->exec_cb = (lv_anim_exec_xcb_t)exec_cb; +} + +/** + * Set the path (curve) of the animation. + * @param a pointer to an initialized `lv_anim_t` variable + * @param path_cb a function to set the current value of the animation. + */ +static inline void lv_anim_set_path_cb(lv_anim_t * a, lv_anim_path_cb_t path_cb) +{ + a->path_cb = path_cb; +} + +/** + * Set a function call when the animation really starts (considering `delay`) + * @param a pointer to an initialized `lv_anim_t` variable + * @param start_cb a function call when the animation starts + */ +static inline void lv_anim_set_start_cb(lv_anim_t * a, lv_anim_start_cb_t start_cb) +{ + a->start_cb = start_cb; +} + +/** + * Set a function to use the current value of the variable and make start and end value + * relative to the returned current value. + * @param a pointer to an initialized `lv_anim_t` variable + * @param get_value_cb a function call when the animation starts + */ +static inline void lv_anim_set_get_value_cb(lv_anim_t * a, lv_anim_get_value_cb_t get_value_cb) +{ + a->get_value_cb = get_value_cb; +} + +/** + * Set a function call when the animation is ready + * @param a pointer to an initialized `lv_anim_t` variable + * @param ready_cb a function call when the animation is ready + */ +static inline void lv_anim_set_ready_cb(lv_anim_t * a, lv_anim_ready_cb_t ready_cb) +{ + a->ready_cb = ready_cb; +} + +/** + * Set a function call when the animation is deleted. + * @param a pointer to an initialized `lv_anim_t` variable + * @param deleted_cb a function call when the animation is deleted + */ +static inline void lv_anim_set_deleted_cb(lv_anim_t * a, lv_anim_deleted_cb_t deleted_cb) +{ + a->deleted_cb = deleted_cb; +} + +/** + * Make the animation to play back to when the forward direction is ready + * @param a pointer to an initialized `lv_anim_t` variable + * @param time the duration of the playback animation in milliseconds. 0: disable playback + */ +static inline void lv_anim_set_playback_time(lv_anim_t * a, uint32_t time) +{ + a->playback_time = time; +} + +/** + * Make the animation to play back to when the forward direction is ready + * @param a pointer to an initialized `lv_anim_t` variable + * @param delay delay in milliseconds before starting the playback animation. + */ +static inline void lv_anim_set_playback_delay(lv_anim_t * a, uint32_t delay) +{ + a->playback_delay = delay; +} + +/** + * Make the animation repeat itself. + * @param a pointer to an initialized `lv_anim_t` variable + * @param cnt repeat count or `LV_ANIM_REPEAT_INFINITE` for infinite repetition. 0: to disable repetition. + */ +static inline void lv_anim_set_repeat_count(lv_anim_t * a, uint16_t cnt) +{ + a->repeat_cnt = cnt; +} + +/** + * Set a delay before repeating the animation. + * @param a pointer to an initialized `lv_anim_t` variable + * @param delay delay in milliseconds before repeating the animation. + */ +static inline void lv_anim_set_repeat_delay(lv_anim_t * a, uint32_t delay) +{ + a->repeat_delay = delay; +} + +/** + * Set a whether the animation's should be applied immediately or only when the delay expired. + * @param a pointer to an initialized `lv_anim_t` variable + * @param en true: apply the start value immediately in `lv_anim_start`; + * false: apply the start value only when `delay` ms is elapsed and the animations really starts + */ +static inline void lv_anim_set_early_apply(lv_anim_t * a, bool en) +{ + a->early_apply = en; +} + +/** + * Set the custom user data field of the animation. + * @param a pointer to an initialized `lv_anim_t` variable + * @param user_data pointer to the new user_data. + */ +#if LV_USE_USER_DATA +static inline void lv_anim_set_user_data(lv_anim_t * a, void * user_data) +{ + a->user_data = user_data; +} +#endif + +/** + * Create an animation + * @param a an initialized 'anim_t' variable. Not required after call. + * @return pointer to the created animation (different from the `a` parameter) + */ +lv_anim_t * lv_anim_start(const lv_anim_t * a); + +/** + * Get a delay before starting the animation + * @param a pointer to an initialized `lv_anim_t` variable + * @return delay before the animation in milliseconds + */ +static inline uint32_t lv_anim_get_delay(lv_anim_t * a) +{ + return -a->act_time; +} + +/** + * Get the time used to play the animation. + * @param a pointer to an animation. + * @return the play time in milliseconds. + */ +uint32_t lv_anim_get_playtime(lv_anim_t * a); + +/** + * Get the user_data field of the animation + * @param a pointer to an initialized `lv_anim_t` variable + * @return the pointer to the custom user_data of the animation + */ +#if LV_USE_USER_DATA +static inline void * lv_anim_get_user_data(lv_anim_t * a) +{ + return a->user_data; +} +#endif + +/** + * Delete an animation of a variable with a given animator function + * @param var pointer to variable + * @param exec_cb a function pointer which is animating 'var', + * or NULL to ignore it and delete all the animations of 'var + * @return true: at least 1 animation is deleted, false: no animation is deleted + */ +bool lv_anim_del(void * var, lv_anim_exec_xcb_t exec_cb); + +/** + * Delete all the animations + */ +void lv_anim_del_all(void); + +/** + * Get the animation of a variable and its `exec_cb`. + * @param var pointer to variable + * @param exec_cb a function pointer which is animating 'var', or NULL to return first matching 'var' + * @return pointer to the animation. + */ +lv_anim_t * lv_anim_get(void * var, lv_anim_exec_xcb_t exec_cb); + +/** + * Get global animation refresher timer. + * @return pointer to the animation refresher timer. + */ +struct _lv_timer_t * lv_anim_get_timer(void); + +/** + * Delete an animation by getting the animated variable from `a`. + * Only animations with `exec_cb` will be deleted. + * This function exists because it's logical that all anim. functions receives an + * `lv_anim_t` as their first parameter. It's not practical in C but might make + * the API more consequent and makes easier to generate bindings. + * @param a pointer to an animation. + * @param exec_cb a function pointer which is animating 'var', + * or NULL to ignore it and delete all the animations of 'var + * @return true: at least 1 animation is deleted, false: no animation is deleted + */ +static inline bool lv_anim_custom_del(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb) +{ + return lv_anim_del(a ? a->var : NULL, (lv_anim_exec_xcb_t)exec_cb); +} + +/** + * Get the animation of a variable and its `exec_cb`. + * This function exists because it's logical that all anim. functions receives an + * `lv_anim_t` as their first parameter. It's not practical in C but might make + * the API more consequent and makes easier to generate bindings. + * @param a pointer to an animation. + * @param exec_cb a function pointer which is animating 'var', or NULL to return first matching 'var' + * @return pointer to the animation. + */ +static inline lv_anim_t * lv_anim_custom_get(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb) +{ + return lv_anim_get(a ? a->var : NULL, (lv_anim_exec_xcb_t)exec_cb); +} + +/** + * Get the number of currently running animations + * @return the number of running animations + */ +uint16_t lv_anim_count_running(void); + +/** + * Calculate the time of an animation with a given speed and the start and end values + * @param speed speed of animation in unit/sec + * @param start start value of the animation + * @param end end value of the animation + * @return the required time [ms] for the animation with the given parameters + */ +uint32_t lv_anim_speed_to_time(uint32_t speed, int32_t start, int32_t end); + +/** + * Manually refresh the state of the animations. + * Useful to make the animations running in a blocking process where + * `lv_timer_handler` can't run for a while. + * Shouldn't be used directly because it is called in `lv_refr_now()`. + */ +void lv_anim_refr_now(void); + +/** + * Calculate the current value of an animation applying linear characteristic + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_linear(const lv_anim_t * a); + +/** + * Calculate the current value of an animation slowing down the start phase + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_in(const lv_anim_t * a); + +/** + * Calculate the current value of an animation slowing down the end phase + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_out(const lv_anim_t * a); + +/** + * Calculate the current value of an animation applying an "S" characteristic (cosine) + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_in_out(const lv_anim_t * a); + +/** + * Calculate the current value of an animation with overshoot at the end + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_overshoot(const lv_anim_t * a); + +/** + * Calculate the current value of an animation with 3 bounces + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_bounce(const lv_anim_t * a); + +/** + * Calculate the current value of an animation applying step characteristic. + * (Set end value on the end of the animation) + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_step(const lv_anim_t * a); + +/********************** + * GLOBAL VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ANIM_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_anim_timeline.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_anim_timeline.h new file mode 100644 index 00000000..d4dd0fcf --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_anim_timeline.h @@ -0,0 +1,103 @@ +/** + * @file lv_anim_timeline.h + * + */ + +#ifndef LV_ANIM_TIMELINE_H +#define LV_ANIM_TIMELINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_anim.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_anim_timeline_t; + +typedef struct _lv_anim_timeline_t lv_anim_timeline_t; + +/********************** +* GLOBAL PROTOTYPES +**********************/ + +/** + * Create an animation timeline. + * @return pointer to the animation timeline. + */ +lv_anim_timeline_t * lv_anim_timeline_create(void); + +/** + * Delete animation timeline. + * @param at pointer to the animation timeline. + */ +void lv_anim_timeline_del(lv_anim_timeline_t * at); + +/** + * Add animation to the animation timeline. + * @param at pointer to the animation timeline. + * @param start_time the time the animation started on the timeline, note that start_time will override the value of delay. + * @param a pointer to an animation. + */ +void lv_anim_timeline_add(lv_anim_timeline_t * at, uint32_t start_time, lv_anim_t * a); + +/** + * Start the animation timeline. + * @param at pointer to the animation timeline. + * @return total time spent in animation timeline. + */ +uint32_t lv_anim_timeline_start(lv_anim_timeline_t * at); + +/** + * Stop the animation timeline. + * @param at pointer to the animation timeline. + */ +void lv_anim_timeline_stop(lv_anim_timeline_t * at); + +/** + * Set the playback direction of the animation timeline. + * @param at pointer to the animation timeline. + * @param reverse whether to play in reverse. + */ +void lv_anim_timeline_set_reverse(lv_anim_timeline_t * at, bool reverse); + +/** + * Set the progress of the animation timeline. + * @param at pointer to the animation timeline. + * @param progress set value 0~65535 to map 0~100% animation progress. + */ +void lv_anim_timeline_set_progress(lv_anim_timeline_t * at, uint16_t progress); + +/** + * Get the time used to play the animation timeline. + * @param at pointer to the animation timeline. + * @return total time spent in animation timeline. + */ +uint32_t lv_anim_timeline_get_playtime(lv_anim_timeline_t * at); + +/** + * Get whether the animation timeline is played in reverse. + * @param at pointer to the animation timeline. + * @return return true if it is reverse playback. + */ +bool lv_anim_timeline_get_reverse(lv_anim_timeline_t * at); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ANIM_TIMELINE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_area.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_area.h new file mode 100644 index 00000000..036767b8 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_area.h @@ -0,0 +1,295 @@ +/** + * @file lv_area.h + * + */ + +#ifndef LV_AREA_H +#define LV_AREA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include +#include + +/********************* + * DEFINES + *********************/ + +#if LV_USE_LARGE_COORD +typedef int32_t lv_coord_t; +#else +typedef int16_t lv_coord_t; +#endif + +/********************** + * TYPEDEFS + **********************/ + +/** + * Represents a point on the screen. + */ +typedef struct { + lv_coord_t x; + lv_coord_t y; +} lv_point_t; + +/** Represents an area of the screen.*/ +typedef struct { + lv_coord_t x1; + lv_coord_t y1; + lv_coord_t x2; + lv_coord_t y2; +} lv_area_t; + +/** Alignments*/ +enum { + LV_ALIGN_DEFAULT = 0, + LV_ALIGN_TOP_LEFT, + LV_ALIGN_TOP_MID, + LV_ALIGN_TOP_RIGHT, + LV_ALIGN_BOTTOM_LEFT, + LV_ALIGN_BOTTOM_MID, + LV_ALIGN_BOTTOM_RIGHT, + LV_ALIGN_LEFT_MID, + LV_ALIGN_RIGHT_MID, + LV_ALIGN_CENTER, + + LV_ALIGN_OUT_TOP_LEFT, + LV_ALIGN_OUT_TOP_MID, + LV_ALIGN_OUT_TOP_RIGHT, + LV_ALIGN_OUT_BOTTOM_LEFT, + LV_ALIGN_OUT_BOTTOM_MID, + LV_ALIGN_OUT_BOTTOM_RIGHT, + LV_ALIGN_OUT_LEFT_TOP, + LV_ALIGN_OUT_LEFT_MID, + LV_ALIGN_OUT_LEFT_BOTTOM, + LV_ALIGN_OUT_RIGHT_TOP, + LV_ALIGN_OUT_RIGHT_MID, + LV_ALIGN_OUT_RIGHT_BOTTOM, +}; +typedef uint8_t lv_align_t; + +enum { + LV_DIR_NONE = 0x00, + LV_DIR_LEFT = (1 << 0), + LV_DIR_RIGHT = (1 << 1), + LV_DIR_TOP = (1 << 2), + LV_DIR_BOTTOM = (1 << 3), + LV_DIR_HOR = LV_DIR_LEFT | LV_DIR_RIGHT, + LV_DIR_VER = LV_DIR_TOP | LV_DIR_BOTTOM, + LV_DIR_ALL = LV_DIR_HOR | LV_DIR_VER, +}; + +typedef uint8_t lv_dir_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize an area + * @param area_p pointer to an area + * @param x1 left coordinate of the area + * @param y1 top coordinate of the area + * @param x2 right coordinate of the area + * @param y2 bottom coordinate of the area + */ +void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2); + +/** + * Copy an area + * @param dest pointer to the destination area + * @param src pointer to the source area + */ +inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src) +{ + dest->x1 = src->x1; + dest->y1 = src->y1; + dest->x2 = src->x2; + dest->y2 = src->y2; +} + +/** + * Get the width of an area + * @param area_p pointer to an area + * @return the width of the area (if x1 == x2 -> width = 1) + */ +static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p) +{ + return (lv_coord_t)(area_p->x2 - area_p->x1 + 1); +} + +/** + * Get the height of an area + * @param area_p pointer to an area + * @return the height of the area (if y1 == y2 -> height = 1) + */ +static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p) +{ + return (lv_coord_t)(area_p->y2 - area_p->y1 + 1); +} + +/** + * Set the width of an area + * @param area_p pointer to an area + * @param w the new width of the area (w == 1 makes x1 == x2) + */ +void lv_area_set_width(lv_area_t * area_p, lv_coord_t w); + +/** + * Set the height of an area + * @param area_p pointer to an area + * @param h the new height of the area (h == 1 makes y1 == y2) + */ +void lv_area_set_height(lv_area_t * area_p, lv_coord_t h); + +/** + * Set the position of an area (width and height will be kept) + * @param area_p pointer to an area + * @param x the new x coordinate of the area + * @param y the new y coordinate of the area + */ +void _lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y); + +/** + * Return with area of an area (x * y) + * @param area_p pointer to an area + * @return size of area + */ +uint32_t lv_area_get_size(const lv_area_t * area_p); + +void lv_area_increase(lv_area_t * area, lv_coord_t w_extra, lv_coord_t h_extra); + +void lv_area_move(lv_area_t * area, lv_coord_t x_ofs, lv_coord_t y_ofs); + +/** + * Get the common parts of two areas + * @param res_p pointer to an area, the result will be stored her + * @param a1_p pointer to the first area + * @param a2_p pointer to the second area + * @return false: the two area has NO common parts, res_p is invalid + */ +bool _lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Join two areas into a third which involves the other two + * @param res_p pointer to an area, the result will be stored here + * @param a1_p pointer to the first area + * @param a2_p pointer to the second area + */ +void _lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Check if a point is on an area + * @param a_p pointer to an area + * @param p_p pointer to a point + * @param radius radius of area (e.g. for rounded rectangle) + * @return false:the point is out of the area + */ +bool _lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord_t radius); + +/** + * Check if two area has common parts + * @param a1_p pointer to an area. + * @param a2_p pointer to an other area + * @return false: a1_p and a2_p has no common parts + */ +bool _lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Check if an area is fully on an other + * @param ain_p pointer to an area which could be in 'aholder_p' + * @param aholder_p pointer to an area which could involve 'ain_p' + * @param radius radius of `aholder_p` (e.g. for rounded rectangle) + * @return true: `ain_p` is fully inside `aholder_p` + */ +bool _lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, lv_coord_t radius); + + +/** + * Check if an area is fully out of an other + * @param aout_p pointer to an area which could be in 'aholder_p' + * @param aholder_p pointer to an area which could involve 'ain_p' + * @param radius radius of `aholder_p` (e.g. for rounded rectangle) + * @return true: `aout_p` is fully outside `aholder_p` + */ +bool _lv_area_is_out(const lv_area_t * aout_p, const lv_area_t * aholder_p, lv_coord_t radius); + +/** + * Check if 2 area is the same + * @param a pointer to an area + * @param b pointer to another area + */ +bool _lv_area_is_equal(const lv_area_t * a, const lv_area_t * b); + +/** + * Align an area to an other + * @param base an are where the other will be aligned + * @param to_align the area to align + * @param align `LV_ALIGN_...` + */ +void lv_area_align(const lv_area_t * base, lv_area_t * to_align, lv_align_t align, lv_coord_t ofs_x, lv_coord_t ofs_y); + +void lv_point_transform(lv_point_t * p, int32_t angle, int32_t zoom, const lv_point_t * pivot); + +/********************** + * MACROS + **********************/ + +#if LV_USE_LARGE_COORD +#define _LV_COORD_TYPE_SHIFT (29U) +#else +#define _LV_COORD_TYPE_SHIFT (13U) +#endif + +#define _LV_COORD_TYPE_MASK (3 << _LV_COORD_TYPE_SHIFT) +#define _LV_COORD_TYPE(x) ((x) & _LV_COORD_TYPE_MASK) /*Extract type specifiers*/ +#define _LV_COORD_PLAIN(x) ((x) & ~_LV_COORD_TYPE_MASK) /*Remove type specifiers*/ + +#define _LV_COORD_TYPE_PX (0 << _LV_COORD_TYPE_SHIFT) +#define _LV_COORD_TYPE_SPEC (1 << _LV_COORD_TYPE_SHIFT) +#define _LV_COORD_TYPE_PX_NEG (3 << _LV_COORD_TYPE_SHIFT) + +#define LV_COORD_IS_PX(x) (_LV_COORD_TYPE(x) == _LV_COORD_TYPE_PX || \ + _LV_COORD_TYPE(x) == _LV_COORD_TYPE_PX_NEG ? true : false) +#define LV_COORD_IS_SPEC(x) (_LV_COORD_TYPE(x) == _LV_COORD_TYPE_SPEC ? true : false) + +#define LV_COORD_SET_SPEC(x) ((x) | _LV_COORD_TYPE_SPEC) + +/*Special coordinates*/ +#define LV_PCT(x) (x < 0 ? LV_COORD_SET_SPEC(1000 - (x)) : LV_COORD_SET_SPEC(x)) +#define LV_COORD_IS_PCT(x) ((LV_COORD_IS_SPEC(x) && _LV_COORD_PLAIN(x) <= 2000) ? true : false) +#define LV_COORD_GET_PCT(x) (_LV_COORD_PLAIN(x) > 1000 ? 1000 - _LV_COORD_PLAIN(x) : _LV_COORD_PLAIN(x)) +#define LV_SIZE_CONTENT LV_COORD_SET_SPEC(2001) + +LV_EXPORT_CONST_INT(LV_SIZE_CONTENT); + +/*Max coordinate value*/ +#define LV_COORD_MAX ((1 << _LV_COORD_TYPE_SHIFT) - 1) +#define LV_COORD_MIN (-LV_COORD_MAX) + +LV_EXPORT_CONST_INT(LV_COORD_MAX); +LV_EXPORT_CONST_INT(LV_COORD_MIN); + +/** + * Convert a percentage value to `lv_coord_t`. + * Percentage values are stored in special range + * @param x the percentage (0..1000) + * @return a coordinate that stores the percentage + */ +static inline lv_coord_t lv_pct(lv_coord_t x) +{ + return LV_PCT(x); +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_assert.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_assert.h new file mode 100644 index 00000000..4625297d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_assert.h @@ -0,0 +1,79 @@ +/** + * @file lv_assert.h + * + */ + +#ifndef LV_ASSERT_H +#define LV_ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "lv_log.h" +#include "lv_mem.h" +#include LV_ASSERT_HANDLER_INCLUDE + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#define LV_ASSERT(expr) \ + do { \ + if(!(expr)) { \ + LV_LOG_ERROR("Asserted at expression: %s", #expr); \ + LV_ASSERT_HANDLER \ + } \ + } while(0) + +#define LV_ASSERT_MSG(expr, msg) \ + do { \ + if(!(expr)) { \ + LV_LOG_ERROR("Asserted at expression: %s (%s)", #expr, msg); \ + LV_ASSERT_HANDLER \ + } \ + } while(0) + +/*----------------- + * ASSERTS + *-----------------*/ + +#if LV_USE_ASSERT_NULL +# define LV_ASSERT_NULL(p) LV_ASSERT_MSG(p != NULL, "NULL pointer"); +#else +# define LV_ASSERT_NULL(p) +#endif + +#if LV_USE_ASSERT_MALLOC +# define LV_ASSERT_MALLOC(p) LV_ASSERT_MSG(p != NULL, "Out of memory"); +#else +# define LV_ASSERT_MALLOC(p) +#endif + +#if LV_USE_ASSERT_MEM_INTEGRITY +# define LV_ASSERT_MEM_INTEGRITY() LV_ASSERT_MSG(lv_mem_test() == LV_RES_OK, "Memory integrity error"); +#else +# define LV_ASSERT_MEM_INTEGRITY() +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ASSERT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_async.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_async.h new file mode 100644 index 00000000..4ad5756d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_async.h @@ -0,0 +1,61 @@ +/** + * @file lv_async.h + * + */ + +#ifndef LV_ASYNC_H +#define LV_ASYNC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "lv_types.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Type for async callback. + */ +typedef void (*lv_async_cb_t)(void *); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Call an asynchronous function the next time lv_timer_handler() is run. This function is likely to return + * **before** the call actually happens! + * @param async_xcb a callback which is the task itself. + * (the 'x' in the argument name indicates that it's not a fully generic function because it not follows + * the `func_name(object, callback, ...)` convention) + * @param user_data custom parameter + */ +lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data); + +/** + * Cancel an asynchronous function call + * @param async_xcb a callback which is the task itself. + * @param user_data custom parameter + */ +lv_res_t lv_async_call_cancel(lv_async_cb_t async_xcb, void * user_data); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ASYNC_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_bidi.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_bidi.h new file mode 100644 index 00000000..fafb4a28 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_bidi.h @@ -0,0 +1,141 @@ +/** + * @file lv_bidi.h + * + */ + +#ifndef LV_BIDI_H +#define LV_BIDI_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include "lv_txt.h" + +/********************* + * DEFINES + *********************/ +/*Special non printable strong characters. + *They can be inserted to texts to affect the run's direction*/ +#define LV_BIDI_LRO "\xE2\x80\xAD" /*U+202D*/ +#define LV_BIDI_RLO "\xE2\x80\xAE" /*U+202E*/ + +/********************** + * TYPEDEFS + **********************/ +enum { + LV_BASE_DIR_LTR = 0x00, + LV_BASE_DIR_RTL = 0x01, + LV_BASE_DIR_AUTO = 0x02, + + LV_BASE_DIR_NEUTRAL = 0x20, + LV_BASE_DIR_WEAK = 0x21, +}; + +typedef uint8_t lv_base_dir_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ +#if LV_USE_BIDI + +/** + * Convert a text to get the characters in the correct visual order according to + * Unicode Bidirectional Algorithm + * @param str_in the text to process + * @param str_out store the result here. Has the be `strlen(str_in)` length + * @param base_dir `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL` + */ +void _lv_bidi_process(const char * str_in, char * str_out, lv_base_dir_t base_dir); + +/** + * Auto-detect the direction of a text based on the first strong character + * @param txt the text to process + * @return `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL` + */ +lv_base_dir_t _lv_bidi_detect_base_dir(const char * txt); + +/** + * Get the logical position of a character in a line + * @param str_in the input string. Can be only one line. + * @param bidi_txt internally the text is bidi processed which buffer can be get here. + * If not required anymore has to freed with `lv_mem_free()` + * Can be `NULL` is unused + * @param len length of the line in character count + * @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL` + * @param visual_pos the visual character position which logical position should be get + * @param is_rtl tell the char at `visual_pos` is RTL or LTR context + * @return the logical character position + */ +uint16_t _lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_base_dir_t base_dir, + uint32_t visual_pos, bool * is_rtl); + +/** + * Get the visual position of a character in a line + * @param str_in the input string. Can be only one line. + * @param bidi_txt internally the text is bidi processed which buffer can be get here. + * If not required anymore has to freed with `lv_mem_free()` + * Can be `NULL` is unused + * @param len length of the line in character count + * @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL` + * @param logical_pos the logical character position which visual position should be get + * @param is_rtl tell the char at `logical_pos` is RTL or LTR context + * @return the visual character position + */ +uint16_t _lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_base_dir_t base_dir, + uint32_t logical_pos, bool * is_rtl); + +/** + * Bidi process a paragraph of text + * @param str_in the string to process + * @param str_out store the result here + * @param len length of the text + * @param base_dir base dir of the text + * @param pos_conv_out an `uint16_t` array to store the related logical position of the character. + * Can be `NULL` is unused + * @param pos_conv_len length of `pos_conv_out` in element count + */ +void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_base_dir_t base_dir, + uint16_t * pos_conv_out, uint16_t pos_conv_len); + +/** + * Get the real text alignment from the a text alignment, base direction and a text. + * @param align LV_TEXT_ALIGN_..., write back the calculated align here (LV_TEXT_ALIGN_LEFT/RIGHT/CENTER) + * @param base_dir LV_BASE_DIR_..., write the calculated base dir here (LV_BASE_DIR_LTR/RTL) + * @param txt a text, used with LV_BASE_DIR_AUTO to determine the base direction + */ +void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt); + + +/********************** + * MACROS + **********************/ + +#else /*LV_USE_BIDI*/ +/** + * For compatibility if LV_USE_BIDI = 0 + * Get the real text alignment from the a text alignment, base direction and a text. + * @param align For LV_TEXT_ALIGN_AUTO give LV_TEXT_ALIGN_LEFT else leave unchanged, write back the calculated align here + * @param base_dir Unused + * @param txt Unused + */ +static inline void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt) +{ + LV_UNUSED(txt); + LV_UNUSED(base_dir); + if(*align == LV_TEXT_ALIGN_AUTO) * align = LV_TEXT_ALIGN_LEFT; +} +#endif /*LV_USE_BIDI*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_BIDI_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_color.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_color.h new file mode 100644 index 00000000..8e80a616 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_color.h @@ -0,0 +1,708 @@ +/** + * @file lv_color.h + * + */ + +#ifndef LV_COLOR_H +#define LV_COLOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "lv_assert.h" +#include "lv_math.h" +#include "lv_types.h" + +/*Error checking*/ +#if LV_COLOR_DEPTH == 24 +#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)" +#endif + +#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0 +#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h" +#endif + +#include + +/********************* + * DEFINES + *********************/ +LV_EXPORT_CONST_INT(LV_COLOR_DEPTH); +LV_EXPORT_CONST_INT(LV_COLOR_16_SWAP); + +/** + * Opacity percentages. + */ +enum { + LV_OPA_TRANSP = 0, + LV_OPA_0 = 0, + LV_OPA_10 = 25, + LV_OPA_20 = 51, + LV_OPA_30 = 76, + LV_OPA_40 = 102, + LV_OPA_50 = 127, + LV_OPA_60 = 153, + LV_OPA_70 = 178, + LV_OPA_80 = 204, + LV_OPA_90 = 229, + LV_OPA_100 = 255, + LV_OPA_COVER = 255, +}; + +#define LV_OPA_MIN 2 /*Opacities below this will be transparent*/ +#define LV_OPA_MAX 253 /*Opacities above this will fully cover*/ + +#if LV_COLOR_DEPTH == 1 +#define LV_COLOR_SIZE 8 +#elif LV_COLOR_DEPTH == 8 +#define LV_COLOR_SIZE 8 +#elif LV_COLOR_DEPTH == 16 +#define LV_COLOR_SIZE 16 +#elif LV_COLOR_DEPTH == 32 +#define LV_COLOR_SIZE 32 +#else +#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!" +#endif + +#if defined(__cplusplus) && !defined(_LV_COLOR_HAS_MODERN_CPP) +/** +* MSVC compiler's definition of the __cplusplus indicating 199711L regardless to C++ standard version +* see https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-cplusplus +* so we use _MSC_VER macro instead of __cplusplus +*/ +#ifdef _MSC_VER +#if _MSC_VER >= 1900 /*Visual Studio 2015*/ +#define _LV_COLOR_HAS_MODERN_CPP 1 +#endif +#else +#if __cplusplus >= 201103L +#define _LV_COLOR_HAS_MODERN_CPP 1 +#endif +#endif +#endif /*__cplusplus*/ + +#ifndef _LV_COLOR_HAS_MODERN_CPP +#define _LV_COLOR_HAS_MODERN_CPP 0 +#endif + +#if _LV_COLOR_HAS_MODERN_CPP +/*Fix msvc compiler error C4576 inside C++ code*/ +#define _LV_COLOR_MAKE_TYPE_HELPER lv_color_t +#else +#define _LV_COLOR_MAKE_TYPE_HELPER (lv_color_t) +#endif + +/*--------------------------------------- + * Macros for all existing color depths + * to set/get values of the color channels + *------------------------------------------*/ +# define LV_COLOR_SET_R1(c, v) (c).ch.red = (uint8_t)((v) & 0x1) +# define LV_COLOR_SET_G1(c, v) (c).ch.green = (uint8_t)((v) & 0x1) +# define LV_COLOR_SET_B1(c, v) (c).ch.blue = (uint8_t)((v) & 0x1) +# define LV_COLOR_SET_A1(c, v) do {} while(0) + +# define LV_COLOR_GET_R1(c) (c).ch.red +# define LV_COLOR_GET_G1(c) (c).ch.green +# define LV_COLOR_GET_B1(c) (c).ch.blue +# define LV_COLOR_GET_A1(c) 0xFF + +# define _LV_COLOR_ZERO_INITIALIZER1 {0x00} +# define LV_COLOR_MAKE1(r8, g8, b8) {(uint8_t)((b8 >> 7) | (g8 >> 7) | (r8 >> 7))} + +# define LV_COLOR_SET_R8(c, v) (c).ch.red = (uint8_t)((v) & 0x7U) +# define LV_COLOR_SET_G8(c, v) (c).ch.green = (uint8_t)((v) & 0x7U) +# define LV_COLOR_SET_B8(c, v) (c).ch.blue = (uint8_t)((v) & 0x3U) +# define LV_COLOR_SET_A8(c, v) do {} while(0) + +# define LV_COLOR_GET_R8(c) (c).ch.red +# define LV_COLOR_GET_G8(c) (c).ch.green +# define LV_COLOR_GET_B8(c) (c).ch.blue +# define LV_COLOR_GET_A8(c) 0xFF + +# define _LV_COLOR_ZERO_INITIALIZER8 {{0x00, 0x00, 0x00}} +# define LV_COLOR_MAKE8(r8, g8, b8) {{(uint8_t)((b8 >> 6) & 0x3U), (uint8_t)((g8 >> 5) & 0x7U), (uint8_t)((r8 >> 5) & 0x7U)}} + +# define LV_COLOR_SET_R16(c, v) (c).ch.red = (uint8_t)((v) & 0x1FU) +#if LV_COLOR_16_SWAP == 0 +# define LV_COLOR_SET_G16(c, v) (c).ch.green = (uint8_t)((v) & 0x3FU) +#else +# define LV_COLOR_SET_G16(c, v) {(c).ch.green_h = (uint8_t)(((v) >> 3) & 0x7); (c).ch.green_l = (uint8_t)((v) & 0x7);} +#endif +# define LV_COLOR_SET_B16(c, v) (c).ch.blue = (uint8_t)((v) & 0x1FU) +# define LV_COLOR_SET_A16(c, v) do {} while(0) + +# define LV_COLOR_GET_R16(c) (c).ch.red +#if LV_COLOR_16_SWAP == 0 +# define LV_COLOR_GET_G16(c) (c).ch.green +#else +# define LV_COLOR_GET_G16(c) (((c).ch.green_h << 3) + (c).ch.green_l) +#endif +# define LV_COLOR_GET_B16(c) (c).ch.blue +# define LV_COLOR_GET_A16(c) 0xFF + +#if LV_COLOR_16_SWAP == 0 +# define _LV_COLOR_ZERO_INITIALIZER16 {{0x00, 0x00, 0x00}} +# define LV_COLOR_MAKE16(r8, g8, b8) {{(uint8_t)((b8 >> 3) & 0x1FU), (uint8_t)((g8 >> 2) & 0x3FU), (uint8_t)((r8 >> 3) & 0x1FU)}} +#else +# define _LV_COLOR_ZERO_INITIALIZER16 {{0x00, 0x00, 0x00, 0x00}} +# define LV_COLOR_MAKE16(r8, g8, b8) {{(uint8_t)((g8 >> 5) & 0x7U), (uint8_t)((r8 >> 3) & 0x1FU), (uint8_t)((b8 >> 3) & 0x1FU), (uint8_t)((g8 >> 2) & 0x7U)}} +#endif + +# define LV_COLOR_SET_R32(c, v) (c).ch.red = (uint8_t)((v) & 0xFF) +# define LV_COLOR_SET_G32(c, v) (c).ch.green = (uint8_t)((v) & 0xFF) +# define LV_COLOR_SET_B32(c, v) (c).ch.blue = (uint8_t)((v) & 0xFF) +# define LV_COLOR_SET_A32(c, v) (c).ch.alpha = (uint8_t)((v) & 0xFF) + +# define LV_COLOR_GET_R32(c) (c).ch.red +# define LV_COLOR_GET_G32(c) (c).ch.green +# define LV_COLOR_GET_B32(c) (c).ch.blue +# define LV_COLOR_GET_A32(c) (c).ch.alpha + +# define _LV_COLOR_ZERO_INITIALIZER32 {{0x00, 0x00, 0x00, 0x00}} +# define LV_COLOR_MAKE32(r8, g8, b8) {{b8, g8, r8, 0xff}} /*Fix 0xff alpha*/ + +/*--------------------------------------- + * Macros for the current color depth + * to set/get values of the color channels + *------------------------------------------*/ +#define LV_COLOR_SET_R(c, v) LV_CONCAT(LV_COLOR_SET_R, LV_COLOR_DEPTH)(c, v) +#define LV_COLOR_SET_G(c, v) LV_CONCAT(LV_COLOR_SET_G, LV_COLOR_DEPTH)(c, v) +#define LV_COLOR_SET_B(c, v) LV_CONCAT(LV_COLOR_SET_B, LV_COLOR_DEPTH)(c, v) +#define LV_COLOR_SET_A(c, v) LV_CONCAT(LV_COLOR_SET_A, LV_COLOR_DEPTH)(c, v) + +#define LV_COLOR_GET_R(c) LV_CONCAT(LV_COLOR_GET_R, LV_COLOR_DEPTH)(c) +#define LV_COLOR_GET_G(c) LV_CONCAT(LV_COLOR_GET_G, LV_COLOR_DEPTH)(c) +#define LV_COLOR_GET_B(c) LV_CONCAT(LV_COLOR_GET_B, LV_COLOR_DEPTH)(c) +#define LV_COLOR_GET_A(c) LV_CONCAT(LV_COLOR_GET_A, LV_COLOR_DEPTH)(c) + +#define _LV_COLOR_ZERO_INITIALIZER LV_CONCAT(_LV_COLOR_ZERO_INITIALIZER, LV_COLOR_DEPTH) +#define LV_COLOR_MAKE(r8, g8, b8) LV_CONCAT(LV_COLOR_MAKE, LV_COLOR_DEPTH)(r8, g8, b8) + +/********************** + * TYPEDEFS + **********************/ + +typedef union { + uint8_t full; /*must be declared first to set all bits of byte via initializer list*/ + union { + uint8_t blue : 1; + uint8_t green : 1; + uint8_t red : 1; + } ch; +} lv_color1_t; + +typedef union { + struct { + uint8_t blue : 2; + uint8_t green : 3; + uint8_t red : 3; + } ch; + uint8_t full; +} lv_color8_t; + +typedef union { + struct { +#if LV_COLOR_16_SWAP == 0 + uint16_t blue : 5; + uint16_t green : 6; + uint16_t red : 5; +#else + uint16_t green_h : 3; + uint16_t red : 5; + uint16_t blue : 5; + uint16_t green_l : 3; +#endif + } ch; + uint16_t full; +} lv_color16_t; + +typedef union { + struct { + uint8_t blue; + uint8_t green; + uint8_t red; + uint8_t alpha; + } ch; + uint32_t full; +} lv_color32_t; + +typedef LV_CONCAT3(uint, LV_COLOR_SIZE, _t) lv_color_int_t; +typedef LV_CONCAT3(lv_color, LV_COLOR_DEPTH, _t) lv_color_t; + +typedef struct { + uint16_t h; + uint8_t s; + uint8_t v; +} lv_color_hsv_t; + +//! @cond Doxygen_Suppress +/*No idea where the guard is required but else throws warnings in the docs*/ +typedef uint8_t lv_opa_t; +//! @endcond + +struct _lv_color_filter_dsc_t; + +typedef lv_color_t (*lv_color_filter_cb_t)(const struct _lv_color_filter_dsc_t *, lv_color_t, lv_opa_t); + +typedef struct _lv_color_filter_dsc_t { + lv_color_filter_cb_t filter_cb; + void * user_data; +} lv_color_filter_dsc_t; + + +typedef enum { + LV_PALETTE_RED, + LV_PALETTE_PINK, + LV_PALETTE_PURPLE, + LV_PALETTE_DEEP_PURPLE, + LV_PALETTE_INDIGO, + LV_PALETTE_BLUE, + LV_PALETTE_LIGHT_BLUE, + LV_PALETTE_CYAN, + LV_PALETTE_TEAL, + LV_PALETTE_GREEN, + LV_PALETTE_LIGHT_GREEN, + LV_PALETTE_LIME, + LV_PALETTE_YELLOW, + LV_PALETTE_AMBER, + LV_PALETTE_ORANGE, + LV_PALETTE_DEEP_ORANGE, + LV_PALETTE_BROWN, + LV_PALETTE_BLUE_GREY, + LV_PALETTE_GREY, + _LV_PALETTE_LAST, + LV_PALETTE_NONE = 0xff, +} lv_palette_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*In color conversations: + * - When converting to bigger color type the LSB weight of 1 LSB is calculated + * E.g. 16 bit Red has 5 bits + * 8 bit Red has 3 bits + * ---------------------- + * 8 bit red LSB = (2^5 - 1) / (2^3 - 1) = 31 / 7 = 4 + * + * - When calculating to smaller color type simply shift out the LSBs + * E.g. 8 bit Red has 3 bits + * 16 bit Red has 5 bits + * ---------------------- + * Shift right with 5 - 3 = 2 + */ +static inline uint8_t lv_color_to1(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + return color.full; +#elif LV_COLOR_DEPTH == 8 + if((LV_COLOR_GET_R(color) & 0x4) || (LV_COLOR_GET_G(color) & 0x4) || (LV_COLOR_GET_B(color) & 0x2)) { + return 1; + } + else { + return 0; + } +#elif LV_COLOR_DEPTH == 16 + if((LV_COLOR_GET_R(color) & 0x10) || (LV_COLOR_GET_G(color) & 0x20) || (LV_COLOR_GET_B(color) & 0x10)) { + return 1; + } + else { + return 0; + } +#elif LV_COLOR_DEPTH == 32 + if((LV_COLOR_GET_R(color) & 0x80) || (LV_COLOR_GET_G(color) & 0x80) || (LV_COLOR_GET_B(color) & 0x80)) { + return 1; + } + else { + return 0; + } +#endif +} + +static inline uint8_t lv_color_to8(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) + return 0; + else + return 0xFF; +#elif LV_COLOR_DEPTH == 8 + return color.full; +#elif LV_COLOR_DEPTH == 16 + lv_color8_t ret; + LV_COLOR_SET_R8(ret, LV_COLOR_GET_R(color) >> 2); /*5 - 3 = 2*/ + LV_COLOR_SET_G8(ret, LV_COLOR_GET_G(color) >> 3); /*6 - 3 = 3*/ + LV_COLOR_SET_B8(ret, LV_COLOR_GET_B(color) >> 3); /*5 - 2 = 3*/ + return ret.full; +#elif LV_COLOR_DEPTH == 32 + lv_color8_t ret; + LV_COLOR_SET_R8(ret, LV_COLOR_GET_R(color) >> 5); /*8 - 3 = 5*/ + LV_COLOR_SET_G8(ret, LV_COLOR_GET_G(color) >> 5); /*8 - 3 = 5*/ + LV_COLOR_SET_B8(ret, LV_COLOR_GET_B(color) >> 6); /*8 - 2 = 6*/ + return ret.full; +#endif +} + +static inline uint16_t lv_color_to16(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) + return 0; + else + return 0xFFFF; +#elif LV_COLOR_DEPTH == 8 + lv_color16_t ret; + LV_COLOR_SET_R16(ret, LV_COLOR_GET_R(color) * 4); /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/ + LV_COLOR_SET_G16(ret, LV_COLOR_GET_G(color) * 9); /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/ + LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) * 10); /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/ + return ret.full; +#elif LV_COLOR_DEPTH == 16 + return color.full; +#elif LV_COLOR_DEPTH == 32 + lv_color16_t ret; + LV_COLOR_SET_R16(ret, LV_COLOR_GET_R(color) >> 3); /*8 - 5 = 3*/ + LV_COLOR_SET_G16(ret, LV_COLOR_GET_G(color) >> 2); /*8 - 6 = 2*/ + LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) >> 3); /*8 - 5 = 3*/ + return ret.full; +#endif +} + +static inline uint32_t lv_color_to32(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) + return 0xFF000000; + else + return 0xFFFFFFFF; +#elif LV_COLOR_DEPTH == 8 + lv_color32_t ret; + LV_COLOR_SET_R32(ret, LV_COLOR_GET_R(color) * 36); /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ + LV_COLOR_SET_G32(ret, LV_COLOR_GET_G(color) * 36); /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ + LV_COLOR_SET_B32(ret, LV_COLOR_GET_B(color) * 85); /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/ + LV_COLOR_SET_A32(ret, 0xFF); + return ret.full; +#elif LV_COLOR_DEPTH == 16 + /** + * The floating point math for conversion is: + * valueto = valuefrom * ( (2^bitsto - 1) / (float)(2^bitsfrom - 1) ) + * The faster integer math for conversion is: + * valueto = ( valuefrom * multiplier + adder ) >> divisor + * multiplier = FLOOR( ( (2^bitsto - 1) << divisor ) / (float)(2^bitsfrom - 1) ) + * + * Find the first divisor where ( adder >> divisor ) <= 0 + * + * 5-bit to 8-bit: ( 31 * multiplier + adder ) >> divisor = 255 + * divisor multiplier adder min (0) max (31) + * 0 8 7 7 255 + * 1 16 14 7 255 + * 2 32 28 7 255 + * 3 65 25 3 255 + * 4 131 19 1 255 + * 5 263 7 0 255 + * + * 6-bit to 8-bit: 255 = ( 63 * multiplier + adder ) >> divisor + * divisor multiplier adder min (0) max (63) + * 0 4 3 3 255 + * 1 8 6 3 255 + * 2 16 12 3 255 + * 3 32 24 3 255 + * 4 64 48 3 255 + * 5 129 33 1 255 + * 6 259 3 0 255 + */ + + lv_color32_t ret; + LV_COLOR_SET_R32(ret, (LV_COLOR_GET_R(color) * 263 + 7) >> 5); + LV_COLOR_SET_G32(ret, (LV_COLOR_GET_G(color) * 259 + 3) >> 6); + LV_COLOR_SET_B32(ret, (LV_COLOR_GET_B(color) * 263 + 7) >> 5); + LV_COLOR_SET_A32(ret, 0xFF); + return ret.full; +#elif LV_COLOR_DEPTH == 32 + return color.full; +#endif +} + +//! @cond Doxygen_Suppress + +/** + * Mix two colors with a given ratio. + * @param c1 the first color to mix (usually the foreground) + * @param c2 the second color to mix (usually the background) + * @param mix The ratio of the colors. 0: full `c2`, 255: full `c1`, 127: half `c1` and half`c2` + * @return the mixed color + */ +LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix) +{ + lv_color_t ret; + +#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0 && LV_COLOR_MIX_ROUND_OFS == 0 + /*Source: https://stackoverflow.com/a/50012418/1999969*/ + mix = (uint32_t)((uint32_t)mix + 4) >> 3; + uint32_t bg = (uint32_t)((uint32_t)c2.full | ((uint32_t)c2.full << 16)) & + 0x7E0F81F; /*0b00000111111000001111100000011111*/ + uint32_t fg = (uint32_t)((uint32_t)c1.full | ((uint32_t)c1.full << 16)) & 0x7E0F81F; + uint32_t result = ((((fg - bg) * mix) >> 5) + bg) & 0x7E0F81F; + ret.full = (uint16_t)((result >> 16) | result); +#elif LV_COLOR_DEPTH != 1 + /*LV_COLOR_DEPTH == 8, 16 or 32*/ + LV_COLOR_SET_R(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_R(c1) * mix + LV_COLOR_GET_R(c2) * + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_G(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_G(c1) * mix + LV_COLOR_GET_G(c2) * + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_B(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_B(c1) * mix + LV_COLOR_GET_B(c2) * + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_A(ret, 0xFF); +#else + /*LV_COLOR_DEPTH == 1*/ + ret.full = mix > LV_OPA_50 ? c1.full : c2.full; +#endif + + return ret; +} + +LV_ATTRIBUTE_FAST_MEM static inline void lv_color_premult(lv_color_t c, uint8_t mix, uint16_t * out) +{ +#if LV_COLOR_DEPTH != 1 + out[0] = (uint16_t)LV_COLOR_GET_R(c) * mix; + out[1] = (uint16_t)LV_COLOR_GET_G(c) * mix; + out[2] = (uint16_t)LV_COLOR_GET_B(c) * mix; +#else + (void) mix; + /*Pre-multiplication can't be used with 1 bpp*/ + out[0] = LV_COLOR_GET_R(c); + out[1] = LV_COLOR_GET_G(c); + out[2] = LV_COLOR_GET_B(c); +#endif + +} + +/** + * Mix two colors with a given ratio. It runs faster then `lv_color_mix` but requires some pre computation. + * @param premult_c1 The first color. Should be preprocessed with `lv_color_premult(c1)` + * @param c2 The second color. As it is no pre computation required on it + * @param mix The ratio of the colors. 0: full `c1`, 255: full `c2`, 127: half `c1` and half `c2`. + * Should be modified like mix = `255 - mix` + * @return the mixed color + * @note 255 won't give clearly `c1`. + */ +LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix_premult(uint16_t * premult_c1, lv_color_t c2, uint8_t mix) +{ + lv_color_t ret; +#if LV_COLOR_DEPTH != 1 + /*LV_COLOR_DEPTH == 8 or 32*/ + LV_COLOR_SET_R(ret, LV_UDIV255(premult_c1[0] + LV_COLOR_GET_R(c2) * mix + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_G(ret, LV_UDIV255(premult_c1[1] + LV_COLOR_GET_G(c2) * mix + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_B(ret, LV_UDIV255(premult_c1[2] + LV_COLOR_GET_B(c2) * mix + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_A(ret, 0xFF); +#else + /*LV_COLOR_DEPTH == 1*/ + /*Restore color1*/ + lv_color_t c1; + LV_COLOR_SET_R(c1, premult_c1[0]); + LV_COLOR_SET_G(c1, premult_c1[1]); + LV_COLOR_SET_B(c1, premult_c1[2]); + ret.full = mix > LV_OPA_50 ? c2.full : c1.full; +#endif + + return ret; +} + +/** + * Mix two colors. Both color can have alpha value. + * @param bg_color background color + * @param bg_opa alpha of the background color + * @param fg_color foreground color + * @param fg_opa alpha of the foreground color + * @param res_color the result color + * @param res_opa the result opacity + */ +LV_ATTRIBUTE_FAST_MEM static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa, + lv_color_t fg_color, lv_opa_t fg_opa, + lv_color_t * res_color, lv_opa_t * res_opa) +{ + /*Pick the foreground if it's fully opaque or the Background is fully transparent*/ + if(fg_opa >= LV_OPA_MAX || bg_opa <= LV_OPA_MIN) { + res_color->full = fg_color.full; + *res_opa = fg_opa; + } + /*Transparent foreground: use the Background*/ + else if(fg_opa <= LV_OPA_MIN) { + res_color->full = bg_color.full; + *res_opa = bg_opa; + } + /*Opaque background: use simple mix*/ + else if(bg_opa >= LV_OPA_MAX) { + *res_color = lv_color_mix(fg_color, bg_color, fg_opa); + *res_opa = LV_OPA_COVER; + } + /*Both colors have alpha. Expensive calculation need to be applied*/ + else { + /*Save the parameters and the result. If they will be asked again don't compute again*/ + static lv_opa_t fg_opa_save = 0; + static lv_opa_t bg_opa_save = 0; + static lv_color_t fg_color_save = _LV_COLOR_ZERO_INITIALIZER; + static lv_color_t bg_color_save = _LV_COLOR_ZERO_INITIALIZER; + static lv_color_t res_color_saved = _LV_COLOR_ZERO_INITIALIZER; + static lv_opa_t res_opa_saved = 0; + + if(fg_opa != fg_opa_save || bg_opa != bg_opa_save || fg_color.full != fg_color_save.full || + bg_color.full != bg_color_save.full) { + fg_opa_save = fg_opa; + bg_opa_save = bg_opa; + fg_color_save.full = fg_color.full; + bg_color_save.full = bg_color.full; + /*Info: + * https://en.wikipedia.org/wiki/Alpha_compositing#Analytical_derivation_of_the_over_operator*/ + res_opa_saved = 255 - ((uint16_t)((uint16_t)(255 - fg_opa) * (255 - bg_opa)) >> 8); + LV_ASSERT(res_opa_saved != 0); + lv_opa_t ratio = (uint16_t)((uint16_t)fg_opa * 255) / res_opa_saved; + res_color_saved = lv_color_mix(fg_color, bg_color, ratio); + + } + + res_color->full = res_color_saved.full; + *res_opa = res_opa_saved; + } +} + +//! @endcond + +/** + * Get the brightness of a color + * @param color a color + * @return the brightness [0..255] + */ +static inline uint8_t lv_color_brightness(lv_color_t color) +{ + lv_color32_t c32; + c32.full = lv_color_to32(color); + uint16_t bright = (uint16_t)(3u * LV_COLOR_GET_R32(c32) + LV_COLOR_GET_B32(c32) + 4u * LV_COLOR_GET_G32(c32)); + return (uint8_t)(bright >> 3); +} + +static inline lv_color_t lv_color_make(uint8_t r, uint8_t g, uint8_t b) +{ + return _LV_COLOR_MAKE_TYPE_HELPER LV_COLOR_MAKE(r, g, b); +} + +static inline lv_color_t lv_color_hex(uint32_t c) +{ +#if LV_COLOR_DEPTH == 16 + lv_color_t r; +#if LV_COLOR_16_SWAP == 0 + /* Convert a 4 bytes per pixel in format ARGB32 to R5G6B5 format + naive way (by calling lv_color_make with components): + r = ((c & 0xFF0000) >> 19) + g = ((c & 0xFF00) >> 10) + b = ((c & 0xFF) >> 3) + rgb565 = (r << 11) | (g << 5) | b + That's 3 mask, 5 bitshift and 2 or operations + + A bit better: + r = ((c & 0xF80000) >> 8) + g = ((c & 0xFC00) >> 5) + b = ((c & 0xFF) >> 3) + rgb565 = r | g | b + That's 3 mask, 3 bitshifts and 2 or operations */ + r.full = (uint16_t)(((c & 0xF80000) >> 8) | ((c & 0xFC00) >> 5) | ((c & 0xFF) >> 3)); +#else + /* We want: rrrr rrrr GGGg gggg bbbb bbbb => gggb bbbb rrrr rGGG */ + r.full = (uint16_t)(((c & 0xF80000) >> 16) | ((c & 0xFC00) >> 13) | ((c & 0x1C00) << 3) | ((c & 0xF8) << 5)); +#endif + return r; +#elif LV_COLOR_DEPTH == 32 + lv_color_t r; + r.full = c | 0xFF000000; + return r; +#else /*LV_COLOR_DEPTH == 8*/ + return lv_color_make((uint8_t)((c >> 16) & 0xFF), (uint8_t)((c >> 8) & 0xFF), (uint8_t)(c & 0xFF)); +#endif +} + +static inline lv_color_t lv_color_hex3(uint32_t c) +{ + return lv_color_make((uint8_t)(((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), (uint8_t)((c & 0xF0) | ((c & 0xF0) >> 4)), + (uint8_t)((c & 0xF) | ((c & 0xF) << 4))); +} + +static inline void lv_color_filter_dsc_init(lv_color_filter_dsc_t * dsc, lv_color_filter_cb_t cb) +{ + dsc->filter_cb = cb; +} + +//! @cond Doxygen_Suppress +//! +LV_ATTRIBUTE_FAST_MEM void lv_color_fill(lv_color_t * buf, lv_color_t color, uint32_t px_num); + +//! @endcond +lv_color_t lv_color_lighten(lv_color_t c, lv_opa_t lvl); + +lv_color_t lv_color_darken(lv_color_t c, lv_opa_t lvl); + +lv_color_t lv_color_change_lightness(lv_color_t c, lv_opa_t lvl); + +/** + * Convert a HSV color to RGB + * @param h hue [0..359] + * @param s saturation [0..100] + * @param v value [0..100] + * @return the given RGB color in RGB (with LV_COLOR_DEPTH depth) + */ +lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v); + +/** + * Convert a 32-bit RGB color to HSV + * @param r8 8-bit red + * @param g8 8-bit green + * @param b8 8-bit blue + * @return the given RGB color in HSV + */ +lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8); + +/** + * Convert a color to HSV + * @param color color + * @return the given color in HSV + */ +lv_color_hsv_t lv_color_to_hsv(lv_color_t color); + +/** + * Just a wrapper around LV_COLOR_CHROMA_KEY because it might be more convenient to use a function in some cases + * @return LV_COLOR_CHROMA_KEY + */ +static inline lv_color_t lv_color_chroma_key(void) +{ + return LV_COLOR_CHROMA_KEY; +} + +/********************** + * PREDEFINED COLORS + **********************/ +/*Source: https://vuetifyjs.com/en/styles/colors/#material-colors*/ + +lv_color_t lv_palette_main(lv_palette_t p); +static inline lv_color_t lv_color_white(void) +{ + return lv_color_make(0xff, 0xff, 0xff); +} +static inline lv_color_t lv_color_black(void) +{ + return lv_color_make(0x00, 0x0, 0x00); +} +lv_color_t lv_palette_lighten(lv_palette_t p, uint8_t lvl); +lv_color_t lv_palette_darken(lv_palette_t p, uint8_t lvl); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_COLOR_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_fs.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_fs.h new file mode 100644 index 00000000..13b2eeb5 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_fs.h @@ -0,0 +1,262 @@ +/** + * @file lv_fs.h + * + */ + +#ifndef LV_FS_H +#define LV_FS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include + +/********************* + * DEFINES + *********************/ +#define LV_FS_MAX_FN_LENGTH 64 +#define LV_FS_MAX_PATH_LENGTH 256 + +/********************** + * TYPEDEFS + **********************/ + +/** + * Errors in the file system module. + */ +enum { + LV_FS_RES_OK = 0, + LV_FS_RES_HW_ERR, /*Low level hardware error*/ + LV_FS_RES_FS_ERR, /*Error in the file system structure*/ + LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/ + LV_FS_RES_FULL, /*Disk full*/ + LV_FS_RES_LOCKED, /*The file is already opened*/ + LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/ + LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/ + LV_FS_RES_TOUT, /*Process time outed*/ + LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/ + LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/ + LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/ + LV_FS_RES_UNKNOWN, /*Other unknown error*/ +}; +typedef uint8_t lv_fs_res_t; + +/** + * File open mode. + */ +enum { + LV_FS_MODE_WR = 0x01, + LV_FS_MODE_RD = 0x02, +}; +typedef uint8_t lv_fs_mode_t; + + +/** + * Seek modes. + */ +typedef enum { + LV_FS_SEEK_SET = 0x00, /**< Set the position from absolutely (from the start of file)*/ + LV_FS_SEEK_CUR = 0x01, /**< Set the position from the current position*/ + LV_FS_SEEK_END = 0x02, /**< Set the position from the end of the file*/ +} lv_fs_whence_t; + +typedef struct _lv_fs_drv_t { + char letter; + uint16_t cache_size; + bool (*ready_cb)(struct _lv_fs_drv_t * drv); + + void * (*open_cb)(struct _lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode); + lv_fs_res_t (*close_cb)(struct _lv_fs_drv_t * drv, void * file_p); + lv_fs_res_t (*read_cb)(struct _lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br); + lv_fs_res_t (*write_cb)(struct _lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw); + lv_fs_res_t (*seek_cb)(struct _lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence); + lv_fs_res_t (*tell_cb)(struct _lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p); + + void * (*dir_open_cb)(struct _lv_fs_drv_t * drv, const char * path); + lv_fs_res_t (*dir_read_cb)(struct _lv_fs_drv_t * drv, void * rddir_p, char * fn); + lv_fs_res_t (*dir_close_cb)(struct _lv_fs_drv_t * drv, void * rddir_p); + +#if LV_USE_USER_DATA + void * user_data; /**< Custom file user data*/ +#endif +} lv_fs_drv_t; + +typedef struct { + uint32_t start; + uint32_t end; + uint32_t file_position; + void * buffer; +} lv_fs_file_cache_t; + +typedef struct { + void * file_d; + lv_fs_drv_t * drv; + lv_fs_file_cache_t * cache; +} lv_fs_file_t; + +typedef struct { + void * dir_d; + lv_fs_drv_t * drv; +} lv_fs_dir_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the File system interface + */ +void _lv_fs_init(void); + +/** + * Initialize a file system driver with default values. + * It is used to surly have known values in the fields ant not memory junk. + * After it you can set the fields. + * @param drv pointer to driver variable to initialize + */ +void lv_fs_drv_init(lv_fs_drv_t * drv); + +/** + * Add a new drive + * @param drv pointer to an lv_fs_drv_t structure which is inited with the + * corresponding function pointers. Only pointer is saved, so the + * driver should be static or dynamically allocated. + */ +void lv_fs_drv_register(lv_fs_drv_t * drv); + +/** + * Give a pointer to a driver from its letter + * @param letter the driver letter + * @return pointer to a driver or NULL if not found + */ +lv_fs_drv_t * lv_fs_get_drv(char letter); + +/** + * Test if a drive is ready or not. If the `ready` function was not initialized `true` will be + * returned. + * @param letter letter of the drive + * @return true: drive is ready; false: drive is not ready + */ +bool lv_fs_is_ready(char letter); + +/** + * Open a file + * @param file_p pointer to a lv_fs_file_t variable + * @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt) + * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode); + +/** + * Close an already opened file + * @param file_p pointer to a lv_fs_file_t variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_close(lv_fs_file_t * file_p); + +/** + * Read from a file + * @param file_p pointer to a lv_fs_file_t variable + * @param buf pointer to a buffer where the read bytes are stored + * @param btr Bytes To Read + * @param br the number of real read bytes (Bytes Read). NULL if unused. + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_read(lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br); + +/** + * Write into a file + * @param file_p pointer to a lv_fs_file_t variable + * @param buf pointer to a buffer with the bytes to write + * @param btw Bytes To Write + * @param bw the number of real written bytes (Bytes Written). NULL if unused. + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_write(lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw); + +/** + * Set the position of the 'cursor' (read write pointer) in a file + * @param file_p pointer to a lv_fs_file_t variable + * @param pos the new position expressed in bytes index (0: start of file) + * @param whence tells from where set the position. See @lv_fs_whence_t + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_seek(lv_fs_file_t * file_p, uint32_t pos, lv_fs_whence_t whence); + +/** + * Give the position of the read write pointer + * @param file_p pointer to a lv_fs_file_t variable + * @param pos_p pointer to store the position of the read write pointer + * @return LV_FS_RES_OK or any error from 'fs_res_t' + */ +lv_fs_res_t lv_fs_tell(lv_fs_file_t * file_p, uint32_t * pos); + +/** + * Initialize a 'fs_dir_t' variable for directory reading + * @param rddir_p pointer to a 'lv_fs_dir_t' variable + * @param path path to a directory + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path); + +/** + * Read the next filename form a directory. + * The name of the directories will begin with '/' + * @param rddir_p pointer to an initialized 'fs_dir_t' variable + * @param fn pointer to a buffer to store the filename + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t * rddir_p, char * fn); + +/** + * Close the directory reading + * @param rddir_p pointer to an initialized 'fs_dir_t' variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p); + +/** + * Fill a buffer with the letters of existing drivers + * @param buf buffer to store the letters ('\0' added after the last letter) + * @return the buffer + */ +char * lv_fs_get_letters(char * buf); + +/** + * Return with the extension of the filename + * @param fn string with a filename + * @return pointer to the beginning extension or empty string if no extension + */ +const char * lv_fs_get_ext(const char * fn); + +/** + * Step up one level + * @param path pointer to a file name + * @return the truncated file name + */ +char * lv_fs_up(char * path); + +/** + * Get the last element of a path (e.g. U:/folder/file -> file) + * @param path pointer to a file name + * @return pointer to the beginning of the last element in the path + */ +const char * lv_fs_get_last(const char * path); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_gc.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_gc.h new file mode 100644 index 00000000..7a98d107 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_gc.h @@ -0,0 +1,97 @@ +/** + * @file lv_gc.h + * + */ + +#ifndef LV_GC_H +#define LV_GC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include +#include "lv_mem.h" +#include "lv_ll.h" +#include "lv_timer.h" +#include "lv_types.h" +#include "liblvgl/draw/lv_img_cache.h" +#include "liblvgl/draw/lv_draw_mask.h" +#include "liblvgl/core/lv_obj_pos.h" + +/********************* + * DEFINES + *********************/ +#if LV_IMG_CACHE_DEF_SIZE +# define LV_IMG_CACHE_DEF 1 +#else +# define LV_IMG_CACHE_DEF 0 +#endif + +#define LV_DISPATCH(f, t, n) f(t, n) +#define LV_DISPATCH_COND(f, t, n, m, v) LV_CONCAT3(LV_DISPATCH, m, v)(f, t, n) + +#define LV_DISPATCH00(f, t, n) LV_DISPATCH(f, t, n) +#define LV_DISPATCH01(f, t, n) +#define LV_DISPATCH10(f, t, n) +#define LV_DISPATCH11(f, t, n) LV_DISPATCH(f, t, n) + +#define LV_ITERATE_ROOTS(f) \ + LV_DISPATCH(f, lv_ll_t, _lv_timer_ll) /*Linked list to store the lv_timers*/ \ + LV_DISPATCH(f, lv_ll_t, _lv_disp_ll) /*Linked list of display device*/ \ + LV_DISPATCH(f, lv_ll_t, _lv_indev_ll) /*Linked list of input device*/ \ + LV_DISPATCH(f, lv_ll_t, _lv_fsdrv_ll) \ + LV_DISPATCH(f, lv_ll_t, _lv_anim_ll) \ + LV_DISPATCH(f, lv_ll_t, _lv_group_ll) \ + LV_DISPATCH(f, lv_ll_t, _lv_img_decoder_ll) \ + LV_DISPATCH(f, lv_ll_t, _lv_obj_style_trans_ll) \ + LV_DISPATCH(f, lv_layout_dsc_t *, _lv_layout_list) \ + LV_DISPATCH_COND(f, _lv_img_cache_entry_t*, _lv_img_cache_array, LV_IMG_CACHE_DEF, 1) \ + LV_DISPATCH_COND(f, _lv_img_cache_entry_t, _lv_img_cache_single, LV_IMG_CACHE_DEF, 0) \ + LV_DISPATCH(f, lv_timer_t*, _lv_timer_act) \ + LV_DISPATCH(f, lv_mem_buf_arr_t , lv_mem_buf) \ + LV_DISPATCH_COND(f, _lv_draw_mask_radius_circle_dsc_arr_t , _lv_circle_cache, LV_DRAW_COMPLEX, 1) \ + LV_DISPATCH_COND(f, _lv_draw_mask_saved_arr_t , _lv_draw_mask_list, LV_DRAW_COMPLEX, 1) \ + LV_DISPATCH(f, void * , _lv_theme_default_styles) \ + LV_DISPATCH(f, void * , _lv_theme_basic_styles) \ + LV_DISPATCH_COND(f, uint8_t *, _lv_font_decompr_buf, LV_USE_FONT_COMPRESSED, 1) \ + LV_DISPATCH(f, uint8_t * , _lv_grad_cache_mem) \ + LV_DISPATCH(f, uint8_t * , _lv_style_custom_prop_flag_lookup_table) + +#define LV_DEFINE_ROOT(root_type, root_name) root_type root_name; +#define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT) + +#if LV_ENABLE_GC == 1 +#if LV_MEM_CUSTOM != 1 +#error "GC requires CUSTOM_MEM" +#endif /*LV_MEM_CUSTOM*/ +#include LV_GC_INCLUDE +#else /*LV_ENABLE_GC*/ +#define LV_GC_ROOT(x) x +#define LV_EXTERN_ROOT(root_type, root_name) extern root_type root_name; +LV_ITERATE_ROOTS(LV_EXTERN_ROOT) +#endif /*LV_ENABLE_GC*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void _lv_gc_clear_roots(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GC_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_ll.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_ll.h similarity index 55% rename from EZ-Template-Example-Project/include/display/lv_misc/lv_ll.h rename to EZ-Template-Example-Project/include/liblvgl/misc/lv_ll.h index 086ba405..d38f6928 100644 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_ll.h +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_ll.h @@ -1,5 +1,5 @@ /** - * @file lv_ll.c + * @file lv_ll.h * Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module. */ @@ -10,13 +10,12 @@ extern "C" { #endif - /********************* * INCLUDES *********************/ -#include "lv_mem.h" #include #include +#include /********************* * DEFINES @@ -26,15 +25,14 @@ extern "C" { * TYPEDEFS **********************/ -/*Dummy type to make handling easier*/ +/** Dummy type to make handling easier*/ typedef uint8_t lv_ll_node_t; -/*Description of a linked list*/ -typedef struct -{ +/** Description of a linked list*/ +typedef struct { uint32_t n_size; - lv_ll_node_t* head; - lv_ll_node_t* tail; + lv_ll_node_t * head; + lv_ll_node_t * tail; } lv_ll_t; /********************** @@ -43,68 +41,70 @@ typedef struct /** * Initialize linked list - * @param ll_dsc pointer to ll_dsc variable + * @param ll_p pointer to lv_ll_t variable * @param node_size the size of 1 node in bytes */ -void lv_ll_init(lv_ll_t * ll_p, uint32_t node_size); +void _lv_ll_init(lv_ll_t * ll_p, uint32_t node_size); /** * Add a new head to a linked list * @param ll_p pointer to linked list * @return pointer to the new head */ -void * lv_ll_ins_head(lv_ll_t * ll_p); +void * _lv_ll_ins_head(lv_ll_t * ll_p); /** * Insert a new node in front of the n_act node * @param ll_p pointer to linked list * @param n_act pointer a node - * @return pointer to the new head + * @return pointer to the new node */ -void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act); +void * _lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act); /** * Add a new tail to a linked list * @param ll_p pointer to linked list * @return pointer to the new tail */ -void * lv_ll_ins_tail(lv_ll_t * ll_p); +void * _lv_ll_ins_tail(lv_ll_t * ll_p); /** * Remove the node 'node_p' from 'll_p' linked list. - * It does not free the the memory of node. + * It does not free the memory of node. * @param ll_p pointer to the linked list of 'node_p' * @param node_p pointer to node in 'll_p' linked list */ -void lv_ll_rem(lv_ll_t * ll_p, void * node_p); +void _lv_ll_remove(lv_ll_t * ll_p, void * node_p); /** * Remove and free all elements from a linked list. The list remain valid but become empty. * @param ll_p pointer to linked list */ -void lv_ll_clear(lv_ll_t * ll_p); +void _lv_ll_clear(lv_ll_t * ll_p); /** * Move a node to a new linked list * @param ll_ori_p pointer to the original (old) linked list * @param ll_new_p pointer to the new linked list * @param node pointer to a node + * @param head true: be the head in the new list + * false be the tail in the new list */ -void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node); +void _lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool head); /** * Return with head node of the linked list * @param ll_p pointer to linked list * @return pointer to the head of 'll_p' */ -void * lv_ll_get_head(const lv_ll_t * ll_p); +void * _lv_ll_get_head(const lv_ll_t * ll_p); /** * Return with tail node of the linked list * @param ll_p pointer to linked list - * @return pointer to the head of 'll_p' + * @return pointer to the tail of 'll_p' */ -void * lv_ll_get_tail(const lv_ll_t * ll_p); +void * _lv_ll_get_tail(const lv_ll_t * ll_p); /** * Return with the pointer of the next node after 'n_act' @@ -112,7 +112,7 @@ void * lv_ll_get_tail(const lv_ll_t * ll_p); * @param n_act pointer a node * @return pointer to the next node */ -void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act); +void * _lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act); /** * Return with the pointer of the previous node after 'n_act' @@ -120,26 +120,48 @@ void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act); * @param n_act pointer a node * @return pointer to the previous node */ -void * lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act); +void * _lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act); + +/** + * Return the length of the linked list. + * @param ll_p pointer to linked list + * @return length of the linked list + */ +uint32_t _lv_ll_get_len(const lv_ll_t * ll_p); /** - * Move a nodw before an other node in the same linked list + * TODO + * @param ll_p + * @param n1_p + * @param n2_p +void lv_ll_swap(lv_ll_t * ll_p, void * n1_p, void * n2_p); + */ + +/** + * Move a node before an other node in the same linked list * @param ll_p pointer to a linked list * @param n_act pointer to node to move * @param n_after pointer to a node which should be after `n_act` */ -void lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after); +void _lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after); + +/** + * Check if a linked list is empty + * @param ll_p pointer to a linked list + * @return true: the linked list is empty; false: not empty + */ +bool _lv_ll_is_empty(lv_ll_t * ll_p); /********************** * MACROS **********************/ -#define LL_READ(list, i) for(i = lv_ll_get_head(&list); i != NULL; i = lv_ll_get_next(&list, i)) +#define _LV_LL_READ(list, i) for(i = _lv_ll_get_head(list); i != NULL; i = _lv_ll_get_next(list, i)) -#define LL_READ_BACK(list, i) for(i = lv_ll_get_tail(&list); i != NULL; i = lv_ll_get_prev(&list, i)) +#define _LV_LL_READ_BACK(list, i) for(i = _lv_ll_get_tail(list); i != NULL; i = _lv_ll_get_prev(list, i)) #ifdef __cplusplus -} /* extern "C" */ +} /*extern "C"*/ #endif #endif diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_log.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_log.h new file mode 100644 index 00000000..cd61905d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_log.h @@ -0,0 +1,154 @@ +/** + * @file lv_log.h + * + */ + +#ifndef LV_LOG_H +#define LV_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include + +#include "lv_types.h" + +/********************* + * DEFINES + *********************/ + +/*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/ + +#define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/ +#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/ +#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/ +#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/ +#define LV_LOG_LEVEL_USER 4 /**< Custom logs from the user*/ +#define LV_LOG_LEVEL_NONE 5 /**< Do not log anything*/ +#define _LV_LOG_LEVEL_NUM 6 /**< Number of log levels*/ + +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_USER); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE); + +typedef int8_t lv_log_level_t; + +#if LV_USE_LOG +/********************** + * TYPEDEFS + **********************/ + +/** + * Log print function. Receives a string buffer to print". + */ +typedef void (*lv_log_print_g_cb_t)(const char * buf); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Register custom print/write function to call when a log is added. + * It can format its "File path", "Line number" and "Description" as required + * and send the formatted log message to a console or serial port. + * @param print_cb a function pointer to print a log + */ +void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb); + +/** + * Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h` + * and/or a print callback if registered with `lv_log_register_print_cb` + * @param format printf-like format string + * @param ... parameters for `format` + */ +void lv_log(const char * format, ...) LV_FORMAT_ATTRIBUTE(1, 2); + +/** + * Add a log + * @param level the level of log. (From `lv_log_level_t` enum) + * @param file name of the file when the log added + * @param line line number in the source code where the log added + * @param func name of the function when the log added + * @param format printf-like format string + * @param ... parameters for `format` + */ +void _lv_log_add(lv_log_level_t level, const char * file, int line, + const char * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6); + +/********************** + * MACROS + **********************/ +#ifndef LV_LOG_TRACE +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE +# define LV_LOG_TRACE(...) _lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_TRACE(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG_INFO +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO +# define LV_LOG_INFO(...) _lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_INFO(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG_WARN +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN +# define LV_LOG_WARN(...) _lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_WARN(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG_ERROR +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR +# define LV_LOG_ERROR(...) _lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_ERROR(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG_USER +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER +# define LV_LOG_USER(...) _lv_log_add(LV_LOG_LEVEL_USER, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_USER(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG +# if LV_LOG_LEVEL < LV_LOG_LEVEL_NONE +# define LV_LOG(...) lv_log(__VA_ARGS__) +# else +# define LV_LOG(...) do {} while(0) +# endif +#endif + +#else /*LV_USE_LOG*/ + +/*Do nothing if `LV_USE_LOG 0`*/ +#define _lv_log_add(level, file, line, ...) +#define LV_LOG_TRACE(...) do {}while(0) +#define LV_LOG_INFO(...) do {}while(0) +#define LV_LOG_WARN(...) do {}while(0) +#define LV_LOG_ERROR(...) do {}while(0) +#define LV_LOG_USER(...) do {}while(0) +#define LV_LOG(...) do {}while(0) + +#endif /*LV_USE_LOG*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LOG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_lru.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_lru.h new file mode 100644 index 00000000..3e9729e0 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_lru.h @@ -0,0 +1,87 @@ +/** + * @file lv_lru.h + * + */ + +#ifndef LV_LRU_H +#define LV_LRU_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#include "lv_types.h" + +#include +#include + + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef enum { + LV_LRU_OK = 0, + LV_LRU_MISSING_CACHE, + LV_LRU_MISSING_KEY, + LV_LRU_MISSING_VALUE, + LV_LRU_LOCK_ERROR, + LV_LRU_VALUE_TOO_LARGE +} lv_lru_res_t; + +typedef void (lv_lru_free_t)(void * v); +typedef struct _lv_lru_item_t lv_lru_item_t; + +typedef struct lv_lru_t { + lv_lru_item_t ** items; + uint64_t access_count; + size_t free_memory; + size_t total_memory; + size_t average_item_length; + size_t hash_table_size; + uint32_t seed; + lv_lru_free_t * value_free; + lv_lru_free_t * key_free; + lv_lru_item_t * free_items; +} lv_lru_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_lru_t * lv_lru_create(size_t cache_size, size_t average_length, lv_lru_free_t * value_free, + lv_lru_free_t * key_free); + +void lv_lru_del(lv_lru_t * cache); + +lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, void * value, size_t value_length); + +lv_lru_res_t lv_lru_get(lv_lru_t * cache, const void * key, size_t key_size, void ** value); + +lv_lru_res_t lv_lru_remove(lv_lru_t * cache, const void * key, size_t key_size); + +/** + * remove the least recently used item + * + * @todo we can optimise this by finding the n lru items, where n = required_space / average_length + */ +void lv_lru_remove_lru_item(lv_lru_t * cache); +/********************** + * MACROS + **********************/ +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LRU_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_math.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_math.h new file mode 100644 index 00000000..24f9ea6c --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_math.h @@ -0,0 +1,143 @@ +/** + * @file lv_math.h + * + */ + +#ifndef LV_MATH_H +#define LV_MATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include + +/********************* + * DEFINES + *********************/ +#define LV_TRIGO_SIN_MAX 32767 +#define LV_TRIGO_SHIFT 15 /**< >> LV_TRIGO_SHIFT to normalize*/ + +#define LV_BEZIER_VAL_MAX 1024 /**< Max time in Bezier functions (not [0..1] to use integers)*/ +#define LV_BEZIER_VAL_SHIFT 10 /**< log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + uint16_t i; + uint16_t f; +} lv_sqrt_res_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +//! @cond Doxygen_Suppress +/** + * Return with sinus of an angle + * @param angle + * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 + */ +LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_sin(int16_t angle); + +static inline LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_cos(int16_t angle) +{ + return lv_trigo_sin(angle + 90); +} + +//! @endcond + +/** + * Calculate a value of a Cubic Bezier function. + * @param t time in range of [0..LV_BEZIER_VAL_MAX] + * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] + * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] + * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] + * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] + * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] + */ +uint32_t lv_bezier3(uint32_t t, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3); + +/** + * Calculate the atan2 of a vector. + * @param x + * @param y + * @return the angle in degree calculated from the given parameters in range of [0..360] + */ +uint16_t lv_atan2(int x, int y); + +//! @cond Doxygen_Suppress + +/** + * Get the square root of a number + * @param x integer which square root should be calculated + * @param q store the result here. q->i: integer part, q->f: fractional part in 1/256 unit + * @param mask optional to skip some iterations if the magnitude of the root is known. + * Set to 0x8000 by default. + * If root < 16: mask = 0x80 + * If root < 256: mask = 0x800 + * Else: mask = 0x8000 + */ +LV_ATTRIBUTE_FAST_MEM void lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask); + +//! @endcond + +/** + * Calculate the integer exponents. + * @param base + * @param power + * @return base raised to the power exponent + */ +int64_t lv_pow(int64_t base, int8_t exp); + +/** + * Get the mapped of a number given an input and output range + * @param x integer which mapped value should be calculated + * @param min_in min input range + * @param max_in max input range + * @param min_out max output range + * @param max_out max output range + * @return the mapped number + */ +int32_t lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out); + +/** + * Get a pseudo random number in the given range + * @param min the minimum value + * @param max the maximum value + * @return return the random number. min <= return_value <= max + */ +uint32_t lv_rand(uint32_t min, uint32_t max); + +/********************** + * MACROS + **********************/ +#define LV_MIN(a, b) ((a) < (b) ? (a) : (b)) +#define LV_MIN3(a, b, c) (LV_MIN(LV_MIN(a,b), c)) +#define LV_MIN4(a, b, c, d) (LV_MIN(LV_MIN(a,b), LV_MIN(c,d))) + +#define LV_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define LV_MAX3(a, b, c) (LV_MAX(LV_MAX(a,b), c)) +#define LV_MAX4(a, b, c, d) (LV_MAX(LV_MAX(a,b), LV_MAX(c,d))) + +#define LV_CLAMP(min, val, max) (LV_MAX(min, (LV_MIN(val, max)))) + +#define LV_ABS(x) ((x) > 0 ? (x) : (-(x))) +#define LV_UDIV255(x) (((x) * 0x8081U) >> 0x17) + +#define LV_IS_SIGNED(t) (((t)(-1)) < ((t)0)) +#define LV_UMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0xFULL << ((sizeof(t) * 8ULL) - 4ULL))) +#define LV_SMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0x7ULL << ((sizeof(t) * 8ULL) - 4ULL))) +#define LV_MAX_OF(t) ((unsigned long)(LV_IS_SIGNED(t) ? LV_SMAX_OF(t) : LV_UMAX_OF(t))) + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_mem.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_mem.h new file mode 100644 index 00000000..fd202aba --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_mem.h @@ -0,0 +1,243 @@ +/** + * @file lv_mem.h + * + */ + +#ifndef LV_MEM_H +#define LV_MEM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include + +#include "lv_types.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Heap information structure. + */ +typedef struct { + uint32_t total_size; /**< Total heap size*/ + uint32_t free_cnt; + uint32_t free_size; /**< Size of available memory*/ + uint32_t free_biggest_size; + uint32_t used_cnt; + uint32_t max_used; /**< Max size of Heap memory used*/ + uint8_t used_pct; /**< Percentage used*/ + uint8_t frag_pct; /**< Amount of fragmentation*/ +} lv_mem_monitor_t; + +typedef struct { + void * p; + uint16_t size; + uint8_t used : 1; +} lv_mem_buf_t; + +typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM]; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the dyn_mem module (work memory and other variables) + */ +void lv_mem_init(void); + +/** + * Clean up the memory buffer which frees all the allocated memories. + * @note It work only if `LV_MEM_CUSTOM == 0` + */ +void lv_mem_deinit(void); + +/** + * Allocate a memory dynamically + * @param size size of the memory to allocate in bytes + * @return pointer to the allocated memory + */ +void * lv_mem_alloc(size_t size); + +/** + * Free an allocated data + * @param data pointer to an allocated memory + */ +void lv_mem_free(void * data); + +/** + * Reallocate a memory with a new size. The old content will be kept. + * @param data pointer to an allocated memory. + * Its content will be copied to the new memory block and freed + * @param new_size the desired new size in byte + * @return pointer to the new memory, NULL on failure + */ +void * lv_mem_realloc(void * data_p, size_t new_size); + +/** + * + * @return + */ +lv_res_t lv_mem_test(void); + +/** + * Give information about the work memory of dynamic allocation + * @param mon_p pointer to a lv_mem_monitor_t variable, + * the result of the analysis will be stored here + */ +void lv_mem_monitor(lv_mem_monitor_t * mon_p); + + +/** + * Get a temporal buffer with the given size. + * @param size the required size + */ +void * lv_mem_buf_get(uint32_t size); + +/** + * Release a memory buffer + * @param p buffer to release + */ +void lv_mem_buf_release(void * p); + +/** + * Free all memory buffers + */ +void lv_mem_buf_free_all(void); + +//! @cond Doxygen_Suppress + +#if LV_MEMCPY_MEMSET_STD + +/** + * Wrapper for the standard memcpy + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +static inline void * lv_memcpy(void * dst, const void * src, size_t len) +{ + return memcpy(dst, src, len); +} + +/** + * Wrapper for the standard memcpy + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +static inline void * lv_memcpy_small(void * dst, const void * src, size_t len) +{ + return memcpy(dst, src, len); +} + +/** + * Wrapper for the standard memset + * @param dst pointer to the destination buffer + * @param v value to set [0..255] + * @param len number of byte to set + */ +static inline void lv_memset(void * dst, uint8_t v, size_t len) +{ + memset(dst, v, len); +} + +/** + * Wrapper for the standard memset with fixed 0x00 value + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +static inline void lv_memset_00(void * dst, size_t len) +{ + memset(dst, 0x00, len); +} + +/** + * Wrapper for the standard memset with fixed 0xFF value + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +static inline void lv_memset_ff(void * dst, size_t len) +{ + memset(dst, 0xFF, len); +} + +#else +/** + * Same as `memcpy` but optimized for 4 byte operation. + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +LV_ATTRIBUTE_FAST_MEM void * lv_memcpy(void * dst, const void * src, size_t len); + +/** + * Same as `memcpy` but optimized to copy only a few bytes. + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +LV_ATTRIBUTE_FAST_MEM static inline void * lv_memcpy_small(void * dst, const void * src, size_t len) +{ + uint8_t * d8 = (uint8_t *)dst; + const uint8_t * s8 = (const uint8_t *)src; + + while(len) { + *d8 = *s8; + d8++; + s8++; + len--; + } + + return dst; +} + +/** + * Same as `memset` but optimized for 4 byte operation. + * @param dst pointer to the destination buffer + * @param v value to set [0..255] + * @param len number of byte to set + */ +LV_ATTRIBUTE_FAST_MEM void lv_memset(void * dst, uint8_t v, size_t len); + +/** + * Same as `memset(dst, 0x00, len)` but optimized for 4 byte operation. + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +LV_ATTRIBUTE_FAST_MEM void lv_memset_00(void * dst, size_t len); + +/** + * Same as `memset(dst, 0xFF, len)` but optimized for 4 byte operation. + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +LV_ATTRIBUTE_FAST_MEM void lv_memset_ff(void * dst, size_t len); + +//! @endcond + +#endif + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MEM_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_printf.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_printf.h new file mode 100644 index 00000000..4cbbd84c --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_printf.h @@ -0,0 +1,92 @@ +/////////////////////////////////////////////////////////////////////////////// +// \author (c) Marco Paland (info@paland.com) +// 2014-2019, PALANDesign Hannover, Germany +// +// \license The MIT License (MIT) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on +// embedded systems with a very limited resources. +// Use this instead of bloated standard/newlib printf. +// These routines are thread safe and reentrant. +// +/////////////////////////////////////////////////////////////////////////////// + +/*Original repository: https://github.com/mpaland/printf*/ + +#ifndef _LV_PRINTF_H_ +#define _LV_PRINTF_H_ + +#if defined(__has_include) + #if __has_include() + #include + /* platform-specific printf format for int32_t, usually "d" or "ld" */ + #define LV_PRId32 PRId32 + #define LV_PRIu32 PRIu32 + #else + #define LV_PRId32 "d" + #define LV_PRIu32 "u" + #endif +#else + /* hope this is correct for ports without __has_include or without inttypes.h */ + #define LV_PRId32 "d" + #define LV_PRIu32 "u" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../lv_conf_internal.h" + +#if LV_SPRINTF_CUSTOM == 0 + +#include +#include + +#include "lv_types.h" + +typedef struct { + const char * fmt; + va_list * va; +} lv_vaformat_t; + +/** + * Tiny snprintf/vsnprintf implementation + * \param buffer A pointer to the buffer where to store the formatted string + * \param count The maximum number of characters to store in the buffer, including a terminating null character + * \param format A string that specifies the format of the output + * \param va A value identifying a variable arguments list + * \return The number of characters that COULD have been written into the buffer, not counting the terminating + * null character. A value equal or larger than count indicates truncation. Only when the returned value + * is non-negative and less than count, the string has been completely written. + */ +int lv_snprintf(char * buffer, size_t count, const char * format, ...) LV_FORMAT_ATTRIBUTE(3, 4); +int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va) LV_FORMAT_ATTRIBUTE(3, 0); + +#else +#include LV_SPRINTF_INCLUDE +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif // _LV_PRINTF_H_ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_style.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_style.h new file mode 100644 index 00000000..44a542dc --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_style.h @@ -0,0 +1,592 @@ +/** + * @file lv_style.h + * + */ + +#ifndef LV_STYLE_H +#define LV_STYLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include +#include "liblvgl/font/lv_font.h" +#include "lv_color.h" +#include "lv_area.h" +#include "lv_anim.h" +#include "lv_txt.h" +#include "lv_types.h" +#include "lv_assert.h" +#include "lv_bidi.h" + +/********************* + * DEFINES + *********************/ + +#define LV_STYLE_SENTINEL_VALUE 0xAABBCCDD + +/** + * Flags for style behavior + * + * The rest of the flags will have _FLAG added to their name in v9. + */ +#define LV_STYLE_PROP_FLAG_NONE (0) +#define LV_STYLE_PROP_INHERIT (1 << 0) /*Inherited*/ +#define LV_STYLE_PROP_EXT_DRAW (1 << 1) /*Requires ext. draw size update when changed*/ +#define LV_STYLE_PROP_LAYOUT_REFR (1 << 2) /*Requires layout update when changed*/ +#define LV_STYLE_PROP_PARENT_LAYOUT_REFR (1 << 3) /*Requires layout update on parent when changed*/ +#define LV_STYLE_PROP_LAYER_REFR (1 << 4) /*Affects layer handling*/ +#define LV_STYLE_PROP_ALL (0x1F) /*Indicating all flags*/ + +/** + * Other constants + */ +#define LV_IMG_ZOOM_NONE 256 /*Value for not zooming the image*/ +LV_EXPORT_CONST_INT(LV_IMG_ZOOM_NONE); + +// *INDENT-OFF* +#if LV_USE_ASSERT_STYLE +#define LV_STYLE_CONST_INIT(var_name, prop_array) \ + const lv_style_t var_name = { \ + .sentinel = LV_STYLE_SENTINEL_VALUE, \ + .v_p = { .const_props = prop_array }, \ + .has_group = 0xFF, \ + .prop1 = LV_STYLE_PROP_ANY, \ + .prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \ + } +#else +#define LV_STYLE_CONST_INIT(var_name, prop_array) \ + const lv_style_t var_name = { \ + .v_p = { .const_props = prop_array }, \ + .has_group = 0xFF, \ + .prop1 = LV_STYLE_PROP_ANY, \ + .prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \ + } +#endif +// *INDENT-ON* + +#define LV_STYLE_PROP_META_INHERIT 0x8000 +#define LV_STYLE_PROP_META_INITIAL 0x4000 +#define LV_STYLE_PROP_META_MASK (LV_STYLE_PROP_META_INHERIT | LV_STYLE_PROP_META_INITIAL) + +#define LV_STYLE_PROP_ID_MASK(prop) ((lv_style_prop_t)((prop) & ~LV_STYLE_PROP_META_MASK)) + +/********************** + * TYPEDEFS + **********************/ + +/** + * Possible options how to blend opaque drawings + */ +enum { + LV_BLEND_MODE_NORMAL, /**< Simply mix according to the opacity value*/ + LV_BLEND_MODE_ADDITIVE, /**< Add the respective color channels*/ + LV_BLEND_MODE_SUBTRACTIVE,/**< Subtract the foreground from the background*/ + LV_BLEND_MODE_MULTIPLY, /**< Multiply the foreground and background*/ + LV_BLEND_MODE_REPLACE, /**< Replace background with foreground in the area*/ +}; + +typedef uint8_t lv_blend_mode_t; + +/** + * Some options to apply decorations on texts. + * 'OR'ed values can be used. + */ +enum { + LV_TEXT_DECOR_NONE = 0x00, + LV_TEXT_DECOR_UNDERLINE = 0x01, + LV_TEXT_DECOR_STRIKETHROUGH = 0x02, +}; + +typedef uint8_t lv_text_decor_t; + +/** + * Selects on which sides border should be drawn + * 'OR'ed values can be used. + */ +enum { + LV_BORDER_SIDE_NONE = 0x00, + LV_BORDER_SIDE_BOTTOM = 0x01, + LV_BORDER_SIDE_TOP = 0x02, + LV_BORDER_SIDE_LEFT = 0x04, + LV_BORDER_SIDE_RIGHT = 0x08, + LV_BORDER_SIDE_FULL = 0x0F, + LV_BORDER_SIDE_INTERNAL = 0x10, /**< FOR matrix-like objects (e.g. Button matrix)*/ +}; +typedef uint8_t lv_border_side_t; + +/** + * The direction of the gradient. + */ +enum { + LV_GRAD_DIR_NONE, /**< No gradient (the `grad_color` property is ignored)*/ + LV_GRAD_DIR_VER, /**< Vertical (top to bottom) gradient*/ + LV_GRAD_DIR_HOR, /**< Horizontal (left to right) gradient*/ +}; + +typedef uint8_t lv_grad_dir_t; + +/** + * The dithering algorithm for the gradient + * Depends on LV_DITHER_GRADIENT + */ +enum { + LV_DITHER_NONE, /**< No dithering, colors are just quantized to the output resolution*/ + LV_DITHER_ORDERED, /**< Ordered dithering. Faster to compute and use less memory but lower quality*/ + LV_DITHER_ERR_DIFF, /**< Error diffusion mode. Slower to compute and use more memory but give highest dither quality*/ +}; + +typedef uint8_t lv_dither_mode_t; + +/** A gradient stop definition. + * This matches a color and a position in a virtual 0-255 scale. + */ +typedef struct { + lv_color_t color; /**< The stop color */ + uint8_t frac; /**< The stop position in 1/255 unit */ +} lv_gradient_stop_t; + +/** A descriptor of a gradient. */ +typedef struct { + lv_gradient_stop_t stops[LV_GRADIENT_MAX_STOPS]; /**< A gradient stop array */ + uint8_t stops_count; /**< The number of used stops in the array */ + lv_grad_dir_t dir : 3; /**< The gradient direction. + * Any of LV_GRAD_DIR_HOR, LV_GRAD_DIR_VER, LV_GRAD_DIR_NONE */ + lv_dither_mode_t dither : 3; /**< Whether to dither the gradient or not. + * Any of LV_DITHER_NONE, LV_DITHER_ORDERED, LV_DITHER_ERR_DIFF */ +} lv_grad_dsc_t; + +/** + * A common type to handle all the property types in the same way. + */ +typedef union { + int32_t num; /**< Number integer number (opacity, enums, booleans or "normal" numbers)*/ + const void * ptr; /**< Constant pointers (font, cone text, etc)*/ + lv_color_t color; /**< Colors*/ +} lv_style_value_t; + +/** + * Enumeration of all built in style properties + * + * Props are split into groups of 16. When adding a new prop to a group, ensure it does not overflow into the next one. + */ +typedef enum { + LV_STYLE_PROP_INV = 0, + + /*Group 0*/ + LV_STYLE_WIDTH = 1, + LV_STYLE_MIN_WIDTH = 2, + LV_STYLE_MAX_WIDTH = 3, + LV_STYLE_HEIGHT = 4, + LV_STYLE_MIN_HEIGHT = 5, + LV_STYLE_MAX_HEIGHT = 6, + LV_STYLE_X = 7, + LV_STYLE_Y = 8, + LV_STYLE_ALIGN = 9, + LV_STYLE_LAYOUT = 10, + LV_STYLE_RADIUS = 11, + + /*Group 1*/ + LV_STYLE_PAD_TOP = 16, + LV_STYLE_PAD_BOTTOM = 17, + LV_STYLE_PAD_LEFT = 18, + LV_STYLE_PAD_RIGHT = 19, + LV_STYLE_PAD_ROW = 20, + LV_STYLE_PAD_COLUMN = 21, + LV_STYLE_BASE_DIR = 22, + LV_STYLE_CLIP_CORNER = 23, + + /*Group 2*/ + LV_STYLE_BG_COLOR = 32, + LV_STYLE_BG_OPA = 33, + LV_STYLE_BG_GRAD_COLOR = 34, + LV_STYLE_BG_GRAD_DIR = 35, + LV_STYLE_BG_MAIN_STOP = 36, + LV_STYLE_BG_GRAD_STOP = 37, + LV_STYLE_BG_GRAD = 38, + LV_STYLE_BG_DITHER_MODE = 39, + LV_STYLE_BG_IMG_SRC = 40, + LV_STYLE_BG_IMG_OPA = 41, + LV_STYLE_BG_IMG_RECOLOR = 42, + LV_STYLE_BG_IMG_RECOLOR_OPA = 43, + LV_STYLE_BG_IMG_TILED = 44, + + /*Group 3*/ + LV_STYLE_BORDER_COLOR = 48, + LV_STYLE_BORDER_OPA = 49, + LV_STYLE_BORDER_WIDTH = 50, + LV_STYLE_BORDER_SIDE = 51, + LV_STYLE_BORDER_POST = 52, + LV_STYLE_OUTLINE_WIDTH = 53, + LV_STYLE_OUTLINE_COLOR = 54, + LV_STYLE_OUTLINE_OPA = 55, + LV_STYLE_OUTLINE_PAD = 56, + + /*Group 4*/ + LV_STYLE_SHADOW_WIDTH = 64, + LV_STYLE_SHADOW_OFS_X = 65, + LV_STYLE_SHADOW_OFS_Y = 66, + LV_STYLE_SHADOW_SPREAD = 67, + LV_STYLE_SHADOW_COLOR = 68, + LV_STYLE_SHADOW_OPA = 69, + LV_STYLE_IMG_OPA = 70, + LV_STYLE_IMG_RECOLOR = 71, + LV_STYLE_IMG_RECOLOR_OPA = 72, + LV_STYLE_LINE_WIDTH = 73, + LV_STYLE_LINE_DASH_WIDTH = 74, + LV_STYLE_LINE_DASH_GAP = 75, + LV_STYLE_LINE_ROUNDED = 76, + LV_STYLE_LINE_COLOR = 77, + LV_STYLE_LINE_OPA = 78, + + /*Group 5*/ + LV_STYLE_ARC_WIDTH = 80, + LV_STYLE_ARC_ROUNDED = 81, + LV_STYLE_ARC_COLOR = 82, + LV_STYLE_ARC_OPA = 83, + LV_STYLE_ARC_IMG_SRC = 84, + LV_STYLE_TEXT_COLOR = 85, + LV_STYLE_TEXT_OPA = 86, + LV_STYLE_TEXT_FONT = 87, + LV_STYLE_TEXT_LETTER_SPACE = 88, + LV_STYLE_TEXT_LINE_SPACE = 89, + LV_STYLE_TEXT_DECOR = 90, + LV_STYLE_TEXT_ALIGN = 91, + + /*Group 6*/ + LV_STYLE_OPA = 96, + LV_STYLE_COLOR_FILTER_DSC = 97, + LV_STYLE_COLOR_FILTER_OPA = 98, + LV_STYLE_ANIM = 99, + LV_STYLE_ANIM_TIME = 100, + LV_STYLE_ANIM_SPEED = 101, + LV_STYLE_TRANSITION = 102, + LV_STYLE_BLEND_MODE = 103, + LV_STYLE_TRANSFORM_WIDTH = 104, + LV_STYLE_TRANSFORM_HEIGHT = 105, + LV_STYLE_TRANSLATE_X = 106, + LV_STYLE_TRANSLATE_Y = 107, + LV_STYLE_TRANSFORM_ZOOM = 108, + LV_STYLE_TRANSFORM_ANGLE = 109, + LV_STYLE_TRANSFORM_PIVOT_X = 110, + LV_STYLE_TRANSFORM_PIVOT_Y = 111, + + _LV_STYLE_LAST_BUILT_IN_PROP = 111, + _LV_STYLE_NUM_BUILT_IN_PROPS = _LV_STYLE_LAST_BUILT_IN_PROP + 1, + + LV_STYLE_PROP_ANY = 0xFFFF, + _LV_STYLE_PROP_CONST = 0xFFFF /* magic value for const styles */ +} lv_style_prop_t; + +enum { + LV_STYLE_RES_NOT_FOUND, + LV_STYLE_RES_FOUND, + LV_STYLE_RES_INHERIT +}; + +typedef uint8_t lv_style_res_t; + +/** + * Descriptor for style transitions + */ +typedef struct { + const lv_style_prop_t * props; /**< An array with the properties to animate.*/ +#if LV_USE_USER_DATA + void * user_data; /**< A custom user data that will be passed to the animation's user_data */ +#endif + lv_anim_path_cb_t path_xcb; /**< A path for the animation.*/ + uint32_t time; /**< Duration of the transition in [ms]*/ + uint32_t delay; /**< Delay before the transition in [ms]*/ +} lv_style_transition_dsc_t; + +/** + * Descriptor of a constant style property. + */ +typedef struct { + lv_style_prop_t prop; + lv_style_value_t value; +} lv_style_const_prop_t; + +/** + * Descriptor of a style (a collection of properties and values). + */ +typedef struct { + +#if LV_USE_ASSERT_STYLE + uint32_t sentinel; +#endif + + /*If there is only one property store it directly. + *For more properties allocate an array*/ + union { + lv_style_value_t value1; + uint8_t * values_and_props; + const lv_style_const_prop_t * const_props; + } v_p; + + uint16_t prop1; + uint8_t has_group; + uint8_t prop_cnt; +} lv_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + + +/** + * Initialize a style + * @param style pointer to a style to initialize + * @note Do not call `lv_style_init` on styles that already have some properties + * because this function won't free the used memory, just sets a default state for the style. + * In other words be sure to initialize styles only once! + */ +void lv_style_init(lv_style_t * style); + +/** + * Clear all properties from a style and free all allocated memories. + * @param style pointer to a style + */ +void lv_style_reset(lv_style_t * style); + +/** + * Register a new style property for custom usage + * @return a new property ID, or LV_STYLE_PROP_INV if there are no more available. + * @example + * lv_style_prop_t MY_PROP; + * static inline void lv_style_set_my_prop(lv_style_t * style, lv_color_t value) { + * lv_style_value_t v = {.color = value}; lv_style_set_prop(style, MY_PROP, v); } + * + * ... + * MY_PROP = lv_style_register_prop(); + * ... + * lv_style_set_my_prop(&style1, lv_palette_main(LV_PALETTE_RED)); + */ +lv_style_prop_t lv_style_register_prop(uint8_t flag); + +/** + * Get the number of custom properties that have been registered thus far. + */ +lv_style_prop_t lv_style_get_num_custom_props(void); + +/** + * Remove a property from a style + * @param style pointer to a style + * @param prop a style property ORed with a state. + * @return true: the property was found and removed; false: the property wasn't found + */ +bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop); + +/** + * Set the value of property in a style. + * This function shouldn't be used directly by the user. + * Instead use `lv_style_set_()`. E.g. `lv_style_set_bg_color()` + * @param style pointer to style + * @param prop the ID of a property (e.g. `LV_STYLE_BG_COLOR`) + * @param value `lv_style_value_t` variable in which a field is set according to the type of `prop` + */ +void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value); + +/** + * Set a special meta state for a property in a style. + * This function shouldn't be used directly by the user. + * @param style pointer to style + * @param prop the ID of a property (e.g. `LV_STYLE_BG_COLOR`) + * @param meta the meta value to attach to the property in the style + */ +void lv_style_set_prop_meta(lv_style_t * style, lv_style_prop_t prop, uint16_t meta); + +/** + * Get the value of a property + * @param style pointer to a style + * @param prop the ID of a property + * @param value pointer to a `lv_style_value_t` variable to store the value + * @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged) + * LV_RES_OK: the property was fond, and `value` is set accordingly + * @note For performance reasons there are no sanity check on `style` + */ +lv_style_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value); + +/** + * Initialize a transition descriptor. + * @param tr pointer to a transition descriptor to initialize + * @param props an array with the properties to transition. The last element must be zero. + * @param path_cb an animation path (ease) callback. If `NULL` liner path will be used. + * @param time duration of the transition in [ms] + * @param delay delay before the transition in [ms] + * @param user_data any custom data that will be saved in the transition animation and will be available when `path_cb` is called + * @example + * const static lv_style_prop_t trans_props[] = { LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, 0 }; + * static lv_style_transition_dsc_t trans1; + * lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0, NULL); + */ +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], + lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data); + +/** + * Get the default value of a property + * @param prop the ID of a property + * @return the default value + */ +lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop); + +/** + * Get the value of a property + * @param style pointer to a style + * @param prop the ID of a property + * @param value pointer to a `lv_style_value_t` variable to store the value + * @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged) + * LV_RES_OK: the property was fond, and `value` is set accordingly + * @note For performance reasons there are no sanity check on `style` + * @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places + */ +static inline lv_style_res_t lv_style_get_prop_inlined(const lv_style_t * style, lv_style_prop_t prop, + lv_style_value_t * value) +{ + if(style->prop1 == LV_STYLE_PROP_ANY) { + const lv_style_const_prop_t * const_prop; + uint32_t i; + for(i = 0; i < style->prop_cnt; i++) { + const_prop = style->v_p.const_props + i; + lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(const_prop->prop); + if(prop_id == prop) { + if(const_prop->prop & LV_STYLE_PROP_META_INHERIT) + return LV_STYLE_RES_INHERIT; + *value = (const_prop->prop & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(prop_id) : const_prop->value; + return LV_STYLE_RES_FOUND; + } + } + return LV_STYLE_RES_NOT_FOUND; + } + + if(style->prop_cnt == 0) return LV_STYLE_RES_NOT_FOUND; + + if(style->prop_cnt > 1) { + uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t); + uint16_t * props = (uint16_t *)tmp; + uint32_t i; + for(i = 0; i < style->prop_cnt; i++) { + lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(props[i]); + if(prop_id == prop) { + if(props[i] & LV_STYLE_PROP_META_INHERIT) + return LV_STYLE_RES_INHERIT; + if(props[i] & LV_STYLE_PROP_META_INITIAL) + *value = lv_style_prop_get_default(prop_id); + else { + lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props; + *value = values[i]; + } + return LV_STYLE_RES_FOUND; + } + } + } + else if(LV_STYLE_PROP_ID_MASK(style->prop1) == prop) { + if(style->prop1 & LV_STYLE_PROP_META_INHERIT) + return LV_STYLE_RES_INHERIT; + *value = (style->prop1 & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(LV_STYLE_PROP_ID_MASK( + style->prop1)) : style->v_p.value1; + return LV_STYLE_RES_FOUND; + } + return LV_STYLE_RES_NOT_FOUND; +} + +/** + * Checks if a style is empty (has no properties) + * @param style pointer to a style + * @return true if the style is empty + */ +bool lv_style_is_empty(const lv_style_t * style); + +/** + * Tell the group of a property. If the a property from a group is set in a style the (1 << group) bit of style->has_group is set. + * It allows early skipping the style if the property is not exists in the style at all. + * @param prop a style property + * @return the group [0..7] 7 means all the custom properties with index > 112 + */ +uint8_t _lv_style_get_prop_group(lv_style_prop_t prop); + +/** + * Get the flags of a built-in or custom property. + * + * @param prop a style property + * @return the flags of the property + */ +uint8_t _lv_style_prop_lookup_flags(lv_style_prop_t prop); + +#include "lv_style_gen.h" + +static inline void lv_style_set_size(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_width(style, value); + lv_style_set_height(style, value); +} + +static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_pad_left(style, value); + lv_style_set_pad_right(style, value); + lv_style_set_pad_top(style, value); + lv_style_set_pad_bottom(style, value); +} + +static inline void lv_style_set_pad_hor(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_pad_left(style, value); + lv_style_set_pad_right(style, value); +} + +static inline void lv_style_set_pad_ver(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_pad_top(style, value); + lv_style_set_pad_bottom(style, value); +} + +static inline void lv_style_set_pad_gap(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_pad_row(style, value); + lv_style_set_pad_column(style, value); +} + +/** + * @brief Check if the style property has a specified behavioral flag. + * + * Do not pass multiple flags to this function as backwards-compatibility is not guaranteed + * for that. + * + * @param prop Property ID + * @param flag Flag + * @return true if the flag is set for this property + */ +static inline bool lv_style_prop_has_flag(lv_style_prop_t prop, uint8_t flag) +{ + return _lv_style_prop_lookup_flags(prop) & flag; +} + +/************************* + * GLOBAL VARIABLES + *************************/ + +/********************** + * MACROS + **********************/ + +#if LV_USE_ASSERT_STYLE +# define LV_ASSERT_STYLE(style_p) \ + do { \ + LV_ASSERT_MSG(style_p != NULL, "The style is NULL"); \ + LV_ASSERT_MSG(style_p->sentinel == LV_STYLE_SENTINEL_VALUE, "Style is not initialized or corrupted"); \ + } while(0) +#else +# define LV_ASSERT_STYLE(p) do{}while(0) +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_STYLE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_style_gen.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_style_gen.h new file mode 100644 index 00000000..8bf3b68f --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_style_gen.h @@ -0,0 +1,504 @@ +void lv_style_set_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_min_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_max_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_height(lv_style_t * style, lv_coord_t value); +void lv_style_set_min_height(lv_style_t * style, lv_coord_t value); +void lv_style_set_max_height(lv_style_t * style, lv_coord_t value); +void lv_style_set_x(lv_style_t * style, lv_coord_t value); +void lv_style_set_y(lv_style_t * style, lv_coord_t value); +void lv_style_set_align(lv_style_t * style, lv_align_t value); +void lv_style_set_transform_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_height(lv_style_t * style, lv_coord_t value); +void lv_style_set_translate_x(lv_style_t * style, lv_coord_t value); +void lv_style_set_translate_y(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_zoom(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_angle(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_pivot_x(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_pivot_y(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_top(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_bottom(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_left(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_right(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_row(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_column(lv_style_t * style, lv_coord_t value); +void lv_style_set_bg_color(lv_style_t * style, lv_color_t value); +void lv_style_set_bg_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_bg_grad_color(lv_style_t * style, lv_color_t value); +void lv_style_set_bg_grad_dir(lv_style_t * style, lv_grad_dir_t value); +void lv_style_set_bg_main_stop(lv_style_t * style, lv_coord_t value); +void lv_style_set_bg_grad_stop(lv_style_t * style, lv_coord_t value); +void lv_style_set_bg_grad(lv_style_t * style, const lv_grad_dsc_t * value); +void lv_style_set_bg_dither_mode(lv_style_t * style, lv_dither_mode_t value); +void lv_style_set_bg_img_src(lv_style_t * style, const void * value); +void lv_style_set_bg_img_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_bg_img_recolor(lv_style_t * style, lv_color_t value); +void lv_style_set_bg_img_recolor_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_bg_img_tiled(lv_style_t * style, bool value); +void lv_style_set_border_color(lv_style_t * style, lv_color_t value); +void lv_style_set_border_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_border_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_border_side(lv_style_t * style, lv_border_side_t value); +void lv_style_set_border_post(lv_style_t * style, bool value); +void lv_style_set_outline_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_outline_color(lv_style_t * style, lv_color_t value); +void lv_style_set_outline_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_outline_pad(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_ofs_x(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_ofs_y(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_spread(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_color(lv_style_t * style, lv_color_t value); +void lv_style_set_shadow_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_img_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_img_recolor(lv_style_t * style, lv_color_t value); +void lv_style_set_img_recolor_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_line_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_line_dash_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_line_dash_gap(lv_style_t * style, lv_coord_t value); +void lv_style_set_line_rounded(lv_style_t * style, bool value); +void lv_style_set_line_color(lv_style_t * style, lv_color_t value); +void lv_style_set_line_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_arc_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_arc_rounded(lv_style_t * style, bool value); +void lv_style_set_arc_color(lv_style_t * style, lv_color_t value); +void lv_style_set_arc_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_arc_img_src(lv_style_t * style, const void * value); +void lv_style_set_text_color(lv_style_t * style, lv_color_t value); +void lv_style_set_text_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_text_font(lv_style_t * style, const lv_font_t * value); +void lv_style_set_text_letter_space(lv_style_t * style, lv_coord_t value); +void lv_style_set_text_line_space(lv_style_t * style, lv_coord_t value); +void lv_style_set_text_decor(lv_style_t * style, lv_text_decor_t value); +void lv_style_set_text_align(lv_style_t * style, lv_text_align_t value); +void lv_style_set_radius(lv_style_t * style, lv_coord_t value); +void lv_style_set_clip_corner(lv_style_t * style, bool value); +void lv_style_set_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_color_filter_dsc(lv_style_t * style, const lv_color_filter_dsc_t * value); +void lv_style_set_color_filter_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_anim(lv_style_t * style, const lv_anim_t * value); +void lv_style_set_anim_time(lv_style_t * style, uint32_t value); +void lv_style_set_anim_speed(lv_style_t * style, uint32_t value); +void lv_style_set_transition(lv_style_t * style, const lv_style_transition_dsc_t * value); +void lv_style_set_blend_mode(lv_style_t * style, lv_blend_mode_t value); +void lv_style_set_layout(lv_style_t * style, uint16_t value); +void lv_style_set_base_dir(lv_style_t * style, lv_base_dir_t value); + +#define LV_STYLE_CONST_WIDTH(val) \ + { \ + .prop = LV_STYLE_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_MIN_WIDTH(val) \ + { \ + .prop = LV_STYLE_MIN_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_MAX_WIDTH(val) \ + { \ + .prop = LV_STYLE_MAX_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_HEIGHT(val) \ + { \ + .prop = LV_STYLE_HEIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_MIN_HEIGHT(val) \ + { \ + .prop = LV_STYLE_MIN_HEIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_MAX_HEIGHT(val) \ + { \ + .prop = LV_STYLE_MAX_HEIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_X(val) \ + { \ + .prop = LV_STYLE_X, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_Y(val) \ + { \ + .prop = LV_STYLE_Y, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ALIGN(val) \ + { \ + .prop = LV_STYLE_ALIGN, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_WIDTH(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_HEIGHT(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_HEIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSLATE_X(val) \ + { \ + .prop = LV_STYLE_TRANSLATE_X, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSLATE_Y(val) \ + { \ + .prop = LV_STYLE_TRANSLATE_Y, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_ZOOM(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_ZOOM, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_ANGLE(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_ANGLE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_PIVOT_X(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_PIVOT_X, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_PIVOT_Y(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_PIVOT_Y, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_TOP(val) \ + { \ + .prop = LV_STYLE_PAD_TOP, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_BOTTOM(val) \ + { \ + .prop = LV_STYLE_PAD_BOTTOM, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_LEFT(val) \ + { \ + .prop = LV_STYLE_PAD_LEFT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_RIGHT(val) \ + { \ + .prop = LV_STYLE_PAD_RIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_ROW(val) \ + { \ + .prop = LV_STYLE_PAD_ROW, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_COLUMN(val) \ + { \ + .prop = LV_STYLE_PAD_COLUMN, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_COLOR(val) \ + { \ + .prop = LV_STYLE_BG_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_BG_OPA(val) \ + { \ + .prop = LV_STYLE_BG_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_GRAD_COLOR(val) \ + { \ + .prop = LV_STYLE_BG_GRAD_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_BG_GRAD_DIR(val) \ + { \ + .prop = LV_STYLE_BG_GRAD_DIR, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_MAIN_STOP(val) \ + { \ + .prop = LV_STYLE_BG_MAIN_STOP, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_GRAD_STOP(val) \ + { \ + .prop = LV_STYLE_BG_GRAD_STOP, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_GRAD(val) \ + { \ + .prop = LV_STYLE_BG_GRAD, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_BG_DITHER_MODE(val) \ + { \ + .prop = LV_STYLE_BG_DITHER_MODE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_IMG_SRC(val) \ + { \ + .prop = LV_STYLE_BG_IMG_SRC, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_BG_IMG_OPA(val) \ + { \ + .prop = LV_STYLE_BG_IMG_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_IMG_RECOLOR(val) \ + { \ + .prop = LV_STYLE_BG_IMG_RECOLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_BG_IMG_RECOLOR_OPA(val) \ + { \ + .prop = LV_STYLE_BG_IMG_RECOLOR_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_IMG_TILED(val) \ + { \ + .prop = LV_STYLE_BG_IMG_TILED, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BORDER_COLOR(val) \ + { \ + .prop = LV_STYLE_BORDER_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_BORDER_OPA(val) \ + { \ + .prop = LV_STYLE_BORDER_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BORDER_WIDTH(val) \ + { \ + .prop = LV_STYLE_BORDER_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BORDER_SIDE(val) \ + { \ + .prop = LV_STYLE_BORDER_SIDE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BORDER_POST(val) \ + { \ + .prop = LV_STYLE_BORDER_POST, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_OUTLINE_WIDTH(val) \ + { \ + .prop = LV_STYLE_OUTLINE_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_OUTLINE_COLOR(val) \ + { \ + .prop = LV_STYLE_OUTLINE_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_OUTLINE_OPA(val) \ + { \ + .prop = LV_STYLE_OUTLINE_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_OUTLINE_PAD(val) \ + { \ + .prop = LV_STYLE_OUTLINE_PAD, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_WIDTH(val) \ + { \ + .prop = LV_STYLE_SHADOW_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_OFS_X(val) \ + { \ + .prop = LV_STYLE_SHADOW_OFS_X, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_OFS_Y(val) \ + { \ + .prop = LV_STYLE_SHADOW_OFS_Y, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_SPREAD(val) \ + { \ + .prop = LV_STYLE_SHADOW_SPREAD, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_COLOR(val) \ + { \ + .prop = LV_STYLE_SHADOW_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_SHADOW_OPA(val) \ + { \ + .prop = LV_STYLE_SHADOW_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_IMG_OPA(val) \ + { \ + .prop = LV_STYLE_IMG_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_IMG_RECOLOR(val) \ + { \ + .prop = LV_STYLE_IMG_RECOLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_IMG_RECOLOR_OPA(val) \ + { \ + .prop = LV_STYLE_IMG_RECOLOR_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_WIDTH(val) \ + { \ + .prop = LV_STYLE_LINE_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_DASH_WIDTH(val) \ + { \ + .prop = LV_STYLE_LINE_DASH_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_DASH_GAP(val) \ + { \ + .prop = LV_STYLE_LINE_DASH_GAP, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_ROUNDED(val) \ + { \ + .prop = LV_STYLE_LINE_ROUNDED, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_COLOR(val) \ + { \ + .prop = LV_STYLE_LINE_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_LINE_OPA(val) \ + { \ + .prop = LV_STYLE_LINE_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ARC_WIDTH(val) \ + { \ + .prop = LV_STYLE_ARC_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ARC_ROUNDED(val) \ + { \ + .prop = LV_STYLE_ARC_ROUNDED, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ARC_COLOR(val) \ + { \ + .prop = LV_STYLE_ARC_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_ARC_OPA(val) \ + { \ + .prop = LV_STYLE_ARC_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ARC_IMG_SRC(val) \ + { \ + .prop = LV_STYLE_ARC_IMG_SRC, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_TEXT_COLOR(val) \ + { \ + .prop = LV_STYLE_TEXT_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_TEXT_OPA(val) \ + { \ + .prop = LV_STYLE_TEXT_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TEXT_FONT(val) \ + { \ + .prop = LV_STYLE_TEXT_FONT, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_TEXT_LETTER_SPACE(val) \ + { \ + .prop = LV_STYLE_TEXT_LETTER_SPACE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TEXT_LINE_SPACE(val) \ + { \ + .prop = LV_STYLE_TEXT_LINE_SPACE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TEXT_DECOR(val) \ + { \ + .prop = LV_STYLE_TEXT_DECOR, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TEXT_ALIGN(val) \ + { \ + .prop = LV_STYLE_TEXT_ALIGN, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_RADIUS(val) \ + { \ + .prop = LV_STYLE_RADIUS, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_CLIP_CORNER(val) \ + { \ + .prop = LV_STYLE_CLIP_CORNER, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_OPA(val) \ + { \ + .prop = LV_STYLE_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_COLOR_FILTER_DSC(val) \ + { \ + .prop = LV_STYLE_COLOR_FILTER_DSC, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_COLOR_FILTER_OPA(val) \ + { \ + .prop = LV_STYLE_COLOR_FILTER_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ANIM(val) \ + { \ + .prop = LV_STYLE_ANIM, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_ANIM_TIME(val) \ + { \ + .prop = LV_STYLE_ANIM_TIME, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ANIM_SPEED(val) \ + { \ + .prop = LV_STYLE_ANIM_SPEED, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSITION(val) \ + { \ + .prop = LV_STYLE_TRANSITION, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_BLEND_MODE(val) \ + { \ + .prop = LV_STYLE_BLEND_MODE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LAYOUT(val) \ + { \ + .prop = LV_STYLE_LAYOUT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BASE_DIR(val) \ + { \ + .prop = LV_STYLE_BASE_DIR, .value = { .num = (int32_t)val } \ + } diff --git a/EZ-Template-Example-Project/include/display/lv_misc/lv_templ.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_templ.h similarity index 96% rename from EZ-Template-Example-Project/include/display/lv_misc/lv_templ.h rename to EZ-Template-Example-Project/include/liblvgl/misc/lv_templ.h index a5459e8d..f7e3c268 100644 --- a/EZ-Template-Example-Project/include/display/lv_misc/lv_templ.h +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_templ.h @@ -30,9 +30,8 @@ extern "C" { * MACROS **********************/ - #ifdef __cplusplus -} /* extern "C" */ +} /*extern "C"*/ #endif #endif /*LV_TEMPL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_timer.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_timer.h new file mode 100644 index 00000000..16572d3d --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_timer.h @@ -0,0 +1,183 @@ +/** + * @file lv_timer.h + */ + +#ifndef LV_TIMER_H +#define LV_TIMER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/hal/lv_hal_tick.h" + +#include +#include + +/********************* + * DEFINES + *********************/ +#ifndef LV_ATTRIBUTE_TIMER_HANDLER +#define LV_ATTRIBUTE_TIMER_HANDLER +#endif + +#define LV_NO_TIMER_READY 0xFFFFFFFF + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_timer_t; + +/** + * Timers execute this type of functions. + */ +typedef void (*lv_timer_cb_t)(struct _lv_timer_t *); + +/** + * Descriptor of a lv_timer + */ +typedef struct _lv_timer_t { + uint32_t period; /**< How often the timer should run*/ + uint32_t last_run; /**< Last time the timer ran*/ + lv_timer_cb_t timer_cb; /**< Timer function*/ + void * user_data; /**< Custom user data*/ + int32_t repeat_count; /**< 1: One time; -1 : infinity; n>0: residual times*/ + uint32_t paused : 1; +} lv_timer_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Init the lv_timer module + */ +void _lv_timer_core_init(void); + +//! @cond Doxygen_Suppress + +/** + * Call it periodically to handle lv_timers. + * @return time till it needs to be run next (in ms) + */ +LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void); + +//! @endcond + +/** + * Call it in the super-loop of main() or threads. It will run lv_timer_handler() + * with a given period in ms. You can use it with sleep or delay in OS environment. + * This function is used to simplify the porting. + * @param __ms the period for running lv_timer_handler() + */ +static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler_run_in_period(uint32_t ms) +{ + static uint32_t last_tick = 0; + uint32_t curr_tick = lv_tick_get(); + + if((curr_tick - last_tick) >= (ms)) { + last_tick = curr_tick; + return lv_timer_handler(); + } + return 1; +} + +/** + * Create an "empty" timer. It needs to initialized with at least + * `lv_timer_set_cb` and `lv_timer_set_period` + * @return pointer to the created timer + */ +lv_timer_t * lv_timer_create_basic(void); + +/** + * Create a new lv_timer + * @param timer_xcb a callback to call periodically. + * (the 'x' in the argument name indicates that it's not a fully generic function because it not follows + * the `func_name(object, callback, ...)` convention) + * @param period call period in ms unit + * @param user_data custom parameter + * @return pointer to the new timer + */ +lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * user_data); + +/** + * Delete a lv_timer + * @param timer pointer to an lv_timer + */ +void lv_timer_del(lv_timer_t * timer); + +/** + * Pause/resume a timer. + * @param timer pointer to an lv_timer + */ +void lv_timer_pause(lv_timer_t * timer); + +void lv_timer_resume(lv_timer_t * timer); + +/** + * Set the callback the timer (the function to call periodically) + * @param timer pointer to a timer + * @param timer_cb the function to call periodically + */ +void lv_timer_set_cb(lv_timer_t * timer, lv_timer_cb_t timer_cb); + +/** + * Set new period for a lv_timer + * @param timer pointer to a lv_timer + * @param period the new period + */ +void lv_timer_set_period(lv_timer_t * timer, uint32_t period); + +/** + * Make a lv_timer ready. It will not wait its period. + * @param timer pointer to a lv_timer. + */ +void lv_timer_ready(lv_timer_t * timer); + +/** + * Set the number of times a timer will repeat. + * @param timer pointer to a lv_timer. + * @param repeat_count -1 : infinity; 0 : stop ; n>0: residual times + */ +void lv_timer_set_repeat_count(lv_timer_t * timer, int32_t repeat_count); + +/** + * Reset a lv_timer. + * It will be called the previously set period milliseconds later. + * @param timer pointer to a lv_timer. + */ +void lv_timer_reset(lv_timer_t * timer); + +/** + * Enable or disable the whole lv_timer handling + * @param en true: lv_timer handling is running, false: lv_timer handling is suspended + */ +void lv_timer_enable(bool en); + +/** + * Get idle percentage + * @return the lv_timer idle in percentage + */ +uint8_t lv_timer_get_idle(void); + +/** + * Iterate through the timers + * @param timer NULL to start iteration or the previous return value to get the next timer + * @return the next timer or NULL if there is no more timer + */ +lv_timer_t * lv_timer_get_next(lv_timer_t * timer); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_tlsf.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_tlsf.h new file mode 100644 index 00000000..f12590b6 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_tlsf.h @@ -0,0 +1,95 @@ +#include "../lv_conf_internal.h" +#if LV_MEM_CUSTOM == 0 + +#ifndef LV_TLSF_H +#define LV_TLSF_H + +/* +** Two Level Segregated Fit memory allocator, version 3.1. +** Written by Matthew Conte +** http://tlsf.baisoku.org +** +** Based on the original documentation by Miguel Masmano: +** http://www.gii.upv.es/tlsf/main/docs +** +** This implementation was written to the specification +** of the document, therefore no GPL restrictions apply. +** +** Copyright (c) 2006-2016, Matthew Conte +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the copyright holder nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY +** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +/* lv_tlsf_t: a TLSF structure. Can contain 1 to N pools. */ +/* lv_pool_t: a block of memory that TLSF can manage. */ +typedef void * lv_tlsf_t; +typedef void * lv_pool_t; + +/* Create/destroy a memory pool. */ +lv_tlsf_t lv_tlsf_create(void * mem); +lv_tlsf_t lv_tlsf_create_with_pool(void * mem, size_t bytes); +void lv_tlsf_destroy(lv_tlsf_t tlsf); +lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf); + +/* Add/remove memory pools. */ +lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void * mem, size_t bytes); +void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool); + +/* malloc/memalign/realloc/free replacements. */ +void * lv_tlsf_malloc(lv_tlsf_t tlsf, size_t bytes); +void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t bytes); +void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size); +size_t lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr); + +/* Returns internal block size, not original request size */ +size_t lv_tlsf_block_size(void * ptr); + +/* Overheads/limits of internal structures. */ +size_t lv_tlsf_size(void); +size_t lv_tlsf_align_size(void); +size_t lv_tlsf_block_size_min(void); +size_t lv_tlsf_block_size_max(void); +size_t lv_tlsf_pool_overhead(void); +size_t lv_tlsf_alloc_overhead(void); + +/* Debugging. */ +typedef void (*lv_tlsf_walker)(void * ptr, size_t size, int used, void * user); +void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void * user); +/* Returns nonzero if any internal consistency check fails. */ +int lv_tlsf_check(lv_tlsf_t tlsf); +int lv_tlsf_check_pool(lv_pool_t pool); + +#if defined(__cplusplus) +}; +#endif + +#endif /*LV_TLSF_H*/ + +#endif /* LV_MEM_CUSTOM == 0 */ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_txt.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_txt.h new file mode 100644 index 00000000..ae60e8b8 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_txt.h @@ -0,0 +1,264 @@ +/** + * @file lv_txt.h + * + */ + +#ifndef LV_TXT_H +#define LV_TXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include "lv_area.h" +#include "liblvgl/font/lv_font.h" +#include "lv_printf.h" +#include "lv_types.h" + +/********************* + * DEFINES + *********************/ +#ifndef LV_TXT_COLOR_CMD +#define LV_TXT_COLOR_CMD "#" +#endif + +#define LV_TXT_ENC_UTF8 1 +#define LV_TXT_ENC_ASCII 2 + +/********************** + * TYPEDEFS + **********************/ + +/** + * Options for text rendering. + */ +enum { + LV_TEXT_FLAG_NONE = 0x00, + LV_TEXT_FLAG_RECOLOR = 0x01, /**< Enable parsing of recolor command*/ + LV_TEXT_FLAG_EXPAND = 0x02, /**< Ignore max-width to avoid automatic word wrapping*/ + LV_TEXT_FLAG_FIT = 0x04, /**< Max-width is already equal to the longest line. (Used to skip some calculation)*/ +}; +typedef uint8_t lv_text_flag_t; + +/** + * State machine for text renderer.*/ +enum { + LV_TEXT_CMD_STATE_WAIT, /**< Waiting for command*/ + LV_TEXT_CMD_STATE_PAR, /**< Processing the parameter*/ + LV_TEXT_CMD_STATE_IN, /**< Processing the command*/ +}; +typedef uint8_t lv_text_cmd_state_t; + +/** Label align policy*/ +enum { + LV_TEXT_ALIGN_AUTO, /**< Align text auto*/ + LV_TEXT_ALIGN_LEFT, /**< Align text to left*/ + LV_TEXT_ALIGN_CENTER, /**< Align text to center*/ + LV_TEXT_ALIGN_RIGHT, /**< Align text to right*/ +}; +typedef uint8_t lv_text_align_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Get size of a text + * @param size_res pointer to a 'point_t' variable to store the result + * @param text pointer to a text + * @param font pointer to font of the text + * @param letter_space letter space of the text + * @param line_space line space of the text + * @param flags settings for the text from ::lv_text_flag_t + * @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid + * line breaks + */ +void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, lv_coord_t letter_space, + lv_coord_t line_space, lv_coord_t max_width, lv_text_flag_t flag); + +/** + * Get the next line of text. Check line length and break chars too. + * @param txt a '\0' terminated string + * @param font pointer to a font + * @param letter_space letter space + * @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid + * line breaks + * @param used_width When used_width != NULL, save the width of this line if + * flag == LV_TEXT_FLAG_NONE, otherwise save -1. + * @param flags settings for the text from 'txt_flag_type' enum + * @return the index of the first char of the new line (in byte index not letter index. With UTF-8 + * they are different) + */ +uint32_t _lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord_t letter_space, + lv_coord_t max_width, lv_coord_t * used_width, lv_text_flag_t flag); + +/** + * Give the length of a text with a given font + * @param txt a '\0' terminate string + * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in + * UTF-8) + * @param font pointer to a font + * @param letter_space letter space + * @param flags settings for the text from 'txt_flag_t' enum + * @return length of a char_num long text + */ +lv_coord_t lv_txt_get_width(const char * txt, uint32_t length, const lv_font_t * font, lv_coord_t letter_space, + lv_text_flag_t flag); + +/** + * Check next character in a string and decide if the character is part of the command or not + * @param state pointer to a txt_cmd_state_t variable which stores the current state of command + * processing + * @param c the current character + * @return true: the character is part of a command and should not be written, + * false: the character should be written + */ +bool _lv_txt_is_cmd(lv_text_cmd_state_t * state, uint32_t c); + +/** + * Insert a string into an other + * @param txt_buf the original text (must be big enough for the result text and NULL terminated) + * @param pos position to insert (0: before the original text, 1: after the first char etc.) + * @param ins_txt text to insert, must be '\0' terminated + */ +void _lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt); + +/** + * Delete a part of a string + * @param txt string to modify, must be '\0' terminated and should point to a heap or stack frame, not read-only memory. + * @param pos position where to start the deleting (0: before the first char, 1: after the first + * char etc.) + * @param len number of characters to delete + */ +void _lv_txt_cut(char * txt, uint32_t pos, uint32_t len); + +/** + * return a new formatted text. Memory will be allocated to store the text. + * @param fmt `printf`-like format + * @return pointer to the allocated text string. + */ +char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap) LV_FORMAT_ATTRIBUTE(1, 0); + +/** + * Decode two encoded character from a string. + * @param txt pointer to '\0' terminated string + * @param letter the first decoded Unicode character or 0 on invalid data code + * @param letter_next the second decoded Unicode character or 0 on invalid data code + * @param ofs start index in 'txt' where to start. + * After the call it will point to the next encoded char in 'txt'. + * NULL to use txt[0] as index + */ +void _lv_txt_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs); + +/** + * Test if char is break char or not (a text can broken here or not) + * @param letter a letter + * @return false: 'letter' is not break char + */ +static inline bool _lv_txt_is_break_char(uint32_t letter) +{ + uint8_t i; + bool ret = false; + + /* each chinese character can be break */ + if(letter >= 0x4E00 && letter <= 0x9FA5) { + return true; + } + + /*Compare the letter to TXT_BREAK_CHARS*/ + for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) { + if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) { + ret = true; /*If match then it is break char*/ + break; + } + } + + return ret; +} + +/*************************************************************** + * GLOBAL FUNCTION POINTERS FOR CHARACTER ENCODING INTERFACE + ***************************************************************/ + +/** + * Give the size of an encoded character + * @param str pointer to a character in a string + * @return length of the encoded character (1,2,3 ...). O in invalid + */ +extern uint8_t (*_lv_txt_encoded_size)(const char *); + +/** + * Convert a Unicode letter to encoded + * @param letter_uni a Unicode letter + * @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü') + */ +extern uint32_t (*_lv_txt_unicode_to_encoded)(uint32_t); + +/** + * Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format. + * @param c a wide character + * @return `c` in the encoded format + */ +extern uint32_t (*_lv_txt_encoded_conv_wc)(uint32_t c); + +/** + * Decode the next encoded character from a string. + * @param txt pointer to '\0' terminated string + * @param i start index in 'txt' where to start. + * After the call it will point to the next encoded char in 'txt'. + * NULL to use txt[0] as index + * @return the decoded Unicode character or 0 on invalid data code + */ +extern uint32_t (*_lv_txt_encoded_next)(const char *, uint32_t *); + +/** + * Get the previous encoded character form a string. + * @param txt pointer to '\0' terminated string + * @param i_start index in 'txt' where to start. After the call it will point to the previous + * encoded char in 'txt'. + * @return the decoded Unicode character or 0 on invalid data + */ +extern uint32_t (*_lv_txt_encoded_prev)(const char *, uint32_t *); + +/** + * Convert a letter index (in the encoded text) to byte index. + * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param enc_id letter index + * @return byte index of the 'enc_id'th letter + */ +extern uint32_t (*_lv_txt_encoded_get_byte_id)(const char *, uint32_t); + +/** + * Convert a byte index (in an encoded text) to character index. + * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param byte_id byte index + * @return character index of the letter at 'byte_id'th position + */ +extern uint32_t (*_lv_txt_encoded_get_char_id)(const char *, uint32_t); + +/** + * Get the number of characters (and NOT bytes) in a string. + * E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes) + * @param txt a '\0' terminated char string + * @return number of characters + */ +extern uint32_t (*_lv_txt_get_encoded_length)(const char *); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TXT_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_txt_ap.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_txt_ap.h new file mode 100644 index 00000000..3519bb60 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_txt_ap.h @@ -0,0 +1,49 @@ +/** + * @file lv_txt_ap.h + * + */ + +#ifndef LV_TXT_AP_H +#define LV_TXT_AP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_txt.h" +#include "liblvgl/draw/lv_draw.h" + +#if LV_USE_ARABIC_PERSIAN_CHARS == 1 + +/********************* + * DEFINES + *********************/ + +#define LV_UNDEF_ARABIC_PERSIAN_CHARS (UINT32_MAX) +#define LV_AP_ALPHABET_BASE_CODE 0x0622 +#define LV_AP_END_CHARS_LIST {0,0,0,0,0,{0,0}} +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +uint32_t _lv_txt_ap_calc_bytes_cnt(const char * txt); +void _lv_txt_ap_proc(const char * txt, char * txt_out); + +/********************** + * MACROS + **********************/ + +#endif // LV_USE_ARABIC_PERSIAN_CHARS + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TXT_AP_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_types.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_types.h new file mode 100644 index 00000000..84aee103 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_types.h @@ -0,0 +1,94 @@ +/** + * @file lv_types.h + * + */ + +#ifndef LV_TYPES_H +#define LV_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include + +/********************* + * DEFINES + *********************/ + +// If __UINTPTR_MAX__ or UINTPTR_MAX are available, use them to determine arch size +#if defined(__UINTPTR_MAX__) && __UINTPTR_MAX__ > 0xFFFFFFFF +#define LV_ARCH_64 + +#elif defined(UINTPTR_MAX) && UINTPTR_MAX > 0xFFFFFFFF +#define LV_ARCH_64 + +// Otherwise use compiler-dependent means to determine arch size +#elif defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) || defined (__aarch64__) +#define LV_ARCH_64 + +#endif + +/********************** + * TYPEDEFS + **********************/ + +/** + * LVGL error codes. + */ +enum { + LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action + function or an operation was failed*/ + LV_RES_OK, /*The object is valid (no deleted) after the action*/ +}; +typedef uint8_t lv_res_t; + +#if defined(__cplusplus) || __STDC_VERSION__ >= 199901L +// If c99 or newer, use the definition of uintptr_t directly from +typedef uintptr_t lv_uintptr_t; + +#else + +// Otherwise, use the arch size determination +#ifdef LV_ARCH_64 +typedef uint64_t lv_uintptr_t; +#else +typedef uint32_t lv_uintptr_t; +#endif + +#endif + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#define LV_UNUSED(x) ((void)x) + +#define _LV_CONCAT(x, y) x ## y +#define LV_CONCAT(x, y) _LV_CONCAT(x, y) + +#define _LV_CONCAT3(x, y, z) x ## y ## z +#define LV_CONCAT3(x, y, z) _LV_CONCAT3(x, y, z) + +#if defined(PYCPARSER) || defined(__CC_ARM) +#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) +#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __GNUC__ > 4) +#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__((format(gnu_printf, fmtstr, vararg))) +#elif (defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)) +#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__((format(printf, fmtstr, vararg))) +#else +#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TYPES_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/misc/lv_utils.h b/EZ-Template-Example-Project/include/liblvgl/misc/lv_utils.h new file mode 100644 index 00000000..84d2bb95 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/misc/lv_utils.h @@ -0,0 +1,58 @@ +/** + * @file lv_utils.h + * + */ + +#ifndef LV_UTILS_H +#define LV_UTILS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** Searches base[0] to base[n - 1] for an item that matches *key. + * + * @note The function cmp must return negative if it's first + * argument (the search key) is less that it's second (a table entry), + * zero if equal, and positive if greater. + * + * @note Items in the array must be in ascending order. + * + * @param key Pointer to item being searched for + * @param base Pointer to first element to search + * @param n Number of elements + * @param size Size of each element + * @param cmp Pointer to comparison function (see #unicode_list_compare as a comparison function + * example) + * + * @return a pointer to a matching item, or NULL if none exists. + */ +void * _lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size, + int32_t (*cmp)(const void * pRef, const void * pElement)); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_arc.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_arc.h new file mode 100644 index 00000000..96f4629b --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_arc.h @@ -0,0 +1,256 @@ +/** + * @file lv_arc.h + * + */ + +#ifndef LV_ARC_H +#define LV_ARC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_ARC != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_ARC_MODE_NORMAL, + LV_ARC_MODE_SYMMETRICAL, + LV_ARC_MODE_REVERSE +}; +typedef uint8_t lv_arc_mode_t; + +typedef struct { + lv_obj_t obj; + uint16_t rotation; + uint16_t indic_angle_start; + uint16_t indic_angle_end; + uint16_t bg_angle_start; + uint16_t bg_angle_end; + int16_t value; /*Current value of the arc*/ + int16_t min_value; /*Minimum value of the arc*/ + int16_t max_value; /*Maximum value of the arc*/ + uint16_t dragging : 1; + uint16_t type : 2; + uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/ + uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/ + uint32_t last_tick; /*Last dragging event timestamp of the arc*/ + int16_t last_angle; /*Last dragging angle of the arc*/ +} lv_arc_t; + +extern const lv_obj_class_t lv_arc_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_arc_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_ARC_DRAW_PART_BACKGROUND, /**< The background arc*/ + LV_ARC_DRAW_PART_FOREGROUND, /**< The foreground arc*/ + LV_ARC_DRAW_PART_KNOB, /**< The knob*/ +} lv_arc_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an arc object + * @param parent pointer to an object, it will be the parent of the new arc + * @return pointer to the created arc + */ +lv_obj_t * lv_arc_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. + * @param obj pointer to an arc object + * @param start the start angle + */ +void lv_arc_set_start_angle(lv_obj_t * obj, uint16_t start); + +/** + * Set the end angle of an arc. 0 deg: right, 90 bottom, etc. + * @param obj pointer to an arc object + * @param end the end angle + */ +void lv_arc_set_end_angle(lv_obj_t * obj, uint16_t end); + +/** + * Set the start and end angles + * @param obj pointer to an arc object + * @param start the start angle + * @param end the end angle + */ +void lv_arc_set_angles(lv_obj_t * obj, uint16_t start, uint16_t end); + +/** + * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc. + * @param obj pointer to an arc object + * @param start the start angle + */ +void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint16_t start); + +/** + * Set the start angle of an arc background. 0 deg: right, 90 bottom etc. + * @param obj pointer to an arc object + * @param end the end angle + */ +void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint16_t end); + +/** + * Set the start and end angles of the arc background + * @param obj pointer to an arc object + * @param start the start angle + * @param end the end angle + */ +void lv_arc_set_bg_angles(lv_obj_t * obj, uint16_t start, uint16_t end); + +/** + * Set the rotation for the whole arc + * @param obj pointer to an arc object + * @param rotation rotation angle + */ +void lv_arc_set_rotation(lv_obj_t * obj, uint16_t rotation); + +/** + * Set the type of arc. + * @param obj pointer to arc object + * @param mode arc's mode + */ +void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type); + +/** + * Set a new value on the arc + * @param obj pointer to an arc object + * @param value new value + */ +void lv_arc_set_value(lv_obj_t * obj, int16_t value); + +/** + * Set minimum and the maximum values of an arc + * @param obj pointer to the arc object + * @param min minimum value + * @param max maximum value + */ +void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max); + +/** + * Set a change rate to limit the speed how fast the arc should reach the pressed point. + * @param obj pointer to an arc object + * @param rate the change rate + */ +void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the start angle of an arc. + * @param obj pointer to an arc object + * @return the start angle [0..360] + */ +uint16_t lv_arc_get_angle_start(lv_obj_t * obj); + +/** + * Get the end angle of an arc. + * @param obj pointer to an arc object + * @return the end angle [0..360] + */ +uint16_t lv_arc_get_angle_end(lv_obj_t * obj); + +/** + * Get the start angle of an arc background. + * @param obj pointer to an arc object + * @return the start angle [0..360] + */ +uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj); + +/** + * Get the end angle of an arc background. + * @param obj pointer to an arc object + * @return the end angle [0..360] + */ +uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj); + +/** + * Get the value of an arc + * @param obj pointer to an arc object + * @return the value of the arc + */ +int16_t lv_arc_get_value(const lv_obj_t * obj); + +/** + * Get the minimum value of an arc + * @param obj pointer to an arc object + * @return the minimum value of the arc + */ +int16_t lv_arc_get_min_value(const lv_obj_t * obj); + +/** + * Get the maximum value of an arc + * @param obj pointer to an arc object + * @return the maximum value of the arc + */ +int16_t lv_arc_get_max_value(const lv_obj_t * obj); + +/** + * Get whether the arc is type or not. + * @param obj pointer to an arc object + * @return arc's mode + */ +lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Align an object to the current position of the arc (knob) + * @param obj pointer to an arc object + * @param obj_to_align pointer to an object to align + * @param r_offset consider the radius larger with this value (< 0: for smaller radius) + */ +void lv_arc_align_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_align, lv_coord_t r_offset); + +/** + * Rotate an object to the current position of the arc (knob) + * @param obj pointer to an arc object + * @param obj_to_align pointer to an object to rotate + * @param r_offset consider the radius larger with this value (< 0: for smaller radius) + */ +void lv_arc_rotate_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_rotate, lv_coord_t r_offset); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_ARC*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ARC_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_bar.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_bar.h new file mode 100644 index 00000000..55d17119 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_bar.h @@ -0,0 +1,164 @@ +/** + * @file lv_bar.h + * + */ + +#ifndef LV_BAR_H +#define LV_BAR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_BAR != 0 + +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/misc/lv_anim.h" +#include "lv_btn.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_BAR_MODE_NORMAL, + LV_BAR_MODE_SYMMETRICAL, + LV_BAR_MODE_RANGE +}; +typedef uint8_t lv_bar_mode_t; + +typedef struct { + lv_obj_t * bar; + int32_t anim_start; + int32_t anim_end; + int32_t anim_state; +} _lv_bar_anim_t; + +typedef struct { + lv_obj_t obj; + int32_t cur_value; /**< Current value of the bar*/ + int32_t min_value; /**< Minimum value of the bar*/ + int32_t max_value; /**< Maximum value of the bar*/ + int32_t start_value; /**< Start value of the bar*/ + lv_area_t indic_area; /**< Save the indicator area. Might be used by derived types*/ + _lv_bar_anim_t cur_value_anim; + _lv_bar_anim_t start_value_anim; + lv_bar_mode_t mode : 2; /**< Type of bar*/ +} lv_bar_t; + +extern const lv_obj_class_t lv_bar_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_bar_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_BAR_DRAW_PART_INDICATOR, /**< The indicator*/ +} lv_bar_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a bar object + * @param parent pointer to an object, it will be the parent of the new bar + * @return pointer to the created bar + */ +lv_obj_t * lv_bar_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the bar + * @param bar pointer to a bar object + * @param value new value + * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately + */ +void lv_bar_set_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim); + +/** + * Set a new start value on the bar + * @param obj pointer to a bar object + * @param value new start value + * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately + */ +void lv_bar_set_start_value(lv_obj_t * obj, int32_t start_value, lv_anim_enable_t anim); + +/** + * Set minimum and the maximum values of a bar + * @param obj pointer to the bar object + * @param min minimum value + * @param max maximum value + */ +void lv_bar_set_range(lv_obj_t * obj, int32_t min, int32_t max); + +/** + * Set the type of bar. + * @param obj pointer to bar object + * @param mode bar type from ::lv_bar_mode_t + */ +void lv_bar_set_mode(lv_obj_t * obj, lv_bar_mode_t mode); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a bar + * @param obj pointer to a bar object + * @return the value of the bar + */ +int32_t lv_bar_get_value(const lv_obj_t * obj); + +/** + * Get the start value of a bar + * @param obj pointer to a bar object + * @return the start value of the bar + */ +int32_t lv_bar_get_start_value(const lv_obj_t * obj); + +/** + * Get the minimum value of a bar + * @param obj pointer to a bar object + * @return the minimum value of the bar + */ +int32_t lv_bar_get_min_value(const lv_obj_t * obj); + +/** + * Get the maximum value of a bar + * @param obj pointer to a bar object + * @return the maximum value of the bar + */ +int32_t lv_bar_get_max_value(const lv_obj_t * obj); + +/** + * Get the type of bar. + * @param obj pointer to bar object + * @return bar type from ::lv_bar_mode_t + */ +lv_bar_mode_t lv_bar_get_mode(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_BAR*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_BAR_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_btn.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_btn.h new file mode 100644 index 00000000..893e6a05 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_btn.h @@ -0,0 +1,56 @@ +/** + * @file lv_btn.h + * + */ + +#ifndef LV_BTN_H +#define LV_BTN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_BTN != 0 +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; +} lv_btn_t; + +extern const lv_obj_class_t lv_btn_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a button object + * @param parent pointer to an object, it will be the parent of the new button + * @return pointer to the created button + */ +lv_obj_t * lv_btn_create(lv_obj_t * parent); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_BTN*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_BTN_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_btnmatrix.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_btnmatrix.h new file mode 100644 index 00000000..31d62bb3 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_btnmatrix.h @@ -0,0 +1,225 @@ +/** + * @file lv_btnmatrix.h + * + */ + +#ifndef LV_BTNMATRIX_H +#define LV_BTNMATRIX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_BTNMATRIX != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ +#define LV_BTNMATRIX_BTN_NONE 0xFFFF +LV_EXPORT_CONST_INT(LV_BTNMATRIX_BTN_NONE); + +/********************** + * TYPEDEFS + **********************/ + +/** Type to store button control bits (disabled, hidden etc.) + * The first 3 bits are used to store the width*/ +enum { + _LV_BTNMATRIX_WIDTH = 0x0007, /**< Reserved to stire the size units*/ + LV_BTNMATRIX_CTRL_HIDDEN = 0x0008, /**< Button hidden*/ + LV_BTNMATRIX_CTRL_NO_REPEAT = 0x0010, /**< Do not repeat press this button.*/ + LV_BTNMATRIX_CTRL_DISABLED = 0x0020, /**< Disable this button.*/ + LV_BTNMATRIX_CTRL_CHECKABLE = 0x0040, /**< The button can be toggled.*/ + LV_BTNMATRIX_CTRL_CHECKED = 0x0080, /**< Button is currently toggled (e.g. checked).*/ + LV_BTNMATRIX_CTRL_CLICK_TRIG = 0x0100, /**< 1: Send LV_EVENT_VALUE_CHANGE on CLICK, 0: Send LV_EVENT_VALUE_CHANGE on PRESS*/ + LV_BTNMATRIX_CTRL_POPOVER = 0x0200, /**< Show a popover when pressing this key*/ + LV_BTNMATRIX_CTRL_RECOLOR = 0x1000, /**< Enable text recoloring with `#color`*/ + _LV_BTNMATRIX_CTRL_RESERVED = 0x2000, /**< Reserved for later use*/ + LV_BTNMATRIX_CTRL_CUSTOM_1 = 0x4000, /**< Custom free to use flag*/ + LV_BTNMATRIX_CTRL_CUSTOM_2 = 0x8000, /**< Custom free to use flag*/ +}; + +typedef uint16_t lv_btnmatrix_ctrl_t; + +typedef bool (*lv_btnmatrix_btn_draw_cb_t)(lv_obj_t * btnm, uint32_t btn_id, const lv_area_t * draw_area, + const lv_area_t * clip_area); + +/*Data of button matrix*/ +typedef struct { + lv_obj_t obj; + const char ** map_p; /*Pointer to the current map*/ + lv_area_t * button_areas; /*Array of areas of buttons*/ + lv_btnmatrix_ctrl_t * ctrl_bits; /*Array of control bytes*/ + uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/ + uint16_t row_cnt; /*Number of rows in 'map_p'(Handled by the library)*/ + uint16_t btn_id_sel; /*Index of the active button (being pressed/released etc) or LV_BTNMATRIX_BTN_NONE*/ + uint8_t one_check : 1; /*Single button toggled at once*/ +} lv_btnmatrix_t; + +extern const lv_obj_class_t lv_btnmatrix_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_btnmatrix_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_BTNMATRIX_DRAW_PART_BTN, /**< The rectangle and label of buttons*/ +} lv_btnmatrix_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a button matrix object + * @param parent pointer to an object, it will be the parent of the new button matrix + * @return pointer to the created button matrix + */ +lv_obj_t * lv_btnmatrix_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new map. Buttons will be created/deleted according to the map. The + * button matrix keeps a reference to the map and so the string array must not + * be deallocated during the life of the matrix. + * @param obj pointer to a button matrix object + * @param map pointer a string array. The last string has to be: "". Use "\n" to make a line break. + */ +void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[]); + +/** + * Set the button control map (hidden, disabled etc.) for a button matrix. + * The control map array will be copied and so may be deallocated after this + * function returns. + * @param obj pointer to a button matrix object + * @param ctrl_map pointer to an array of `lv_btn_ctrl_t` control bytes. The + * length of the array and position of the elements must match + * the number and order of the individual buttons (i.e. excludes + * newline entries). + * An element of the map should look like e.g.: + * `ctrl_map[0] = width | LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_TGL_ENABLE` + */ +void lv_btnmatrix_set_ctrl_map(lv_obj_t * obj, const lv_btnmatrix_ctrl_t ctrl_map[]); + +/** + * Set the selected buttons + * @param obj pointer to button matrix object + * @param btn_id 0 based index of the button to modify. (Not counting new lines) + */ +void lv_btnmatrix_set_selected_btn(lv_obj_t * obj, uint16_t btn_id); + +/** + * Set the attributes of a button of the button matrix + * @param obj pointer to button matrix object + * @param btn_id 0 based index of the button to modify. (Not counting new lines) + * @param ctrl OR-ed attributs. E.g. `LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CHECKABLE` + */ +void lv_btnmatrix_set_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl); + +/** + * Clear the attributes of a button of the button matrix + * @param obj pointer to button matrix object + * @param btn_id 0 based index of the button to modify. (Not counting new lines) + * @param ctrl OR-ed attributs. E.g. `LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CHECKABLE` + */ +void lv_btnmatrix_clear_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl); + +/** + * Set attributes of all buttons of a button matrix + * @param obj pointer to a button matrix object + * @param ctrl attribute(s) to set from `lv_btnmatrix_ctrl_t`. Values can be ORed. + */ +void lv_btnmatrix_set_btn_ctrl_all(lv_obj_t * obj, lv_btnmatrix_ctrl_t ctrl); + +/** + * Clear the attributes of all buttons of a button matrix + * @param obj pointer to a button matrix object + * @param ctrl attribute(s) to set from `lv_btnmatrix_ctrl_t`. Values can be ORed. + * @param en true: set the attributes; false: clear the attributes + */ +void lv_btnmatrix_clear_btn_ctrl_all(lv_obj_t * obj, lv_btnmatrix_ctrl_t ctrl); + +/** + * Set a single button's relative width. + * This method will cause the matrix be regenerated and is a relatively + * expensive operation. It is recommended that initial width be specified using + * `lv_btnmatrix_set_ctrl_map` and this method only be used for dynamic changes. + * @param obj pointer to button matrix object + * @param btn_id 0 based index of the button to modify. + * @param width relative width compared to the buttons in the same row. [1..7] + */ +void lv_btnmatrix_set_btn_width(lv_obj_t * obj, uint16_t btn_id, uint8_t width); + +/** + * Make the button matrix like a selector widget (only one button may be checked at a time). + * `LV_BTNMATRIX_CTRL_CHECKABLE` must be enabled on the buttons to be selected using + * `lv_btnmatrix_set_ctrl()` or `lv_btnmatrix_set_btn_ctrl_all()`. + * @param obj pointer to a button matrix object + * @param en whether "one check" mode is enabled + */ +void lv_btnmatrix_set_one_checked(lv_obj_t * obj, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current map of a button matrix + * @param obj pointer to a button matrix object + * @return the current map + */ +const char ** lv_btnmatrix_get_map(const lv_obj_t * obj); + +/** + * Get the index of the lastly "activated" button by the user (pressed, released, focused etc) + * Useful in the `event_cb` to get the text of the button, check if hidden etc. + * @param obj pointer to button matrix object + * @return index of the last released button (LV_BTNMATRIX_BTN_NONE: if unset) + */ +uint16_t lv_btnmatrix_get_selected_btn(const lv_obj_t * obj); + +/** + * Get the button's text + * @param obj pointer to button matrix object + * @param btn_id the index a button not counting new line characters. + * @return text of btn_index` button + */ +const char * lv_btnmatrix_get_btn_text(const lv_obj_t * obj, uint16_t btn_id); + +/** + * Get the whether a control value is enabled or disabled for button of a button matrix + * @param obj pointer to a button matrix object + * @param btn_id the index of a button not counting new line characters. + * @param ctrl control values to check (ORed value can be used) + * @return true: the control attribute is enabled false: disabled + */ +bool lv_btnmatrix_has_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl); + +/** + * Tell whether "one check" mode is enabled or not. + * @param obj Button matrix object + * @return true: "one check" mode is enabled; false: disabled + */ +bool lv_btnmatrix_get_one_checked(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_BTNMATRIX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_BTNMATRIX_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_canvas.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_canvas.h new file mode 100644 index 00000000..f92a1c5c --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_canvas.h @@ -0,0 +1,280 @@ +/** + * @file lv_canvas.h + * + */ + +#ifndef LV_CANVAS_H +#define LV_CANVAS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_CANVAS != 0 + +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/widgets/lv_img.h" +#include "liblvgl/draw/lv_draw_img.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +extern const lv_obj_class_t lv_canvas_class; + +/*Data of canvas*/ +typedef struct { + lv_img_t img; + lv_img_dsc_t dsc; +} lv_canvas_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a canvas object + * @param parent pointer to an object, it will be the parent of the new canvas + * @return pointer to the created canvas + */ +lv_obj_t * lv_canvas_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a buffer for the canvas. + * @param buf a buffer where the content of the canvas will be. + * The required size is (lv_img_color_format_get_px_size(cf) * w) / 8 * h) + * It can be allocated with `lv_mem_alloc()` or + * it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or + * it can be an address in RAM or external SRAM + * @param canvas pointer to a canvas object + * @param w width of the canvas + * @param h height of the canvas + * @param cf color format. `LV_IMG_CF_...` + */ +void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); + +/** + * Set the color of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param c color of the pixel + */ +void lv_canvas_set_px_color(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c); + +/** + * DEPRECATED: added only for backward compatibility + */ +static inline void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c) +{ + lv_canvas_set_px_color(canvas, x, y, c); +} + +/** + * Set the opacity of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param opa opacity of the pixel (0..255) + */ +void lv_canvas_set_px_opa(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_opa_t opa); + + +/** + * Set the palette color of a canvas with index format. Valid only for `LV_IMG_CF_INDEXED1/2/4/8` + * @param canvas pointer to canvas object + * @param id the palette color to set: + * - for `LV_IMG_CF_INDEXED1`: 0..1 + * - for `LV_IMG_CF_INDEXED2`: 0..3 + * - for `LV_IMG_CF_INDEXED4`: 0..15 + * - for `LV_IMG_CF_INDEXED8`: 0..255 + * @param c the color to set + */ +void lv_canvas_set_palette(lv_obj_t * canvas, uint8_t id, lv_color_t c); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the color of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @return color of the point + */ +lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y); + +/** + * Get the image of the canvas as a pointer to an `lv_img_dsc_t` variable. + * @param canvas pointer to a canvas object + * @return pointer to the image descriptor. + */ +lv_img_dsc_t * lv_canvas_get_img(lv_obj_t * canvas); + +/*===================== + * Other functions + *====================*/ + +/** + * Copy a buffer to the canvas + * @param canvas pointer to a canvas object + * @param to_copy buffer to copy. The color format has to match with the canvas's buffer color + * format + * @param x left side of the destination position + * @param y top side of the destination position + * @param w width of the buffer to copy + * @param h height of the buffer to copy + */ +void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, lv_coord_t y, lv_coord_t w, + lv_coord_t h); + +/** + * Transform and image and store the result on a canvas. + * @param canvas pointer to a canvas object to store the result of the transformation. + * @param img pointer to an image descriptor to transform. + * Can be the image descriptor of an other canvas too (`lv_canvas_get_img()`). + * @param angle the angle of rotation (0..3600), 0.1 deg resolution + * @param zoom zoom factor (256 no zoom); + * @param offset_x offset X to tell where to put the result data on destination canvas + * @param offset_y offset X to tell where to put the result data on destination canvas + * @param pivot_x pivot X of rotation. Relative to the source canvas + * Set to `source width / 2` to rotate around the center + * @param pivot_y pivot Y of rotation. Relative to the source canvas + * Set to `source height / 2` to rotate around the center + * @param antialias apply anti-aliasing during the transformation. Looks better but slower. + */ +void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x, + lv_coord_t offset_y, + int32_t pivot_x, int32_t pivot_y, bool antialias); + +/** + * Apply horizontal blur on the canvas + * @param canvas pointer to a canvas object + * @param area the area to blur. If `NULL` the whole canvas will be blurred. + * @param r radius of the blur + */ +void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r); + +/** + * Apply vertical blur on the canvas + * @param canvas pointer to a canvas object + * @param area the area to blur. If `NULL` the whole canvas will be blurred. + * @param r radius of the blur + */ +void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r); + +/** + * Fill the canvas with color + * @param canvas pointer to a canvas + * @param color the background color + * @param opa the desired opacity + */ +void lv_canvas_fill_bg(lv_obj_t * canvas, lv_color_t color, lv_opa_t opa); + +/** + * Draw a rectangle on the canvas + * @param canvas pointer to a canvas object + * @param x left coordinate of the rectangle + * @param y top coordinate of the rectangle + * @param w width of the rectangle + * @param h height of the rectangle + * @param draw_dsc descriptor of the rectangle + */ +void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, + const lv_draw_rect_dsc_t * draw_dsc); + +/** + * Draw a text on the canvas. + * @param canvas pointer to a canvas object + * @param x left coordinate of the text + * @param y top coordinate of the text + * @param max_w max width of the text. The text will be wrapped to fit into this size + * @param draw_dsc pointer to a valid label descriptor `lv_draw_label_dsc_t` + * @param txt text to display + */ +void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, + lv_draw_label_dsc_t * draw_dsc, const char * txt); + +/** + * Draw an image on the canvas + * @param canvas pointer to a canvas object + * @param x left coordinate of the image + * @param y top coordinate of the image + * @param src image source. Can be a pointer an `lv_img_dsc_t` variable or a path an image. + * @param draw_dsc pointer to a valid label descriptor `lv_draw_img_dsc_t` + */ +void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, + const lv_draw_img_dsc_t * draw_dsc); + +/** + * Draw a line on the canvas + * @param canvas pointer to a canvas object + * @param points point of the line + * @param point_cnt number of points + * @param draw_dsc pointer to an initialized `lv_draw_line_dsc_t` variable + */ +void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t points[], uint32_t point_cnt, + const lv_draw_line_dsc_t * draw_dsc); + +/** + * Draw a polygon on the canvas + * @param canvas pointer to a canvas object + * @param points point of the polygon + * @param point_cnt number of points + * @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable + */ +void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t points[], uint32_t point_cnt, + const lv_draw_rect_dsc_t * draw_dsc); + +/** + * Draw an arc on the canvas + * @param canvas pointer to a canvas object + * @param x origo x of the arc + * @param y origo y of the arc + * @param r radius of the arc + * @param start_angle start angle in degrees + * @param end_angle end angle in degrees + * @param draw_dsc pointer to an initialized `lv_draw_line_dsc_t` variable + */ +void lv_canvas_draw_arc(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t r, int32_t start_angle, + int32_t end_angle, const lv_draw_arc_dsc_t * draw_dsc); + +/********************** + * MACROS + **********************/ +#define LV_CANVAS_BUF_SIZE_TRUE_COLOR(w, h) LV_IMG_BUF_SIZE_TRUE_COLOR(w, h) +#define LV_CANVAS_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h) LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h) +#define LV_CANVAS_BUF_SIZE_TRUE_COLOR_ALPHA(w, h) LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h) + +/*+ 1: to be sure no fractional row*/ +#define LV_CANVAS_BUF_SIZE_ALPHA_1BIT(w, h) LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) +#define LV_CANVAS_BUF_SIZE_ALPHA_2BIT(w, h) LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h) +#define LV_CANVAS_BUF_SIZE_ALPHA_4BIT(w, h) LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h) +#define LV_CANVAS_BUF_SIZE_ALPHA_8BIT(w, h) LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h) + +/*4 * X: for palette*/ +#define LV_CANVAS_BUF_SIZE_INDEXED_1BIT(w, h) LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h) +#define LV_CANVAS_BUF_SIZE_INDEXED_2BIT(w, h) LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h) +#define LV_CANVAS_BUF_SIZE_INDEXED_4BIT(w, h) LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h) +#define LV_CANVAS_BUF_SIZE_INDEXED_8BIT(w, h) LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h) + +#endif /*LV_USE_CANVAS*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CANVAS_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_checkbox.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_checkbox.h new file mode 100644 index 00000000..6b2bdc39 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_checkbox.h @@ -0,0 +1,97 @@ +/** + * @file lv_cb.h + * + */ + +#ifndef LV_CHECKBOX_H +#define LV_CHECKBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_CHECKBOX != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + char * txt; + uint32_t static_txt : 1; +} lv_checkbox_t; + +extern const lv_obj_class_t lv_checkbox_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_checkbox_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_CHECKBOX_DRAW_PART_BOX, /**< The tick box*/ +} lv_checkbox_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a check box object + * @param parent pointer to an object, it will be the parent of the new button + * @return pointer to the created check box + */ +lv_obj_t * lv_checkbox_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of a check box. `txt` will be copied and may be deallocated + * after this function returns. + * @param cb pointer to a check box + * @param txt the text of the check box. NULL to refresh with the current text. + */ +void lv_checkbox_set_text(lv_obj_t * obj, const char * txt); + +/** + * Set the text of a check box. `txt` must not be deallocated during the life + * of this checkbox. + * @param cb pointer to a check box + * @param txt the text of the check box. + */ +void lv_checkbox_set_text_static(lv_obj_t * obj, const char * txt); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a check box + * @param cb pointer to check box object + * @return pointer to the text of the check box + */ +const char * lv_checkbox_get_text(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CHECKBOX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CHECKBOX_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_dropdown.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_dropdown.h new file mode 100644 index 00000000..9848b145 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_dropdown.h @@ -0,0 +1,254 @@ +/** + * @file lv_dropdown.h + * + */ + +#ifndef LV_DROPDOWN_H +#define LV_DROPDOWN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_DROPDOWN != 0 + +/*Testing of dependencies*/ + +#if LV_USE_LABEL == 0 +#error "lv_dropdown: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)" +#endif + +#include "../widgets/lv_label.h" + +/********************* + * DEFINES + *********************/ +#define LV_DROPDOWN_POS_LAST 0xFFFF +LV_EXPORT_CONST_INT(LV_DROPDOWN_POS_LAST); + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + lv_obj_t * list; /**< The dropped down list*/ + const char * text; /**< Text to display on the dropdown's button*/ + const void * symbol; /**< Arrow or other icon when the drop-down list is closed*/ + char * options; /**< Options in a '\n' separated list*/ + uint16_t option_cnt; /**< Number of options*/ + uint16_t sel_opt_id; /**< Index of the currently selected option*/ + uint16_t sel_opt_id_orig; /**< Store the original index on focus*/ + uint16_t pr_opt_id; /**< Index of the currently pressed option*/ + lv_dir_t dir : 4; /**< Direction in which the list should open*/ + uint8_t static_txt : 1; /**< 1: Only a pointer is saved in `options`*/ + uint8_t selected_highlight: 1; /**< 1: Make the selected option highlighted in the list*/ +} lv_dropdown_t; + +typedef struct { + lv_obj_t obj; + lv_obj_t * dropdown; +} lv_dropdown_list_t; + +extern const lv_obj_class_t lv_dropdown_class; +extern const lv_obj_class_t lv_dropdownlist_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a drop-down list object + * @param parent pointer to an object, it will be the parent of the new drop-down list + * @return pointer to the created drop-down list + */ +lv_obj_t * lv_dropdown_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set text of the drop-down list's button. + * If set to `NULL` the selected option's text will be displayed on the button. + * If set to a specific text then that text will be shown regardless of the selected option. + * @param obj pointer to a drop-down list object + * @param txt the text as a string (Only its pointer is saved) + */ +void lv_dropdown_set_text(lv_obj_t * obj, const char * txt); + +/** + * Set the options in a drop-down list from a string. + * The options will be copied and saved in the object so the `options` can be destroyed after calling this function + * @param obj pointer to drop-down list object + * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" + */ +void lv_dropdown_set_options(lv_obj_t * obj, const char * options); + +/** + * Set the options in a drop-down list from a static string (global, static or dynamically allocated). + * Only the pointer of the option string will be saved. + * @param obj pointer to drop-down list object + * @param options a static string with '\n' separated options. E.g. "One\nTwo\nThree" + */ +void lv_dropdown_set_options_static(lv_obj_t * obj, const char * options); + +/** + * Add an options to a drop-down list from a string. Only works for non-static options. + * @param obj pointer to drop-down list object + * @param option a string without '\n'. E.g. "Four" + * @param pos the insert position, indexed from 0, LV_DROPDOWN_POS_LAST = end of string + */ +void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos); + +/** + * Clear all options in a drop-down list. Works with both static and dynamic options. + * @param obj pointer to drop-down list object + */ +void lv_dropdown_clear_options(lv_obj_t * obj); + +/** + * Set the selected option + * @param obj pointer to drop-down list object + * @param sel_opt id of the selected option (0 ... number of option - 1); + */ +void lv_dropdown_set_selected(lv_obj_t * obj, uint16_t sel_opt); + +/** + * Set the direction of the a drop-down list + * @param obj pointer to a drop-down list object + * @param dir LV_DIR_LEFT/RIGHT/TOP/BOTTOM + */ +void lv_dropdown_set_dir(lv_obj_t * obj, lv_dir_t dir); + +/** + * Set an arrow or other symbol to display when on drop-down list's button. Typically a down caret or arrow. + * @param obj pointer to drop-down list object + * @param symbol a text like `LV_SYMBOL_DOWN`, an image (pointer or path) or NULL to not draw symbol icon + * @note angle and zoom transformation can be applied if the symbol is an image. + * E.g. when drop down is checked (opened) rotate the symbol by 180 degree + */ +void lv_dropdown_set_symbol(lv_obj_t * obj, const void * symbol); + +/** + * Set whether the selected option in the list should be highlighted or not + * @param obj pointer to drop-down list object + * @param en true: highlight enabled; false: disabled + */ +void lv_dropdown_set_selected_highlight(lv_obj_t * obj, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the list of a drop-down to allow styling or other modifications + * @param obj pointer to a drop-down list object + * @return pointer to the list of the drop-down + */ +lv_obj_t * lv_dropdown_get_list(lv_obj_t * obj); + +/** + * Get text of the drop-down list's button. + * @param obj pointer to a drop-down list object + * @return the text as string, `NULL` if no text + */ +const char * lv_dropdown_get_text(lv_obj_t * obj); + +/** + * Get the options of a drop-down list + * @param obj pointer to drop-down list object + * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") + */ +const char * lv_dropdown_get_options(const lv_obj_t * obj); + +/** + * Get the index of the selected option + * @param obj pointer to drop-down list object + * @return index of the selected option (0 ... number of option - 1); + */ +uint16_t lv_dropdown_get_selected(const lv_obj_t * obj); + +/** + * Get the total number of options + * @param obj pointer to drop-down list object + * @return the total number of options in the list + */ +uint16_t lv_dropdown_get_option_cnt(const lv_obj_t * obj); + +/** + * Get the current selected option as a string + * @param obj pointer to drop-down object + * @param buf pointer to an array to store the string + * @param buf_size size of `buf` in bytes. 0: to ignore it. + */ +void lv_dropdown_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size); + +/** + * Get the index of an option. + * @param obj pointer to drop-down object + * @param option an option as string + * @return index of `option` in the list of all options. -1 if not found. + */ +int32_t lv_dropdown_get_option_index(lv_obj_t * obj, const char * option); + +/** + * Get the symbol on the drop-down list. Typically a down caret or arrow. + * @param obj pointer to drop-down list object + * @return the symbol or NULL if not enabled + */ +const char * lv_dropdown_get_symbol(lv_obj_t * obj); + +/** + * Get whether the selected option in the list should be highlighted or not + * @param obj pointer to drop-down list object + * @return true: highlight enabled; false: disabled + */ +bool lv_dropdown_get_selected_highlight(lv_obj_t * obj); + +/** + * Get the direction of the drop-down list + * @param obj pointer to a drop-down list object + * @return LV_DIR_LEF/RIGHT/TOP/BOTTOM + */ +lv_dir_t lv_dropdown_get_dir(const lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Open the drop.down list + * @param obj pointer to drop-down list object + */ +void lv_dropdown_open(lv_obj_t * dropdown_obj); + +/** + * Close (Collapse) the drop-down list + * @param obj pointer to drop-down list object + */ +void lv_dropdown_close(lv_obj_t * obj); + +/** + * Tells whether the list is opened or not + * @param obj pointer to a drop-down list object + * @return true if the list os opened + */ +bool lv_dropdown_is_open(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_DROPDOWN*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DROPDOWN_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_img.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_img.h new file mode 100644 index 00000000..5513a26c --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_img.h @@ -0,0 +1,234 @@ +/** + * @file lv_img.h + * + */ + +#ifndef LV_IMG_H +#define LV_IMG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_IMG != 0 + +/*Testing of dependencies*/ +#if LV_USE_LABEL == 0 +#error "lv_img: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/misc/lv_fs.h" +#include "liblvgl/draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Data of image + */ +typedef struct { + lv_obj_t obj; + const void * src; /*Image source: Pointer to an array or a file or a symbol*/ + lv_point_t offset; + lv_coord_t w; /*Width of the image (Handled by the library)*/ + lv_coord_t h; /*Height of the image (Handled by the library)*/ + uint16_t angle; /*rotation angle of the image*/ + lv_point_t pivot; /*rotation center of the image*/ + uint16_t zoom; /*256 means no zoom, 512 double size, 128 half size*/ + uint8_t src_type : 2; /*See: lv_img_src_t*/ + uint8_t cf : 5; /*Color format from `lv_img_color_format_t`*/ + uint8_t antialias : 1; /*Apply anti-aliasing in transformations (rotate, zoom)*/ + uint8_t obj_size_mode: 2; /*Image size mode when image size and object size is different.*/ +} lv_img_t; + +extern const lv_obj_class_t lv_img_class; + +/** + * Image size mode, when image size and object size is different + */ +enum { + /** Zoom doesn't affect the coordinates of the object, + * however if zoomed in the image is drawn out of the its coordinates. + * The layout's won't change on zoom */ + LV_IMG_SIZE_MODE_VIRTUAL = 0, + + /** If the object size is set to SIZE_CONTENT, then object size equals zoomed image size. + * It causes layout recalculation. + * If the object size is set explicitly, the image will be cropped when zoomed in.*/ + LV_IMG_SIZE_MODE_REAL, +}; + +typedef uint8_t lv_img_size_mode_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an image object + * @param parent pointer to an object, it will be the parent of the new image + * @return pointer to the created image + */ +lv_obj_t * lv_img_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the image data to display on the object + * @param obj pointer to an image object + * @param src_img 1) pointer to an ::lv_img_dsc_t descriptor (converted by LVGL's image converter) (e.g. &my_img) or + * 2) path to an image file (e.g. "S:/dir/img.bin")or + * 3) a SYMBOL (e.g. LV_SYMBOL_OK) + */ +void lv_img_set_src(lv_obj_t * obj, const void * src); + +/** + * Set an offset for the source of an image so the image will be displayed from the new origin. + * @param obj pointer to an image + * @param x the new offset along x axis. + */ +void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x); + +/** + * Set an offset for the source of an image. + * so the image will be displayed from the new origin. + * @param obj pointer to an image + * @param y the new offset along y axis. + */ +void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y); + + +/** + * Set the rotation angle of the image. + * The image will be rotated around the set pivot set by `lv_img_set_pivot()` + * Note that indexed and alpha only images can't be transformed. + * @param obj pointer to an image object + * @param angle rotation angle in degree with 0.1 degree resolution (0..3600: clock wise) + */ +void lv_img_set_angle(lv_obj_t * obj, int16_t angle); + +/** + * Set the rotation center of the image. + * The image will be rotated around this point. + * @param obj pointer to an image object + * @param x rotation center x of the image + * @param y rotation center y of the image + */ +void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + + +/** + * Set the zoom factor of the image. + * Note that indexed and alpha only images can't be transformed. + * @param img pointer to an image object + * @param zoom the zoom factor. + * @example 256 or LV_ZOOM_IMG_NONE for no zoom + * @example <256: scale down + * @example >256 scale up + * @example 128 half size + * @example 512 double size + */ +void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom); + +/** + * Enable/disable anti-aliasing for the transformations (rotate, zoom) or not. + * The quality is better with anti-aliasing looks better but slower. + * @param obj pointer to an image object + * @param antialias true: anti-aliased; false: not anti-aliased + */ +void lv_img_set_antialias(lv_obj_t * obj, bool antialias); + +/** + * Set the image object size mode. + * + * @param obj pointer to an image object + * @param mode the new size mode. + */ +void lv_img_set_size_mode(lv_obj_t * obj, lv_img_size_mode_t mode); +/*===================== + * Getter functions + *====================*/ + +/** + * Get the source of the image + * @param obj pointer to an image object + * @return the image source (symbol, file name or ::lv-img_dsc_t for C arrays) + */ +const void * lv_img_get_src(lv_obj_t * obj); + +/** + * Get the offset's x attribute of the image object. + * @param img pointer to an image + * @return offset X value. + */ +lv_coord_t lv_img_get_offset_x(lv_obj_t * obj); + +/** + * Get the offset's y attribute of the image object. + * @param obj pointer to an image + * @return offset Y value. + */ +lv_coord_t lv_img_get_offset_y(lv_obj_t * obj); + +/** + * Get the rotation angle of the image. + * @param obj pointer to an image object + * @return rotation angle in 0.1 degrees (0..3600) + */ +uint16_t lv_img_get_angle(lv_obj_t * obj); + +/** + * Get the pivot (rotation center) of the image. + * @param img pointer to an image object + * @param pivot store the rotation center here + */ +void lv_img_get_pivot(lv_obj_t * obj, lv_point_t * pivot); + +/** + * Get the zoom factor of the image. + * @param obj pointer to an image object + * @return zoom factor (256: no zoom) + */ +uint16_t lv_img_get_zoom(lv_obj_t * obj); + +/** + * Get whether the transformations (rotate, zoom) are anti-aliased or not + * @param obj pointer to an image object + * @return true: anti-aliased; false: not anti-aliased + */ +bool lv_img_get_antialias(lv_obj_t * obj); + +/** + * Get the size mode of the image + * @param obj pointer to an image object + * @return element of @ref lv_img_size_mode_t + */ +lv_img_size_mode_t lv_img_get_size_mode(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +/** Use this macro to declare an image in a C file*/ +#define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name; + +#endif /*LV_USE_IMG*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMG_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_label.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_label.h new file mode 100644 index 00000000..39a68db0 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_label.h @@ -0,0 +1,246 @@ +/** + * @file lv_label.h + * + */ + +#ifndef LV_LABEL_H +#define LV_LABEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../lv_conf_internal.h" + +#if LV_USE_LABEL != 0 + +#include +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/font/lv_font.h" +#include "liblvgl/font/lv_symbol_def.h" +#include "liblvgl/misc/lv_txt.h" +#include "liblvgl/draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ +#define LV_LABEL_WAIT_CHAR_COUNT 3 +#define LV_LABEL_DOT_NUM 3 +#define LV_LABEL_POS_LAST 0xFFFF +#define LV_LABEL_TEXT_SELECTION_OFF LV_DRAW_LABEL_NO_TXT_SEL + +LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM); +LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST); +LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SELECTION_OFF); + +/********************** + * TYPEDEFS + **********************/ + +/** Long mode behaviors. Used in 'lv_label_ext_t'*/ +enum { + LV_LABEL_LONG_WRAP, /**< Keep the object width, wrap the too long lines and expand the object height*/ + LV_LABEL_LONG_DOT, /**< Keep the size and write dots at the end if the text is too long*/ + LV_LABEL_LONG_SCROLL, /**< Keep the size and roll the text back and forth*/ + LV_LABEL_LONG_SCROLL_CIRCULAR, /**< Keep the size and roll the text circularly*/ + LV_LABEL_LONG_CLIP, /**< Keep the size and clip the text out of it*/ +}; +typedef uint8_t lv_label_long_mode_t; + +typedef struct { + lv_obj_t obj; + char * text; + union { + char * tmp_ptr; /*Pointer to the allocated memory containing the character replaced by dots*/ + char tmp[LV_LABEL_DOT_NUM + 1]; /*Directly store the characters if <=4 characters*/ + } dot; + uint32_t dot_end; /*The real text length, used in dot mode*/ + +#if LV_LABEL_LONG_TXT_HINT + lv_draw_label_hint_t hint; +#endif + +#if LV_LABEL_TEXT_SELECTION + uint32_t sel_start; + uint32_t sel_end; +#endif + + lv_point_t offset; /*Text draw position offset*/ + lv_label_long_mode_t long_mode : 3; /*Determine what to do with the long texts*/ + uint8_t static_txt : 1; /*Flag to indicate the text is static*/ + uint8_t recolor : 1; /*Enable in-line letter re-coloring*/ + uint8_t expand : 1; /*Ignore real width (used by the library with LV_LABEL_LONG_SCROLL)*/ + uint8_t dot_tmp_alloc : 1; /*1: dot is allocated, 0: dot directly holds up to 4 chars*/ +} lv_label_t; + +extern const lv_obj_class_t lv_label_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a label object + * @param parent pointer to an object, it will be the parent of the new label. + * @return pointer to the created button + */ +lv_obj_t * lv_label_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new text for a label. Memory will be allocated to store the text by the label. + * @param obj pointer to a label object + * @param text '\0' terminated character string. NULL to refresh with the current text. + */ +void lv_label_set_text(lv_obj_t * obj, const char * text); + +/** + * Set a new formatted text for a label. Memory will be allocated to store the text by the label. + * @param obj pointer to a label object + * @param fmt `printf`-like format + * @example lv_label_set_text_fmt(label1, "%d user", user_num); + */ +void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) LV_FORMAT_ATTRIBUTE(2, 3); + +/** + * Set a static text. It will not be saved by the label so the 'text' variable + * has to be 'alive' while the label exists. + * @param obj pointer to a label object + * @param text pointer to a text. NULL to refresh with the current text. + */ +void lv_label_set_text_static(lv_obj_t * obj, const char * text); + +/** + * Set the behavior of the label with longer text then the object size + * @param obj pointer to a label object + * @param long_mode the new mode from 'lv_label_long_mode' enum. + * In LV_LONG_WRAP/DOT/SCROLL/SCROLL_CIRC the size of the label should be set AFTER this function + */ +void lv_label_set_long_mode(lv_obj_t * obj, lv_label_long_mode_t long_mode); + +/** + * Enable the recoloring by in-line commands + * @param obj pointer to a label object + * @param en true: enable recoloring, false: disable + * @example "This is a #ff0000 red# word" + */ +void lv_label_set_recolor(lv_obj_t * obj, bool en); + +/** + * Set where text selection should start + * @param obj pointer to a label object + * @param index character index from where selection should start. `LV_LABEL_TEXT_SELECTION_OFF` for no selection + */ +void lv_label_set_text_sel_start(lv_obj_t * obj, uint32_t index); + +/** + * Set where text selection should end + * @param obj pointer to a label object + * @param index character index where selection should end. `LV_LABEL_TEXT_SELECTION_OFF` for no selection + */ +void lv_label_set_text_sel_end(lv_obj_t * obj, uint32_t index); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a label + * @param obj pointer to a label object + * @return the text of the label + */ +char * lv_label_get_text(const lv_obj_t * obj); + +/** + * Get the long mode of a label + * @param obj pointer to a label object + * @return the current long mode + */ +lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * obj); + +/** + * Get the recoloring attribute + * @param obj pointer to a label object + * @return true: recoloring is enabled, false: disable + */ +bool lv_label_get_recolor(const lv_obj_t * obj); + +/** + * Get the relative x and y coordinates of a letter + * @param obj pointer to a label object + * @param index index of the character [0 ... text length - 1]. + * Expressed in character index, not byte index (different in UTF-8) + * @param pos store the result here (E.g. index = 0 gives 0;0 coordinates if the text if aligned to the left) + */ +void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t * pos); + +/** + * Get the index of letter on a relative point of a label. + * @param obj pointer to label object + * @param pos pointer to point with coordinates on a the label + * @return The index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter if aligned to the left) + * Expressed in character index and not byte index (different in UTF-8) + */ +uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in); + +/** + * Check if a character is drawn under a point. + * @param obj pointer to a label object + * @param pos Point to check for character under + * @return whether a character is drawn under the point + */ +bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos); + +/** + * @brief Get the selection start index. + * @param obj pointer to a label object. + * @return selection start index. `LV_LABEL_TEXT_SELECTION_OFF` if nothing is selected. + */ +uint32_t lv_label_get_text_selection_start(const lv_obj_t * obj); + +/** + * @brief Get the selection end index. + * @param obj pointer to a label object. + * @return selection end index. `LV_LABEL_TXT_SEL_OFF` if nothing is selected. + */ +uint32_t lv_label_get_text_selection_end(const lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Insert a text to a label. The label text can not be static. + * @param obj pointer to a label object + * @param pos character index to insert. Expressed in character index and not byte index. + * 0: before first char. LV_LABEL_POS_LAST: after last char. + * @param txt pointer to the text to insert + */ +void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt); + +/** + * Delete characters from a label. The label text can not be static. + * @param obj pointer to a label object + * @param pos character index from where to cut. Expressed in character index and not byte index. + * 0: start in from of the first character + * @param cnt number of characters to cut + */ +void lv_label_cut_text(lv_obj_t * obj, uint32_t pos, uint32_t cnt); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_LABEL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LABEL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_line.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_line.h new file mode 100644 index 00000000..622ef810 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_line.h @@ -0,0 +1,93 @@ +/** + * @file lv_line.h + * + */ + +#ifndef LV_LINE_H +#define LV_LINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_LINE != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of line*/ +typedef struct { + lv_obj_t obj; + const lv_point_t * point_array; /**< Pointer to an array with the points of the line*/ + uint16_t point_num; /**< Number of points in 'point_array'*/ + uint8_t y_inv : 1; /**< 1: y == 0 will be on the bottom*/ +} lv_line_t; + +extern const lv_obj_class_t lv_line_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a line object + * @param parent pointer to an object, it will be the parent of the new line + * @return pointer to the created line + */ +lv_obj_t * lv_line_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set an array of points. The line object will connect these points. + * @param obj pointer to a line object + * @param points an array of points. Only the address is saved, so the array needs to be alive while the line exists + * @param point_num number of points in 'point_a' + */ +void lv_line_set_points(lv_obj_t * obj, const lv_point_t points[], uint16_t point_num); + +/** + * Enable (or disable) the y coordinate inversion. + * If enabled then y will be subtracted from the height of the object, + * therefore the y = 0 coordinate will be on the bottom. + * @param obj pointer to a line object + * @param en true: enable the y inversion, false:disable the y inversion + */ +void lv_line_set_y_invert(lv_obj_t * obj, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the y inversion attribute + * @param obj pointer to a line object + * @return true: y inversion is enabled, false: disabled + */ +bool lv_line_get_y_invert(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_LINE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LINE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_objx_templ.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_objx_templ.h new file mode 100644 index 00000000..f363df4e --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_objx_templ.h @@ -0,0 +1,81 @@ +/** + * @file lv_templ.h + * + */ + +/** + * TODO Remove these instructions + * Search and replace: templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) + * + */ + +#ifndef LV_TEMPL_H +#define LV_TEMPL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_TEMPL != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of template*/ +typedef struct { + lv_ANCESTOR_t ancestor; /*The ancestor widget, e.g. lv_slider_t slider*/ + /*New data for this type*/ +} lv_templ_t; + +extern const lv_obj_class_t lv_templ_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a templ object + * @param parent pointer to an object, it will be the parent of the new templ + * @return pointer to the created bar + */ +lv_obj_t * lv_templ_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TEMPL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TEMPL_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_roller.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_roller.h new file mode 100644 index 00000000..4984c262 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_roller.h @@ -0,0 +1,138 @@ +/** + * @file lv_roller.h + * + */ + +#ifndef LV_ROLLER_H +#define LV_ROLLER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_ROLLER != 0 + +/*Testing of dependencies*/ +#if LV_USE_LABEL == 0 +#error "lv_roller: lv_label is required. Enable it in lv_conf.h (LV_USE_ROLLER 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** Roller mode.*/ +enum { + LV_ROLLER_MODE_NORMAL, /**< Normal mode (roller ends at the end of the options).*/ + LV_ROLLER_MODE_INFINITE, /**< Infinite mode (roller can be scrolled forever).*/ +}; + +typedef uint8_t lv_roller_mode_t; + +typedef struct { + lv_obj_t obj; + uint16_t option_cnt; /**< Number of options*/ + uint16_t sel_opt_id; /**< Index of the current option*/ + uint16_t sel_opt_id_ori; /**< Store the original index on focus*/ + lv_roller_mode_t mode : 1; + uint32_t moved : 1; +} lv_roller_t; + +extern const lv_obj_class_t lv_roller_class; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a roller object + * @param parent pointer to an object, it will be the parent of the new roller. + * @return pointer to the created roller + */ +lv_obj_t * lv_roller_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the options on a roller + * @param obj pointer to roller object + * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" + * @param mode `LV_ROLLER_MODE_NORMAL` or `LV_ROLLER_MODE_INFINITE` + */ +void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_t mode); + +/** + * Set the selected option + * @param obj pointer to a roller object + * @param sel_opt index of the selected option (0 ... number of option - 1); + * @param anim_en LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately + */ +void lv_roller_set_selected(lv_obj_t * obj, uint16_t sel_opt, lv_anim_enable_t anim); + +/** + * Set the height to show the given number of rows (options) + * @param obj pointer to a roller object + * @param row_cnt number of desired visible rows + */ +void lv_roller_set_visible_row_count(lv_obj_t * obj, uint8_t row_cnt); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the index of the selected option + * @param obj pointer to a roller object + * @return index of the selected option (0 ... number of option - 1); + */ +uint16_t lv_roller_get_selected(const lv_obj_t * obj); + +/** + * Get the current selected option as a string. + * @param obj pointer to ddlist object + * @param buf pointer to an array to store the string + * @param buf_size size of `buf` in bytes. 0: to ignore it. + */ +void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size); + + +/** + * Get the options of a roller + * @param obj pointer to roller object + * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") + */ +const char * lv_roller_get_options(const lv_obj_t * obj); + +/** + * Get the total number of options + * @param obj pointer to a roller object + * @return the total number of options + */ +uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_ROLLER*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ROLLER_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_slider.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_slider.h new file mode 100644 index 00000000..20c940f8 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_slider.h @@ -0,0 +1,195 @@ +/** + * @file lv_slider.h + * + */ + +#ifndef LV_SLIDER_H +#define LV_SLIDER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_SLIDER != 0 + +/*Testing of dependencies*/ +#if LV_USE_BAR == 0 +#error "lv_slider: lv_bar is required. Enable it in lv_conf.h (LV_USE_BAR 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "lv_bar.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_SLIDER_MODE_NORMAL = LV_BAR_MODE_NORMAL, + LV_SLIDER_MODE_SYMMETRICAL = LV_BAR_MODE_SYMMETRICAL, + LV_SLIDER_MODE_RANGE = LV_BAR_MODE_RANGE +}; +typedef uint8_t lv_slider_mode_t; + +typedef struct { + lv_bar_t bar; /*Add the ancestor's type first*/ + lv_area_t left_knob_area; + lv_area_t right_knob_area; + int32_t * value_to_set; /*Which bar value to set*/ + uint8_t dragging : 1; /*1: the slider is being dragged*/ + uint8_t left_knob_focus : 1; /*1: with encoder now the right knob can be adjusted*/ +} lv_slider_t; + +extern const lv_obj_class_t lv_slider_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_slider_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_SLIDER_DRAW_PART_KNOB, /**< The main (right) knob's rectangle*/ + LV_SLIDER_DRAW_PART_KNOB_LEFT, /**< The left knob's rectangle*/ +} lv_slider_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a slider object + * @param parent pointer to an object, it will be the parent of the new slider. + * @return pointer to the created slider + */ +lv_obj_t * lv_slider_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the slider + * @param obj pointer to a slider object + * @param value the new value + * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately + */ +static inline void lv_slider_set_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim) +{ + lv_bar_set_value(obj, value, anim); +} + +/** + * Set a new value for the left knob of a slider + * @param obj pointer to a slider object + * @param value new value + * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately + */ +static inline void lv_slider_set_left_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim) +{ + lv_bar_set_start_value(obj, value, anim); +} + +/** + * Set minimum and the maximum values of a bar + * @param obj pointer to the slider object + * @param min minimum value + * @param max maximum value + */ +static inline void lv_slider_set_range(lv_obj_t * obj, int32_t min, int32_t max) +{ + lv_bar_set_range(obj, min, max); +} + +/** + * Set the mode of slider. + * @param obj pointer to a slider object + * @param mode the mode of the slider. See ::lv_slider_mode_t + */ +static inline void lv_slider_set_mode(lv_obj_t * obj, lv_slider_mode_t mode) +{ + lv_bar_set_mode(obj, (lv_bar_mode_t)mode); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of the main knob of a slider + * @param obj pointer to a slider object + * @return the value of the main knob of the slider + */ +static inline int32_t lv_slider_get_value(const lv_obj_t * obj) +{ + return lv_bar_get_value(obj); +} + +/** + * Get the value of the left knob of a slider + * @param obj pointer to a slider object + * @return the value of the left knob of the slider + */ +static inline int32_t lv_slider_get_left_value(const lv_obj_t * obj) +{ + return lv_bar_get_start_value(obj); +} + +/** + * Get the minimum value of a slider + * @param obj pointer to a slider object + * @return the minimum value of the slider + */ +static inline int32_t lv_slider_get_min_value(const lv_obj_t * obj) +{ + return lv_bar_get_min_value(obj); +} + +/** + * Get the maximum value of a slider + * @param obj pointer to a slider object + * @return the maximum value of the slider + */ +static inline int32_t lv_slider_get_max_value(const lv_obj_t * obj) +{ + return lv_bar_get_max_value(obj); +} + +/** + * Give the slider is being dragged or not + * @param obj pointer to a slider object + * @return true: drag in progress false: not dragged + */ +bool lv_slider_is_dragged(const lv_obj_t * obj); + +/** + * Get the mode of the slider. + * @param obj pointer to a bar object + * @return see ::lv_slider_mode_t + */ +static inline lv_slider_mode_t lv_slider_get_mode(lv_obj_t * slider) +{ + lv_bar_mode_t mode = lv_bar_get_mode(slider); + if(mode == LV_BAR_MODE_SYMMETRICAL) return LV_SLIDER_MODE_SYMMETRICAL; + else if(mode == LV_BAR_MODE_RANGE) return LV_SLIDER_MODE_RANGE; + else return LV_SLIDER_MODE_NORMAL; +} + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_SLIDER*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_SLIDER_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_switch.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_switch.h new file mode 100644 index 00000000..63ec4276 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_switch.h @@ -0,0 +1,61 @@ +/** + * @file lv_switch.h + * + */ + +#ifndef LV_SWITCH_H +#define LV_SWITCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_SWITCH != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/** Switch knob extra area correction factor */ +#define _LV_SWITCH_KNOB_EXT_AREA_CORRECTION 2 + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + int32_t anim_state; +} lv_switch_t; + +extern const lv_obj_class_t lv_switch_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a switch object + * @param parent pointer to an object, it will be the parent of the new switch + * @return pointer to the created switch + */ +lv_obj_t * lv_switch_create(lv_obj_t * parent); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_SWITCH*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_SWITCH_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_table.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_table.h new file mode 100644 index 00000000..311d9149 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_table.h @@ -0,0 +1,210 @@ +/** + * @file lv_table.h + * + */ + +#ifndef LV_TABLE_H +#define LV_TABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_TABLE != 0 + +/*Testing of dependencies*/ +#if LV_USE_LABEL == 0 +#error "lv_table: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ +#define LV_TABLE_CELL_NONE 0XFFFF +LV_EXPORT_CONST_INT(LV_TABLE_CELL_NONE); + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_TABLE_CELL_CTRL_MERGE_RIGHT = 1 << 0, + LV_TABLE_CELL_CTRL_TEXT_CROP = 1 << 1, + LV_TABLE_CELL_CTRL_CUSTOM_1 = 1 << 4, + LV_TABLE_CELL_CTRL_CUSTOM_2 = 1 << 5, + LV_TABLE_CELL_CTRL_CUSTOM_3 = 1 << 6, + LV_TABLE_CELL_CTRL_CUSTOM_4 = 1 << 7, +}; + +typedef uint8_t lv_table_cell_ctrl_t; + +/*Data of table*/ +typedef struct { + lv_obj_t obj; + uint16_t col_cnt; + uint16_t row_cnt; + char ** cell_data; + lv_coord_t * row_h; + lv_coord_t * col_w; + uint16_t col_act; + uint16_t row_act; +} lv_table_t; + +extern const lv_obj_class_t lv_table_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_table_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_TABLE_DRAW_PART_CELL, /**< A cell*/ +} lv_table_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a table object + * @param parent pointer to an object, it will be the parent of the new table + * @return pointer to the created table + */ +lv_obj_t * lv_table_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the value of a cell. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param txt text to display in the cell. It will be copied and saved so this variable is not required after this function call. + * @note New roes/columns are added automatically if required + */ +void lv_table_set_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col, const char * txt); + +/** + * Set the value of a cell. Memory will be allocated to store the text by the table. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param fmt `printf`-like format + * @note New roes/columns are added automatically if required + */ +void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, const char * fmt, ...); + +/** + * Set the number of rows + * @param obj table pointer to a Table object + * @param row_cnt number of rows + */ +void lv_table_set_row_cnt(lv_obj_t * obj, uint16_t row_cnt); + +/** + * Set the number of columns + * @param obj table pointer to a Table object + * @param col_cnt number of columns. + */ +void lv_table_set_col_cnt(lv_obj_t * obj, uint16_t col_cnt); + +/** + * Set the width of a column + * @param obj table pointer to a Table object + * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] + * @param w width of the column + */ +void lv_table_set_col_width(lv_obj_t * obj, uint16_t col_id, lv_coord_t w); + +/** + * Add control bits to the cell. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param ctrl OR-ed values from ::lv_table_cell_ctrl_t + */ +void lv_table_add_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl); + + +/** + * Clear control bits of the cell. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param ctrl OR-ed values from ::lv_table_cell_ctrl_t + */ +void lv_table_clear_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a cell. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return text in the cell + */ +const char * lv_table_get_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col); + +/** + * Get the number of rows. + * @param obj table pointer to a Table object + * @return number of rows. + */ +uint16_t lv_table_get_row_cnt(lv_obj_t * obj); + +/** + * Get the number of columns. + * @param obj table pointer to a Table object + * @return number of columns. + */ +uint16_t lv_table_get_col_cnt(lv_obj_t * obj); + +/** + * Get the width of a column + * @param obj table pointer to a Table object + * @param col id of the column [0 .. LV_TABLE_COL_MAX -1] + * @return width of the column + */ +lv_coord_t lv_table_get_col_width(lv_obj_t * obj, uint16_t col); + +/** + * Get whether a cell has the control bits + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param ctrl OR-ed values from ::lv_table_cell_ctrl_t + * @return true: all control bits are set; false: not all control bits are set + */ +bool lv_table_has_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl); + +/** + * Get the selected cell (pressed and or focused) + * @param obj pointer to a table object + * @param row pointer to variable to store the selected row (LV_TABLE_CELL_NONE: if no cell selected) + * @param col pointer to variable to store the selected column (LV_TABLE_CELL_NONE: if no cell selected) + */ +void lv_table_get_selected_cell(lv_obj_t * obj, uint16_t * row, uint16_t * col); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TABLE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TABLE_H*/ diff --git a/EZ-Template-Example-Project/include/liblvgl/widgets/lv_textarea.h b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_textarea.h new file mode 100644 index 00000000..cfa47e47 --- /dev/null +++ b/EZ-Template-Example-Project/include/liblvgl/widgets/lv_textarea.h @@ -0,0 +1,358 @@ +/** + * @file lv_textarea.h + * + */ + +#ifndef LV_TEXTAREA_H +#define LV_TEXTAREA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_TEXTAREA != 0 + +/*Testing of dependencies*/ +#if LV_USE_LABEL == 0 +#error "lv_ta: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ +#define LV_TEXTAREA_CURSOR_LAST (0x7FFF) /*Put the cursor after the last character*/ + +LV_EXPORT_CONST_INT(LV_TEXTAREA_CURSOR_LAST); + +/********************** + * TYPEDEFS + **********************/ + +/*Data of text area*/ +typedef struct { + lv_obj_t obj; + lv_obj_t * label; /*Label of the text area*/ + char * placeholder_txt; /*Place holder label. only visible if text is an empty string*/ + char * pwd_tmp; /*Used to store the original text in password mode*/ + char * pwd_bullet; /*Replacement characters displayed in password mode*/ + const char * accepted_chars; /*Only these characters will be accepted. NULL: accept all*/ + uint32_t max_length; /*The max. number of characters. 0: no limit*/ + uint16_t pwd_show_time; /*Time to show characters in password mode before change them to '*'*/ + struct { + lv_coord_t valid_x; /*Used when stepping up/down to a shorter line. + *(Used by the library)*/ + uint32_t pos; /*The current cursor position + *(0: before 1st letter; 1: before 2nd letter ...)*/ + lv_area_t area; /*Cursor area relative to the Text Area*/ + uint32_t txt_byte_pos; /*Byte index of the letter after (on) the cursor*/ + uint8_t show : 1; /*Cursor is visible now or not (Handled by the library)*/ + uint8_t click_pos : 1; /*1: Enable positioning the cursor by clicking the text area*/ + } cursor; +#if LV_LABEL_TEXT_SELECTION + uint32_t sel_start; /*Temporary values for text selection*/ + uint32_t sel_end; + uint8_t text_sel_in_prog : 1; /*User is in process of selecting*/ + uint8_t text_sel_en : 1; /*Text can be selected on this text area*/ +#endif + uint8_t pwd_mode : 1; /*Replace characters with '*'*/ + uint8_t one_line : 1; /*One line mode (ignore line breaks)*/ +} lv_textarea_t; + +extern const lv_obj_class_t lv_textarea_class; + +enum { + LV_PART_TEXTAREA_PLACEHOLDER = LV_PART_CUSTOM_FIRST, +}; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a text area object + * @param parent pointer to an object, it will be the parent of the new text area + * @return pointer to the created text area + */ +lv_obj_t * lv_textarea_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Insert a character to the current cursor position. + * To add a wide char, e.g. 'Á' use `_lv_txt_encoded_conv_wc('Á')` + * @param obj pointer to a text area object + * @param c a character (e.g. 'a') + */ +void lv_textarea_add_char(lv_obj_t * obj, uint32_t c); + +/** + * Insert a text to the current cursor position + * @param obj pointer to a text area object + * @param txt a '\0' terminated string to insert + */ +void lv_textarea_add_text(lv_obj_t * obj, const char * txt); + +/** + * Delete a the left character from the current cursor position + * @param obj pointer to a text area object + */ +void lv_textarea_del_char(lv_obj_t * obj); + +/** + * Delete the right character from the current cursor position + * @param obj pointer to a text area object + */ +void lv_textarea_del_char_forward(lv_obj_t * obj); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of a text area + * @param obj pointer to a text area object + * @param txt pointer to the text + */ +void lv_textarea_set_text(lv_obj_t * obj, const char * txt); + +/** + * Set the placeholder text of a text area + * @param obj pointer to a text area object + * @param txt pointer to the text + */ +void lv_textarea_set_placeholder_text(lv_obj_t * obj, const char * txt); + +/** + * Set the cursor position + * @param obj pointer to a text area object + * @param pos the new cursor position in character index + * < 0 : index from the end of the text + * LV_TEXTAREA_CURSOR_LAST: go after the last character + */ +void lv_textarea_set_cursor_pos(lv_obj_t * obj, int32_t pos); + +/** + * Enable/Disable the positioning of the cursor by clicking the text on the text area. + * @param obj pointer to a text area object + * @param en true: enable click positions; false: disable + */ +void lv_textarea_set_cursor_click_pos(lv_obj_t * obj, bool en); + +/** + * Enable/Disable password mode + * @param obj pointer to a text area object + * @param en true: enable, false: disable + */ +void lv_textarea_set_password_mode(lv_obj_t * obj, bool en); + +/** + * Set the replacement characters to show in password mode + * @param obj pointer to a text area object + * @param bullet pointer to the replacement text + */ +void lv_textarea_set_password_bullet(lv_obj_t * obj, const char * bullet); + +/** + * Configure the text area to one line or back to normal + * @param obj pointer to a text area object + * @param en true: one line, false: normal + */ +void lv_textarea_set_one_line(lv_obj_t * obj, bool en); + +/** + * Set a list of characters. Only these characters will be accepted by the text area + * @param obj pointer to a text area object + * @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789" + */ +void lv_textarea_set_accepted_chars(lv_obj_t * obj, const char * list); + +/** + * Set max length of a Text Area. + * @param obj pointer to a text area object + * @param num the maximal number of characters can be added (`lv_textarea_set_text` ignores it) + */ +void lv_textarea_set_max_length(lv_obj_t * obj, uint32_t num); + +/** + * In `LV_EVENT_INSERT` the text which planned to be inserted can be replaced by an other text. + * It can be used to add automatic formatting to the text area. + * @param obj pointer to a text area object + * @param txt pointer to a new string to insert. If `""` no text will be added. + * The variable must be live after the `event_cb` exists. (Should be `global` or `static`) + */ +void lv_textarea_set_insert_replace(lv_obj_t * obj, const char * txt); + +/** + * Enable/disable selection mode. + * @param obj pointer to a text area object + * @param en true or false to enable/disable selection mode + */ +void lv_textarea_set_text_selection(lv_obj_t * obj, bool en); + +/** + * Set how long show the password before changing it to '*' + * @param obj pointer to a text area object + * @param time show time in milliseconds. 0: hide immediately. + */ +void lv_textarea_set_password_show_time(lv_obj_t * obj, uint16_t time); + +/** + * Deprecated: use the normal text_align style property instead + * Set the label's alignment. + * It sets where the label is aligned (in one line mode it can be smaller than the text area) + * and how the lines of the area align in case of multiline text area + * @param obj pointer to a text area object + * @param align the align mode from ::lv_text_align_t + */ +void lv_textarea_set_align(lv_obj_t * obj, lv_text_align_t align); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a text area. In password mode it gives the real text (not '*'s). + * @param obj pointer to a text area object + * @return pointer to the text + */ +const char * lv_textarea_get_text(const lv_obj_t * obj); + +/** + * Get the placeholder text of a text area + * @param obj pointer to a text area object + * @return pointer to the text + */ +const char * lv_textarea_get_placeholder_text(lv_obj_t * obj); + +/** + * Get the label of a text area + * @param obj pointer to a text area object + * @return pointer to the label object + */ +lv_obj_t * lv_textarea_get_label(const lv_obj_t * obj); + +/** + * Get the current cursor position in character index + * @param obj pointer to a text area object + * @return the cursor position + */ +uint32_t lv_textarea_get_cursor_pos(const lv_obj_t * obj); + +/** + * Get whether the cursor click positioning is enabled or not. + * @param obj pointer to a text area object + * @return true: enable click positions; false: disable + */ +bool lv_textarea_get_cursor_click_pos(lv_obj_t * obj); + +/** + * Get the password mode attribute + * @param obj pointer to a text area object + * @return true: password mode is enabled, false: disabled + */ +bool lv_textarea_get_password_mode(const lv_obj_t * obj); + +/** + * Get the replacement characters to show in password mode + * @param obj pointer to a text area object + * @return pointer to the replacement text + */ +const char * lv_textarea_get_password_bullet(lv_obj_t * obj); + +/** + * Get the one line configuration attribute + * @param obj pointer to a text area object + * @return true: one line configuration is enabled, false: disabled + */ +bool lv_textarea_get_one_line(const lv_obj_t * obj); + +/** + * Get a list of accepted characters. + * @param obj pointer to a text area object + * @return list of accented characters. + */ +const char * lv_textarea_get_accepted_chars(lv_obj_t * obj); + +/** + * Get max length of a Text Area. + * @param obj pointer to a text area object + * @return the maximal number of characters to be add + */ +uint32_t lv_textarea_get_max_length(lv_obj_t * obj); + +/** + * Find whether text is selected or not. + * @param obj pointer to a text area object + * @return whether text is selected or not + */ +bool lv_textarea_text_is_selected(const lv_obj_t * obj); + +/** + * Find whether selection mode is enabled. + * @param obj pointer to a text area object + * @return true: selection mode is enabled, false: disabled + */ +bool lv_textarea_get_text_selection(lv_obj_t * obj); + +/** + * Set how long show the password before changing it to '*' + * @param obj pointer to a text area object + * @return show time in milliseconds. 0: hide immediately. + */ +uint16_t lv_textarea_get_password_show_time(lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Clear the selection on the text area. + * @param obj pointer to a text area object + */ +void lv_textarea_clear_selection(lv_obj_t * obj); + +/** + * Move the cursor one character right + * @param obj pointer to a text area object + */ +void lv_textarea_cursor_right(lv_obj_t * obj); + +/** + * Move the cursor one character left + * @param obj pointer to a text area object + */ +void lv_textarea_cursor_left(lv_obj_t * obj); + +/** + * Move the cursor one line down + * @param obj pointer to a text area object + */ +void lv_textarea_cursor_down(lv_obj_t * obj); + +/** + * Move the cursor one line up + * @param obj pointer to a text area object + */ +void lv_textarea_cursor_up(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TEXTAREA_H*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TEXTAREA_H*/ diff --git a/EZ-Template-Example-Project/include/main.h b/EZ-Template-Example-Project/include/main.h index a57785d1..987e2f24 100644 --- a/EZ-Template-Example-Project/include/main.h +++ b/EZ-Template-Example-Project/include/main.h @@ -45,6 +45,8 @@ // More includes here... #include "autons.hpp" +#include "subsystems.hpp" + /** * If you find doing pros::Motor() to be tedious and you'd prefer just to do diff --git a/EZ-Template-Example-Project/include/okapi/api/coreProsAPI.hpp b/EZ-Template-Example-Project/include/okapi/api/coreProsAPI.hpp index ab1aa694..a5653366 100644 --- a/EZ-Template-Example-Project/include/okapi/api/coreProsAPI.hpp +++ b/EZ-Template-Example-Project/include/okapi/api/coreProsAPI.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef THREADS_STD #include diff --git a/EZ-Template-Example-Project/include/okapi/impl/device/motor/motor.hpp b/EZ-Template-Example-Project/include/okapi/impl/device/motor/motor.hpp index 78c5b3b0..dd9cf0a5 100644 --- a/EZ-Template-Example-Project/include/okapi/impl/device/motor/motor.hpp +++ b/EZ-Template-Example-Project/include/okapi/impl/device/motor/motor.hpp @@ -358,73 +358,6 @@ class Motor : public AbstractMotor { */ std::int32_t setVoltageLimit(std::int32_t ilimit) override; - /** - * Sets new PID constants. - * - * @param ikF the feed-forward constant - * @param ikP the proportional constant - * @param ikI the integral constant - * @param ikD the derivative constant - * @return 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. - */ - virtual std::int32_t setPosPID(double ikF, double ikP, double ikI, double ikD); - - /** - * Sets new PID constants. - * - * @param ikF the feed-forward constant - * @param ikP the proportional constant - * @param ikI the integral constant - * @param ikD the derivative constant - * @param ifilter a constant used for filtering the profile acceleration - * @param ilimit the integral limit - * @param ithreshold the threshold for determining if a position movement has reached its goal - * @param iloopSpeed the rate at which the PID computation is run (in ms) - * @return 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. - */ - virtual std::int32_t setPosPIDFull(double ikF, - double ikP, - double ikI, - double ikD, - double ifilter, - double ilimit, - double ithreshold, - double iloopSpeed); - - /** - * Sets new PID constants. - * - * @param ikF the feed-forward constant - * @param ikP the proportional constant - * @param ikI the integral constant - * @param ikD the derivative constant - * @return `1` if the operation was successful or `PROS_ERR` if the operation failed, setting - * errno. - */ - virtual std::int32_t setVelPID(double ikF, double ikP, double ikI, double ikD); - - /** - * Sets new PID constants. - * - * @param ikF the feed-forward constant - * @param ikP the proportional constant - * @param ikI the integral constant - * @param ikD the derivative constant - * @param ifilter a constant used for filtering the profile acceleration - * @param ilimit the integral limit - * @param ithreshold the threshold for determining if a position movement has reached its goal - * @param iloopSpeed the rate at which the PID computation is run (in ms) - * @return 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. - */ - virtual std::int32_t setVelPIDFull(double ikF, - double ikP, - double ikI, - double ikD, - double ifilter, - double ilimit, - double ithreshold, - double iloopSpeed); - /** * Get the encoder associated with this motor. * diff --git a/EZ-Template-Example-Project/include/pros/abstract_motor.hpp b/EZ-Template-Example-Project/include/pros/abstract_motor.hpp new file mode 100644 index 00000000..d2a3e31f --- /dev/null +++ b/EZ-Template-Example-Project/include/pros/abstract_motor.hpp @@ -0,0 +1,1144 @@ +/** + * \file abstract_motor.hpp + * \ingroup cpp-abstract-motor + * + * Contains prototypes for AbstractMotor, the abstract base class of both + * motors and motor groups. Abstract motors cannot be directly constructed, but + * you can use motors and motor groups as abstract motors. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * All rights reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _PROS_ABSTRACT_MOTORS_HPP_ +#define _PROS_ABSTRACT_MOTORS_HPP_ + +#include +#include + +#include "pros/device.hpp" +#include "pros/motors.h" +#include "rtos.hpp" + +namespace pros { +inline namespace v5 { + +/** + * \enum MotorBrake + * Indicates the current 'brake mode' of a motor. + */ +enum class MotorBrake { + coast = 0, ///< Motor coasts when stopped, traditional behavior + brake = 1, ///< Motor brakes when stopped + hold = 2, ///< Motor actively holds position when stopped + invalid = INT32_MAX ///< Invalid brake mode +}; + +/** + * \enum MotorEncoderUnits + * Indicates the units used by the motor encoders. + */ +enum class MotorEncoderUnits { + degrees = 0, ///< Position is recorded as angle in degrees as a floating point number + deg = 0, ///< Position is recorded as angle in degrees as a floating point number + rotations = 1, ///< Position is recorded as angle in rotations as a floating point number + counts = 2, ///< Position is recorded as raw encoder ticks as a whole number + invalid = INT32_MAX ///< Invalid motor encoder units +}; + +// Alias for MotorEncoderUnits +using MotorUnits = MotorEncoderUnits; + +enum class MotorGears { + ratio_36_to_1 = 0, ///< 36:1, 100 RPM, Red gear set + red = ratio_36_to_1, ///< 36:1, 100 RPM, Red gear set + rpm_100 = ratio_36_to_1, ///< 36:1, 100 RPM, Red gear set + ratio_18_to_1 = 1, ///< 18:1, 200 RPM, Green gear set + green = ratio_18_to_1, ///< 18:1, 200 RPM, Green gear set + rpm_200 = ratio_18_to_1, ///< 18:1, 200 RPM, Green gear set + ratio_6_to_1 = 2, ///< 6:1, 600 RPM, Blue gear set + blue = ratio_6_to_1, ///< 6:1, 600 RPM, Blue gear set + rpm_600 = ratio_6_to_1, ///< 6:1, 600 RPM, Blue gear set + invalid = INT32_MAX ///< Error return code +}; + + +// Provide Aliases for MotorGears +using MotorGearset = MotorGears; +using MotorCart = MotorGears; +using MotorCartridge = MotorGears; +using MotorGear = MotorGears; + +/** + * \ingroup cpp-abstract-motor + */ +class AbstractMotor { + /** + * \addtogroup cpp-abstract-motor + * @{ + */ + public: + /// \name Motor movement functions + /// These functions allow programmers to make motors move + ///@{ + + /** + * Sets the voltage for the motor from -127 to 127. + * + * This is designed to map easily to the input from the controller's analog + * stick for simple opcontrol use. The actual behavior of the motor is + * analogous to use of motor_move(), or motorSet() from the PROS 2 API. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param voltage + * The new motor voltage from -127 to 127 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move(std::int32_t voltage) const = 0; + + /** + * Sets the target absolute position for the motor to move to. + * + * This movement is relative to the position of the motor when initialized or + * the position when it was most recently reset with + * pros::Motor::set_zero_position(). + * + * \note This function simply sets the target for the motor, it does not block + * program execution until the movement finishes. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param position + * The absolute position to move to in the motor's encoder units + * \param velocity + * The maximum allowable velocity for the movement in RPM + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move_absolute(const double position, const std::int32_t velocity) const = 0; + + /** + * Sets the relative target position for the motor to move to. + * + * This movement is relative to the current position of the motor as given in + * pros::Motor::motor_get_position(). Providing 10.0 as the position parameter + * would result in the motor moving clockwise 10 units, no matter what the + * current position is. + * + * \note This function simply sets the target for the motor, it does not block + * program execution until the movement finishes. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param position + * The relative position to move to in the motor's encoder units + * \param velocity + * The maximum allowable velocity for the movement in RPM + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move_relative(const double position, const std::int32_t velocity) const = 0; + + /** + * Sets the velocity for the motor. + * + * This velocity corresponds to different actual speeds depending on the + * gearset used for the motor. This results in a range of +-100 for + * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for + * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent + * speed, as opposed to setting the motor's voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param velocity + * The new motor velocity from -+-100, +-200, or +-600 depending on the + * motor's gearset + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move_velocity(const std::int32_t velocity) const = 0; + + /** + * Sets the output voltage for the motor from -12000 to 12000 in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param port + * The V5 port number from 1-21 + * \param voltage + * The new voltage value from -12000 to 12000 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move_voltage(const std::int32_t voltage) const = 0; + + /** + * Stops the motor using the currently configured brake mode. + * + * This function sets motor velocity to zero, which will cause it to act + * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, + * this function may behave differently than calling move_absolute(0) + * or motor_move_relative(0). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + */ + virtual std::int32_t brake(void) const = 0; + + /** + * Changes the output velocity for a profiled movement (motor_move_absolute or + * motor_move_relative). This will have no effect if the motor is not following + * a profiled movement. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param velocity + * The new motor velocity from +-100, +-200, or +-600 depending on the + * motor's gearset + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t modify_profiled_velocity(const std::int32_t velocity) const = 0; + + /** + * Gets the target position set for the motor by the user, with a parameter + * for the motor index. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The target position in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + */ + virtual double get_target_position(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the target position(s) set for the motor(s) by the user + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector containing the target position(s) in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + */ + virtual std::vector get_target_position_all(void) const = 0; + + /** + * Gets the velocity commanded to the motor by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The commanded motor velocity from +-100, +-200, or +-600, or + * PROS_ERR if the operation failed, setting errno. + */ + virtual std::int32_t get_target_velocity(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the velocity/velocities commanded to the motor(s) by the user + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the commanded motor velocity/velocities from +-100, + * +-200, or +-600, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::vector get_target_velocity_all(void) const = 0; + + ///@} + + /// \name Motor telemetry functions + /// \addtogroup cpp-motor-telemetry + /// These functions allow programmers to collect telemetry from motors + ///@{ + + /** + * Gets the actual velocity of the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual double get_actual_velocity(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the actual velocity/velocities of the motor(s) + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the motor's/motors' actual velocity/velocities in RPM or PROS_ERR_F + * if the operation failed, setting errno. + */ + virtual std::vector get_actual_velocity_all(void) const = 0; + + /** + * Gets the current drawn by the motor in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's current in mA or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::int32_t get_current_draw(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the current(s) drawn by the motor(s) in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector conatining the motor's/motors' current(s) in mA or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::vector get_current_draw_all(void) const = 0; + + /** + * Gets the direction of movement for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + */ + virtual std::int32_t get_direction(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the direction(s) of movement for the motor(s). + * + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector containing 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + */ + virtual std::vector get_direction_all(void) const = 0; + + /** + * Gets the efficiency of the motor in percent. + * + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's efficiency in percent or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual double get_efficiency(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the efficiency/efficiencies of the motor(s) in percent. + * + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector containing the motor's/motors' efficiency/efficiencies in percent or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual std::vector get_efficiency_all(void) const = 0; + + /** + * Gets the faults experienced by the motor. + * + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A bitfield containing the motor's faults. + */ + virtual std::uint32_t get_faults(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the faults experienced by the motor(s). + * + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \return A bitfield containing the motor's/motors' faults. + */ + virtual std::vector get_faults_all(void) const = 0; + /** + * Gets the flags set by the motor's operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A bitfield containing the motor's flags. + */ + virtual std::uint32_t get_flags(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the flags set by the motor's/motors' operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A bitfield containing the motor's/motors' flags. + */ + virtual std::vector get_flags_all(void) const = 0; + + /** + * Gets the absolute position of the motor in its encoder units. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + */ + virtual double get_position(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the absolute position(s) of the motor(s) in its encoder units. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + + * + * \return A vector containing the motor's/motors' absolute position(s) in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + */ + virtual std::vector get_position_all(void) const = 0; + + /** + * Gets the power drawn by the motor in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual double get_power(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the power(s) drawn by the motor(s) in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the motor's/motors' power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual std::vector get_power_all(void) const = 0; + + /** + * Gets the raw encoder count of the motor at a given timestamp. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param[in] timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The raw encoder count at the given timestamp or PROS_ERR if the + * operation failed. + */ + virtual std::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the raw encoder count(s) of the motor(s) at a given timestamp. + * + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \param timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \return A vector containing the raw encoder count(s) at the given timestamp or PROS_ERR if the + * operation failed. + */ + virtual std::vector get_raw_position_all(std::uint32_t* const timestamp) const = 0; + + /** + * Gets the temperature of the motor in degrees Celsius. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + */ + virtual double get_temperature(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the temperature(s) of the motor(s) in degrees Celsius. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' temperature(s) in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + */ + virtual std::vector get_temperature_all(void) const = 0; + /** + * Gets the torque generated by the motor in Newton Meters (Nm). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + */ + virtual double get_torque(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the torque(s) generated by the motor(s) in Newton Meters (Nm). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' torque(s) in Nm or PROS_ERR_F if the operation failed, + * setting errno. + */ + virtual std::vector get_torque_all(void) const = 0; + /** + * Gets the voltage delivered to the motor in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + */ + virtual std::int32_t get_voltage(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the voltage(s) delivered to the motor(s) in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' voltage(s) in mV or PROS_ERR_F if the operation failed, + * setting errno. + */ + virtual std::vector get_voltage_all(void) const = 0; + + /** + * Checks if the motor is drawing over its current limit. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::int32_t is_over_current(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of whether each motor is drawing over its current limit. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::vector is_over_current_all(void) const = 0; + + /** + * Gets the temperature limit flag for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::int32_t is_over_temp(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the temperature limit flag(s) for the motor(s). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::vector is_over_temp_all(void) const = 0; + + ///@} + + /// \name Motor configuration functions + /// \addtogroup cpp-motor-configuration + /// These functions allow programmers to configure the behavior of motors + ///@{ + + /** + * Gets the brake mode that was set for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return One of MotorBrake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + */ + virtual MotorBrake get_brake_mode(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the brake mode(s) that was set for the motor(s). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing MotorBrake(s), according to what was set for the + * motor(s), or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + */ + virtual std::vector get_brake_mode_all(void) const = 0; + + /** + * Gets the current limit for the motor in mA. + * + * The default value is 2500 mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::int32_t get_current_limit(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the current limit(s) for the motor(s) in mA. + * + * The default value is 2500 mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' current limit(s) in mA or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::vector get_current_limit_all(void) const = 0; + + /** + * Gets the encoder units that were set for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return One of MotorUnits according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + */ + virtual MotorUnits get_encoder_units(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the encoder units that were set for the motor(s). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector of MotorUnits according to what is set for the + * motor(s) or E_MOTOR_ENCODER_INVALID if the operation failed. + */ + virtual std::vector get_encoder_units_all(void) const = 0; + + /** + * Gets the gearset that was set for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return One of MotorGears according to what is set for the motor, + * or pros::MotorGears::invalid if the operation failed. + */ + virtual MotorGears get_gearing(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the gearset(s) that was/were set for the motor(s). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector of MotorGears according to what is set for the motor(s), + * or pros::MotorGears::invalid if the operation failed. + */ + virtual std::vector get_gearing_all(void) const = 0; + + /** + * @brief Gets returns a vector with all the port numbers in the motor group. + * + * @return std::vector + */ + virtual std::vector get_port_all(void) const = 0; + + /** + * Gets the voltage limit set by the user. + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::int32_t get_voltage_limit(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the voltage limit(s) set by the user. + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' voltage limit(s) in V or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::vector get_voltage_limit_all(void) const = 0; + + /** + * Gets the operation direction of the motor as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::int32_t is_reversed(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the operation direction(s) of the motor(s) as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::vector is_reversed_all(void) const = 0; + + /** + * Sets one of MotorBrake to the motor. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_brake_mode_all(const MotorBrake mode) const = 0; + virtual std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const = 0; + /** + * Sets the current limit for the motor in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param limit + * The new current limit in mA + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_current_limit_all(const std::int32_t limit) const = 0; + /** + * Sets one of MotorUnits for the motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param units + * The new motor encoder units + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_encoder_units_all(const MotorUnits units) const = 0; + virtual std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const = 0; + /** + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param gearset + * The new motor gearset + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_gearing_all(const MotorGears gearset) const = 0; + virtual std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const = 0; + + /** + * Sets the reverse flag for the motor. + * + * This will invert its movements and the values returned for its position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param reverse + * True reverses the motor, false is default + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0) = 0; + virtual std::int32_t set_reversed_all(const bool reverse) = 0; + + /** + * Sets the voltage limit for the motor in Volts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param limit + * The new voltage limit in Volts + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_voltage_limit_all(const std::int32_t limit) const = 0; + + /** + * Sets the position for the motor in its encoder units. + * + * This will be the future reference point for the motor's "absolute" + * position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param position + * The new reference position in its encoder units + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_zero_position_all(const double position) const = 0; + + /** + * Sets the "absolute" zero position of the motor to its current position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t tare_position(const std::uint8_t index = 0) const = 0; + virtual std::int32_t tare_position_all(void) const = 0; + virtual std::int8_t get_port(const std::uint8_t index = 0) const = 0; + /** + * @brief Returns the number of objects + * + * @return std::int8_t + */ + virtual std::int8_t size(void) const = 0; + + ///@} + private: +}; + +} // namespace v5 +} // namespace pros + +///@} + +#endif diff --git a/EZ-Template-Example-Project/include/pros/adi.h b/EZ-Template-Example-Project/include/pros/adi.h index 8f0f556f..f1bbe373 100644 --- a/EZ-Template-Example-Project/include/pros/adi.h +++ b/EZ-Template-Example-Project/include/pros/adi.h @@ -1,18 +1,21 @@ /** * \file pros/adi.h + * \ingroup c-adi * * Contains prototypes for interfacing with the ADI. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-adi ADI (TriPort) C API + * \note The external ADI API can be found [here.](@ref ext-adi) + * \note Additional example code for this module can be found in its [Tutorial.](@ref adi) */ #ifndef _PROS_ADI_H_ @@ -30,6 +33,16 @@ namespace pros { #endif /** + * \ingroup c-adi + */ + +/** + * \addtogroup c-adi + * @{ + */ + +/** + * \enum adi_port_config_e * Represents the port type for an ADI port. */ typedef enum adi_port_config_e { @@ -70,6 +83,7 @@ typedef enum adi_port_config_e { } adi_port_config_e_t; /** + * \enum adi_potentiometer_type_e_t * Represents the potentiometer version type. */ typedef enum adi_potentiometer_type_e { @@ -126,11 +140,16 @@ typedef enum adi_potentiometer_type_e { namespace c { #endif -/******************************************************************************/ -/** General ADI Use Functions **/ -/** **/ -/** These functions allow for interaction with any ADI port type **/ -/******************************************************************************/ +/** @} Add to group c-adi*/ + +/** + * \ingroup c-adi + */ + +/** + * \addtogroup c-adi + * @{ + */ /** * Gets the configuration for the given ADI port. @@ -144,6 +163,17 @@ namespace c { * the configuration * * \return The ADI configuration for the given port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * // Displays the value of E_ADI_ANALOG_IN + * printf("Port Type: %d\n", adi_port_get_config(ANALOG_SENSOR_PORT)); + * } + * \endcode */ adi_port_config_e_t adi_port_get_config(uint8_t port); @@ -159,6 +189,16 @@ adi_port_config_e_t adi_port_get_config(uint8_t port); * will be returned * * \return The value stored for the given port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * printf("Port Value: %d\n", adi_get_value(ANALOG_SENSOR_PORT)); + * } + * \endcode */ int32_t adi_port_get_value(uint8_t port); @@ -176,6 +216,15 @@ int32_t adi_port_get_value(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * } + * \endcode */ int32_t adi_port_set_config(uint8_t port, adi_port_config_e_t type); @@ -197,47 +246,19 @@ int32_t adi_port_set_config(uint8_t port, adi_port_config_e_t type); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void initialize() { + * adi_port_set_config(DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT); + * adi_set_value(DIGITAL_SENSOR_PORT, HIGH); + * } + * \endcode */ int32_t adi_port_set_value(uint8_t port, int32_t value); -/******************************************************************************/ -/** PROS 2 Compatibility Functions **/ -/** **/ -/** These functions provide similar functionality to the PROS 2 API **/ -/******************************************************************************/ - -/** - * Used for adi_digital_write() to specify a logic HIGH state to output. - * - * In reality, using any non-zero expression or "true" will work to set a pin to - * HIGH. - */ -#define HIGH 1 -/** - * Used for adi_digital_write() to specify a logic LOW state to output. - * - * In reality, using a zero expression or "false" will work to set a pin to LOW. - */ -#define LOW 0 - -/** - * adi_pin_mode() state for a digital input. - */ -#define INPUT 0x00 -/** - * adi_pin_mode() state for a digital output. - */ -#define OUTPUT 0x01 -/** - * adi_pin_mode() state for an analog input. - */ -#define INPUT_ANALOG 0x02 - -/** - * adi_pin_mode() state for an analog output. - */ -#define OUTPUT_ANALOG 0x03 - /** * Calibrates the analog sensor on the specified port and returns the new * calibration value. @@ -251,6 +272,9 @@ int32_t adi_port_set_value(uint8_t port, int32_t value); * * Do not use this function when the sensor value might be unstable * (gyro rotation, accelerometer movement). + * + * \note The ADI currently returns data at 10ms intervals, in constrast to the + * calibrate function’s 1ms sample rate. * * This function uses the following values of errno when an error state is * reached: @@ -260,6 +284,17 @@ int32_t adi_port_set_value(uint8_t port, int32_t value); * The ADI port to calibrate (from 1-8, 'a'-'h', 'A'-'H') * * \return The average sensor value computed by this function + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * adi_analog_calibrate(ANALOG_SENSOR_PORT); + * printf("Calibrated Reading: %d\n", adi_analog_read_calibrated(ANALOG_SENSOR_PORT)); + * // All readings from then on will be calibrated + * } + * \endcode */ int32_t adi_analog_calibrate(uint8_t port); @@ -280,6 +315,18 @@ int32_t adi_analog_calibrate(uint8_t port); * * \return The analog sensor value, where a value of 0 reflects an input voltage * of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Reading: %d\n", adi_analog_read(ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_analog_read(uint8_t port); @@ -302,6 +349,18 @@ int32_t adi_analog_read(uint8_t port); * * \return The difference of the sensor value from its calibrated default from * -4095 to 4095 + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Reading: %d\n", adi_analog_read_calibrated(ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_analog_read_calibrated(uint8_t port); @@ -329,6 +388,19 @@ int32_t adi_analog_read_calibrated(uint8_t port); * * \return The difference of the sensor value from its calibrated default from * -16384 to 16384 + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * adi_analog_calibrate(ANALOG_SENSOR_PORT); + * printf("Sensor Reading: %d\n", adi_analog_read_calibrated_HR(ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_analog_read_calibrated_HR(uint8_t port); @@ -349,6 +421,18 @@ int32_t adi_analog_read_calibrated_HR(uint8_t port); * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') * * \return True if the pin is HIGH, or false if it is LOW + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Value: %d\n", adi_digital_read(DIGITAL_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_digital_read(uint8_t port); @@ -373,6 +457,20 @@ int32_t adi_digital_read(uint8_t port); * * \return 1 if the button is pressed and had not been pressed * the last time this function was called, 0 otherwise. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * if (adi_digital_get_new_press(DIGITAL_SENSOR_PORT)) { + * // Toggle pneumatics or other state operations + * } + * delay(5); + * } + * } + * \endcode */ int32_t adi_digital_get_new_press(uint8_t port); @@ -394,6 +492,20 @@ int32_t adi_digital_get_new_press(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT + * + * void opcontrol() { + * bool state = LOW; + * while (true) { + * state != state; + * adi_digital_write(DIGITAL_SENSOR_PORT, state); + * delay(5); // toggle the sensor value every 50ms + * } + * } + * \endcode */ int32_t adi_digital_write(uint8_t port, bool value); @@ -411,6 +523,15 @@ int32_t adi_digital_write(uint8_t port, bool value); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * adi_pin_mode(ANALOG_SENSOR_PORT, INPUT_ANALOG); + * } + * \endcode */ int32_t adi_pin_mode(uint8_t port, uint8_t mode); @@ -430,6 +551,17 @@ int32_t adi_pin_mode(uint8_t port, uint8_t mode); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * adi_motor_set(MOTOR_PORT, 127); // Go full speed forward + * delay(1000); + * adi_motor_set(MOTOR_PORT, 0); // Stop the motor + * } + * \endcode */ int32_t adi_motor_set(uint8_t port, int8_t speed); @@ -445,6 +577,18 @@ int32_t adi_motor_set(uint8_t port, int8_t speed); * The ADI port to get (from 1-8, 'a'-'h', 'A'-'H') * * \return The last set speed of the motor on the given port + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * adi_motor_set(MOTOR_PORT, 127); // Go full speed forward + * printf("Commanded Motor Power: %d\n", adi_motor_get(MOTOR_PORT)); // Will display 127 + * delay(1000); + * adi_motor_set(MOTOR_PORT, 0); // Stop the motor + * } + * \endcode */ int32_t adi_motor_get(uint8_t port); @@ -461,14 +605,25 @@ int32_t adi_motor_get(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * adi_motor_set(MOTOR_PORT, 127); // Go full speed forward + * delay(1000); + * // adi_motor_set(MOTOR_PORT, 0); // Stop the motor + * adi_motor_stop(MOTOR_PORT); // use this instead + * } + * \endcode */ int32_t adi_motor_stop(uint8_t port); /** * Reference type for an initialized encoder. * - * This merely contains the port number for the encoder, unlike its use as an - * object to store encoder data in PROS 2. + * This merely contains the port number for the encoder. */ typedef int32_t adi_encoder_t; @@ -481,13 +636,26 @@ typedef int32_t adi_encoder_t; * reached: * ENXIO - The given value is not within the range of ADI Ports * EADDRINUSE - The port is not configured as an encoder - * * \param enc * The adi_encoder_t object from adi_encoder_init() to read * * \return The signed and cumulative number of counts since the last start or * reset + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * printf("Encoder Value: %d\n", adi_encoder_get(enc)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_encoder_get(adi_encoder_t enc); @@ -510,6 +678,20 @@ int32_t adi_encoder_get(adi_encoder_t enc); * * \return An adi_encoder_t object to be stored and used for later calls to * encoder functions + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * printf("Encoder Value: %d\n", adi_encoder_get(enc)); + * delay(5); + * } + * } + * \endcode */ adi_encoder_t adi_encoder_init(uint8_t port_top, uint8_t port_bottom, bool reverse); @@ -530,6 +712,18 @@ adi_encoder_t adi_encoder_init(uint8_t port_top, uint8_t port_bottom, bool rever * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false); + * delay(1000); // Move the encoder around in this time + * adi_encoder_reset(enc); // The encoder is now zero again + * } + * \endcode */ int32_t adi_encoder_reset(adi_encoder_t enc); @@ -546,14 +740,25 @@ int32_t adi_encoder_reset(adi_encoder_t enc); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false); + * // Use the encoder + * adi_encoder_shutdown(enc); + * } + * \endcode */ int32_t adi_encoder_shutdown(adi_encoder_t enc); /** * Reference type for an initialized ultrasonic. * - * This merely contains the port number for the ultrasonic, unlike its use as an - * object to store ultrasonic data in PROS 2. + * This merely contains the port number for the ultrasonic. */ typedef int32_t adi_ultrasonic_t; @@ -574,6 +779,21 @@ typedef int32_t adi_ultrasonic_t; * * \return The distance to the nearest object in m^-4 (10000 indicates 1 meter), * measured from the sensor's mounting points. + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", adi_ultrasonic_get(ult)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_ultrasonic_get(adi_ultrasonic_t ult); @@ -594,6 +814,21 @@ int32_t adi_ultrasonic_get(adi_ultrasonic_t ult); * * \return An adi_ultrasonic_t object to be stored and used for later calls to * ultrasonic functions + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", adi_ultrasonic_get(ult)); + * delay(5); + * } + * } + * \endcode */ adi_ultrasonic_t adi_ultrasonic_init(uint8_t port_ping, uint8_t port_echo); @@ -610,14 +845,29 @@ adi_ultrasonic_t adi_ultrasonic_init(uint8_t port_ping, uint8_t port_echo); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", adi_ultrasonic_get(ult)); + * delay(5); + * } + * adi_ultrasonic_shutdown(ult); + * } + * \endcode */ int32_t adi_ultrasonic_shutdown(adi_ultrasonic_t ult); /** * Reference type for an initialized gyroscope. * - * This merely contains the port number for the gyroscope, unlike its use as an - * object to store gyro data in PROS 2. + * This merely contains the port number for the gyroscope. */ typedef int32_t adi_gyro_t; @@ -638,6 +888,21 @@ typedef int32_t adi_gyro_t; * The adi_gyro_t object for which the angle will be returned * * \return The gyro angle in degrees. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * + * void opcontrol() { + * adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", adi_gyro_get(gyro)); + * delay(5); + * } + * } + * \endcode */ double adi_gyro_get(adi_gyro_t gyro); @@ -662,6 +927,21 @@ double adi_gyro_get(adi_gyro_t gyro); * * \return An adi_gyro_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * + * void opcontrol() { + * adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", adi_gyro_get(gyro)); + * delay(5); + * } + * } + * \endcode */ adi_gyro_t adi_gyro_init(uint8_t port, double multiplier); @@ -678,6 +958,29 @@ adi_gyro_t adi_gyro_init(uint8_t port, double multiplier); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * + * void opcontrol() { + * adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER); + * uint32_t now = millis(); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", adi_gyro_get(gyro)); + * + * if (millis() - now > 2000) { + * // Reset the gyro every 2 seconds + * adi_gyro_reset(gyro); + * now = millis(); + * } + * + * delay(5); + * } + * } + * \endcode */ int32_t adi_gyro_reset(adi_gyro_t gyro); @@ -694,14 +997,36 @@ int32_t adi_gyro_reset(adi_gyro_t gyro); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * + * void opcontrol() { + * adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER); + * uint32_t now = millis(); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", adi_gyro_get(gyro)); + * + * if (millis() - now > 2000) { + * adi_gyro_shutdown(gyro); + * // Shut down the gyro after two seconds + * break; + * } + * + * delay(5); + * } + * } + * \endcode */ int32_t adi_gyro_shutdown(adi_gyro_t gyro); /** * Reference type for an initialized potentiometer. * - * This merely contains the port number for the potentiometer, unlike its use as an - * object to store potentiometer data in PROS 2. + * This merely contains the port number for the potentiometer. */ typedef int32_t adi_potentiometer_t; @@ -718,6 +1043,20 @@ typedef int32_t adi_potentiometer_t; * * \return An adi_potentiometer_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * + * void opcontrol() { + * adi_potentiometer_t potentiometer = adi_potentiometer_init(POTENTIOMETER_PORT); + * while (true) { + * // Print the potentiometer's angle + * printf("Angle: %lf\n", adi_potentiometer_get_angle(potentiometer)); + * delay(5); + * } + * } + * \endcode */ adi_potentiometer_t adi_potentiometer_init(uint8_t port); @@ -736,6 +1075,21 @@ adi_potentiometer_t adi_potentiometer_init(uint8_t port); * * \return An adi_potentiometer_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * #define POTENTIOMETER_TYPE E_ADI_POT_EDR + * + * void opcontrol() { + * adi_potentiometer_t potentiometer = adi_potentiometer_type_init(POTENTIOMETER_PORT, POTENTIOMETER_TYPE); + * while (true) { + * // Print the potentiometer's angle + * printf("Angle: %lf\n", adi_potentiometer_get_angle(potentiometer)); + * delay(5); + * } + * } + * \endcode */ adi_potentiometer_t adi_potentiometer_type_init(uint8_t port, adi_potentiometer_type_e_t potentiometer_type); @@ -754,6 +1108,20 @@ adi_potentiometer_t adi_potentiometer_type_init(uint8_t port, adi_potentiometer_ * The adi_potentiometer_t object for which the angle will be returned * * \return The potentiometer angle in degrees. + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * + * void opcontrol() { + * adi_potentiometer_t potentiometer = adi_potentiometer_t(POTENTIOMETER_PORT); + * while (true) { + * // Print the potnetiometer's angle + * printf("Angle: %lf\n", adi_potentiometer_get_angle(potentiometer)); + * delay(5); + * } + * } + * \endcode */ double adi_potentiometer_get_angle(adi_potentiometer_t potentiometer); @@ -761,7 +1129,7 @@ double adi_potentiometer_get_angle(adi_potentiometer_t potentiometer); * Reference type for an initialized addressable led. * * This merely contains the port number for the led, unlike its use as an - * object to store led data in PROS 2. + * object to store led data in the C++ API. */ typedef int32_t adi_led_t; @@ -779,6 +1147,21 @@ typedef int32_t adi_led_t; * * \return An adi_led_t object containing the given port, or PROS_ERR if the * initialization failed, setting errno + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the led to the colors in the buffer + * adi_led_set(led, buffer, 10); + * delay(5); + * } + * } + * \endcode */ adi_led_t adi_led_init(uint8_t port); @@ -795,6 +1178,25 @@ adi_led_t adi_led_init(uint8_t port); * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw * @param buffer_length length of buffer to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the led to the colors in the buffer + * adi_led_set(led, buffer, 10); + * delay(5); + * + * // Clear the led strip + * adi_led_clear(led); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_clear_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length); @@ -811,6 +1213,21 @@ int32_t adi_led_clear_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_lengt * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw * @param buffer_length length of buffer to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the led strip to the colors in the buffer + * adi_led_set(led, buffer, 10); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_set(adi_led_t led, uint32_t* buffer, uint32_t buffer_length); @@ -828,6 +1245,21 @@ int32_t adi_led_set(adi_led_t led, uint32_t* buffer, uint32_t buffer_length); * @param buffer_length length of buffer to clear * @param color color to set all the led strip value to * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the led strip to red + * adi_led_set_all(led, buffer, 10, 0xFF0000); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_set_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color); @@ -846,6 +1278,21 @@ int32_t adi_led_set_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, * @param color color to clear all the led strip to * @param pixel_position position of the pixel to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the first pixel to red + * adi_led_set_pixel(led, buffer, 10, 0xFF0000, 0); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_set_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, uint32_t pixel_position); @@ -863,9 +1310,70 @@ int32_t adi_led_set_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_lengt * @param buffer_length length of the input buffer * @param pixel_position position of the pixel to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the first pixel to red + * adi_led_set_pixel(led, buffer, 10, 0xFF0000, 0); + * delay(5); + * + * // Clear the first pixel + * adi_led_clear_pixel(led, buffer, 10, 0); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_clear_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t pixel_position); +/** + * \name Ease of use macro definitions + * These functions provide ease of use definitions for the ADI functions. + * @{ + */ + +/** + * Used for adi_digital_write() to specify a logic HIGH state to output. + * + * In reality, using any non-zero expression or "true" will work to set a pin to + * HIGH. + */ +#define HIGH 1 +/** + * Used for adi_digital_write() to specify a logic LOW state to output. + * + * In reality, using a zero expression or "false" will work to set a pin to LOW. + */ +#define LOW 0 + +/** + * adi_pin_mode() state for a digital input. + */ +#define INPUT 0x00 +/** + * adi_pin_mode() state for a digital output. + */ +#define OUTPUT 0x01 +/** + * adi_pin_mode() state for an analog input. + */ +#define INPUT_ANALOG 0x02 + +/** + * adi_pin_mode() state for an analog output. + */ +#define OUTPUT_ANALOG 0x03 + +/** @} Name: Ease of use macro definitions*/ + +/** @} Add to group: c-adi*/ + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/EZ-Template-Example-Project/include/pros/adi.hpp b/EZ-Template-Example-Project/include/pros/adi.hpp index c2fd258d..75429c98 100644 --- a/EZ-Template-Example-Project/include/pros/adi.hpp +++ b/EZ-Template-Example-Project/include/pros/adi.hpp @@ -1,39 +1,55 @@ /** * \file pros/adi.hpp + * \ingroup cpp-adi * * Contains prototypes for interfacing with the ADI. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-adi ADI (TriPort) C++ API + * \note The external ADI API can be found [here.](@ref ext-adi) + * \note Additional example code for this module can be found in its [Tutorial.](@ref adi) */ #ifndef _PROS_ADI_HPP_ #define _PROS_ADI_HPP_ #include +#include #include #include -#include +#include #include "pros/adi.h" -namespace pros { +#define LEGACY_TYPEDEF(old_name, new_name) \ + using old_name [[deprecated("use " #new_name " instead")]] = new_name +namespace pros { +namespace adi { + /** type definition for the pair of smart port and adi port for the basic adi devices */ using ext_adi_port_pair_t = std::pair; /** type definition for the triplet of smart port and two adi ports for the two wire adi devices*/ using ext_adi_port_tuple_t = std::tuple; + +/** + * \ingroup cpp-adi + */ +class Port { + /** + * \addtogroup cpp-adi + * @{ + */ -class ADIPort { public: /** * Configures an ADI port to act as a given sensor type. @@ -47,8 +63,23 @@ class ADIPort { * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param type * The configuration type for the port + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * #define POTENTIOMETER_TYPE pros::E_ADI_POT_EDR + * + * void opcontrol() { + * pros::ADIPotentiometer potentiometer (POTENTIOMETER_PORT, POTENTIOMETER_TYPE); + * while (true) { + * // Get the potentiometer angle + * std::cout << "Angle: " << potnetiometer.get_angle(); + * pros::delay(10); + * } + * } + * \endcode */ - explicit ADIPort(std::uint8_t adi_port, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED); + explicit Port(std::uint8_t adi_port, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED); /** * Configures an ADI port on an adi expander to act as a given sensor type. @@ -63,13 +94,35 @@ class ADIPort { * (from 1-8, 'a'-'h', 'A'-'H') to configure * \param type * The configuration type for the port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 'a' + * #define EXT_ADI_SMART_PORT 1 + * + * void initialize() { + * pros::adi::Port sensor ({{ EXT_ADI_SMART_PORT , ANALOG_SENSOR_PORT }}, E_ADI_ANALOG_IN); + * // Displays the value of E_ADI_ANALOG_IN + * std::cout << "Port Type: " << sensor.get_config(); + * } + * \endcode */ - ADIPort(ext_adi_port_pair_t port_pair, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED); + explicit Port(ext_adi_port_pair_t port_pair, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED); /** * Gets the configuration for the given ADI port. * * \return The ADI configuration for the given port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * void initialize() { + * adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * // Displays the value of E_ADI_ANALOG_IN + * printf("Port Type: %d\n", adi_port_get_config(ANALOG_SENSOR_PORT)); + * } + * \endcode */ std::int32_t get_config() const; @@ -77,6 +130,16 @@ class ADIPort { * Gets the value for the given ADI port. * * \return The value stored for the given port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Port sensor (ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * std::cout << "Port Value: " << sensor.get_value(); + * } + * \endcode */ std::int32_t get_value() const; @@ -88,6 +151,18 @@ class ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::Port sensor (ANALOG_SENSOR_PORT, E_ADI_DIGITAL_IN); + * // Do things as a digital sensor + * // Digital is unplugged and an analog is plugged in + * sensor.set_config(E_ADI_ANALOG_IN); + * } + * \endcode */ std::int32_t set_config(adi_port_config_e_t type) const; @@ -102,15 +177,57 @@ class ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::Port sensor (DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT); + * sensor.set_value(DIGITAL_SENSOR_PORT, HIGH); + * } + * \endcode */ std::int32_t set_value(std::int32_t value) const; + /** + * Gets the port of the sensor. + * + * \return returns a tuple of integer ports. + * + * \note The parts of the tuple are {smart port, adi port, second adi port (when applicable)}. + * + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 // 'A' + * + * void initialize() { + * pros::adi::AnalogIn sensor (DIGITAL_SENSOR_PORT); + * + * // Getting values from the tuple using std::get + * int sensorSmartPort = std::get<0>(sensor.get_port()); // First value + * int sensorAdiPort = std::get<1>(sensor.get_port()); // Second value + * + * // Prints the first and second value from the port tuple (The Adi Port. The first value is the Smart Port) + * printf("Sensor Smart Port: %d\n", sensorSmartPort); + * printf("Sensor Adi Port: %d\n", sensorAdiPort); + * } + * \endcode + */ + virtual ext_adi_port_tuple_t get_port() const; + protected: std::uint8_t _smart_port; std::uint8_t _adi_port; }; +///@} -class ADIAnalogIn : protected ADIPort { +class AnalogIn : protected Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as an Analog Input. @@ -125,25 +242,49 @@ class ADIAnalogIn : protected ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT); + * while (true) { + * // Use the sensor + * } + * } + * \endcode */ - explicit ADIAnalogIn(std::uint8_t adi_port); + explicit AnalogIn(std::uint8_t adi_port); /** - * Configures an ADI port on an adi expander to act as an Analog Input. + * Configures an ADI port to act as an Analog Input. * * This function uses the following values of errno when an error state is * reached: * ENXIO - Either the ADI port value or the smart port value is not within its * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * - * \param port_pair - * The pair of the smart port number (from 1-22) and the - * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * \param adi_port + * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define EXT_ADI_SENSOR_PORT 1 + * #define ADI_PORT 'a' + * + * void opcontrol() { + * pros::ADIAnalogIn sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); + * while (true) { + * // Use the sensor + * } + * } + * \endcode */ - ADIAnalogIn(ext_adi_port_pair_t port_pair); + explicit AnalogIn(ext_adi_port_pair_t port_pair); /** * Calibrates the analog sensor on the specified port and returns the new @@ -153,29 +294,44 @@ class ADIAnalogIn : protected ADIPort { * this time and computes an average from approximately 500 samples, 1 ms * apart, for a 0.5 s period of calibration. The average value thus calculated * is returned and stored for later calls to the - * pros::ADIAnalogIn::get_value_calibrated() and - * pros::ADIAnalogIn::get_value_calibrated_HR() functions. These functions + * pros::AnalogIn::get_value_calibrated() and + * pros::AnalogIn::get_value_calibrated_HR() functions. These functions * will return the difference between this value and the current sensor value * when called. * * Do not use this function when the sensor value might be unstable (gyro * rotation, accelerometer movement). + * + * \note The ADI currently returns data at 10ms intervals, in contrast to the + * calibrate function’s 1ms sample rate. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port is not configured as an analog input * * \return The average sensor value computed by this function + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT); + * sensor.calibrate(ANALOG_SENSOR_PORT); + * std::cout << "Calibrated Reading:" << sensor.get_value_calibrated(); + * // All readings from then on will be calibrated + * } + * \endcode */ std::int32_t calibrate() const; /** * Gets the 12 bit calibrated value of an analog input port. * - * The pros::ADIAnalogIn::calibrate() function must be run first. This + * The pros::adi::AnalogIn::calibrate() function must be run first. This * function is inappropriate for sensor values intended for integration, as * round-off error can accumulate causing drift over time. Use - * pros::ADIAnalogIn::get_value_calibrated_HR() instead. + * pros::adi::AnalogIn::get_value_calibrated_HR() instead. * * This function uses the following values of errno when an error state is * reached: @@ -183,13 +339,25 @@ class ADIAnalogIn : protected ADIPort { * * \return The difference of the sensor value from its calibrated default from * -4095 to 4095 + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT); + * sensor.calibrate(ANALOG_SENSOR_PORT); + * std::cout << "Calibrated Reading:" << sensor.get_value_calibrated(); + * // All readings from then on will be calibrated + * } + * \endcode */ std::int32_t get_value_calibrated() const; /** * Gets the 16 bit calibrated value of an analog input port. * - * The pros::ADIAnalogIn::calibrate() function must be run first. This is + * The pros::adi::AnalogIn::calibrate() function must be run first. This is * intended for integrated sensor values such as gyros and accelerometers to * reduce drift due to round-off, and should not be used on a sensor such as a * line tracker or potentiometer. @@ -205,32 +373,72 @@ class ADIAnalogIn : protected ADIPort { * * \return The difference of the sensor value from its calibrated default from * -16384 to 16384 + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT); + * sensor.calibrate(ANALOG_SENSOR_PORT); + * std::cout << "Calibrated Reading:" << sensor.get_value_calibrated(); + * // All readings from then on will be calibrated + * } + * \endcode */ std::int32_t get_value_calibrated_HR() const; /** - * Gets the 12-bit value of the specified port. - * - * The value returned is undefined if the analog pin has been switched to a - * different mode. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port is not configured as an analog input - * + * Reads an analog input channel and returns the 12-bit value. + * + * The value returned is undefined if the analog pin has been switched to a different mode. The meaning of the returned value varies depending on the sensor attached. + * + * Inherited from ADIPort::get_value. + * + * This function uses the following values of errno when an error state is reached: + * EADDRINUSE - The port is not configured as an analog input (e.g. the port has been reconfigured) + * * \return The analog sensor value, where a value of 0 reflects an input * voltage of nearly 0 V and a value of 4095 reflects an input voltage of * nearly 5 V + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT); + * std::cout << "Sensor Reading:" << sensor.get_value(); + * } + * \endcode */ - using ADIPort::get_value; + using Port::get_value; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * AnalogIn [smart_port: analog_in._smart_port, adi_port: analog_in._adi_port, + * value calibrated: (12 bit calibrated value), + * value calibrated HR: (16 bit calibrated value), value: (12 bit value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::AnalogIn& analog_in); + + using Port::get_port; }; +///@} + // using ADIPotentiometer = ADIAnalogIn; -using ADILineSensor = ADIAnalogIn; -using ADILightSensor = ADIAnalogIn; -using ADIAccelerometer = ADIAnalogIn; +using LineSensor = AnalogIn; +using LightSensor = AnalogIn; +using Accelerometer = AnalogIn; -class ADIAnalogOut : private ADIPort { +class AnalogOut : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as an Analog Output. @@ -242,8 +450,18 @@ class ADIAnalogOut : private ADIPort { * * \param adi_port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::AnalogOut sensor (ANALOG_SENSOR_PORT); + * // Use the sensor + * } + * @endcode */ - explicit ADIAnalogOut(std::uint8_t adi_port); + explicit AnalogOut(std::uint8_t adi_port); /** * Configures an ADI port on an adi_expander to act as an Analog Output. @@ -256,30 +474,64 @@ class ADIAnalogOut : private ADIPort { * \param port_pair * The pair of the smart port number (from 1-22) and the * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure - * + * + * \b Example + * \code + * #define EXT_ADI_SMART_PORT 1 + * #define ADI_PORT 'a' + * + * void opcontrol() { + * pros::AnalogOut sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); + * // Use the sensor + * } + * \endcode */ - ADIAnalogOut(ext_adi_port_pair_t port_pair); + explicit AnalogOut(ext_adi_port_pair_t port_pair); /** - * Sets the value for the given ADI port. + * Sets the output for the Analog Output from 0 (0V) to 4095 (5V). * - * This only works on ports configured as outputs, and the behavior will - * change depending on the configuration of the port. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port is not configured as an analog output + * Inherited from ADIPort::set_value. + * + * This function uses the following values of errno when an error state is reached: + * EACCES - Another resource is currently trying to access the ADI. * * \param value * The value to set the ADI port to * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::AnalogOut sensor (ANALOG_SENSOR_PORT); + * sensor.set_value(4095); // Set the port to 5V + * } + * \endcode */ - using ADIPort::set_value; + using Port::set_value; + + using Port::get_port; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * AnalogOut [smart_port: analog_out._smart_port, adi_port: analog_out._adi_port, + * value: (value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::AnalogOut& analog_out); }; +///@} -class ADIDigitalOut : private ADIPort { +class DigitalOut : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as a Digital Output. @@ -293,8 +545,23 @@ class ADIDigitalOut : private ADIPort { * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param init_state * The initial state for the port + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * bool state = LOW; + * pros::adi::DigitalOut sensor (DIGITAL_SENSOR_PORT, state); + * while (true) { + * state != state; + * sensor.set_value(state); + * pros::delay(10); // toggle the sensor value every 50ms + * } + * } + * \endcode */ - explicit ADIDigitalOut(std::uint8_t adi_port, bool init_state = LOW); + explicit DigitalOut(std::uint8_t adi_port, bool init_state = LOW); /** * Configures an ADI port on an adi_expander to act as a Digital Output. @@ -309,28 +576,74 @@ class ADIDigitalOut : private ADIPort { * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param init_state * The initial state for the port + * + * \b Example + * \code + * #define EXT_ADI_SMART_PORT 1 + * #define ADI_PORT 'a' + * + * void opcontrol() { + * bool state = LOW; + * pros::adi::DigitalOut sensor ( {{ EXT_ADI_SMART_PORT , ADI_PORT }}); + * while (true) { + * state != state; + * sensor.set_value(state); + * pros::delay(10); // toggle the sensor value every 50ms + * } + * } + * \endcode */ - ADIDigitalOut(ext_adi_port_pair_t port_pair, bool init_state = LOW); + explicit DigitalOut(ext_adi_port_pair_t port_pair, bool init_state = LOW); /** - * Sets the value for the given ADI port. - * - * This only works on ports configured as outputs, and the behavior will - * change depending on the configuration of the port. + * Sets the digital value (1 or 0) of a pin. * + * Inherited from ADIPort::set_value. + * * This function uses the following values of errno when an error state is * reached: - * ENODEV - The port is not configured as a digital output + * EADDRINUSE - The port is not configured as a digital output (e.g. the port has been reconfigured) * * \param value * The value to set the ADI port to * * \return if the operation was successful or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * bool state = LOW; + * pros::adi::DigitalOut sensor (DIGITAL_SENSOR_PORT); + * while (true) { + * state != state; + * sensor.set_value(state); + * pros::delay(10); // toggle the sensor value every 50ms + * } + * } + * \endcode */ - using ADIPort::set_value; + using Port::set_value; + + using Port::get_port; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * DigitalOut [smart_port: digital_out._smart_port, adi_port: digital_out._adi_port, + * value: (value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::DigitalOut& digital_out); }; +///@} -class ADIDigitalIn : private ADIPort { +class DigitalIn : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as a Digital Input. @@ -342,8 +655,18 @@ class ADIDigitalIn : private ADIPort { * * \param adi_port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::adi::DigitalIn sensor (ANALOG_SENSOR_PORT); + * // Use the sensor + * } + * \endcode */ - explicit ADIDigitalIn(std::uint8_t adi_port); + explicit DigitalIn(std::uint8_t adi_port); /** * Configures an ADI port on an adi_expander to act as a Digital Input. @@ -356,8 +679,19 @@ class ADIDigitalIn : private ADIPort { * \param port_pair * The pair of the smart port number (from 1-22) and the * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define EXT_ADI_SMART_PORT 1 + * #define ADI_PORT 'a' + * + * void opcontrol() { + * pros::adi::DigitalIn sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); + * // Use the sensor + * } + * \endcode */ - ADIDigitalIn(ext_adi_port_pair_t port_pair); + explicit DigitalIn(ext_adi_port_pair_t port_pair); /** * Gets a rising-edge case for a digital button press. @@ -376,24 +710,74 @@ class ADIDigitalIn : private ADIPort { * * \return 1 if the button is pressed and had not been pressed the last time * this function was called, 0 otherwise. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::adi::DigitalIn sensor (DIGITAL_SENSOR_PORT); + * while (true) { + * if (sensor.get_new_press()) { + * // Toggle pneumatics or other state operations + * } + * pros::delay(10); + * } + * } + * \endcode */ std::int32_t get_new_press() const; /** - * Gets the value for the given ADI port. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port is not configured as a digital input + * Gets the digital value (1 or 0) of a pin. + * + * Inherited from ADIPort::get_value. + * + * This function uses the following values of errno when an error state is reached: + * + * EADDRINUSE - The port is not configured as a digital input (e.g. the port has been reconfigured) + * + * Analogous to adi_digital_read. * * \return The value stored for the given port + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::adi::DigitalIn sensor (DIGITAL_SENSOR_PORT); + * while (true) { + * std::cout << "Sensor Value:" << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - using ADIPort::get_value; + using Port::get_value; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * DigitalIn [smart_port: digital_in._smart_port, adi_port: digital_in._adi_port, + * value: (value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::DigitalIn& digital_in); + + using Port::get_port; }; -using ADIButton = ADIDigitalIn; +///@} + +//Derived Class(es) from DigitalIn +using Button = DigitalIn; -class ADIMotor : private ADIPort { +class Motor : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as a Motor. @@ -405,8 +789,21 @@ class ADIMotor : private ADIPort { * * \param adi_port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Motor motor (MOTOR_PORT); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.set_value(0); // Stop the motor + * } + * \endcode */ - explicit ADIMotor(std::uint8_t adi_port); + explicit Motor(std::uint8_t adi_port); /** * Configures an ADI port on an adi_expander to act as a Motor. @@ -419,8 +816,22 @@ class ADIMotor : private ADIPort { * \param port_pair * The pair of the smart port number (from 1-22) and the * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define EXT_ADI_SMART_PORT 1 + * #define ADI_MOTOR_PORT 'a' + * + * void opcontrol() { + * pros::adi::Motor motor ( {{ EXT_ADI_SMART_PORT , ADI_MOTOR_PORT}} ); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.set_value(0); // Stop the motor + * } + * \endcode */ - ADIMotor(ext_adi_port_pair_t port_pair); + explicit Motor(ext_adi_port_pair_t port_pair); /** * Stops the motor on the given port. @@ -431,6 +842,19 @@ class ADIMotor : private ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Motor motor (MOTOR_PORT); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.stop(); // Stop the motor + * } + * \endcode */ std::int32_t stop() const; @@ -447,8 +871,21 @@ class ADIMotor : private ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Motor motor (MOTOR_PORT); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.set_value(0); // Stop the motor + * } + * \endcode */ - using ADIPort::set_value; + using Port::set_value; /** * Gets the last set speed of the motor on the given port. @@ -457,12 +894,33 @@ class ADIMotor : private ADIPort { * reached: * ENODEV - The port is not configured as a motor * - * \return The last set speed of the motor on the given port + * \return The last set speed of the motor on the given + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Motor motor (MOTOR_PORT); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.set_value(0); // Stop the motor + * } + * \endcode */ - using ADIPort::get_value; + using Port::get_value; + + using Port::get_port; }; -class ADIEncoder : private ADIPort { +///@} + +class Encoder : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures a set of ADI ports to act as an Encoder. @@ -478,8 +936,19 @@ class ADIEncoder : private ADIPort { * The "bottom" wire from the encoder sensor * \param reverse * If "true", the sensor will count in the opposite direction + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); + * // Use the sensor + * } + * \endcode */ - ADIEncoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed = false); + explicit Encoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed = false); /** * Configures a set of ADI ports on an adi_expander to act as an Encoder. @@ -494,13 +963,22 @@ class ADIEncoder : private ADIPort { * sensor with the removable cover side up, and the "bottom" wire from * the encoder sensor * \param reverse - * If "true", the sensor will count in the opposite direction + * If "true", the sensor will count in theopposite direction + * + * \b Example + * \code + * #define PORT_TOP 'A' + * #define PORT_BOTTOM 'B' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Encoder sensor ({ SMART_PORT, PORT_TOP, PORT_BOTTOM }, false); + * // Use the sensor + * } + * \endcode */ - ADIEncoder(ext_adi_port_tuple_t port_tuple, bool reversed = false); + explicit Encoder(ext_adi_port_tuple_t port_tuple, bool reversed = false); - // Delete copy constructor to prevent a compilation error from the constructor above. - ADIEncoder(ADIEncoder &) = delete; - /** * Sets the encoder value to zero. * @@ -513,6 +991,18 @@ class ADIEncoder : private ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); + * delay(1000); // Move the encoder around in this time + * sensor.reset(); // The encoder is now zero again + * } + * \endcode */ std::int32_t reset() const; @@ -526,12 +1016,45 @@ class ADIEncoder : private ADIPort { * ENODEV - The port is not configured as a motor * * \return The signed and cumulative number of counts since the last start or - * reset + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * std::cout << "Encoder Value: " << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ std::int32_t get_value() const; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * Encoder [smart_port: encoder._smart_port, adi_port: encoder._adi_port, + * value: (value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::Encoder& encoder); + ext_adi_port_tuple_t get_port() const override; + + private: + ext_adi_port_pair_t _port_pair; + }; -class ADIUltrasonic : private ADIPort { +///@} + +class Ultrasonic : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures a set of ADI ports to act as an Ultrasonic sensor. @@ -547,8 +1070,23 @@ class ADIUltrasonic : private ADIPort { * \param port_echo * The port connected to the yellow INPUT cable. This should be in the * next highest port following port_ping. + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * pros::adi::Ultrasonic sensor (PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * std::cout << "Distance: " << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIUltrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo); + explicit Ultrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo); /** * Configures a set of ADI ports on an adi_expander to act as an Ultrasonic sensor. @@ -563,8 +1101,24 @@ class ADIUltrasonic : private ADIPort { * OUTPUT cable (1, 3, 5, 7 or 'A', 'C', 'E', 'G'), and the port * connected to the yellow INPUT cable (the next) highest port * following port_ping). + * + * \b Example + * \code + * #define PORT_PING 'A' + * #define PORT_ECHO 'B' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Ultrasonic sensor ( {{ SMART_PORT, PORT_PING, PORT_ECHO }} ); + * while (true) { + * // Print the distance read by the ultrasonic + * std::cout << "Distance: " << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIUltrasonic(ext_adi_port_tuple_t port_tuple); + explicit Ultrasonic(ext_adi_port_tuple_t port_tuple); /** * Gets the current ultrasonic sensor value in centimeters. @@ -579,19 +1133,42 @@ class ADIUltrasonic : private ADIPort { * * \return The distance to the nearest object in m^-4 (10000 indicates 1 * meter), measured from the sensor's mounting points. + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * pros::adi::Ultrasonic sensor (PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * std::cout << "Distance: " << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ std::int32_t get_value() const; + + using Port::get_port; }; -class ADIGyro : private ADIPort { +///@} + +class Gyro : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Initializes a gyroscope on the given port. If the given port has not * previously been configured as a gyro, then this function starts a 1300ms * calibration period. * - * It is highly recommended that an ADIGyro object be created in initialize() - * when the robot is stationary to ensure proper calibration. If an ADIGyro + * It is highly recommended that an Gyro object be created in initialize() + * when the robot is stationary to ensure proper calibration. If an Gyro * object is declared at the global scope, a hardcoded 1300ms delay at the * beginning of initialize will be necessary to ensure that the gyro's * returned values are correct at the beginning of autonomous/opcontrol. @@ -605,17 +1182,31 @@ class ADIGyro : private ADIPort { * The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H') * \param multiplier * A scalar value that will be multiplied by the gyro heading value - * supplied by the ADI + * supplied by the + * + * \b Example + * \code + * #define GYRO_PORT 1 + * + * void opcontrol() { + * pros::adi::Gyro gyro (GYRO_PORT); + * while (true) { + * // Get the gyro heading + * std::cout << "Distance: " << gyro.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - explicit ADIGyro(std::uint8_t adi_port, double multiplier = 1); + explicit Gyro(std::uint8_t adi_port, double multiplier = 1); /** * Initializes a gyroscope on the given port of an adi expander. If the given * port has not previously been configured as a gyro, then this function starts * a 1300ms calibration period. * - * It is highly recommended that an ADIGyro object be created in initialize() - * when the robot is stationary to ensure proper calibration. If an ADIGyro + * It is highly recommended that an adi::Gyro object be created in initialize() + * when the robot is stationary to ensure proper calibration. If an adi::Gyro * object is declared at the global scope, a hardcoded 1300ms delay at the * beginning of initialize will be necessary to ensure that the gyro's * returned values are correct at the beginning of autonomous/opcontrol. @@ -630,10 +1221,25 @@ class ADIGyro : private ADIPort { * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param multiplier * A scalar value that will be multiplied by the gyro heading value - * supplied by the ADI + * supplied by the + * + * \b Example + * \code + * #define ADI_GYRO_PORT 'a' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Gyro gyro ({{ SMART_PORT , ADI_GYRO_PORT }}); + * while (true) { + * // Get the gyro heading + * std::cout << "Distance: " << gyro.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIGyro(ext_adi_port_pair_t port_pair, double multiplier = 1); - + explicit Gyro(ext_adi_port_pair_t port_pair, double multiplier = 1); + /** * Gets the current gyro angle in tenths of a degree. Unless a multiplier is * applied to the gyro, the return value will be a whole number representing @@ -647,6 +1253,20 @@ class ADIGyro : private ADIPort { * ENODEV - The port is not configured as a gyro * * \return The gyro angle in degrees. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * + * void opcontrol() { + * pros::adi::Gyro gyro (GYRO_PORT); + * while (true) { + * // Get the gyro heading + * std::cout << "Distance: " << gyro.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ double get_value() const; @@ -659,11 +1279,41 @@ class ADIGyro : private ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * + * void opcontrol() { + * pros::adi::Gyro gyro (GYRO_PORT); + * std::uint32_t now = pros::millis(); + * while (true) { + * // Get the gyro heading + * std::cout << "Distance: " << gyro.get_value(); + * + * if (pros::millis() - now > 2000) { + * // Reset the gyro every 2 seconds + * gyro.reset(); + * now = pros::millis(); + * } + * + * pros::delay(10); + * } + * } + * \endcode */ std::int32_t reset() const; + + using Port::get_port; }; -class ADIPotentiometer : public ADIAnalogIn { +///@} + +class Potentiometer : public AnalogIn { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as a Potentiometer. @@ -677,8 +1327,23 @@ class ADIPotentiometer : public ADIAnalogIn { * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param potentiometer_type * An adi_potentiometer_type_e_t enum value specifying the potentiometer version type + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * #define POTENTIOMETER_TYPE pros::E_ADI_POT_EDR + * + * void opcontrol() { + * pros::adi::Potentiometer potentiometer (POTENTIOMETER_PORT, POTENTIOMETER_TYPE); + * while (true) { + * // Get the potentiometer angle + * std::cout << "Angle: " << potentiometer.get_angle(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIPotentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR); + explicit Potentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR); /** * Configures an ADI port on an adi_expander to act as a Potentiometer. @@ -693,8 +1358,23 @@ class ADIPotentiometer : public ADIAnalogIn { * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param potentiometer_type * An adi_potentiometer_type_e_t enum value specifying the potentiometer version type + * + * \b Example + * \code + * #define ADI_POTENTIOMETER_PORT 'a' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Potentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }}); + * while (true) { + * // Get the potentiometer angle + * std::cout << "Angle: " << potentiometer.get_angle(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIPotentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR); + explicit Potentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR); /** * Gets the current potentiometer angle in tenths of a degree. @@ -706,8 +1386,23 @@ class ADIPotentiometer : public ADIAnalogIn { * reached: * ENXIO - The given value is not within the range of ADI Ports * EADDRINUSE - The port is not configured as a potentiometer - + * * \return The potentiometer angle in degrees. + * + * \b Example + * \code + * #define ADI_POTENTIOMETER_PORT 'a' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Potentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }}); + * while (true) { + * // Get the potentiometer angle + * std::cout << "Angle: " << potentiometer.get_angle(); + * pros::delay(10); + * } + * } + * \endcode */ double get_angle() const; @@ -725,7 +1420,7 @@ class ADIPotentiometer : public ADIAnalogIn { * voltage of nearly 0 V and a value of 4095 reflects an input voltage of * nearly 5 V */ - using ADIAnalogIn::get_value; + using AnalogIn::get_value; /** * Calibrates the potentiometer on the specified port and returns the new @@ -735,7 +1430,7 @@ class ADIPotentiometer : public ADIAnalogIn { * this time and computes an average from approximately 500 samples, 1 ms * apart, for a 0.5 s period of calibration. The average value thus calculated * is returned and stored for later calls to the - * pros::ADIPotentiometer::get_value_calibrated() function. This function + * pros::adi::Potentiometer::get_value_calibrated() function. This function * will return the difference between this value and the current sensor value * when called. * @@ -747,12 +1442,12 @@ class ADIPotentiometer : public ADIAnalogIn { * * \return The average potentiometer value computed by this function */ - using ADIAnalogIn::calibrate; + using AnalogIn::calibrate; /** * Gets the 12 bit calibrated value of a potentiometer port. * - * The pros::ADIPotentiometer::calibrate() function must be run first. + * The pros::adi::Potentiometer::calibrate() function must be run first. * * This function uses the following values of errno when an error state is * reached: @@ -761,10 +1456,27 @@ class ADIPotentiometer : public ADIAnalogIn { * \return The difference of the potentiometer value from its calibrated default from * -4095 to 4095 */ - using ADIAnalogIn::get_value_calibrated; + using AnalogIn::get_value_calibrated; + + /** + * This is the overload for the << operator for printing to streams + * Potentiometer [value: (value), value calibrated: (calibrated value), + * angle: (angle)] + * Prints in format(this below is all in one line with no new line): + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::Potentiometer& potentiometer); + + using Port::get_port; + }; -class ADILed : protected ADIPort { +///@} + +class Led : protected Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * @brief Configures an ADI port to act as a LED. @@ -778,8 +1490,24 @@ class ADILed : protected ADIPort { * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param length * The number of LEDs in the chain + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set entire LED strip to red + * led.set_all(0xFF0000); + * pros::delay(20); + * } + * } + * \endcode + * */ - ADILed(std::uint8_t adi_port, std::uint32_t length); + explicit Led(std::uint8_t adi_port, std::uint32_t length); /** * @brief Configures an ADI port on a adi_expander to act as a LED. @@ -794,8 +1522,24 @@ class ADILed : protected ADIPort { * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param length * The number of LEDs in the chain + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define SMART_PORT 1 + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led ({{ SMART_PORT , LED_PORT }}, LED_LENGTH); + * while (true) { + * // Set entire LED strip to red + * led.set_all(0xFF0000); + * pros::delay(20); + * } + * } + * \endcode */ - ADILed(ext_adi_port_pair_t port_pair, std::uint32_t length); + explicit Led(ext_adi_port_pair_t port_pair, std::uint32_t length); /** * @brief Operator overload to access the buffer in the ADILed class, it is @@ -803,6 +1547,27 @@ class ADILed : protected ADIPort { * * @param i 0 indexed pixel of the lED * @return uint32_t& the address of the buffer at i to modify + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first 3 pixels to red, green, and blue + * led.set_pixel(0xFF0000, 0); + * led.set_pixel(0x00FF00, 1); + * led.set_pixel(0x0000FF, 2); + * pros::delay(20); + * + * // Use the [] operator to set the first pixel to black + * led.operator[](0) = 0x000000; + * led.update(); + * pros::delay(20); + * } + * } */ std::uint32_t& operator[] (size_t i); @@ -816,6 +1581,27 @@ class ADILed : protected ADIPort { * EADDRINUSE - The port is not configured for ADI output * * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first 3 pixels to red, green, and blue + * led.set_pixel(0xFF0000, 0); + * led.set_pixel(0x00FF00, 1); + * led.set_pixel(0x0000FF, 2); + * pros::delay(20); + * + * // Clear the led strip of color + * led.clear(); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t clear_all(); std::int32_t clear(); @@ -830,6 +1616,29 @@ class ADILed : protected ADIPort { * EADDRINUSE - The port is not configured for ADI output * * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first 3 pixels to red, green, and blue + * led.set_pixel(0xFF0000, 0); + * led.set_pixel(0x00FF00, 1); + * led.set_pixel(0x0000FF, 2); + * pros::delay(20); + * + * // Use the [] operator to set the first pixel to black + * led.operator[](0) = 0x000000; + * // Update the led strip with the new values + * led.update(); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t update() const; @@ -843,6 +1652,21 @@ class ADILed : protected ADIPort { * * @param color color to set all the led strip value to * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the entire led strip to blue + * led.set_all(0x0000FF); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t set_all(uint32_t color); @@ -857,6 +1681,21 @@ class ADILed : protected ADIPort { * @param color color to clear all the led strip to * @param pixel_position position of the pixel to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first pixel to blue + * led.set_pixel(0x0000FF, 0); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t set_pixel(uint32_t color, uint32_t pixel_position); @@ -870,6 +1709,25 @@ class ADILed : protected ADIPort { * * @param pixel_position position of the pixel to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first pixel to blue + * led.set_pixel(0x0000FF, 0); + * pros::delay(20); + * + * // Clear the first pixel + * led.clear_pixel(0); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t clear_pixel(uint32_t pixel_position); @@ -882,15 +1740,306 @@ class ADILed : protected ADIPort { * EADDRINUSE - The port is not configured for ADI output * * @return The length (in pixels) of the LED strip + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Get the length of the led strip + * int length = led.length(); + * pros::lcd::print(1, "Length: %d", length); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t length(); + using Port::get_port; + protected: std::vector _buffer; }; +///@} + +/// @brief Alias for ADILed +using LED = Led; + +class Pneumatics : public DigitalOut { + /** + * \addtogroup cpp-adi + * @{ + */ + public: + + /** + * Creates a Pneumatics object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of ADI Ports + * + * \param adi_port + * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * \param start_extended + * If true, the pneumatic will start extended when the program starts. + * By default, the piston starts retracted when the program starts. + * \param extended_is_low + * A flag to set whether the the pneumatic is extended when the ADI + * it receives a high or a low value. When true, the extended state + * corresponds to a output low on the ADI port. This allows the user + * to reverse the behavior of the pneumatics if needed. + * + * /b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics left_piston('a', false); // Starts retracted, extends when the ADI port is high + * pros::adi::Pneumatics right_piston('b', false, true); // Starts retracted, extends when the ADI port is low + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) { + * left_piston.retract(); + * } + * + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_2)) { + * left_piston.retract(); + * } + * + * pros::delay(10); + * } + * + * \endcode + */ + explicit Pneumatics(std::uint8_t adi_port, + bool start_extended, + bool extended_is_low = false + ); + + /** + * Creates a Pneumatics object for the given port pair. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of ADI Ports + * + * \param port_pair + * The pair of the smart port number (from 1-22) and the + * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * \param start_extended + * If true, the pneumatic will start extended when the program starts. + * By default, the piston starts retracted when the program starts. + * \param extended_is_low + * A flag to set whether the the pneumatic is extended when the ADI + * it receives a high or a low value. When true, the extended state + * corresponds to a output low on the ADI port. This allows the user + * to reverse the behavior of the pneumatics if needed. + * + * /b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics left_piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high + * pros::adi::Pneumatics right_piston({1, 'b'}, false, true); // Starts retracted, extends when the ADI port is low + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) { + * left_piston.retract(); + * } + * + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R2)) { + * left_piston.retract(); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + explicit Pneumatics(ext_adi_port_pair_t port_pair, + bool start_extended, + bool extended_is_low = false + ); + + /** + * Extends the piston, if not already extended. + * + * \return 1 if the piston newly extended, 0 if the piston was already + * extended, or PROS_ERR is the operation failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { + * left_piston.retract(); + * } + * if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { + * left_piston.toggle(); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + std::int32_t extend(); -// Alias for ADILed -using ADILED = ADILed; + /** + * Retracts the piston, if not already retracted. + * + * \return 1 if the piston newly retracted, 0 if the piston was already + * retracted, or PROS_ERR is the operation failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { + * left_piston.retract(); + * } + * if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { + * left_piston.toggle(); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + std::int32_t retract(); + + /** + * Puts the piston into the opposite state of its current state. + * If it is retracted, it will extend. If it is extended, it will retract. + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \return 1 if the piston successfully toggled, or PROS_ERR if the + * operation failed, setting errno. + * + *\b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { + * left_piston.retract(); + * } + * if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { + * left_piston.toggle(); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + std::int32_t toggle(); + + /** + * Returns whether the piston is extended or not. + * + * \return true if the piston is extended, false if it is retracted. + * + * \b Example + * \code + * #define ADI_PNEUMATICS_PORT 'a' + * + * void opcontrol() { + * pros::adi::Pneumatics pneumatics (ADI_PNEUMATICS_PORT); + * while (true) { + * // Check if the piston is extended + * if (pneumatics.is_extended()) { + * printf("The pneumatic is extended\n"); + * } + * else { + * printf("The pneumatic is not extended\n"); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + bool is_extended() const; + +private: + bool state; // Holds the physical state of the ADI port + bool extended_is_low; // A flag that sets whether extended corresponds to + // a low signal + + +}; +///@} + +} // namespace adi + +/* +Pros4 upgrade backwards compatibility for ADI api. + +Prints a deprecated warning when user uses old pros::ADIDevice style API. +Remove when and if fully removing old API. +*/ +LEGACY_TYPEDEF(ADIPort, pros::adi::Port); +LEGACY_TYPEDEF(ADIAnalogIn, pros::adi::AnalogIn); +LEGACY_TYPEDEF(ADIAnalogOut, pros::adi::AnalogOut); +LEGACY_TYPEDEF(ADIDigitalIn, pros::adi::DigitalIn); +LEGACY_TYPEDEF(ADIDigitalOut, pros::adi::DigitalOut); +LEGACY_TYPEDEF(ADIMotor, pros::adi::Motor); +LEGACY_TYPEDEF(ADIGyro, pros::adi::Gyro); +LEGACY_TYPEDEF(ADIEncoder, pros::adi::Encoder); +LEGACY_TYPEDEF(ADIUltrasonic, pros::adi::Ultrasonic); +LEGACY_TYPEDEF(LED, pros::adi::Led); + +// Backwards Compatibility for Derived Classes +LEGACY_TYPEDEF(ADIPotentiometer,pros::adi::Potentiometer); +LEGACY_TYPEDEF(ADILineSensor,pros::adi::LineSensor); +LEGACY_TYPEDEF(ADILightSensor,pros::adi::LightSensor); +LEGACY_TYPEDEF(ADIAccelerometer,pros::adi::Accelerometer); +LEGACY_TYPEDEF(ADIButton,pros::adi::Button); +LEGACY_TYPEDEF(ADIPneumatics,pros::adi::Pneumatics); +LEGACY_TYPEDEF(ADILED, pros::adi::Led); +LEGACY_TYPEDEF(ADILed, pros::adi::Led); } // namespace pros diff --git a/EZ-Template-Example-Project/include/pros/api_legacy.h b/EZ-Template-Example-Project/include/pros/api_legacy.h deleted file mode 100644 index deb7d222..00000000 --- a/EZ-Template-Example-Project/include/pros/api_legacy.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * \file pros/api_legacy.h - * - * PROS 2 Legacy API header - * - * Contains declarations for functions that are name-compatible with the PROS 2 - * API. Some functions from the PROS 2 API are not useful or cannot be - * implemented in PROS 3, but most common functions are available. - * - * This file should not be modified by users, since it gets replaced whenever - * a kernel upgrade occurs. - * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. - * All rights reserved. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef _PROS_API_LEGACY_H_ -#define _PROS_API_LEGACY_H_ - -#include "api.h" - -#ifdef __cplusplus -#define _NAMESPACE pros:: -#define _CNAMESPACE pros::c:: -#else -#define _NAMESPACE -#define _CNAMESPACE -#endif - -/** - * From adi.h - */ -#define analogCalibrate(port) adi_analog_calibrate(port) -#define analogRead(port) adi_analog_read(port) -#define analogReadCalibrated(port) adi_analog_read_calibrated(port) -#define analogReadCalibratedHR(port) adi_analog_read_calibrated_HR(port) -#define digitalRead(port) adi_digital_read(port) -#define digitalWrite(port, value) adi_digital_write(port, value) -#define pinMode(port, mode) adi_pin_mode(port, mode) -#define adiMotorSet(port, speed) adi_motor_set(port, speed) -#define adiMotorGet(port) adi_motor_get(port) -#define adiMotorStop(port) adi_motor_stop(port) -#define encoderGet(enc) adi_encoder_get(enc) -#define encoderInit(portTop, portBottom, reverse) adi_encoder_init(portTop, portBottom, reverse) -#define encoderShutdown(enc) adi_encoder_shutdown(enc) -#define ultrasonicGet(ult) adi_ultrasonic_get(ult) -#define ultrasonicInit(portEcho, portPing) adi_ultrasonic_init(portEcho, portPing) -#define ultrasonicShutdown(ult) adi_ultrasonic_shutdown(ult) - -typedef _CNAMESPACE adi_encoder_t Encoder; -typedef _CNAMESPACE adi_ultrasonic_t Ultrasonic; - -/** - * From llemu.h - */ -#define lcdInit lcd_initialize -#define lcdReadButtons lcd_read_buttons -#define lcdClear lcd_clear -#define lcdClearLine lcd_clear_line -#define lcdShutdown lcd_shutdown -#define lcdPrint(line, fmt, ...) lcd_print(line, fmt, __VA_ARGS__) -#define lcdSetText(line, text) lcd_set_text(line, text) - -/** - * From misc.h - */ -#define isEnabled() (!competition_is_disabled()) -#define isAutonomous competition_is_autonomous -#define isOnline competition_is_connected -#define isJoystickConnected(id) controller_is_connected(id) -#define joystickGetAnalog(id, channel) controller_get_analog(id, channel) - -/** - * From rtos.h - */ -#define taskCreate(taskCode, stackDepth, parameters, priority) \ - task_create(taskCode, parameters, priority, stackDepth, "") -#define taskDelete(task) task_delete(task) -#define taskDelay task_delay -#define taskDelayUntil(previousWakeTime, cycleTime) task_delay_until(previousWakeTime, cycleTime) -#define taskPriorityGet(task) task_get_priority(task) -#define taskPrioritySet(task, newPriority) task_priority_set(task, newPriority) -#define taskGetState(task) task_get_state(task) -#define taskSuspend(task) task_suspend(task) -#define taskResume(task) task_resume(task) -#define taskGetCount task_get_count -#define mutexCreate mutex_create -#define mutexTake(mutex, blockTime) mutex_take(mutex, blockTime) -#define mutexGive(mutex) mutex_give(mutex) - -typedef _NAMESPACE task_t TaskHandle; -typedef _NAMESPACE mutex_t Mutex; - -/** - * From motors.h - */ -#define motorSet(port, speed) motor_move(port, speed) -#define motorGet(port) motor_get_voltage(port) -#define motorStop(port) motor_move(port, 0) - -#undef _NAMESPACE -#undef _CNAMESPACE - -#endif // _PROS_API_LEGACY_H_ diff --git a/EZ-Template-Example-Project/include/pros/apix.h b/EZ-Template-Example-Project/include/pros/apix.h index 876a98c8..165c0541 100644 --- a/EZ-Template-Example-Project/include/pros/apix.h +++ b/EZ-Template-Example-Project/include/pros/apix.h @@ -1,5 +1,6 @@ /** * \file pros/apix.h + * \ingroup apix * * PROS Extended API header * @@ -7,26 +8,27 @@ * functions do not typically have as much error handling or require deeper * knowledge of real time operating systems. * - * Visit https://pros.cs.purdue.edu/v5/extended/api.html to learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup apix Extended API + * \note Also included in the Extended API is [LVGL.](https://lvgl.io/) */ #ifndef _PROS_API_EXTENDED_H_ #define _PROS_API_EXTENDED_H_ #include "api.h" +#include "pros/device.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wall" -#include "display/lvgl.h" #pragma GCC diagnostic pop #include "pros/serial.h" @@ -36,12 +38,17 @@ namespace pros::c { extern "C" { #endif -/******************************************************************************/ -/** RTOS FACILITIES **/ -/** **/ -/** **/ -/**See https://pros.cs.purdue.edu/v5/extended/multitasking.html to learn more**/ -/******************************************************************************/ +/** + * \ingroup apix + */ + +/** + * \addtogroup apix + * @{ + */ + +/// \name RTOS Facilities +///@{ typedef void* queue_t; typedef void* sem_t; @@ -50,19 +57,25 @@ typedef void* sem_t; * Unblocks a task in the Blocked state (e.g. waiting for a delay, on a * semaphore, etc.). * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#abort_delay for - * details. + * \param task + * The task to unblock + * + * \return True if the task was unblocked, false otherwise + * + * \b Example: + * \code + * task_t task = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * task_delay(1000); + * // in another task somewhere else, this will abort the task_delay bove: + * task_abort_delay(task); + * \endcode */ bool task_abort_delay(task_t task); /** * Notify a task when a target task is being deleted. * - * This function will configure the PROS kernel to call - * task_notify_ext(task_to_notify, value, action, NULL) when target_task is - * deleted. - * - * * \param target_task * The task being watched for deletion * \param task_to_notify @@ -71,6 +84,19 @@ bool task_abort_delay(task_t task); * The value to supply to task_notify_ext * \param notify_action * The action to supply to task_notify_ext + * + * \b Example: + * \code + * task_t task_to_delete = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * task_t task_to_notify = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn2"); + * + * task_notify_ext(task_to_notify, 0, NOTIFY_ACTION_INCREMENT, NULL); + * + * task_notify_when_deleting(task_to_delete, task_get_current(), 0, NOTIFY_ACTION_NONE); + * task_delete(task_to_delete); + * \endcode */ void task_notify_when_deleting(task_t target_task, task_t task_to_notify, uint32_t value, notify_action_e_t notify_action); @@ -78,64 +104,127 @@ void task_notify_when_deleting(task_t target_task, task_t task_to_notify, uint32 /** * Creates a recursive mutex which can be locked recursively by the owner. * - * See - * https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes - * for details. - * * \return A newly created recursive mutex. + * + * \b Example: + * \code + * mutex_t mutex = mutex_recursive_create(); + * + * void task_fn(void* param) { + * while(1) { + * mutex_recursive_take(mutex, 1000); + * // critical section + * mutex_recursive_give(mutex); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ mutex_t mutex_recursive_create(void); /** * Takes a recursive mutex. * - * See - * https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes - * for details. - * * \param mutex * A mutex handle created by mutex_recursive_create * \param wait_time * Amount of time to wait before timing out * * \return 1 if the mutex was obtained, 0 otherwise + * + * \b Example: + * \code + * mutex_t mutex = mutex_recursive_create(); + * + * void task_fn(void* param) { + * while(1) { + * mutex_recursive_take(mutex, 1000); + * // critical section + * mutex_recursive_give(mutex); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ bool mutex_recursive_take(mutex_t mutex, uint32_t timeout); /** * Gives a recursive mutex. * - * See - * https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes - * for details. - * * \param mutex * A mutex handle created by mutex_recursive_create * * \return 1 if the mutex was obtained, 0 otherwise + * + * \b Example: + * \code + * mutex_t mutex = mutex_recursive_create(); + * + * void task_fn(void* param) { + * while(1) { + * mutex_recursive_take(mutex, 1000); + * // critical section + * mutex_recursive_give(mutex); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ bool mutex_recursive_give(mutex_t mutex); /** * Returns a handle to the current owner of a mutex. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#extra for - * details. - * * \param mutex * A mutex handle * * \return A handle to the current task that owns the mutex, or NULL if the * mutex isn't owned. + * + * \b Example: + * \code + * mutex_t mutex = mutex_create(); + * + * void task_fn(void* param) { + * while(1) { + * mutex_take(mutex, 1000); + * // critical section + * mutex_give(mutex); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * void opcontrol(void) { +* while (1) { +* if (joystick_get_digital(1, 7, JOY_UP)) { +* task_t owner = mutex_get_owner(mutex); +* if (owner != NULL) { +* printf("Mutex is owned by task %s", task_get_name(owner)); +* } else { +* printf("Mutex is not owned"); +* } +* } +* task_delay(20); +* } +* } + * \endcode */ task_t mutex_get_owner(mutex_t mutex); /** * Creates a counting sempahore. * - * See https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores for - *details. - * * \param max_count * The maximum count value that can be reached. * \param init_count @@ -143,28 +232,86 @@ task_t mutex_get_owner(mutex_t mutex); * * \return A newly created semaphore. If an error occurred, NULL will be * returned and errno can be checked for hints as to why sem_create failed. + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * + * void task_fn(void* param) { + * while(1) { + * sem_take(sem, 1000); + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ sem_t sem_create(uint32_t max_count, uint32_t init_count); /** * Deletes a semaphore (or binary semaphore) * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#semaphores for - * details. - * * \param sem * Semaphore to delete + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * + * void task_fn(void* param) { + * while(1) { + * sem_take(sem, 1000); + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * void opcontrol(void) { + * while (1) { + * if (joystick_get_digital(1, 7, JOY_UP)) { + * // honestly this is a bad example because you should never + * // delete a semaphore like this + * sem_delete(sem); + * } + * task_delay(20); + * } + * } + * + * \endcode */ void sem_delete(sem_t sem); /** * Creates a binary semaphore. * - * See - * https://pros.cs.purdue.edu/v5/extended/multitasking#.htmlbinary_semaphores - * for details. - * * \return A newly created semaphore. + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_binary_create(); + * + * void task_fn(void* param) { + * while(1) { + * sem_take(sem, 1000); + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ sem_t sem_binary_create(void); @@ -172,9 +319,6 @@ sem_t sem_binary_create(void); * Waits for the semaphore's value to be greater than 0. If the value is already * greater than 0, this function immediately returns. * - * See https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores for - * details. - * * \param sem * Semaphore to wait on * \param timeout @@ -185,44 +329,98 @@ sem_t sem_binary_create(void); * \return True if the semaphore was successfully take, false otherwise. If * false is returned, then errno is set with a hint about why the sempahore * couldn't be taken. + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * + * void task_fn(void* param) { + * while(1) { + * if(!sem_wait(sem, 1000)) { + * printf("Failed to take semaphore"); + * task_delay(1000); + * continue; + * } + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * void opcontrol(void) { + * while (1) { + * if (sem_wait(sem, 0))) { + * printf("Semaphore is available"); + * } + * task_delay(20); + * } + * } + * \endcode */ bool sem_wait(sem_t sem, uint32_t timeout); /** * Increments a semaphore's value. * - * See https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores for - * details. - * * \param sem * Semaphore to post * * \return True if the value was incremented, false otherwise. If false is * returned, then errno is set with a hint about why the semaphore couldn't be * taken. + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * + * void task_fn(void* param) { + * while(1) { + * sem_post(sem); // increments, mimicking to "claim" + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ bool sem_post(sem_t sem); /** * Returns the current value of the semaphore. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#extra for - * details. - * * \param sem * A semaphore handle * * \return The current value of the semaphore (e.g. the number of resources * available) + * + * \b Example of sem_get_count: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * printf("semaphore count: %d", sem_get_count(sem)); + * // semaphore count: 0 + * sem_take(sem, 1000); + * printf("semaphore count: %d", sem_get_count(sem)); + * // semaphore count: 1 + * sem_give(sem); + * printf("semaphore count: %d", sem_get_count(sem)); + * // semaphore count: 0 + * + * \endcode */ uint32_t sem_get_count(sem_t sem); /** * Creates a queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param length * The maximum number of items that the queue can contain. * \param item_size @@ -230,6 +428,17 @@ uint32_t sem_get_count(sem_t sem); * * \return A handle to a newly created queue, or NULL if the queue cannot be * created. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue length: %d", queue_get_length(queue)); + * } + * \endcode */ queue_t queue_create(uint32_t length, uint32_t item_size); @@ -237,9 +446,6 @@ queue_t queue_create(uint32_t length, uint32_t item_size); * Posts an item to the front of a queue. The item is queued by copy, not by * reference. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle * \param item @@ -250,6 +456,16 @@ queue_t queue_create(uint32_t length, uint32_t item_size); * indefinitely. * * \return True if the item was preprended, false otherwise. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue length: %d", queue_get_length(queue)); + * } */ bool queue_prepend(queue_t queue, const void* item, uint32_t timeout); @@ -257,9 +473,6 @@ bool queue_prepend(queue_t queue, const void* item, uint32_t timeout); * Posts an item to the end of a queue. The item is queued by copy, not by * reference. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle * \param item @@ -270,15 +483,23 @@ bool queue_prepend(queue_t queue, const void* item, uint32_t timeout); * indefinitely. * * \return True if the item was preprended, false otherwise. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue length: %d", queue_get_length(queue)); + * } + * \endcode */ bool queue_append(queue_t queue, const void* item, uint32_t timeout); /** * Receive an item from a queue without removing the item from the queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle * \param buffer @@ -288,15 +509,26 @@ bool queue_append(queue_t queue, const void* item, uint32_t timeout); * the time of the call. TIMEOUT_MAX can be used to block indefinitely. * * \return True if an item was copied into the buffer, false otherwise. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * char* item = "Hello! this is a test"; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * char* recv = malloc(sizeof("Hello! this is a test")); + * queue_peek(queue, recv, 1000); + * printf("Queue: %s", recv); + * free(recv); + * } + * \endcode */ bool queue_peek(queue_t queue, void* const buffer, uint32_t timeout); /** * Receive an item from the queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle * \param buffer @@ -308,43 +540,80 @@ bool queue_peek(queue_t queue, void* const buffer, uint32_t timeout); * is zero and the queue is empty. * * \return True if an item was copied into the buffer, false otherwise. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * char* item = "Hello! this is a test"; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * char* recv = malloc(sizeof("Hello! this is a test")); + * queue_recv(queue, recv, 1000); + * printf("Queue: %s", recv); + * free(recv); + * } + * \endcode */ bool queue_recv(queue_t queue, void* const buffer, uint32_t timeout); /** * Return the number of messages stored in a queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle. * * \return The number of messages available in the queue. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue waiting: %d", queue_get_waiting(queue)); + * } + * \endcode */ uint32_t queue_get_waiting(const queue_t queue); /** * Return the number of spaces left in a queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle. * * \return The number of spaces available in the queue. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue available: %d", queue_get_available(queue)); + * } + * \endcode */ uint32_t queue_get_available(const queue_t queue); /** * Delete a queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * Queue handle to delete + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * queue_delete(queue); + * } + * \endcode */ void queue_delete(queue_t queue); @@ -353,36 +622,26 @@ void queue_delete(queue_t queue); * * \param queue * Queue handle to reset + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * queue_reset(queue); + * } + * \endcode */ void queue_reset(queue_t queue); -/******************************************************************************/ -/** Device Registration **/ -/******************************************************************************/ +///@} -/* - * List of possible v5 devices - * - * This list contains all current V5 Devices, and mirrors V5_DeviceType from the - * api. - */ -typedef enum v5_device_e { - E_DEVICE_NONE = 0, - E_DEVICE_MOTOR = 2, - E_DEVICE_ROTATION = 4, - E_DEVICE_IMU = 6, - E_DEVICE_DISTANCE = 7, - E_DEVICE_RADIO = 8, - E_DEVICE_VISION = 11, - E_DEVICE_ADI = 12, - E_DEVICE_OPTICAL = 16, - E_DEVICE_GPS = 20, - E_DEVICE_SERIAL = 129, - E_DEVICE_GENERIC __attribute__((deprecated("use E_DEVICE_SERIAL instead"))) = E_DEVICE_SERIAL, - E_DEVICE_UNDEFINED = 255 -} v5_device_e_t; +/// \name Device Registration +///@{ -/* +/** * Registers a device in the given zero-indexed port * * Registers a device of the given type in the given port into the registry, if @@ -400,10 +659,17 @@ typedef enum v5_device_e { * The type of device to register * * \return 1 upon success, PROS_ERR upon failure + * + * \b Example: + * \code + * void opcontrol(void) { + * registry_bind_port(1, E_DEVICE_MOTOR); + * } + * \endcode */ int registry_bind_port(uint8_t port, v5_device_e_t device_type); -/* +/** * Deregisters a devices from the given zero-indexed port * * Removes the device registed in the given port, if there is one. @@ -416,10 +682,18 @@ int registry_bind_port(uint8_t port, v5_device_e_t device_type); * The port number to deregister * * \return 1 upon success, PROS_ERR upon failure + * + * \b Example: + * \code + * void opcontrol(void) { + * registry_bind_port(1, E_DEVICE_MOTOR); + * registry_unbind_port(1); + * } + * \endcode */ int registry_unbind_port(uint8_t port); -/* +/** * Returns the type of device registered to the zero-indexed port. * * This function uses the following values of errno when an error state is @@ -431,10 +705,18 @@ int registry_unbind_port(uint8_t port); * * \return The type of device that is registered into the port (NOT what is * plugged in) + * + * \b Example: + * \code + * void opcontrol(void) { + * registry_bind_port(1, E_DEVICE_MOTOR); + * printf("port 1 is registered to a motor: %d", registry_get_bound_type(1) == E_DEVICE_MOTOR); + * } + * \endcode */ v5_device_e_t registry_get_bound_type(uint8_t port); -/* +/** * Returns the type of the device plugged into the zero-indexed port. * * This function uses the following values of errno when an error state is @@ -446,12 +728,22 @@ v5_device_e_t registry_get_bound_type(uint8_t port); * * \return The type of device that is plugged into the port (NOT what is * registered) + * + * \b Example: + * \code + * void opcontrol(void) { + * registry_bind_port(1, E_DEVICE_MOTOR); + * printf("port 1 is registered to a motor: %d", registry_get_plugged_type(1) == E_DEVICE_MOTOR); + * } + * \endcode */ v5_device_e_t registry_get_plugged_type(uint8_t port); -/******************************************************************************/ -/** Filesystem **/ -/******************************************************************************/ +///@} + +/// \name Filesystem +///@{ + /** * Control settings of the serial driver. * @@ -460,10 +752,16 @@ v5_device_e_t registry_get_plugged_type(uint8_t port); * details on the different actions. * \param extra_arg * An argument to pass in based on the action + * + * \b Example: + * \code + * void opcontrol(void) { + * serctl(SERCTL_SET_BAUDRATE, (void*) 9600); + * } */ int32_t serctl(const uint32_t action, void* const extra_arg); -/** +/* * Control settings of the microSD card driver. * * \param action @@ -487,9 +785,69 @@ int32_t serctl(const uint32_t action, void* const extra_arg); * microSD card file) * \param extra_arg * An argument to pass in based on the action + * + * \b Example: + * \code + * void opcontrol(void) { + * int32_t fd = open("serial", O_RDWR); + * fdctl(fd, SERCTL_SET_BAUDRATE, (void*) 9600); + * } + * \endcode */ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); +/** + * Sets the reverse flag for the motor. + * + * This will invert its movements and the values returned for its position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor + * + * \param port + * The V5 port number from 1-21 + * \param reverse + * True reverses the motor, false is default + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_set_reversed(1, true); + * printf("Is this motor reversed? %d\n", motor_is_reversed(1)); + * } + * \endcode + */ +int32_t motor_set_reversed(int8_t port, const bool reverse); + +/** + * Gets the operation direction of the motor as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor + * + * \param port + * The V5 port number from 1-21 + * + * \return 1 if the motor has been reversed and 0 if the motor was not reversed, + * or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * printf("Is the motor reversed? %d\n", motor_is_reversed(1)); + * // Prints "Is the motor reversed? 0" + * } + * \endcode + */ +int32_t motor_is_reversed(int8_t port); + /** * Action macro to pass into serctl or fdctl that activates the stream * identifier. @@ -497,8 +855,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * When used with serctl, the extra argument must be the little endian * representation of the stream identifier (e.g. "sout" -> 0x74756f73) * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_ACTIVATE 10 @@ -509,8 +865,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * When used with serctl, the extra argument must be the little endian * representation of the stream identifier (e.g. "sout" -> 0x74756f73) * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_DEACTIVATE 11 @@ -520,8 +874,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * The extra argument is not used with this action, provide any value (e.g. * NULL) instead * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_BLKWRITE 12 @@ -531,8 +883,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * The extra argument is not used with this action, provide any value (e.g. * NULL) instead * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_NOBLKWRITE 13 @@ -543,8 +893,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * The extra argument is not used with this action, provide any value (e.g. * NULL) instead * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_ENABLE_COBS 14 @@ -555,8 +903,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * The extra argument is not used with this action, provide any value (e.g. * NULL) instead * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_DISABLE_COBS 15 @@ -564,8 +910,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * Action macro to check if there is data available from the Generic Serial * Device * - * The extra argument is not used with this action, provide any value (e.g. - * NULL) instead */ #define DEVCTL_FIONREAD 16 @@ -573,8 +917,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * Action macro to check if there is space available in the Generic Serial * Device's output buffer * - * The extra argument is not used with this action, provide any value (e.g. - * NULL) instead */ #define DEVCTL_FIONWRITE 18 @@ -585,6 +927,10 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); */ #define DEVCTL_SET_BAUDRATE 17 +///@} + +///@} + #ifdef __cplusplus } } diff --git a/EZ-Template-Example-Project/include/pros/colors.h b/EZ-Template-Example-Project/include/pros/colors.h index 0aa4cb35..b70a8f99 100644 --- a/EZ-Template-Example-Project/include/pros/colors.h +++ b/EZ-Template-Example-Project/include/pros/colors.h @@ -1,4 +1,4 @@ -/* +/** * \file pros/colors.h * * Contains macro definitions of colors (as `uint32_t`) @@ -11,6 +11,18 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License v. 2.0. If a copy of the MPL was not distributed with this * file You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-colors Colors C API + */ + +/** + * \ingroup c-colors + * \note These functions can be used for dynamic device instantiation. + */ + +/** + * \addtogroup c-colors + * @{ */ #ifndef _PROS_COLORS_H_ @@ -21,151 +33,172 @@ #define COLOR2G(COLOR) ((COLOR >> 8) & 0xff) #define COLOR2B(COLOR) (COLOR & 0xff) -#define COLOR_ALICE_BLUE 0x00F0F8FF -#define COLOR_ANTIQUE_WHITE 0x00FAEBD7 -#define COLOR_AQUA 0x0000FFFF -#define COLOR_AQUAMARINE 0x007FFFD4 -#define COLOR_AZURE 0x00F0FFFF -#define COLOR_BEIGE 0x00F5F5DC -#define COLOR_BISQUE 0x00FFE4C4 -#define COLOR_BLACK 0x00000000 -#define COLOR_BLANCHED_ALMOND 0x00FFEBCD -#define COLOR_BLUE 0x000000FF -#define COLOR_BLUE_VIOLET 0x008A2BE2 -#define COLOR_BROWN 0x00A52A2A -#define COLOR_BURLY_WOOD 0x00DEB887 -#define COLOR_CADET_BLUE 0x005F9EA0 -#define COLOR_CHARTREUSE 0x007FFF00 -#define COLOR_CHOCOLATE 0x00D2691E -#define COLOR_CORAL 0x00FF7F50 -#define COLOR_CORNFLOWER_BLUE 0x006495ED -#define COLOR_CORNSILK 0x00FFF8DC -#define COLOR_CRIMSON 0x00DC143C -#define COLOR_CYAN 0x0000FFFF -#define COLOR_DARK_BLUE 0x0000008B -#define COLOR_DARK_CYAN 0x00008B8B -#define COLOR_DARK_GOLDENROD 0x00B8860B -#define COLOR_DARK_GRAY 0x00A9A9A9 -#define COLOR_DARK_GREEN 0x00006400 -#define COLOR_DARK_KHAKI 0x00BDB76B -#define COLOR_DARK_MAGENTA 0x008B008B -#define COLOR_DARK_OLIVE_GREEN 0x00556B2F -#define COLOR_DARK_ORANGE 0x00FF8C00 -#define COLOR_DARK_ORCHID 0x009932CC -#define COLOR_DARK_RED 0x008B0000 -#define COLOR_DARK_SALMON 0x00E9967A -#define COLOR_DARK_SEA_GREEN 0x008FBC8F -#define COLOR_DARK_SLATE_GRAY 0x002F4F4F -#define COLOR_DARK_TURQUOISE 0x0000CED1 -#define COLOR_DARK_VIOLET 0x009400D3 -#define COLOR_DEEP_PINK 0x00FF1493 -#define COLOR_DEEP_SKY_BLUE 0x0000BFFF -#define COLOR_DIM_GRAY 0x00696969 -#define COLOR_DODGER_BLUE 0x001E90FF -#define COLOR_FIRE_BRICK 0x00B22222 -#define COLOR_FLORAL_WHITE 0x00FFFAF0 -#define COLOR_FOREST_GREEN 0x00228B22 -#define COLOR_FUCHSIA 0x00FF00FF -#define COLOR_GAINSBORO 0x00DCDCDC -#define COLOR_GHOST_WHITE 0x00F8F8FF -#define COLOR_GOLD 0x00FFD700 -#define COLOR_GOLDENROD 0x00DAA520 -#define COLOR_GRAY 0x00808080 -#define COLOR_GREEN 0x00008000 -#define COLOR_GREEN_YELLOW 0x00ADFF2F -#define COLOR_HONEYDEW 0x00F0FFF0 -#define COLOR_HOT_PINK 0x00FF69B4 -#define COLOR_INDIAN_RED 0x00CD5C5C -#define COLOR_INDIGO 0x004B0082 -#define COLOR_IVORY 0x00FFFFF0 -#define COLOR_KHAKI 0x00F0E68C -#define COLOR_LAVENDER 0x00E6E6FA -#define COLOR_LAVENDER_BLUSH 0x00FFF0F5 -#define COLOR_LAWN_GREEN 0x007CFC00 -#define COLOR_LEMON_CHIFFON 0x00FFFACD -#define COLOR_LIGHT_BLUE 0x00ADD8E6 -#define COLOR_LIGHT_CORAL 0x00F08080 -#define COLOR_LIGHT_CYAN 0x00E0FFFF -#define COLOR_LIGHT_GOLDENROD_YELLOW 0x00FAFAD2 -#define COLOR_LIGHT_GREEN 0x0090EE90 -#define COLOR_LIGHT_GRAY 0x00D3D3D3 -#define COLOR_LIGHT_PINK 0x00FFB6C1 -#define COLOR_LIGHT_SALMON 0x00FFA07A -#define COLOR_LIGHT_SEA_GREEN 0x0020B2AA -#define COLOR_LIGHT_SKY_BLUE 0x0087CEFA -#define COLOR_LIGHT_SLATE_GRAY 0x00778899 -#define COLOR_LIGHT_STEEL_BLUE 0x00B0C4DE -#define COLOR_LIGHT_YELLOW 0x00FFFFE0 -#define COLOR_LIME 0x0000FF00 -#define COLOR_LIME_GREEN 0x0032CD32 -#define COLOR_LINEN 0x00FAF0E6 -#define COLOR_MAGENTA 0x00FF00FF -#define COLOR_MAROON 0x00800000 -#define COLOR_MEDIUM_AQUAMARINE 0x0066CDAA -#define COLOR_MEDIUM_BLUE 0x000000CD -#define COLOR_MEDIUM_ORCHID 0x00BA55D3 -#define COLOR_MEDIUM_PURPLE 0x009370DB -#define COLOR_MEDIUM_SEA_GREEN 0x003CB371 -#define COLOR_MEDIUM_SLATE_BLUE 0x007B68EE -#define COLOR_MEDIUM_SPRING_GREEN 0x0000FA9A -#define COLOR_MEDIUM_TURQUOISE 0x0048D1CC -#define COLOR_MEDIUM_VIOLET_RED 0x00C71585 -#define COLOR_MIDNIGHT_BLUE 0x00191970 -#define COLOR_MINT_CREAM 0x00F5FFFA -#define COLOR_MISTY_ROSE 0x00FFE4E1 -#define COLOR_MOCCASIN 0x00FFE4B5 -#define COLOR_NAVAJO_WHITE 0x00FFDEAD -#define COLOR_NAVY 0x00000080 -#define COLOR_OLD_LACE 0x00FDF5E6 -#define COLOR_OLIVE 0x00808000 -#define COLOR_OLIVE_DRAB 0x006B8E23 -#define COLOR_ORANGE 0x00FFA500 -#define COLOR_ORANGE_RED 0x00FF4500 -#define COLOR_ORCHID 0x00DA70D6 -#define COLOR_PALE_GOLDENROD 0x00EEE8AA -#define COLOR_PALE_GREEN 0x0098FB98 -#define COLOR_PALE_TURQUOISE 0x00AFEEEE -#define COLOR_PALE_VIOLET_RED 0x00DB7093 -#define COLOR_PAPAY_WHIP 0x00FFEFD5 -#define COLOR_PEACH_PUFF 0x00FFDAB9 -#define COLOR_PERU 0x00CD853F -#define COLOR_PINK 0x00FFC0CB -#define COLOR_PLUM 0x00DDA0DD -#define COLOR_POWDER_BLUE 0x00B0E0E6 -#define COLOR_PURPLE 0x00800080 -#define COLOR_RED 0x00FF0000 -#define COLOR_ROSY_BROWN 0x00BC8F8F -#define COLOR_ROYAL_BLUE 0x004169E1 -#define COLOR_SADDLE_BROWN 0x008B4513 -#define COLOR_SALMON 0x00FA8072 -#define COLOR_SANDY_BROWN 0x00F4A460 -#define COLOR_SEA_GREEN 0x002E8B57 -#define COLOR_SEASHELL 0x00FFF5EE -#define COLOR_SIENNA 0x00A0522D -#define COLOR_SILVER 0x00C0C0C0 -#define COLOR_SKY_BLUE 0x0087CEEB -#define COLOR_SLATE_BLUE 0x006A5ACD -#define COLOR_SLATE_GRAY 0x00708090 -#define COLOR_SNOW 0x00FFFAFA -#define COLOR_SPRING_GREEN 0x0000FF7F -#define COLOR_STEEL_BLUE 0x004682B4 -#define COLOR_TAN 0x00D2B48C -#define COLOR_TEAL 0x00008080 -#define COLOR_THISTLE 0x00D8BFD8 -#define COLOR_TOMATO 0x00FF6347 -#define COLOR_TURQUOISE 0x0040E0D0 -#define COLOR_VIOLET 0x00EE82EE -#define COLOR_WHEAT 0x00F5DEB3 -#define COLOR_WHITE 0x00FFFFFF -#define COLOR_WHITE_SMOKE 0x00F5F5F5 -#define COLOR_YELLOW 0x00FFFF00 -#define COLOR_YELLOW_GREEN 0x009ACD32 -#define COLOR_DARK_GREY COLOR_DARK_GRAY -#define COLOR_DARK_SLATE_GREY COLOR_DARK_SLATE_GRAY -#define COLOR_DIM_GREY COLOR_DIM_GRAY -#define COLOR_GREY COLOR_GRAY -#define COLOR_LIGHT_GREY COLOR_LIGHT_GRAY -#define COLOR_LIGHT_SLATE_GREY COLOR_LIGHT_SLATE_GRAY -#define COLOR_SLATE_GREY COLOR_SLATE_GRAY +#ifdef __cplusplus +namespace pros { +namespace c { +#endif + +/** + * \enum color_e_t + * @brief + * Enum of possible colors + * + * Contains common colors, all members are self descriptive. + */ +typedef enum color_e { + COLOR_ALICE_BLUE = 0x00F0F8FF, + COLOR_ANTIQUE_WHITE = 0x00FAEBD7, + COLOR_AQUA = 0x0000FFFF, + COLOR_AQUAMARINE = 0x007FFFD4, + COLOR_AZURE = 0x00F0FFFF, + COLOR_BEIGE = 0x00F5F5DC, + COLOR_BISQUE = 0x00FFE4C4, + COLOR_BLACK = 0x00000000, + COLOR_BLANCHED_ALMOND = 0x00FFEBCD, + COLOR_BLUE = 0x000000FF, + COLOR_BLUE_VIOLET = 0x008A2BE2, + COLOR_BROWN = 0x00A52A2A, + COLOR_BURLY_WOOD = 0x00DEB887, + COLOR_CADET_BLUE = 0x005F9EA0, + COLOR_CHARTREUSE = 0x007FFF00, + COLOR_CHOCOLATE = 0x00D2691E, + COLOR_CORAL = 0x00FF7F50, + COLOR_CORNFLOWER_BLUE = 0x006495ED, + COLOR_CORNSILK = 0x00FFF8DC, + COLOR_CRIMSON = 0x00DC143C, + COLOR_CYAN = 0x0000FFFF, + COLOR_DARK_BLUE = 0x0000008B, + COLOR_DARK_CYAN = 0x00008B8B, + COLOR_DARK_GOLDENROD = 0x00B8860B, + COLOR_DARK_GRAY = 0x00A9A9A9, + COLOR_DARK_GREY = COLOR_DARK_GRAY, + COLOR_DARK_GREEN = 0x00006400, + COLOR_DARK_KHAKI = 0x00BDB76B, + COLOR_DARK_MAGENTA = 0x008B008B, + COLOR_DARK_OLIVE_GREEN = 0x00556B2F, + COLOR_DARK_ORANGE = 0x00FF8C00, + COLOR_DARK_ORCHID = 0x009932CC, + COLOR_DARK_RED = 0x008B0000, + COLOR_DARK_SALMON = 0x00E9967A, + COLOR_DARK_SEA_GREEN = 0x008FBC8F, + COLOR_DARK_SLATE_GRAY = 0x002F4F4F, + COLOR_DARK_SLATE_GREY = COLOR_DARK_SLATE_GRAY, + COLOR_DARK_TURQUOISE = 0x0000CED1, + COLOR_DARK_VIOLET = 0x009400D3, + COLOR_DEEP_PINK = 0x00FF1493, + COLOR_DEEP_SKY_BLUE = 0x0000BFFF, + COLOR_DIM_GRAY = 0x00696969, + COLOR_DIM_GREY = COLOR_DIM_GRAY, + COLOR_DODGER_BLUE = 0x001E90FF, + COLOR_FIRE_BRICK = 0x00B22222, + COLOR_FLORAL_WHITE = 0x00FFFAF0, + COLOR_FOREST_GREEN = 0x00228B22, + COLOR_FUCHSIA = 0x00FF00FF, + COLOR_GAINSBORO = 0x00DCDCDC, + COLOR_GHOST_WHITE = 0x00F8F8FF, + COLOR_GOLD = 0x00FFD700, + COLOR_GOLDENROD = 0x00DAA520, + COLOR_GRAY = 0x00808080, + COLOR_GREY = COLOR_GRAY, + COLOR_GREEN = 0x00008000, + COLOR_GREEN_YELLOW = 0x00ADFF2F, + COLOR_HONEYDEW = 0x00F0FFF0, + COLOR_HOT_PINK = 0x00FF69B4, + COLOR_INDIAN_RED = 0x00CD5C5C, + COLOR_INDIGO = 0x004B0082, + COLOR_IVORY = 0x00FFFFF0, + COLOR_KHAKI = 0x00F0E68C, + COLOR_LAVENDER = 0x00E6E6FA, + COLOR_LAVENDER_BLUSH = 0x00FFF0F5, + COLOR_LAWN_GREEN = 0x007CFC00, + COLOR_LEMON_CHIFFON = 0x00FFFACD, + COLOR_LIGHT_BLUE = 0x00ADD8E6, + COLOR_LIGHT_CORAL = 0x00F08080, + COLOR_LIGHT_CYAN = 0x00E0FFFF, + COLOR_LIGHT_GOLDENROD_YELLOW = 0x00FAFAD2, + COLOR_LIGHT_GREEN = 0x0090EE90, + COLOR_LIGHT_GRAY = 0x00D3D3D3, + COLOR_LIGHT_GREY = COLOR_LIGHT_GRAY, + COLOR_LIGHT_PINK = 0x00FFB6C1, + COLOR_LIGHT_SALMON = 0x00FFA07A, + COLOR_LIGHT_SEA_GREEN = 0x0020B2AA, + COLOR_LIGHT_SKY_BLUE = 0x0087CEFA, + COLOR_LIGHT_SLATE_GRAY = 0x00778899, + COLOR_LIGHT_SLATE_GREY = COLOR_LIGHT_SLATE_GRAY, + COLOR_LIGHT_STEEL_BLUE = 0x00B0C4DE, + COLOR_LIGHT_YELLOW = 0x00FFFFE0, + COLOR_LIME = 0x0000FF00, + COLOR_LIME_GREEN = 0x0032CD32, + COLOR_LINEN = 0x00FAF0E6, + COLOR_MAGENTA = 0x00FF00FF, + COLOR_MAROON = 0x00800000, + COLOR_MEDIUM_AQUAMARINE = 0x0066CDAA, + COLOR_MEDIUM_BLUE = 0x000000CD, + COLOR_MEDIUM_ORCHID = 0x00BA55D3, + COLOR_MEDIUM_PURPLE = 0x009370DB, + COLOR_MEDIUM_SEA_GREEN = 0x003CB371, + COLOR_MEDIUM_SLATE_BLUE = 0x007B68EE, + COLOR_MEDIUM_SPRING_GREEN = 0x0000FA9A, + COLOR_MEDIUM_TURQUOISE = 0x0048D1CC, + COLOR_MEDIUM_VIOLET_RED = 0x00C71585, + COLOR_MIDNIGHT_BLUE = 0x00191970, + COLOR_MINT_CREAM = 0x00F5FFFA, + COLOR_MISTY_ROSE = 0x00FFE4E1, + COLOR_MOCCASIN = 0x00FFE4B5, + COLOR_NAVAJO_WHITE = 0x00FFDEAD, + COLOR_NAVY = 0x00000080, + COLOR_OLD_LACE = 0x00FDF5E6, + COLOR_OLIVE = 0x00808000, + COLOR_OLIVE_DRAB = 0x006B8E23, + COLOR_ORANGE = 0x00FFA500, + COLOR_ORANGE_RED = 0x00FF4500, + COLOR_ORCHID = 0x00DA70D6, + COLOR_PALE_GOLDENROD = 0x00EEE8AA, + COLOR_PALE_GREEN = 0x0098FB98, + COLOR_PALE_TURQUOISE = 0x00AFEEEE, + COLOR_PALE_VIOLET_RED = 0x00DB7093, + COLOR_PAPAY_WHIP = 0x00FFEFD5, + COLOR_PEACH_PUFF = 0x00FFDAB9, + COLOR_PERU = 0x00CD853F, + COLOR_PINK = 0x00FFC0CB, + COLOR_PLUM = 0x00DDA0DD, + COLOR_POWDER_BLUE = 0x00B0E0E6, + COLOR_PURPLE = 0x00800080, + COLOR_RED = 0x00FF0000, + COLOR_ROSY_BROWN = 0x00BC8F8F, + COLOR_ROYAL_BLUE = 0x004169E1, + COLOR_SADDLE_BROWN = 0x008B4513, + COLOR_SALMON = 0x00FA8072, + COLOR_SANDY_BROWN = 0x00F4A460, + COLOR_SEA_GREEN = 0x002E8B57, + COLOR_SEASHELL = 0x00FFF5EE, + COLOR_SIENNA = 0x00A0522D, + COLOR_SILVER = 0x00C0C0C0, + COLOR_SKY_BLUE = 0x0087CEEB, + COLOR_SLATE_BLUE = 0x006A5ACD, + COLOR_SLATE_GRAY = 0x00708090, + COLOR_SLATE_GREY = COLOR_SLATE_GRAY, + COLOR_SNOW = 0x00FFFAFA, + COLOR_SPRING_GREEN = 0x0000FF7F, + COLOR_STEEL_BLUE = 0x004682B4, + COLOR_TAN = 0x00D2B48C, + COLOR_TEAL = 0x00008080, + COLOR_THISTLE = 0x00D8BFD8, + COLOR_TOMATO = 0x00FF6347, + COLOR_TURQUOISE = 0x0040E0D0, + COLOR_VIOLET = 0x00EE82EE, + COLOR_WHEAT = 0x00F5DEB3, + COLOR_WHITE = 0x00FFFFFF, + COLOR_WHITE_SMOKE = 0x00F5F5F5, + COLOR_YELLOW = 0x00FFFF00, + COLOR_YELLOW_GREEN = 0x009ACD32, +} color_e_t; + + ///@} + +#ifdef __cplusplus +} // namespace c +} // namespace pros +#endif #endif // _PROS_COLORS_H_ diff --git a/EZ-Template-Example-Project/include/pros/colors.hpp b/EZ-Template-Example-Project/include/pros/colors.hpp index e3d0ba13..970c2cfa 100644 --- a/EZ-Template-Example-Project/include/pros/colors.hpp +++ b/EZ-Template-Example-Project/include/pros/colors.hpp @@ -11,12 +11,30 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License v. 2.0. If a copy of the MPL was not distributed with this * file You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-colors C++ Color API */ #ifndef _PROS_COLORS_HPP_ #define _PROS_COLORS_HPP_ namespace pros{ +/** + * \ingroup cpp-colors + */ + +/** + * \addtogroup cpp-colors + * @{ + */ + +/** + * \enum Color + * @brief + * Enum class of possible colors + * + * Contains common colors, all members are self descriptive. + */ enum class Color { alice_blue = 0x00F0F8FF, antique_white = 0x00FAEBD7, @@ -167,4 +185,6 @@ enum class Color { }; } // namespace pros + ///@} + #endif //_PROS_COLORS_HPP_ diff --git a/EZ-Template-Example-Project/include/pros/device.h b/EZ-Template-Example-Project/include/pros/device.h new file mode 100644 index 00000000..889e0085 --- /dev/null +++ b/EZ-Template-Example-Project/include/pros/device.h @@ -0,0 +1,91 @@ +/** + * \file pros/device.h + * + * Contains functions for interacting with VEX devices. + * + * + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-device VEX Generic Device C API (For Advanced Users) + */ + +#ifndef _PROS_DEVICE_H_ +#define _PROS_DEVICE_H_ + +#include + +#ifdef __cplusplus +namespace pros::c { +extern "C" { +#endif + +/** + * \ingroup c-device + * \note These functions can be used for dynamic device instantiation. + */ + +/** + * \addtogroup c-device + * @{ + */ + +/** + * \enum v5_device_e + * \brief + * List of possible v5 devices + * + * This list contains all current V5 Devices, and mirrors V5_DeviceType from the + * api. + */ +typedef enum v5_device_e { + E_DEVICE_NONE = 0, ///< No device is plugged into the port + E_DEVICE_MOTOR = 2, ///< A motor is plugged into the port + E_DEVICE_ROTATION = 4, ///< A rotation sensor is plugged into the port + E_DEVICE_IMU = 6, ///< An inertial sensor is plugged into the port + E_DEVICE_DISTANCE = 7, ///< A distance sensor is plugged into the port + E_DEVICE_RADIO = 8, ///< A radio is plugged into the port + E_DEVICE_VISION = 11, ///< A vision sensor is plugged into the port + E_DEVICE_ADI = 12, ///< This port is an ADI expander + E_DEVICE_OPTICAL = 16, ///< An optical sensor is plugged into the port + E_DEVICE_GPS = 20, ///< A GPS sensor is plugged into the port + E_DEVICE_SERIAL = 129, ///< A serial device is plugged into the port + E_DEVICE_GENERIC __attribute__((deprecated("use E_DEVICE_SERIAL instead"))) = E_DEVICE_SERIAL, + E_DEVICE_UNDEFINED = 255 ///< The device type is not defined, or is not a valid device +} v5_device_e_t; + +/** + * Gets the type of device on given port. + * + * \return The device type as an enum. + * + * \b Example + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + * while (true) { + * v5_device_e_t pt = get_plugged_type(DEVICE_PORT); + * printf("device plugged type: {plugged type: %d}\n", pt); + * delay(20); + * } + * } + * \endcode +*/ +v5_device_e_t get_plugged_type(uint8_t port); + +///@} + +#ifdef __cplusplus +} // namespace c +} // namespace pros +#endif + +#endif // _PROS_DEVICE_H_ diff --git a/EZ-Template-Example-Project/include/pros/device.hpp b/EZ-Template-Example-Project/include/pros/device.hpp new file mode 100644 index 00000000..5055d489 --- /dev/null +++ b/EZ-Template-Example-Project/include/pros/device.hpp @@ -0,0 +1,205 @@ +/** + * \file pros/device.hpp + * + * Base class for all smart devices. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-device VEX Generic Device C++ API (For Advanced Users) + */ + +#ifndef _PROS_DEVICE_HPP_ +#define _PROS_DEVICE_HPP_ + +#include "pros/misc.hpp" +#include "pros/rtos.hpp" + +namespace pros { +inline namespace v5 { +/** + * \ingroup cpp-device + * \note These functions can be used for dynamic device instantiation. + */ + +/** + * \addtogroup cpp-device + * @{ + */ + +/** + * \enum DeviceType + * \brief + * Enum of possible v5 devices. + * + * Contains all current V5 Devices. + */ +enum class DeviceType { + none = 0, ///< No device is plugged into the port + motor = 2, ///< A motor is plugged into the port + rotation = 4, ///< A rotation sensor is plugged into the port + imu = 6, ///< An inertial sensor is plugged into the port + distance = 7, ///< A distance sensor is plugged into the port + radio = 8, ///< A radio is plugged into the port + vision = 11, ///< A vision sensor is plugged into the port + adi = 12, ///< This port is an ADI expander + optical = 16, ///< An optical sensor is plugged into the port + gps = 20, ///< A GPS sensor is plugged into the port + serial = 129, ///< A serial device is plugged into the port + undefined = 255 ///< The device type is not defined, or is not a valid device +}; + +class Device { + public: + /** + * Creates a Device object. + * + * \param port The V5 port number from 1-21 + * + * \b Example + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + * Device device(DEVICE_PORT); + * } + * \endcode + */ + explicit Device(const std::uint8_t port); + + /** + * Gets the port number of the Smart Device. + * + * \return The smart device's port number. + * + * \b Example + * \code + * void opcontrol() { + * #define DEVICE_PORT 1 + * while (true) { + * Device device(DEVICE_PORT); + * printf("device plugged type: {port: %d}\n", device.get_port()); + * delay(20); + * } + * } + * \endcode + */ + std::uint8_t get_port(void) const; + + /** + * Checks if the device is installed. + * + * \return true if the corresponding device is installed, false otherwise. + * \b Example + * + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + * Device device(DEVICE_PORT); + * while (true) { + * printf("device plugged type: {is_installed: %d}\n", device.is_installed()); + * delay(20); + * } + * } + * \endcode + */ + virtual bool is_installed(); + + /** + * Gets the type of device. + * + * This function uses the following values of errno when an error state is + * reached: + * EACCES - Mutex of port cannot be taken (access denied). + * + * \return The device type as an enum. + * + * \b Example + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + Device device(DEVICE_PORT); + * while (true) { + * DeviceType dt = device.get_plugged_type(); + * printf("device plugged type: {plugged type: %d}\n", dt); + * delay(20); + * } + * } + * \endcode + */ + pros::DeviceType get_plugged_type() const; + + + /** + * Gets the type of device on a given port. + * + * This function uses the following values of errno when an error state is + * reached: + * EACCES - Mutex of port cannot be taken (access denied). + * + * \param port The V5 port number from 1-21 + * + * \return The device type as an enum. + * + * \b Example + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + * while (true) { + * DeviceType dt = pros::Device::get_plugged_type(DEVICE_PORT); + * printf("device plugged type: {plugged type: %d}\n", dt); + * delay(20); + * } + * } + * \endcode + */ + static pros::DeviceType get_plugged_type(std::uint8_t port); + + /** + * Gets all devices of a given device type. + * + * \param device_type The pros::DeviceType enum that matches the type of device desired. + * + * \return A vector of Device objects for the given device type. + * + * \b Example + * \code + * void opcontrol() { + * std::vector motor_devices = pros::Device::get_all_devices(pros::DeviceType::motor); // All Device objects are motors + * } + * \endcode + */ + + static std::vector get_all_devices(pros::DeviceType device_type = pros::DeviceType::undefined); + + protected: + /** + * Creates a Device object. + * + * \param port The V5 port number from 1-21 + * + * \param deviceType The type of the constructed device + */ + Device(const std::uint8_t port, const enum DeviceType deviceType) : + _port(port), + _deviceType(deviceType) {} + + protected: + const std::uint8_t _port; + const enum DeviceType _deviceType = pros::DeviceType::none; + + ///@} +}; +} // namespace v5 +} // namespace pros + +#endif diff --git a/EZ-Template-Example-Project/include/pros/distance.h b/EZ-Template-Example-Project/include/pros/distance.h index 783da8fd..63bcd417 100644 --- a/EZ-Template-Example-Project/include/pros/distance.h +++ b/EZ-Template-Example-Project/include/pros/distance.h @@ -1,19 +1,19 @@ /** * \file pros/distance.h + * \ingroup c-distance * * Contains prototypes for functions related to the VEX Distance sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/distance.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-distance VEX Distance Sensor C API */ #ifndef _PROS_DISTANCE_H_ @@ -28,6 +28,15 @@ namespace pros { namespace c { #endif +/** + * \ingroup c-distance + */ + +/** + * \addtogroup c-distance + * @{ + */ + /** * Get the currently measured distance from the sensor in mm * @@ -36,9 +45,21 @@ namespace c { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Distance Sensor * - * \param port The V5 Distance Sensor port number from 1-21 + * \param port The V5 Distance Sensor port number from 1-21 * \return The distance value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Distance Value: %d mm\n", distance_get(DISTANCE_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t distance_get(uint8_t port); @@ -57,6 +78,18 @@ int32_t distance_get(uint8_t port); * \param port The V5 Distance Sensor port number from 1-21 * \return The confidence value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Distance Confidence Value: %d\n", distance_get_confidence(DISTANCE_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t distance_get_confidence(uint8_t port); @@ -75,6 +108,18 @@ int32_t distance_get_confidence(uint8_t port); * \param port The V5 Distance Sensor port number from 1-21 * \return The size value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Distance Object Size: %d\n", distance_get_object_size(DISTANCE_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t distance_get_object_size(uint8_t port); @@ -89,9 +134,23 @@ int32_t distance_get_object_size(uint8_t port); * \param port The V5 Distance Sensor port number from 1-21 * \return The velocity value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Distance Object Velocity: %f\n", distance_get_object_velocity(DISTANCE_PORT)); + * delay(20); + * } + * } + * \endcode */ double distance_get_object_velocity(uint8_t port); +///@} + #ifdef __cplusplus } } diff --git a/EZ-Template-Example-Project/include/pros/distance.hpp b/EZ-Template-Example-Project/include/pros/distance.hpp index 0007035d..ae93928b 100644 --- a/EZ-Template-Example-Project/include/pros/distance.hpp +++ b/EZ-Template-Example-Project/include/pros/distance.hpp @@ -1,30 +1,40 @@ /** * \file pros/distance.hpp + * \ingroup cpp-distance * * Contains prototypes for the V5 Distance Sensor-related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/distance.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-distance VEX Distance Sensor C++ API */ #ifndef _PROS_DISTANCE_HPP_ #define _PROS_DISTANCE_HPP_ #include +#include +#include "pros/device.hpp" #include "pros/distance.h" namespace pros { -class Distance { +inline namespace v5 { +/** + * \ingroup cpp-distance + */ +class Distance : public Device { + /** + * \addtogroup cpp-distance + * @{ + */ public: /** * Creates a Distance Sensor object for the given port. @@ -36,9 +46,19 @@ class Distance { * * \param port * The V5 port number from 1-21 + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * Distance distance(DISTANCE_PORT); + * } + * \endcode */ - explicit Distance(const std::uint8_t port); + Distance(const std::uint8_t port); + Distance(const Device& device) : Distance(device.get_port()){}; /** * Get the currently measured distance from the sensor in mm * @@ -48,10 +68,65 @@ class Distance { * ENODEV - The port cannot be configured as an Distance Sensor * * \return The distance value or PROS_ERR if the operation failed, setting - * errno. + * errno. Will return 9999 if the sensor can not detect an object. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance confidence: %d\n", distance.get()); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t get(); + /** + * Get the currently measured distance from the sensor in mm. + * \note This function is identical to get(). + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \return The distance value or PROS_ERR if the operation failed, setting + * errno. Will return 9999 if the sensor can not detect an object. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance confidence: %d\n", distance.get_distance()); + * delay(20); + * } + * } + * \endcode + */ + virtual std::int32_t get_distance(); + + /** + * Gets all distance sensors. + * + * \return A vector of Distance sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector distance_all = pros::Distance::get_all_devices(); // All distance sensors that are + * connected + * } + * \endcode + */ + static std::vector get_all_devices(); + /** * Get the confidence in the distance reading * @@ -66,6 +141,19 @@ class Distance { * * \return The confidence value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance confidence: %d\n", distance.get_confidence()); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t get_confidence(); @@ -82,7 +170,20 @@ class Distance { * ENODEV - The port cannot be configured as an Distance Sensor * * \return The size value or PROS_ERR if the operation failed, setting - * errno. + * errno. Will return -1 if the sensor is not able to determine object size. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance confidence: %d\n", distance.get_object_size()); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t get_object_size(); @@ -96,19 +197,51 @@ class Distance { * * \return The velocity value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * + * void opcontrol() { + * Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance Object velocity: %f\n", distance.get_object_velocity()); + * delay(20); + * } + * } + * \endcode */ virtual double get_object_velocity(); /** - * Gets the port number of the distance sensor. + * This is the overload for the << operator for printing to streams * - * \return The distance sensor's port number. + * Prints in format(this below is all in one line with no new line): + * Distance [port: (port number), distance: (distance), confidence: (confidence), + * object size: (object size), object velocity: (object velocity)] */ - std::uint8_t get_port(); + friend std::ostream& operator<<(std::ostream& os, pros::Distance& distance); private: - const std::uint8_t _port; + ///@} }; + +namespace literals { +/** + * Constructs a Distance sensor object from a literal ending in _dist via calling the constructor + * + * \return a pros::Distance for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Distance dist = 2_dist; //Makes an dist object on port 2 + * } + * \endcode + */ +const pros::Distance operator"" _dist(const unsigned long long int d); +} // namespace literals +} // namespace v5 } // namespace pros #endif diff --git a/EZ-Template-Example-Project/include/pros/error.h b/EZ-Template-Example-Project/include/pros/error.h index a7e4e54e..17dd6d3d 100644 --- a/EZ-Template-Example-Project/include/pros/error.h +++ b/EZ-Template-Example-Project/include/pros/error.h @@ -18,12 +18,25 @@ #include "limits.h" // Different Byte Size Errors + +/// @brief +/// Return This on Byte Sized Return Error #define PROS_ERR_BYTE (INT8_MAX) + +/// @brief +/// Return This on 2 Byte Sized Return Error #define PROS_ERR_2_BYTE (INT16_MAX) + +/// @brief +/// Return This on 4 Byte Sized Return Error #define PROS_ERR (INT32_MAX) + +/// @brief +/// Return This on 8 Byte Sized Return Error #define PROS_ERR_F (INFINITY) -// Return This on Success +/// @brief +/// Return This on Success (1) #define PROS_SUCCESS (1) #endif diff --git a/EZ-Template-Example-Project/include/pros/ext_adi.h b/EZ-Template-Example-Project/include/pros/ext_adi.h index f75ee051..421b1938 100644 --- a/EZ-Template-Example-Project/include/pros/ext_adi.h +++ b/EZ-Template-Example-Project/include/pros/ext_adi.h @@ -1,18 +1,20 @@ /** * \file pros/ext_adi.h + * \ingroup ext-adi * * Contains prototypes for interfacing with the 3-Wire Expander. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup ext-adi ADI Expander C API + * \note The internal ADI API can be found [here.](@ref c-adi) */ #ifndef _PROS_EXT_ADI_H_ @@ -36,6 +38,15 @@ namespace pros { namespace c { #endif +/** + * \ingroup ext-adi + */ + +/** + * \addtogroup ext-adi + * @{ + */ + /******************************************************************************/ /** General ADI Use Functions **/ /** **/ @@ -57,6 +68,19 @@ namespace c { * the configuration * * \return The ADI configuration for the given port + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * // Displays the value of E_ADI_ANALOG_IN + * printf("Port Type: %d\n", ext_adi_port_get_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * } + * \endcode */ adi_port_config_e_t ext_adi_port_get_config(uint8_t smart_port, uint8_t adi_port); @@ -75,6 +99,18 @@ adi_port_config_e_t ext_adi_port_get_config(uint8_t smart_port, uint8_t adi_port * the configuration * * \return The value stored for the given port + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * printf("Port Value: %d\n", ext_adi_get_value(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * } + * \endcode */ int32_t ext_adi_port_get_value(uint8_t smart_port, uint8_t adi_port); @@ -95,6 +131,17 @@ int32_t ext_adi_port_get_value(uint8_t smart_port, uint8_t adi_port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * } + * \endcode */ int32_t ext_adi_port_set_config(uint8_t smart_port, uint8_t adi_port, adi_port_config_e_t type); @@ -119,6 +166,18 @@ int32_t ext_adi_port_set_config(uint8_t smart_port, uint8_t adi_port, adi_port_c * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define DIGITAL_SENSOR_PORT 1 + * + * void initialize() { + * ext_adi_port_set_config(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT); + * ext_adi_set_value(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, HIGH); + * } + * \endcode */ int32_t ext_adi_port_set_value(uint8_t smart_port, uint8_t adi_port, int32_t value); @@ -147,6 +206,20 @@ int32_t ext_adi_port_set_value(uint8_t smart_port, uint8_t adi_port, int32_t val * The ADI port to calibrate (from 1-8, 'a'-'h', 'A'-'H') * * \return The average sensor value computed by this function + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * ext_adi_analog_calibrate(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT); + * printf("Calibrated Reading: %d\n", + * ext_adi_analog_read_calibrated(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * // All readings from then on will be calibrated + * } + * \endcode */ int32_t ext_adi_analog_calibrate(uint8_t smart_port, uint8_t adi_port); @@ -170,6 +243,20 @@ int32_t ext_adi_analog_calibrate(uint8_t smart_port, uint8_t adi_port); * * \return The analog sensor value, where a value of 0 reflects an input voltage * of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Reading: %d\n", ext_adi_analog_read(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_analog_read(uint8_t smart_port, uint8_t adi_port); @@ -195,6 +282,20 @@ int32_t ext_adi_analog_read(uint8_t smart_port, uint8_t adi_port); * * \return The difference of the sensor value from its calibrated default from * -4095 to 4095 + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Reading: %d\n", ext_adi_analog_read_calibrated(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_analog_read_calibrated(uint8_t smart_port, uint8_t adi_port); @@ -225,6 +326,22 @@ int32_t ext_adi_analog_read_calibrated(uint8_t smart_port, uint8_t adi_port); * * \return The difference of the sensor value from its calibrated default from * -16384 to 16384 + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * ext_adi_analog_calibrate(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT); + * + * printf("Sensor Reading: %d\n", ext_adi_analog_read_calibrated_HR(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_analog_read_calibrated_HR(uint8_t smart_port, uint8_t adi_port); @@ -248,6 +365,21 @@ int32_t ext_adi_analog_read_calibrated_HR(uint8_t smart_port, uint8_t adi_port); * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') * * \return True if the pin is HIGH, or false if it is LOW + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf(“Sensor Value: %dn”, + * ext_adi_digital_read(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_digital_read(uint8_t smart_port, uint8_t adi_port); @@ -275,6 +407,22 @@ int32_t ext_adi_digital_read(uint8_t smart_port, uint8_t adi_port); * * \return 1 if the button is pressed and had not been pressed * the last time this function was called, 0 otherwise. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * if (ext_adi_digital_get_new_press(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT)) { + * // Toggle pneumatics or other state operations + * } + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_digital_get_new_press(uint8_t smart_port, uint8_t adi_port); @@ -299,6 +447,23 @@ int32_t ext_adi_digital_get_new_press(uint8_t smart_port, uint8_t adi_port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * bool state = LOW; + * while (true) { + * state != state; + * ext_adi_digital_write(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, state); + * + * delay(5); // toggle the sensor value every 50ms + * } + * } + * \endcode */ int32_t ext_adi_digital_write(uint8_t smart_port, uint8_t adi_port, bool value); @@ -319,6 +484,17 @@ int32_t ext_adi_digital_write(uint8_t smart_port, uint8_t adi_port, bool value); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * ext_adi_pin_mode(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, INPUT_ANALOG); + * } + * \endcode */ int32_t ext_adi_pin_mode(uint8_t smart_port, uint8_t adi_port, uint8_t mode); @@ -341,6 +517,19 @@ int32_t ext_adi_pin_mode(uint8_t smart_port, uint8_t adi_port, uint8_t mode); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 127); // Go full speed forward + * delay(1000); + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor + * } + * \endcode */ int32_t ext_adi_motor_set(uint8_t smart_port, uint8_t adi_port, int8_t speed); @@ -359,6 +548,22 @@ int32_t ext_adi_motor_set(uint8_t smart_port, uint8_t adi_port, int8_t speed); * The ADI port to get (from 1-8, 'a'-'h', 'A'-'H') * * \return The last set speed of the motor on the given port + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 # + * define MOTOR_PORT 1 + * + * void opcontrol() { + * ext_adi_motor_set(ADI_EXPANDER_PORT, + * MOTOR_PORT, 127); // Go full speed forward + * printf(“Commanded Motor Power: %dn”, + * ext_adi_motor_get(ADI_EXPANDER_PORT, MOTOR_PORT)); // Will display 127 + * delay(1000); + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor + * } + * \endcode */ int32_t ext_adi_motor_get(uint8_t smart_port, uint8_t adi_port); @@ -378,14 +583,27 @@ int32_t ext_adi_motor_get(uint8_t smart_port, uint8_t adi_port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 127); // Go full speed forward + * delay(1000); + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor + * ext_adi_motor_stop(ADI_EXPANDER_PORT, MOTOR_PORT); // use this instead + * } + * \endcode */ int32_t ext_adi_motor_stop(uint8_t smart_port, uint8_t adi_port); /** * Reference type for an initialized encoder. * - * This merely contains the port number for the encoder, unlike its use as an - * object to store encoder data in PROS 2. + * This merely contains the port number for the encoder. */ typedef int32_t ext_adi_encoder_t; @@ -405,6 +623,23 @@ typedef int32_t ext_adi_encoder_t; * * \return The signed and cumulative number of counts since the last start or * reset + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define PORT_TOP 1 #define PORT_BOTTOM 2 + * + * void opcontrol() { + * ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, + * PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * printf(“Encoder Value: %dn”, + * ext_adi_encoder_get(enc)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_encoder_get(ext_adi_encoder_t enc); @@ -429,6 +664,22 @@ int32_t ext_adi_encoder_get(ext_adi_encoder_t enc); * * \return An adi_encoder_t object to be stored and used for later calls to * encoder functions + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * printf("Encoder Value: %d\n", ext_adi_encoder_get(enc)); + * delay(5); + * } + * } + * \endcode */ ext_adi_encoder_t ext_adi_encoder_init(uint8_t smart_port, uint8_t adi_port_top, uint8_t adi_port_bottom, bool reverse); @@ -449,6 +700,20 @@ ext_adi_encoder_t ext_adi_encoder_init(uint8_t smart_port, uint8_t adi_port_top, * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false); + * delay(1000); // Move the encoder around in this time + * ext_adi_encoder_reset(enc); // The encoder is now zero again + * } + * \endcode */ int32_t ext_adi_encoder_reset(ext_adi_encoder_t enc); @@ -466,14 +731,27 @@ int32_t ext_adi_encoder_reset(ext_adi_encoder_t enc); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false); + * // Use the encoder + * ext_adi_encoder_shutdown(enc); + * } + * \endcode */ int32_t ext_adi_encoder_shutdown(ext_adi_encoder_t enc); /** * Reference type for an initialized ultrasonic. * - * This merely contains the port number for the ultrasonic, unlike its use as an - * object to store encoder data in PROS 2. + * This merely contains the port number for the ultrasonic. */ typedef int32_t ext_adi_ultrasonic_t; @@ -495,6 +773,23 @@ typedef int32_t ext_adi_ultrasonic_t; * * \return The distance to the nearest object in m^-4 (10000 indicates 1 meter), * measured from the sensor's mounting points. + * + * \b Example + * \code + * + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", ext_adi_ultrasonic_get(ult)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_ultrasonic_get(ext_adi_ultrasonic_t ult); @@ -518,6 +813,23 @@ int32_t ext_adi_ultrasonic_get(ext_adi_ultrasonic_t ult); * * \return An adi_ultrasonic_t object to be stored and used for later calls to * ultrasonic functions + * + * \b Example + * \code + * + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", ext_adi_ultrasonic_get(ult)); + * delay(5); + * } + * } + * \endcode */ ext_adi_ultrasonic_t ext_adi_ultrasonic_init(uint8_t smart_port, uint8_t adi_port_ping, uint8_t adi_port_echo); @@ -535,14 +847,31 @@ ext_adi_ultrasonic_t ext_adi_ultrasonic_init(uint8_t smart_port, uint8_t adi_por * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", ext_adi_ultrasonic_get(ult)); + * delay(5); + * } + * ext_adi_ultrasonic_shutdown(ult); + * } + * \endcode */ int32_t ext_adi_ultrasonic_shutdown(ext_adi_ultrasonic_t ult); /** * Reference type for an initialized gyroscope. * - * This merely contains the port number for the gyroscope, unlike its use as an - * object to store gyro data in PROS 2. + * This merely contains the port number for the gyroscope. * * (Might Be useless with the wire expander.) */ @@ -566,6 +895,23 @@ typedef int32_t ext_adi_gyro_t; * The adi_gyro_t object for which the angle will be returned * * \return The gyro angle in degrees. + * + * \b Example + * \code + * + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", ext_adi_gyro_get(gyro)); + * delay(5); + * } + * } + * \endcode */ double ext_adi_gyro_get(ext_adi_gyro_t gyro); @@ -593,6 +939,23 @@ double ext_adi_gyro_get(ext_adi_gyro_t gyro); * * \return An adi_gyro_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example + * \code + * + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", ext_adi_gyro_get(gyro)); + * delay(5); + * } + * } + * \endcode */ ext_adi_gyro_t ext_adi_gyro_init(uint8_t smart_port, uint8_t adi_port, double multiplier); @@ -610,6 +973,31 @@ ext_adi_gyro_t ext_adi_gyro_init(uint8_t smart_port, uint8_t adi_port, double mu * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER); + * uint32_t now = millis(); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", ext_adi_gyro_get(gyro)); + * + * if (millis() - now > 2000) { + * // Reset the gyro every 2 seconds + * ext_adi_gyro_reset(gyro); + * now = millis(); + * } + * + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_gyro_reset(ext_adi_gyro_t gyro); @@ -627,14 +1015,38 @@ int32_t ext_adi_gyro_reset(ext_adi_gyro_t gyro); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER); + * uint32_t now = millis(); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", ext_adi_gyro_get(gyro)); + * + * if (millis() - now > 2000) { + * ext_adi_gyro_shutdown(gyro); + * // Shut down the gyro after two seconds + * break; + * } + * + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_gyro_shutdown(ext_adi_gyro_t gyro); /** * Reference type for an initialized potentiometer. * - * This merely contains the port number for the potentiometer, unlike its use as an - * object to store gyro data in PROS 2. + * This merely contains the port number for the potentiometer. */ typedef int32_t ext_adi_potentiometer_t; @@ -645,10 +1057,8 @@ typedef int32_t ext_adi_potentiometer_t; * reached: * ENXIO - The given value is not within the range of ADI Ports * EADDRINUSE - The port is not configured as a potentiometer - * - * \param smart_port - * The smart port with the adi expander (1-21) - * \param adi_port + * + * \param port * The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H') * \param potentiometer_type * An adi_potentiometer_type_e_t enum value specifying the potentiometer version type @@ -677,7 +1087,10 @@ ext_adi_potentiometer_t ext_adi_potentiometer_init(uint8_t smart_port, uint8_t a double ext_adi_potentiometer_get_angle(ext_adi_potentiometer_t potentiometer); /** - * Reference type for an initialized addressable led, which stores its smart and adi port. + * Reference type for an initialized addressable led. + * + * This merely contains the port number for the led, unlike its use as an + * object to store led data in the C++ API. */ typedef int32_t ext_adi_led_t; @@ -697,6 +1110,25 @@ typedef int32_t ext_adi_led_t; * * \return An ext_adi_led_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with a single color of red + * uint32_t buffer[1] = {0xFF0000}; + * + * while (true) { + * // Set the led to colors in the buffer + * ext_adi_led_set(led, buffer, 1); + * delay(5); + * } + * } + * \endcode */ ext_adi_led_t ext_adi_led_init(uint8_t smart_port, uint8_t adi_port); @@ -713,6 +1145,29 @@ ext_adi_led_t ext_adi_led_init(uint8_t smart_port, uint8_t adi_port); * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw * @param buffer_length length of buffer to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with a single color of red + * uint32_t buffer[1] = {0xFF0000}; + * + * while (true) { + * // Set the led to colors in the buffer + * ext_adi_led_set(led, buffer, 1); + * delay(5); + * + * // Clear the led + * ext_adi_led_clear_all(led, buffer, 1); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_clear_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length); @@ -729,6 +1184,25 @@ int32_t ext_adi_led_clear_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buff * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw * @param buffer_length length of buffer to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with a single color of red + * uint32_t buffer[1] = {0xFF0000}; + * + * while (true) { + * // Set the led to colors in the buffer + * ext_adi_led_set(led, buffer, 1); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_set(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length); @@ -746,6 +1220,25 @@ int32_t ext_adi_led_set(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_len * @param buffer_length length of buffer to clear * @param color color to set all the led strip value to * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with a single color of red + * uint32_t buffer[1] = {0xFF0000}; + * + * while (true) { + * // Set the entire led strip to red + * ext_adi_led_set_all(led, buffer, 1, 0xFF0000); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_set_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color); @@ -764,6 +1257,25 @@ int32_t ext_adi_led_set_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer * @param color color to clear all the led strip to * @param pixel_position position of the pixel to clear (0 indexed) * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with multiple colors + * uint32_t buffer[3] = {0xFF0000, 0x00FF00, 0x0000FF}; + * + * while (true) { + * // Set the first pixel to red + * ext_adi_led_set_pixel(led, buffer, 3, 0xFF0000, 0); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_set_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, uint32_t pixel_position); @@ -781,9 +1293,34 @@ int32_t ext_adi_led_set_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buff * @param buffer_length length of the input buffer * @param pixel_position position of the pixel to clear (0 indexed) * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with multiple colors + * uint32_t buffer[3] = {0xFF0000, 0x00FF00, 0x0000FF}; + * + * while (true) { + * // Set the first pixel to red + * ext_adi_led_set_pixel(led, buffer, 3, 0xFF0000, 0); + * delay(5); + * + * // Clear the first pixel + * ext_adi_led_clear_pixel(led, buffer, 3, 0); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_clear_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t pixel_position); +///@} + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/EZ-Template-Example-Project/include/pros/gps.h b/EZ-Template-Example-Project/include/pros/gps.h index 917f6938..c4d4fdfe 100644 --- a/EZ-Template-Example-Project/include/pros/gps.h +++ b/EZ-Template-Example-Project/include/pros/gps.h @@ -1,19 +1,20 @@ /** * \file pros/gps.h + * \ingroup c-gps * * Contains prototypes for functions related to the VEX GPS. * - * Visit https://pros.cs.purdue.edu/v5/api/c/gps.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-gps VEX GPS Sensor C API + * \note For a pros-specific usage guide on the GPS, please check out our article [here.](@ref gps) */ #ifndef _PROS_GPS_H_ @@ -25,26 +26,85 @@ #ifdef __cplusplus extern "C" { namespace pros { -namespace c { -#endif +#endif +/** + * \ingroup c-gps + */ + +/** + * \addtogroup c-gps + * @{ + */ + +/** + * \struct gps_position_s_t + */ +typedef struct __attribute__((__packed__)) gps_position_s { + /// X Position (meters) + double x; + /// Y Position (meters) + double y; +} gps_position_s_t; + +/** + * \struct gps_status_s_t + */ typedef struct __attribute__((__packed__)) gps_status_s { - double x; ///< X Position (meters) - double y; ///< Y Position (meters) - double pitch; ///< Percieved Pitch based on GPS + IMU - double roll; ///< Percieved Roll based on GPS + IMU - double yaw; ///< Percieved Yaw based on GPS + IMU + /// X Position (meters) + double x; + /// Y Position (meters) + double y; + /// Perceived Pitch based on GPS + IMU + double pitch; + /// Perceived Roll based on GPS + IMU + double roll; + /// Perceived Yaw based on GPS + IMU + double yaw; } gps_status_s_t; +/** + * \struct gps_orientation_s_t + */ +typedef struct __attribute__((__packed__)) gps_orientation_s { + /// Perceived Pitch based on GPS + IMU + double pitch; + /// Perceived Roll based on GPS + IMU + double roll; + /// Perceived Yaw based on GPS + IMU + double yaw; +} gps_orientation_s_t; + + +/** + * \struct gps_raw_s + */ struct gps_raw_s { - double x; ///< Percieved Pitch based on GPS + IMU - double y; ///< Percieved Roll based on GPS + IMU - double z; ///< Percieved Yaw based on GPS + IMU + /// Perceived Pitch based on GPS + IMU + double x; + /// Perceived Roll based on GPS + IMU + double y; + /// Perceived Yaw based on GPS + IMU + double z; }; +/** + * \struct gps_accel_s_t + * + */ typedef struct gps_raw_s gps_accel_s_t; + +/** + * \struct gps_gyro_s_t + * + */ typedef struct gps_raw_s gps_gyro_s_t; +#ifdef __cplusplus +namespace c { +#endif + + /** * Set the GPS's offset relative to the center of turning in meters, * as well as its initial position. @@ -69,6 +129,20 @@ typedef struct gps_raw_s gps_gyro_s_t; * Heading with 0 being north on the field, in degrees [0,360) going clockwise * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * #define X_OFFSET .225 + * #define Y_OFFSET .223 + * #define X_INITIAL 1.54 + * #define Y_INITIAL 1.14 + * #define HEADING_INITIAL 90 + * + * void initialize() { + * gps_initialize_full(GPS_PORT, X_OFFSET, Y_OFFSET, X_INITIAL, Y_INITIAL, HEADING_INITIAL); + * } + * \endcode */ int32_t gps_initialize_full(uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset); @@ -90,11 +164,22 @@ int32_t gps_initialize_full(uint8_t port, double xInitial, double yInitial, doub * Cartesian 4-Quadrant Y offset from center of turning (meters) * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * #define X_OFFSET -.225 + * #define Y_OFFSET .225 + * + * void initialize() { + * gps_set_offset(GPS_PORT, X_OFFSET, Y_OFFSET); + * } + * \endcode */ int32_t gps_set_offset(uint8_t port, double xOffset, double yOffset); /** - * Get the GPS's location relative to the center of turning/origin in meters. + * Get the GPS's cartesian location relative to the center of turning/origin in meters. * * This function uses the following values of errno when an error state is * reached: @@ -104,14 +189,25 @@ int32_t gps_set_offset(uint8_t port, double xOffset, double yOffset); * * \param port * The V5 GPS port number from 1-21 - * \param xOffset - * Pointer to cartesian 4-Quadrant X offset from center of turning (meters) - * \param yOffset - * Pointer to cartesian 4-Quadrant Y offset from center of turning (meters) - * \return 1 if the operation was successful or PROS_ERR if the operation + * \return A struct (gps_position_s_t) containing the X and Y values if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_position_s_t pos; + * + * while (true) { + * pos = gps_get_offset(GPS_PORT); + * screen_print(TEXT_MEDIUM, 1, "X Offset: %4d, Y Offset: %4d", pos.x, pos.y); + * delay(20); + * } + * } + * \endcode */ -int32_t gps_get_offset(uint8_t port, double* xOffset, double* yOffset); +gps_position_s_t gps_get_offset(uint8_t port); /** * Sets the robot's location relative to the center of the field in meters. @@ -132,6 +228,18 @@ int32_t gps_get_offset(uint8_t port, double* xOffset, double* yOffset); * Heading with 0 being north on the field, in degrees [0,360) going clockwise * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * #define X_INITIAL -1.15 + * #define Y_INITIAL 1.45 + * #define HEADING_INITIAL 90 + * + * void initialize() { + * gps_set_position(GPS_PORT, X_INITIAL, Y_INITIAL, HEADING_INITIAL); + * } + * \endcode */ int32_t gps_set_position(uint8_t port, double xInitial, double yInitial, double headingInitial); @@ -150,6 +258,19 @@ int32_t gps_set_position(uint8_t port, double xInitial, double yInitial, double * Data rate in milliseconds (Minimum: 5 ms) * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * #define GPS_DATA_RATE 5 + * + * void initialize() { + * gps_set_data_rate(GPS_PORT, GPS_DATA_RATE); + * while (true) { + * // Do something + * } + * } + * \endcode */ int32_t gps_set_data_rate(uint8_t port, uint32_t rate); @@ -167,6 +288,17 @@ int32_t gps_set_data_rate(uint8_t port, uint32_t rate); * * \return Possible RMS (Root Mean Squared) error in meters for GPS position. * If the operation failed, returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double error; + * error = gps_get_error(GPS_PORT); + * screen_print(TEXT_MEDIUM, 1, "Error: %4d", error); + * } + * \endcode */ double gps_get_error(uint8_t port); @@ -185,8 +317,56 @@ double gps_get_error(uint8_t port); * \return A struct (gps_status_s_t) containing values mentioned above. * If the operation failed, all the structure's members are filled with * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_status_s_t status; + * + * while (true) { + * status = gps_get_position_and_orientation(GPS_PORT); + * printf("X: %f, Y: %f, Pitch: %f, Roll: %f, Yaw: %f\n", status.x, status.y, status.pitch, status.roll, status.yaw); + * delay(20); + * } + * } + * \endcode */ -gps_status_s_t gps_get_status(uint8_t port); +gps_status_s_t gps_get_position_and_orientation(uint8_t port); + +/** + * Gets the x and y position on the field of the GPS in meters. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return A struct (gps_position_s_t) containing values mentioned above. + * If the operation failed, all the structure's members are filled with + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_position_s_t position; + * + * while (true) { + * position = gps_get_position(GPS_PORT); + * printf("X: %f, Y: %f\n", position.x, position.y); + * delay(20); + * } + * } + * \endcode + */ +gps_position_s_t gps_get_position(uint8_t port); /** * Gets the X position in meters of the robot relative to the starting position. @@ -202,8 +382,23 @@ gps_status_s_t gps_get_status(uint8_t port); * * \return The X position in meters. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double pos_x; + * + * while (true) { + * pos_x = gps_get_position_x(GPS_PORT); + * printf("X: %f\n", pos_x); + * delay(20); + * } + * } + * \endcode */ -double gps_get_x_position(uint8_t port); +double gps_get_position_x(uint8_t port); /** * Gets the Y position in meters of the robot relative to the starting position. @@ -219,11 +414,26 @@ double gps_get_x_position(uint8_t port); * * \return The Y position in meters. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double pos_y; + * + * while (true) { + * pos_y = gps_get_position_y(GPS_PORT); + * printf("Y: %f\n", pos_y); + * delay(20); + * } + * } + * \endcode */ -double gps_get_y_position(uint8_t port); +double gps_get_position_y(uint8_t port); /** - * Gets the pitch of the GPS in degrees relative to the starting orientation. + * Gets the pitch, roll, and yaw of the GPS relative to the starting orientation. * * This function uses the following values of errno when an error state is * reached: @@ -233,14 +443,62 @@ double gps_get_y_position(uint8_t port); * * \param port * The V5 GPS port number from 1-21 + * + * \return A struct (gps_orientation_s_t) containing values mentioned above. + * If the operation failed, all the structure's members are filled with + * PROS_ERR_F and errno is set. * - * \return The pitch in (-90,90] degree values. If the operation failed, + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_orientation_s_t orientation; + * + * while (true) { + * orientation = gps_get_orientation(GPS_PORT); + * printf("pitch: %f, roll: %f, yaw: %f\n", orientation.pitch, orientation.roll, orientation.yaw); + * delay(20); + * } + * } + * \endcode +*/ +gps_orientation_s_t gps_get_orientation(uint8_t port); + +/** + * Gets the pitch of the robot in degrees relative to the starting oreintation. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return The pitch in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double pitch; + * + * while (true) { + * pitch = gps_get_pitch(GPS_PORT); + * printf("pitch: %f\n", pitch); + * delay(20); + * } + * } + * \endcode */ double gps_get_pitch(uint8_t port); /** - * Gets the roll of the GPS in degrees relative to the starting orientation. + * Gets the roll of the robot in degrees relative to the starting oreintation. * * This function uses the following values of errno when an error state is * reached: @@ -251,13 +509,28 @@ double gps_get_pitch(uint8_t port); * \param port * The V5 GPS port number from 1-21 * - * \return The roll in (-180,180] degree values. If the operation failed, + * \return The roll in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double roll; + * + * while (true) { + * roll = gps_get_roll(GPS_PORT); + * printf("roll: %f\n", roll); + * delay(20); + * } + * } + * \endcode */ double gps_get_roll(uint8_t port); /** - * Gets the yaw of the GPS in degrees relative to the starting orientation. + * Gets the yaw of the robot in degrees relative to the starting oreintation. * * This function uses the following values of errno when an error state is * reached: @@ -268,8 +541,23 @@ double gps_get_roll(uint8_t port); * \param port * The V5 GPS port number from 1-21 * - * \return The yaw in (-180,180] degree values. If the operation failed, + * \return The yaw in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double yaw; + * + * while (true) { + * yaw = gps_get_yaw(GPS_PORT); + * printf("yaw: %f\n", yaw); + * delay(20); + * } + * } + * \endcode */ double gps_get_yaw(uint8_t port); @@ -287,6 +575,21 @@ double gps_get_yaw(uint8_t port); * * \return The heading in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double heading; + * + * while (true) { + * heading = gps_get_heading(GPS_PORT); + * printf("heading: %f\n", heading); + * delay(20); + * } + * } + * \endcode */ double gps_get_heading(uint8_t port); @@ -304,11 +607,26 @@ double gps_get_heading(uint8_t port); * * \return The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation * fails, returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double heading_raw; + * + * while (true) { + * heading_raw = gps_get_heading_raw(GPS_PORT); + * printf("heading_raw: %f\n", heading_raw); + * delay(20); + * } + * } + * \endcode */ double gps_get_heading_raw(uint8_t port); /** - * Gets the GPS sensor's elapsed rotation value + * Get the GPS's raw gyroscope values * * This function uses the following values of errno when an error state is * reached: @@ -318,60 +636,119 @@ double gps_get_heading_raw(uint8_t port); * * \param port * The V5 GPS port number from 1-21 - * \return The elased heading in degrees. If the operation fails, returns - * PROS_ERR_F and errno is set. + * \return A struct (gps_gyro_s_t) containing values mentioned above. + * If the operation failed, all the + * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_gyro_s_t gyro; + * + * while (true) { + * gyro = gps_get_gyro(GPS_PORT); + * printf("Gyro: %f %f %f\n", gyro.x, gyro.y, gyro.z); + * delay(20); + * } + * } + * \endcode */ -double gps_get_rotation(uint8_t port); +gps_gyro_s_t gps_get_gyro_rate(uint8_t port); /** - * Set the GPS sensor's rotation value to target value - * + * Get the GPS's raw gyroscope value in x-axis + * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a GPS * EAGAIN - The sensor is still calibrating - * + * * \param port * The V5 GPS port number from 1-21 - * \param target - * Target rotation value to set rotation value to - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t gps_set_rotation(uint8_t port, double target); + * \return The raw gyroscope value in x-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double gyro_x; + * + * while (true) { + * gyro_x = gps_get_gyro_x(GPS_PORT); + * printf("gyro_x: %f\n", gyro_x); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_gyro_rate_x(uint8_t port); /** - * Tare the GPS sensor's rotation value - * + * Get the GPS's raw gyroscope value in y-axis + * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a GPS * EAGAIN - The sensor is still calibrating - * + * * \param port * The V5 GPS port number from 1-21 - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t gps_tare_rotation(uint8_t port); + * \return The raw gyroscope value in y-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double gyro_y; + * + * while (true) { + * gyro_y = gps_get_gyro_y(GPS_PORT); + * printf("gyro_y: %f\n", gyro_y); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_gyro_rate_y(uint8_t port); /** - * Get the GPS's raw gyroscope values - * + * Get the GPS's raw gyroscope value in z-axis + * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a GPS * EAGAIN - The sensor is still calibrating - * + * * \param port * The V5 GPS port number from 1-21 - * \return The raw gyroscope values. If the operation failed, all the - * structure's members are filled with PROS_ERR_F and errno is set. - */ -gps_gyro_s_t gps_get_gyro_rate(uint8_t port); + * \return The raw gyroscope value in z-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double gyro_z; + * + * while (true) { + * gyro_z = gps_get_gyro_z(GPS_PORT); + * printf("gyro_z: %f\n", gyro_z); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_gyro_rate_z(uint8_t port); /** * Get the GPS's raw accelerometer values @@ -384,11 +761,120 @@ gps_gyro_s_t gps_get_gyro_rate(uint8_t port); * * \param port * The V5 GPS's port number from 1-21 - * \return The raw accelerometer values. If the operation failed, all the + * \return A struct (gps_accel_s_t) containing values mentioned above. + * If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_accel_s_t accel; + * + * while (true) { + * accel = gps_get_accel(GPS_PORT); + * printf("X: %f, Y: %f, Z: %f\n", accel.x, accel.y, accel.z); + * delay(20); + * } + * } + * \endcode */ gps_accel_s_t gps_get_accel(uint8_t port); +/** + * Get the GPS's raw accelerometer value in x-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS's port number from 1-21 + * \return The raw accelerometer value in x-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double accel_x; + * + * while (true) { + * accel_x = gps_get_accel_x(GPS_PORT); + * printf("accel_x: %f\n", accel_x); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_accel_x(uint8_t port); + +/** + * Get the GPS's raw accelerometer value in y-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS's port number from 1-21 + * \return The raw accelerometer value in y-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double accel_y; + * + * while (true) { + * accel_y = gps_get_accel_y(GPS_PORT); + * printf("accel_y: %f\n", accel_y); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_accel_y(uint8_t port); + +/** + * Get the GPS's raw accelerometer value in z-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS's port number from 1-21 + * \return The raw accelerometer value in z-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double accel_z; + * + * while (true) { + * accel_z = gps_get_accel_z(GPS_PORT); + * printf("accel_z: %f\n", accel_z); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_accel_z(uint8_t port); + #ifdef __cplusplus } } diff --git a/EZ-Template-Example-Project/include/pros/gps.hpp b/EZ-Template-Example-Project/include/pros/gps.hpp index 7a321239..332e60b0 100644 --- a/EZ-Template-Example-Project/include/pros/gps.hpp +++ b/EZ-Template-Example-Project/include/pros/gps.hpp @@ -1,19 +1,20 @@ /** * \file pros/gps.hpp + * \ingroup cpp-gps * * Contains prototypes for functions related to the VEX GPS. * - * Visit https://pros.cs.purdue.edu/v5/api/cpp/gps.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-gps VEX GPS Sensor C API + * \note For a pros-specific usage guide on the GPS, please check out our article [here.](@ref gps) */ #ifndef _PROS_GPS_HPP_ @@ -22,26 +23,131 @@ #include #include +#include +#include "pros/device.hpp" #include "pros/gps.h" namespace pros { -class Gps { - const std::uint8_t _port; +inline namespace v5 { +/** + * \ingroup cpp-gps + * @{ + */ +class Gps : public Device { + /** + * \addtogroup cpp-gps + * @{ + */ public: - Gps(const std::uint8_t port) : _port(port){}; + /** + * Creates a GPS object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 port number from 1-21 + * \b Example: + * \code + * pros::Gps gps(1); + * \endcode + * + */ + Gps(const std::uint8_t port) : Device(port, DeviceType::gps){}; - Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial) : _port(port) { + Gps(const Device& device) : Gps(device.get_port()){}; + + /** + * Creates a GPS object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 port number from 1-21 + * \param xInitial + * Cartesian 4-Quadrant X initial position (meters) + * \param yInitial + * Cartesian 4-Quadrant Y initial position (meters) + * \param headingInitial + * Initial heading (degrees) + * + * \b Example: + * \code + * pros::Gps gps(1, 1.30, 1.20, 90); + * \endcode + * + */ + explicit Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial) + : Device(port, DeviceType::gps) { pros::c::gps_set_position(port, xInitial, yInitial, headingInitial); }; - Gps(const std::uint8_t port, double xOffset, double yOffset) : _port(port) { + /** + * Creates a GPS object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 port number from 1-21 + * \param xOffset + * Cartesian 4-Quadrant X offset from center of turning (meters) + * \param yOffset + * Cartesian 4-Quadrant Y offset from center of turning (meters) + * + * \b Example: + * \code + * pros::Gps gps(1, 1.30, 1.20); + * \endcode + * + */ + explicit Gps(const std::uint8_t port, double xOffset, double yOffset) : Device(port, DeviceType::gps) { pros::c::gps_set_offset(port, xOffset, yOffset); }; - Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset) - : _port(port) { + /** + * Creates a GPS object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 port number from 1-21 + * \param xInitial + * Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters) + * \param yInitial + * Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters) + * \param headingInitial + * Initial Heading, with 0 being North, 90 being East, 180 being South, and 270 being West (degrees) + * \param xOffset + * Cartesian 4-Quadrant X offset from center of turning (meters) + * \param yOffset + * Cartesian 4-Quadrant Y offset from center of turning (meters) + * + * \b Example: + * \code + * pros::Gps gps(1, 1.30, 1.20, 180, 1.30, 1.20); + * \endcode + * + */ + explicit Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset, + double yOffset) + : Device(port, DeviceType::gps) { pros::c::gps_initialize_full(port, xInitial, yInitial, headingInitial, xOffset, yOffset); }; @@ -52,8 +158,8 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \param xOffset * Cartesian 4-Quadrant X offset from center of turning (meters) @@ -67,6 +173,20 @@ class Gps { * Heading with 0 being north on the field, in degrees [0,360) going clockwise * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4); + * // this is equivalent to the above line + * gps.initialize_full(1.1, 1.2, 180, .4, .4); + * while (true) { + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t initialize_full(double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset) const; @@ -77,8 +197,8 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \param xOffset * Cartesian 4-Quadrant X offset from center of turning (meters) @@ -86,26 +206,68 @@ class Gps { * Cartesian 4-Quadrant Y offset from center of turning (meters) * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4); + * // this is equivalent to the above line + * gps.set_offset(.4, .4); + * while (true) { + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t set_offset(double xOffset, double yOffset) const; /** - * Get the GPS's location relative to the center of turning/origin in meters. + + * Gets all GPS sensors. + * + * \return A vector of Gps sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector gps_all = pros::Gps::get_all_devices(); // All GPS sensors that are connected + * } + * \endcode + */ + static std::vector get_all_devices(); + + /** + * Get the GPS's cartesian location relative to the center of turning/origin in meters. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \param xOffset - * Pointer to cartesian 4-Quadrant X offset from center of turning (meters) - * \param yOffset - * Pointer to cartesian 4-Quadrant Y offset from center of turning (meters) - * \return 1 if the operation was successful or PROS_ERR if the operation + * \param port + * The V5 GPS port number from 1-21 + * \return A struct (gps_position_s_t) containing the X and Y values if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_position_s_t pos; + * Gps gps(GPS_PORT); + * while (true) { + * pos = gps.get_offset(); + * screen_print(TEXT_MEDIUM, 1, "X Offset: %4d, Y Offset: %4d", pos.x, pos.y); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_offset(double* xOffset, double* yOffset) const; + virtual pros::gps_position_s_t get_offset() const; /** * Sets the robot's location relative to the center of the field in meters. @@ -113,8 +275,8 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \param xInitial * Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters) @@ -124,6 +286,21 @@ class Gps { * Heading with 0 being north on the field, in degrees [0,360) going clockwise * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps.set_position(1.3, 1.4, 180); + * while (true) { + * printf("X: %f, Y: %f, Heading: %f\n", gps.get_position().x, + * gps.get_position().y, gps.get_position().heading); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t set_position(double xInitial, double yInitial, double headingInitial) const; @@ -133,13 +310,28 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \param rate * Data rate in milliseconds (Minimum: 5 ms) * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps.set_data_rate(10); + * while (true) { + * printf("X: %f, Y: %f, Heading: %f\n", gps.get_position().x, + * gps.get_position().y, gps.get_position().heading); + * delay(10); + * } + * } + * \endcode */ virtual std::int32_t set_data_rate(std::uint32_t rate) const; @@ -149,11 +341,23 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return Possible RMS (Root Mean Squared) error in meters for GPS position. * If the operation failed, returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * double error = gps.get_error(); + * printf("Error: %f\n", error); + * pros::delay(20); + * } + * \endcode */ virtual double get_error() const; @@ -163,30 +367,89 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * * \return A struct (gps_status_s_t) containing values mentioned above. * If the operation failed, all the structure's members are filled with * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps_status_s_t status; + * while (true) { + * status = gps.get_position_and_orientation(); + * printf("X: %f, Y: %f, Roll: %f, Pitch: %f, Yaw: %f\n", + * status.x, status.y, status.roll, status.pitch, status.yaw); + * delay(20); + * } + * } + * \endcode */ - virtual pros::c::gps_status_s_t get_status() const; + virtual pros::gps_status_s_t get_position_and_orientation() const; /** - * Gets the X position in meters of the robot relative to the starting position. + * Gets the x and y position on the field of the GPS in meters. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \return A struct (gps_position_s_t) containing values mentioned above. + * If the operation failed, all the structure's members are filled with + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps_position_s_t position; + * while (true) { + * position = gps.get_position(); + * printf("X: %f, Y: %f\n", position.x, position.y); + * delay(20); + * } + * } + * \endcode + */ + virtual pros::gps_position_s_t get_position() const; + + /** + * Gets the X position in meters of the robot relative to the starting position. * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The X position in meters. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double pos_x = gps.get_position_x(); + * printf("X: %f\n", pos_x); + * pros::delay(20); + * } + * } + * \endcode */ - virtual double get_x_position() const; + virtual double get_position_x() const; /** * Gets the Y position in meters of the robot relative to the starting position. @@ -194,57 +457,140 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. - * + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The Y position in meters. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double pos_y = gps.get_position_y(); + * printf("Y: %f\n", pos_y); + * pros::delay(20); + * } + * } + * \endcode */ - virtual double get_y_position() const; + virtual double get_position_y() const; /** - * Gets the pitch of the GPS in degrees relative to the starting orientation. + * Gets the pitch, roll, and yaw of the GPS relative to the starting orientation. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \return A struct (gps_orientation_s_t) containing values mentioned above. + * If the operation failed, all the structure's members are filled with + * PROS_ERR_F and errno is set. * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps_orientation_s_t orientation; + * while (true) { + * orientation = gps.get_orientation(); + * printf("pitch: %f, roll: %f, yaw: %f\n", orientation.pitch, + * orientation.roll, orientation.yaw); + * delay(20); + * } + * } + * \endcode + */ + virtual pros::gps_orientation_s_t get_orientation() const; + + /** + * Gets the pitch of the robot in degrees relative to the starting oreintation. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The pitch in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double pitch = gps.get_pitch(); + * printf("pitch: %f\n", pitch); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_pitch() const; /** - * Gets the roll of the GPS in degrees relative to the starting orientation. + * Gets the roll of the robot in degrees relative to the starting oreintation. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. - * + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The roll in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double roll = gps.get_roll(); + * printf("roll: %f\n", roll); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_roll() const; /** - * Gets the yaw of the GPS in degrees relative to the starting orientation. + * Gets the yaw of the robot in degrees relative to the starting oreintation. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. - * + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The yaw in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double yaw = gps.get_yaw(); + * printf("yaw: %f\n", yaw); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_yaw() const; @@ -254,12 +600,26 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * * \return The heading in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double heading = gps.get_heading(); + * printf("Heading: %f\n", heading); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_heading() const; @@ -269,71 +629,139 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation * fails, returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double heading = gps.get_heading_raw(); + * printf("Heading: %f\n", heading); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_heading_raw() const; /** - * Gets the GPS sensor's elapsed rotation value + * Get the GPS's raw gyroscope value in z-axis * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \return The elased heading in degrees. If the operation fails, returns + * \return The raw gyroscope value in z-axis. If the operation fails, returns * PROS_ERR_F and errno is set. + * + \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double gyro_z = gps.get_gyro_z(); + * printf("gyro_z: %f\n", gyro_z); + * pros::delay(20); + * } + * } + * \endcode */ - virtual double get_rotation() const; + virtual pros::gps_gyro_s_t get_gyro_rate() const; /** - * Set the GPS sensor's rotation value to target value + * Get the GPS's raw gyroscope value in x-axis * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \param target - * Target rotation value to set rotation value to - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \return The raw gyroscope value in x-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double gyro_x = gps.get_gyro_x(); + * printf("gyro_x: %f\n", gyro_x); + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t set_rotation(double target) const; + virtual double get_gyro_rate_x() const; /** - * Tare the GPS sensor's rotation value + * Get the GPS's raw gyroscope value in y-axis * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \return The raw gyroscope value in y-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double gyro_y = gps.get_gyro_y(); + * printf("gyro_y: %f\n", gyro_y); + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t tare_rotation() const; + virtual double get_gyro_rate_y() const; /** - * Get the GPS's raw gyroscope values + * Get the GPS's raw gyroscope value in z-axis * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \return The raw gyroscope values. If the operation failed, all the - * structure's members are filled with PROS_ERR_F and errno is set. - */ - virtual pros::c::gps_gyro_s_t get_gyro_rate() const; + * \return The raw gyroscope value in z-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double gyro_z = gps.get_gyro_z(); + * printf("gyro_z: %f\n", gyro_z); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_gyro_rate_z() const; /** * Get the GPS's raw accelerometer values @@ -341,19 +769,169 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating * - * \param port - * The V5 GPS's port number from 1-21 * \return The raw accelerometer values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. */ - virtual pros::c::gps_accel_s_t get_accel() const; + virtual pros::gps_accel_s_t get_accel() const; + + /** + * Get the GPS's raw accelerometer value in x-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \return The raw accelerometer value in x-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double accel_x = gps.get_accel_x(); + * printf("accel_x: %f\n", accel_x); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_accel_x() const; + /** + * Get the GPS's raw accelerometer value in y-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \return The raw accelerometer value in y-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double accel_y = gps.get_accel_y(); + * printf("accel_y: %f\n", accel_y); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_accel_y() const; + + /** + * Get the GPS's raw accelerometer value in z-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \return The raw accelerometer value in z-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double accel_z = gps.get_accel_z(); + * printf("accel_z: %f\n", accel_z); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_accel_z() const; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format: + * Gps [port: gps._port, x: (x position), y: (y position), heading: (gps heading), rotation: (gps rotation)] + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * std::cout << gps << std::endl; + * pros::delay(20); + * } + * } + * \endcode + */ + friend std::ostream& operator<<(std::ostream& os, const pros::Gps& gps); + + /** + * Gets a gps sensor that is plugged in to the brain + * + * \note The first time this function is called it returns the gps sensor at the lowest port + * If this function is called multiple times, it will cycle through all the ports. + * For example, if you have 1 gps sensor on the robot + * this function will always return a gps sensor object for that port. + * If you have 2 gps sensors, all the odd numered calls to this function will return objects + * for the lower port number, + * all the even number calls will return gps objects for the higher port number + * + * + * This functions uses the following values of errno when an error state is + * reached: + * ENODEV - No gps sensor is plugged into the brain + * + * \return A gps object corresponding to a port that a gps sensor is connected to the brain + * If no gps sensor is plugged in, it returns a gps sensor on port PROS_ERR_BYTE + * + */ + static Gps get_gps(); + ///@} }; // Gps Class +namespace literals { +/** + * Constructs a Gps object with the given port number + * + * \b Example + * \code + * using namespace literals; + * + * void opcontrol() { + * pros::Gps gps = 1_gps; + * while (true) { + * pos = gps.get_position(); + * screen_print(TEXT_MEDIUM, 1, "X Position: %4d, Y Position: %4d", pos.x, pos.y); + * delay(20); + * } + * } + * \endcode + */ +const pros::Gps operator""_gps(const unsigned long long int g); +} // namespace literals + +/// @brief +/// Alias for Gps is GPS for user convenience. using GPS = Gps; +} // namespace v5 } // namespace pros + #endif diff --git a/EZ-Template-Example-Project/include/pros/imu.h b/EZ-Template-Example-Project/include/pros/imu.h index d87508c4..63cc7384 100644 --- a/EZ-Template-Example-Project/include/pros/imu.h +++ b/EZ-Template-Example-Project/include/pros/imu.h @@ -1,19 +1,19 @@ /** * \file pros/imu.h + * \ingroup c-imu * * Contains prototypes for functions related to the VEX Inertial sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-imu VEX Inertial Sensor C API */ #ifndef _PROS_IMU_H_ @@ -25,24 +25,44 @@ #ifdef __cplusplus extern "C" { namespace pros { -namespace c { #endif +/** + * \ingroup c-imu + * */ + +/** + * \addtogroup c-imu + * @{ + */ + +/** + * \enum imu_status_e_t + * @brief Indicates IMU status. + */ typedef enum imu_status_e { - E_IMU_STATUS_READY = 0, // IMU is connected but not currently calibrating - E_IMU_STATUS_CALIBRATING = 1, // IMU is calibrating - E_IMU_STATUS_ERROR = 0xFF, // NOTE: used for returning an error from the get_status function, not that the IMU is - // necessarily in an error state + E_IMU_STATUS_READY = 0, // IMU is connected but not currently calibrating + /** The IMU is calibrating */ + E_IMU_STATUS_CALIBRATING = 1, + /** Used to indicate that an error state was reached in the imu_get_status function,\ + not that the IMU is necessarily in an error state */ + E_IMU_STATUS_ERROR = 0xFF, } imu_status_e_t; typedef enum imu_orientation_e { - E_IMU_Z_UP = 0, // IMU has the Z axis UP (VEX Logo facing DOWN) - E_IMU_Z_DOWN = 1, // IMU has the Z axis DOWN (VEX Logo facing UP) - E_IMU_X_UP = 2, // IMU has the X axis UP - E_IMU_X_DOWN = 3, // IMU has the X axis DOWN - E_IMU_Y_UP = 4, // IMU has the Y axis UP - E_IMU_Y_DOWN = 5, // IMU has the Y axis DOWN + E_IMU_Z_UP = 0, // IMU has the Z axis UP (VEX Logo facing DOWN) + E_IMU_Z_DOWN = 1, // IMU has the Z axis DOWN (VEX Logo facing UP) + E_IMU_X_UP = 2, // IMU has the X axis UP + E_IMU_X_DOWN = 3, // IMU has the X axis DOWN + E_IMU_Y_UP = 4, // IMU has the Y axis UP + E_IMU_Y_DOWN = 5, // IMU has the Y axis DOWN + E_IMU_ORIENTATION_ERROR = 0xFF // NOTE: used for returning an error from the get_physical_orientation function, not + // that the IMU is necessarily in an error state } imu_orientation_e_t; + +/** + * \struct quaternion_s_t + */ typedef struct __attribute__((__packed__)) quaternion_s { double x; double y; @@ -50,21 +70,44 @@ typedef struct __attribute__((__packed__)) quaternion_s { double w; } quaternion_s_t; +/** + * \struct imu_raw_s + * + */ struct imu_raw_s { double x; double y; double z; }; +/** + * \struct imu_gyro_s_t + * + */ typedef struct imu_raw_s imu_gyro_s_t; + +/** + * \struct imu_accel_s_t + * + */ typedef struct imu_raw_s imu_accel_s_t; +/** + * \struct euler_s_t + * + */ typedef struct __attribute__((__packed__)) euler_s { double pitch; double roll; double yaw; } euler_s_t; +#ifdef __cplusplus +namespace c { +#endif +/** + * \def IMU_MINIMUM_DATA_RATE + */ #ifdef PROS_USE_SIMPLE_NAMES #ifdef __cplusplus #define IMU_STATUS_CALIBRATING pros::E_IMU_STATUS_CALIBRATING @@ -94,6 +137,24 @@ typedef struct __attribute__((__packed__)) euler_s { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void initialize() { + * imu_reset(IMU_PORT); + * int time = millis(); + * int iter = 0; + * while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) { + * printf("IMU calibrating... %d\n", iter); + * iter += 10; + * delay(10); + * } + * // should print about 2000 ms + * printf("IMU is done calibrating (took %d ms)\n", iter - time); + * } + * \endcode */ int32_t imu_reset(uint8_t port); @@ -118,7 +179,6 @@ int32_t imu_reset(uint8_t port); * failed (timing out or port claim failure), setting errno. */ int32_t imu_reset_blocking(uint8_t port); - /** * Set the Inertial Sensor's refresh interval in milliseconds. * @@ -142,6 +202,11 @@ int32_t imu_reset_blocking(uint8_t port); * \param rate The data refresh interval in milliseconds * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * \endcode */ int32_t imu_set_data_rate(uint8_t port, uint32_t rate); @@ -162,6 +227,18 @@ int32_t imu_set_data_rate(uint8_t port, uint32_t rate); * The V5 Inertial Sensor port number from 1-21 * \return The degree value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU get rotation: %f degrees\n", imu_get_rotation(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ double imu_get_rotation(uint8_t port); @@ -183,6 +260,18 @@ double imu_get_rotation(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return The degree value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU get heading: %f degrees\n", imu_get_heading(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ double imu_get_heading(uint8_t port); @@ -200,6 +289,19 @@ double imu_get_heading(uint8_t port); * \return The quaternion representing the sensor's orientation. If the * operation failed, all the quaternion's members are filled with PROS_ERR_F and * errno is set. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * quaternion_s_t qt = imu_get_quaternion(IMU_PORT); + * printf("IMU quaternion: {x: %f, y: %f, z: %f, w: %f}\n", qt.x, qt.y, qt.z, qt.w); + * delay(20); + * } + * } + * \endcode */ quaternion_s_t imu_get_quaternion(uint8_t port); @@ -217,11 +319,24 @@ quaternion_s_t imu_get_quaternion(uint8_t port); * \return The Euler angles representing the sensor's orientation. If the * operation failed, all the structure's members are filled with PROS_ERR_F and * errno is set. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * euler_s_t eu = imu_get_euler(IMU_PORT); + * printf("IMU euler angles: {pitch: %f, roll: %f, yaw: %f}\n", eu.pitch, eu.roll, eu.yaw); + * delay(20); + * } + * } + * \endcode */ euler_s_t imu_get_euler(uint8_t port); /** - * Get the Inertial Sensor's pitch angle bounded by (-180,180) + * Get the Inertial Sensor's raw gyroscope values * * This function uses the following values of errno when an error state is * reached: @@ -233,11 +348,23 @@ euler_s_t imu_get_euler(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return The pitch angle, or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU pitch: %f\n", imu_get_pitch(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ -double imu_get_pitch(uint8_t port); +imu_gyro_s_t imu_get_gyro_rate(uint8_t port); /** - * Get the Inertial Sensor's roll angle bounded by (-180,180) + * Get the Inertial Sensor's raw acceleroneter values * * This function uses the following values of errno when an error state is * reached: @@ -248,11 +375,23 @@ double imu_get_pitch(uint8_t port); * \param port * The V5 Inertial Sensor port number from 1-21 * \return The roll angle, or PROS_ERR_F if the operation failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU roll: %f\n", imu_get_roll(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ -double imu_get_roll(uint8_t port); +imu_accel_s_t imu_get_accel(uint8_t port); /** - * Get the Inertial Sensor's yaw angle bounded by (-180,180) + * Get the Inertial Sensor's status * * This function uses the following values of errno when an error state is * reached: @@ -263,11 +402,25 @@ double imu_get_roll(uint8_t port); * \param port * The V5 Inertial Sensor port number from 1-21 * \return The yaw angle, or PROS_ERR_F if the operation failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU yaw: %f\n", imu_get_yaw(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ -double imu_get_yaw(uint8_t port); +imu_status_e_t imu_get_status(uint8_t port); +// Value set functions: /** - * Get the Inertial Sensor's raw gyroscope values + * Sets the current reading of the Inertial Sensor's euler values to + * target euler values. Will default to +/- 180 if target exceeds +/- 180. * * This function uses the following values of errno when an error state is * reached: @@ -279,11 +432,24 @@ double imu_get_yaw(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return The raw gyroscope values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * int32_t val = imu_set_euler(IMU_PORT, {45, 60, 90}); + * printf("IMU : {gyro vals: %d}\n", val); + * delay(20); + * } + * } + * \endcode */ -imu_gyro_s_t imu_get_gyro_rate(uint8_t port); +int32_t imu_set_euler(uint8_t port, euler_s_t target); /** - * Get the Inertial Sensor's raw acceleroneter values + * Get the Inertial Sensor's pitch angle bounded by (-180,180) * * This function uses the following values of errno when an error state is * reached: @@ -295,29 +461,80 @@ imu_gyro_s_t imu_get_gyro_rate(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return The raw accelerometer values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * imu_accel_s_t accel = imu_get_accel(IMU_PORT); + * printf("IMU accel values: {x: %f, y: %f, z: %f}\n", accel.x, accel.y, accel.z); + * delay(20); + * } + * } + * \endcode */ -imu_accel_s_t imu_get_accel(uint8_t port); +double imu_get_pitch(uint8_t port); /** - * Get the Inertial Sensor's status + * Get the Inertial Sensor's roll angle bounded by (-180,180) * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Inertial Sensor + * EAGAIN - The sensor is still calibrating * * \param port * The V5 Inertial Sensor port number from 1-21 * \return The Inertial Sensor's status code, or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void initialize() { + * imu_reset(IMU_PORT); + * int time = millis(); + * int iter = 0; + * while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) { + * printf("IMU calibrating... %d\n", iter); + * iter += 10; + * delay(10); + * } + * // should print about 2000 ms + * printf("IMU is done calibrating (took %d ms)\n", iter - time); + * } + * \endcode */ -imu_status_e_t imu_get_status(uint8_t port); +double imu_get_roll(uint8_t port); + +/** + * Get the Inertial Sensor's yaw angle bounded by (-180,180) + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Inertial Sensor + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 Inertial Sensor port number from 1-21 + * \return The yaw angle, or PROS_ERR_F if the operation failed, setting errno. + */ +double imu_get_yaw(uint8_t port); // NOTE: not used // void imu_set_mode(uint8_t port, uint32_t mode); // uint32_t imu_get_mode(uint8_t port); -// Value reset functions: +/** + * \name Value Reset Functions + * @{ + */ + /** * Resets the current reading of the Inertial Sensor's heading to zero * @@ -331,6 +548,20 @@ imu_status_e_t imu_get_status(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_heading(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_heading(uint8_t port); @@ -347,6 +578,20 @@ int32_t imu_tare_heading(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_rotation(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_rotation(uint8_t port); @@ -363,6 +608,18 @@ int32_t imu_tare_rotation(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_pitch(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_pitch(uint8_t port); @@ -379,6 +636,20 @@ int32_t imu_tare_pitch(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_roll(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_roll(uint8_t port); @@ -395,6 +666,20 @@ int32_t imu_tare_roll(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_yaw(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_yaw(uint8_t port); @@ -411,6 +696,20 @@ int32_t imu_tare_yaw(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_euler(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_euler(uint8_t port); @@ -427,10 +726,30 @@ int32_t imu_tare_euler(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare(uint8_t port); -// Value set functions: +/** @} */ + +/** + * \name Value Set Functions + * @{ + */ + /** * Sets the current reading of the Inertial Sensor's euler values to * target euler values. Will default to +/- 180 if target exceeds +/- 180. @@ -447,6 +766,20 @@ int32_t imu_tare(uint8_t port); * Target euler values for the euler values to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_euler(IMU_PORT, {45,45,45}); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_euler(uint8_t port, euler_s_t target); @@ -465,6 +798,20 @@ int32_t imu_set_euler(uint8_t port, euler_s_t target); * Target value for the rotation value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_rotation(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_rotation(uint8_t port, double target); @@ -484,6 +831,20 @@ int32_t imu_set_rotation(uint8_t port, double target); * Target value for the heading value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_heading(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_heading(uint8_t port, double target); @@ -503,6 +864,20 @@ int32_t imu_set_heading(uint8_t port, double target); * Target value for the pitch value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_pitch(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_pitch(uint8_t port, double target); @@ -522,6 +897,20 @@ int32_t imu_set_pitch(uint8_t port, double target); * Target value for the roll value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_roll(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_roll(uint8_t port, double target); @@ -541,6 +930,19 @@ int32_t imu_set_roll(uint8_t port, double target); * Target value for the yaw value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1void opcontrol() { + * + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_yaw(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_yaw(uint8_t port, double target); @@ -559,6 +961,10 @@ int32_t imu_set_yaw(uint8_t port, double target); */ imu_orientation_e_t imu_get_physical_orientation(uint8_t port); +/** @} */ + +/** @} */ + #ifdef __cplusplus } } diff --git a/EZ-Template-Example-Project/include/pros/imu.hpp b/EZ-Template-Example-Project/include/pros/imu.hpp index 3f6f3933..19240220 100644 --- a/EZ-Template-Example-Project/include/pros/imu.hpp +++ b/EZ-Template-Example-Project/include/pros/imu.hpp @@ -1,34 +1,114 @@ /** * \file pros/imu.hpp + * \ingroup cpp-imu * * Contains prototypes for functions related to the VEX Inertial sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-imu VEX Inertial Sensor C++ API */ #ifndef _PROS_IMU_HPP_ #define _PROS_IMU_HPP_ #include +#include +#include "pros/device.hpp" #include "pros/imu.h" namespace pros { -class Imu { - const std::uint8_t _port; +/** + * \ingroup cpp-imu + * */ + +/** + * \addtogroup cpp-imu + * @{ + */ + +/** + * \enum Imu_Status + * @brief Indicates IMU status. + */ + +enum class ImuStatus { + ready = 0, + /** The IMU is calibrating */ + calibrating = 19, + /** Used to indicate that an error state was reached in the imu_get_status function,\ + not that the IMU is necessarily in an error state */ + error = 0xFF, +}; + +inline namespace v5 { +/** + * \ingroup cpp-imu + */ +class Imu : public Device { + /** + * \addtogroup cpp-imu + * ///@{ + */ public: - Imu(const std::uint8_t port) : _port(port){}; + /** + * Creates an Imu object for the given port + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * + * \param port + * The V5 Inertial Sensor port number from 1-21 + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Do something with the sensor data + * } + * } + * \endcode + */ + + + Imu(const std::uint8_t port) : Device(port, DeviceType::imu){}; + + Imu(const Device& device) : Imu(device.get_port()){}; + /** + * Gets a IMU sensor that is plugged in to the brain + * + * \note The first time this function is called it returns the IMU sensor at the lowest port + * If this function is called multiple times, it will cycle through all the ports. + * For example, if you have 1 IMU sensor on the robot + * this function will always return a IMU sensor object for that port. + * If you have 2 IMU sensors, all the odd numered calls to this function will return objects + * for the lower port number, + * all the even number calls will return IMU objects for the higher port number + * + * + * This functions uses the following values of errno when an error state is + * reached: + * ENODEV - No IMU sensor is plugged into the brain + * + * \return A IMU object corresponding to a port that a IMU sensor is connected to the brain + * If no IMU sensor is plugged in, it returns a IMU sensor on port PROS_ERR_BYTE + * + */ + static Imu get_imu(); /** * Calibrate IMU * @@ -48,6 +128,19 @@ class Imu { * Whether this function blocks during calibration. * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * imu.calibrate(); + * // Block until calibration is complete + * imu.reset(true); + * } + * \endcode */ virtual std::int32_t reset(bool blocking = false) const; /** @@ -68,12 +161,51 @@ class Imu { * ENODEV - The port cannot be configured as an Inertial Sensor * EAGAIN - The sensor is still calibrating * - * \param rate - * The data refresh interval in milliseconds + * \param rate The data refresh interval in milliseconds * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the refresh rate to 5ms + * std::int32_t status = imu.set_data_rate(5); + * delay(20); + * + * // Check if the operation was successful + * if (status == PROS_ERR) { + * // Do something with the error + * } + * + * // Do something with the sensor data + * } + * } + * \endcode */ virtual std::int32_t set_data_rate(std::uint32_t rate) const; + + + /** + * Gets all IMU sensors. + * + * \return A vector of Imu sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector imu_all = pros::Imu::get_all_devices(); // All IMU sensors that are connected + * } + * \endcode + */ + + static std::vector get_all_devices(); + /** * Get the total number of degrees the Inertial Sensor has spun about the z-axis * @@ -91,6 +223,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The degree value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the total number of degrees the sensor has spun + * printf("Total rotation: %f\n", imu.get_rotation()); + * delay(20); + * } + * } + * \endcode */ virtual double get_rotation() const; /** @@ -111,6 +259,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The degree value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's heading + * printf("Heading: %f\n", imu.get_heading()); + * delay(20); + * } + * } + * \endcode */ virtual double get_heading() const; /** @@ -127,8 +291,25 @@ class Imu { * \return The quaternion representing the sensor's orientation. If the * operation failed, all the quaternion's members are filled with PROS_ERR_F and * errno is set. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's quaternion + * pros::quaternion_s_t quat = imu.get_quaternion(); + * cout << "Quaternion: " << quat.w << ", " << quat.x << ", " << quat.y << ", " << quat.z << endl; + * delay(20); + * } + * } + * \endcode */ - virtual pros::c::quaternion_s_t get_quaternion() const; + virtual pros::quaternion_s_t get_quaternion() const; /** * Get the Euler angles representing the Inertial Sensor's orientation * @@ -143,8 +324,25 @@ class Imu { * \return The Euler angles representing the sensor's orientation. If the * operation failed, all the structure's members are filled with PROS_ERR_F and * errno is set. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's Euler angles + * pros::euler_s_t euler = imu.get_euler(); + * cout << "Euler: " << euler.roll << ", " << euler.pitch << ", " << euler.yaw << endl; + * delay(20); + * } + * } + * \endcode */ - virtual pros::c::euler_s_t get_euler() const; + virtual pros::euler_s_t get_euler() const; /** * Get the Inertial Sensor's pitch angle bounded by (-180,180) * @@ -158,6 +356,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The pitch angle, or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's pitch + * printf("Pitch: %f\n", imu.get_pitch()); + * delay(20); + * } + * } + * \endcode */ virtual double get_pitch() const; /** @@ -172,6 +386,22 @@ class Imu { * \param port * The V5 Inertial Sensor port number from 1-21 * \return The roll angle, or PROS_ERR_F if the operation failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's roll + * printf("Roll: %f\n", imu.get_roll()); + * delay(20); + * } + * } + * \endcode */ virtual double get_roll() const; /** @@ -186,6 +416,22 @@ class Imu { * \param port * The V5 Inertial Sensor port number from 1-21 * \return The yaw angle, or PROS_ERR_F if the operation failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's yaw + * printf("Yaw: %f\n", imu.get_yaw()); + * delay(20); + * } + * } + * \endcode */ virtual double get_yaw() const; /** @@ -201,8 +447,25 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The raw gyroscope values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's raw gyroscope values + * pros::imu_gyro_s_t gyro = imu.get_gyro_rate(); + * cout << "Gyro: " << gyro.x << ", " << gyro.y << ", " << gyro.z << endl; + * delay(20); + * } + * } + * \endcode */ - virtual pros::c::imu_gyro_s_t get_gyro_rate() const; + virtual pros::imu_gyro_s_t get_gyro_rate() const; /** * Resets the current reading of the Inertial Sensor's rotation to zero * @@ -216,6 +479,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's rotation value to 10 + * imu.set_rotation(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's rotation value to 0 + * imu.tare_rotation(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_rotation() const; /** @@ -231,6 +516,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's heading value to 10 + * imu.set_heading(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's heading value to 0 + * imu.tare_heading(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_heading() const; /** @@ -246,6 +553,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's pitch value to 10 + * imu.set_pitch(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's pitch value to 0 + * imu.tare_pitch(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_pitch() const; /** @@ -261,6 +590,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's yaw value to 10 + * imu.set_yaw(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's yaw value to 0 + * imu.tare_yaw(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_yaw() const; /** @@ -276,6 +627,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's roll value to 10 + * imu.set_roll(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's roll value to 0 + * imu.tare_roll(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_roll() const; /** @@ -291,6 +664,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Reset all values of the sensor to 0 + * imu.tare(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare() const; /** @@ -306,6 +695,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Reset all euler values of the sensor to 0 + * imu.tare_euler(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_euler() const; /** @@ -324,6 +729,24 @@ class Imu { * Target value for the heading value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's heading value to 10 + * imu.set_heading(10); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_heading(const double target) const; /** @@ -341,6 +764,24 @@ class Imu { * Target value for the rotation value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's rotation value to 10 + * imu.set_rotation(10); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_rotation(const double target) const; /** @@ -359,6 +800,24 @@ class Imu { * Target value for yaw value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's yaw value to 10 + * imu.set_yaw(10); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_yaw(const double target) const; /** @@ -376,6 +835,24 @@ class Imu { * Target value for the pitch value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's pitch value to 10 + * imu.set_pitch(10); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_pitch(const double target) const; /** @@ -394,6 +871,24 @@ class Imu { * Target euler values for the euler values to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's roll value to 100 + * imu.set_roll(100); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_roll(const double target) const; /** @@ -412,8 +907,26 @@ class Imu { * Target euler values for the euler values to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's euler values to 50 + * imu.set_euler(50); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ - virtual std::int32_t set_euler(const pros::c::euler_s_t target) const; + virtual std::int32_t set_euler(const pros::euler_s_t target) const; /** * Get the Inertial Sensor's raw accelerometer values * @@ -427,8 +940,27 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The raw accelerometer values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's raw accelerometer values + * pros::imu_accel_s_t accel = imu.get_accel(); + * printf("x: %f, y: %f, z: %f\n", accel.x, accel.y, accel.z); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ - virtual pros::c::imu_accel_s_t get_accel() const; + virtual pros::imu_accel_s_t get_accel() const; /** * Get the Inertial Sensor's status * @@ -436,21 +968,63 @@ class Imu { * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Inertial Sensor + * EAGAIN - The sensor is still calibrating * * \param port * The V5 Inertial Sensor port number from 1-21 * \return The Inertial Sensor's status code, or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's status + * pros::ImuStatus status = imu.get_status(); + * cout << "Status: " << status << endl; + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ - virtual pros::c::imu_status_e_t get_status() const; + virtual pros::ImuStatus get_status() const; /** * Check whether the IMU is calibrating * * \return true if the V5 Inertial Sensor is calibrating or false * false if it is not. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Calibrate the sensor + * imu.calibrate(); + * delay(20); + * + * // Check if the sensor is calibrating + * if (imu.is_calibrating()) { + * printf("Calibrating...\n"); + * } + * + * // Do something with sensor + * } + * } + * \endcode */ virtual bool is_calibrating() const; - /** * Returns the physical orientation of the IMU * @@ -464,11 +1038,40 @@ class Imu { * \returns The physical orientation of the Inertial Sensor or PROS_ERR if an error occured. * */ - virtual pros::c::imu_orientation_e_t get_physical_orientation() const; + virtual imu_orientation_e_t get_physical_orientation() const; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * Imu [port: imu._port, rotation: (rotation), heading: (heading), + * pitch: (pitch angle), roll: (roll angle), yaw: (yaw angle), + * gyro rate: {x,y,z}, get accel: {x,y,z}, calibrating: (calibrating boolean)] + */ + friend std::ostream& operator<<(std::ostream& os, const pros::Imu& imu); + + ///@} }; -using IMU = Imu; +namespace literals { +/** + * Constructs a Imu from a literal ending in _imu via calling the constructor + * + * \return a pros::Imu for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Imu imu = 2_imu; //Makes an IMU object on port 2 + * } + * \endcode + */ +const pros::Imu operator"" _imu(const unsigned long long int i); +} // namespace literals +using IMU = Imu; +} // namespace v5 } // namespace pros #endif diff --git a/EZ-Template-Example-Project/include/pros/link.h b/EZ-Template-Example-Project/include/pros/link.h index 212834cc..9cd6eead 100644 --- a/EZ-Template-Example-Project/include/pros/link.h +++ b/EZ-Template-Example-Project/include/pros/link.h @@ -1,19 +1,19 @@ /** * \file pros/link.h + * \ingroup c-link * * Contains prototypes for functions related to the robot to robot communications. * - * Visit https://pros.cs.purdue.edu/v5/api/c/link.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-link VEX Link C API */ #ifndef _PROS_LINK_H_ @@ -27,27 +27,42 @@ extern "C" { namespace pros { #endif +/** + * \ingroup c-link + * */ + +/** + * \addtogroup c-link + * @{ + */ + +/** + * \enum link_type_e_t + * \brief Enum for the type of link (TX or RX) + */ typedef enum link_type_e { - E_LINK_RECIEVER = 0, - E_LINK_TRANSMITTER, - E_LINK_RX = E_LINK_RECIEVER, - E_LINK_TX = E_LINK_TRANSMITTER + E_LINK_RECIEVER = 0, ///< Indicates that the radio is a reciever. + E_LINK_TRANSMITTER, ///< Indicates that the link is a transmitter. + E_LINK_RX = E_LINK_RECIEVER, ///< Alias for E_LINK_RECIEVER + E_LINK_TX = E_LINK_TRANSMITTER ///< Alias for E_LINK_TRANSMITTER } link_type_e_t; #ifdef PROS_USE_SIMPLE_NAMES #ifdef __cplusplus -#define LINK_RECIEVER pros::E_LINK_RECIEVER +#define LINK_RECEIVER pros::E_LINK_RECEIVER #define LINK_TRANSMITTER pros::E_LINK_TRANSMITTER #define LINK_RX pros::E_LINK_RX #define LINK_TX pros::E_LINK_TX #else -#define LINK_RECIEVER E_LINK_RECIEVER +#define LINK_RECEIVER E_LINK_RECEIVER #define LINK_TRANSMITTER E_LINK_TRANSMITTER #define LINK_RX E_LINK_RX #define LINK_TX E_LINK_TX #endif #endif +/// @brief +/// The maximum size of a link buffer #define LINK_BUFFER_SIZE 512 #ifdef __cplusplus @@ -59,23 +74,33 @@ namespace c { * 1 to 2 second delay from when this function is called to when the link is initializes. * PROS currently only supports the use of one radio per brain. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * - * \param port + * \param port * The port of the radio for the intended link. * \param link_id * Unique link ID in the form of a string, needs to be different from other links in * the area. * \param type - * Indicates whether the radio link on the brain is a transmitter or reciever, - * with the transmitter having double the transmitting bandwidth as the recieving + * Indicates whether the radio link on the brain is a transmitter or receiver, + * with the transmitter having double the transmitting bandwidth as the receiving * end (1040 bytes/s vs 520 bytes/s). * * \return PROS_ERR if initialization fails, 1 if the initialization succeeds. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * #define LINK_ID "ROBOT1" + * + * void initialize() { + * link_init(LINK_TRANSMITTER_PORT, LINK_ID, E_LINK_TRANSMITTER); + * } + * \endcode */ uint32_t link_init(uint8_t port, const char* link_id, link_type_e_t type); @@ -85,187 +110,308 @@ uint32_t link_init(uint8_t port, const char* link_id, link_type_e_t type); * from when this function is called to when the link is initializes. * PROS currently only supports the use of one radio per brain. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * - * \param port + * \param port * The port of the radio for the intended link. * \param link_id * Unique link ID in the form of a string, needs to be different from other links in * the area. * \param type - * Indicates whether the radio link on the brain is a transmitter or reciever, - * with the transmitter having double the transmitting bandwidth as the recieving + * Indicates whether the radio link on the brain is a transmitter or receiver, + * with the transmitter having double the transmitting bandwidth as the receiving * end (1040 bytes/s vs 520 bytes/s). * * \return PROS_ERR if initialization fails, 1 if the initialization succeeds. + * + * \b Example + * \code + * #define LINK_PORT 1 + * #define LINK_ID "ROBOT1" + * + * void initialize() { + * link_init(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER); + * link_init_override(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER); + * } + * \endcode */ uint32_t link_init_override(uint8_t port, const char* link_id, link_type_e_t type); /** * Checks if a radio link on a port is active or not. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * - * \param port + * + * \param port * The port of the radio for the intended link. * * \return If a radio is connected to a port and it's connected to a link. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * if (link_connected(LINK_TRANSMITTER_PORT)) { + * screen_print(TEXT_MEDIUM, 1, "Link connected!"); + * } + * delay(20); + * } + * } + * \endcode */ bool link_connected(uint8_t port); /** - * Returns the bytes of data available to be read - * - * This function uses the following values of errno when an error state is + * Returns the bytes of data available to be read + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * - * \param port + * + * \param port * The port of the radio for the intended link. * * \return PROS_ERR if port is not a link/radio, else the bytes available to be * read by the user. + * + * \b Example + * \code + * #define LINK_RECIVER_PORT 1 + * + * void opcontrol() { + * while (true) { + * uint32_t receiveable_size = link_raw_receivable_size(LINK_RECIVER_PORT); + * screen_print(TEXT_MEDIUM, 1, "link_raw_receiveable_size: %d", receiveable_size); + * delay(20); + * } + * } + * \endcode */ uint32_t link_raw_receivable_size(uint8_t port); /** * Returns the bytes of data available in transmission buffer. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * - * \param port + * + * \param port * The port of the radio for the intended link. * - * \return PROS_ERR if port is not a link/radio, + * \return PROS_ERR if port is not a link/radio, + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * uint32_t transmittable_size = link_raw_transmittable_size(LINK_TRANSMITTER_PORT); + * screen_print(TEXT_MEDIUM, 1, "link_raw_transmittable_size: %d", transmittable_size); + * delay(20); + * } + * } + * \endcode */ uint32_t link_raw_transmittable_size(uint8_t port); /** * Send raw serial data through vexlink. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no + * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no * room in the FIFO buffer (queue) to transmit the data. * EINVAL - The data given is NULL - * - * \param port + * + * \param port * The port of the radio for the intended link. * \param data * Buffer with data to send * \param data_size * Bytes of data to be read to the destination buffer - * - * \return PROS_ERR if port is not a link, and the successfully transmitted + * + * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* data = "Hello!"; + * link_transmit_raw(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); + * delay(20); + * } + * } + * \endcode */ uint32_t link_transmit_raw(uint8_t port, void* data, uint16_t data_size); /** * Receive raw serial data through vexlink. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer - * or destination buffer. - * - * \param port + * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer + * or destination buffer. + * + * \param port * The port of the radio for the intended link. * \param dest * Destination buffer to read data to * \param data_size * Bytes of data to be read to the destination buffer - * - * \return PROS_ERR if port is not a link, and the successfully received + * + * \return PROS_ERR if port is not a link, and the successfully received * data size if it succeeded. + * + * \b Example + * \code + * #define LINK_RECIVER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* result; + * char* expected = "Hello!"; + * link_receive_raw(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected)); + * delay(20); + * } + * } + * \endcode */ uint32_t link_receive_raw(uint8_t port, void* dest, uint16_t data_size); /** * Send packeted message through vexlink, with a checksum and start byte. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no + * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no * room in the FIFO buffer (queue) to transmit the data. * EINVAL - The data given is NULL - * - * \param port + * + * \param port * The port of the radio for the intended link. * \param data * Buffer with data to send * \param data_size * Bytes of data to be read to the destination buffer - * - * \return PROS_ERR if port is not a link, and the successfully transmitted + * + * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* data = "Hello!"; + * link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); + * delay(20); + * } + * } + * \endcode */ uint32_t link_transmit(uint8_t port, void* data, uint16_t data_size); /** * Receive packeted message through vexlink, with a checksum and start byte. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer - * or destination buffer. + * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer + * or destination buffer. * EBADMSG - Protocol error related to start byte, data size, or checksum. - * - * \param port + * + * \param port * The port of the radio for the intended link. * \param dest * Destination buffer to read data to * \param data_size * Bytes of data to be read to the destination buffer - * - * \return PROS_ERR if port is not a link or protocol error, and the successfully + * + * \return PROS_ERR if port is not a link or protocol error, and the successfully * transmitted data size if it succeeded. + * + * \b Example + * \code + * #define LINK_RECIVER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* result; + * char* expected = "Hello!"; + * link_receive(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected)); + * delay(20); + * } + * } + * \endcode */ uint32_t link_receive(uint8_t port, void* dest, uint16_t data_size); /** * Clear the receive buffer of the link, and discarding the data. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * - * \param port + * + * \param port * The port of the radio for the intended link. - * - * \return PROS_ERR if port is not a link, and the successfully received + * + * \return PROS_ERR if port is not a link, and the successfully received * data size if it succeeded. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* data = "Hello!"; + * link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); + * link_clear_receive_buf(LINK_TRANSMITTER_PORT); + * delay(20); + * } + * } + * \endcode */ uint32_t link_clear_receive_buf(uint8_t port); +///@} + #ifdef __cplusplus } } diff --git a/EZ-Template-Example-Project/include/pros/link.hpp b/EZ-Template-Example-Project/include/pros/link.hpp index d6c18f3a..68bb5e51 100644 --- a/EZ-Template-Example-Project/include/pros/link.hpp +++ b/EZ-Template-Example-Project/include/pros/link.hpp @@ -1,19 +1,19 @@ /** * \file pros/link.hpp + * \ingroup cpp-link * * Contains prototypes for functions related to robot to robot communications. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/link.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * Copyright (c) 2017-2021, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-link VEX Link C++ API */ #ifndef _PROS_LINK_HPP_ #define _PROS_LINK_HPP_ @@ -22,18 +22,25 @@ #include #include "pros/link.h" +#include "pros/device.hpp" namespace pros { -class Link { +/** + * \ingroup cpp-link + */ +class Link : public Device { + /** + * \addtogroup cpp-link + * ///@{ + */ private: - std::uint8_t _port; public: /** * Initializes a link on a radio port, with an indicated type. There might be a * 1 to 2 second delay from when this function is called to when the link is initializes. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -45,33 +52,46 @@ class Link { * Unique link ID in the form of a string, needs to be different from other links in * the area. * \param type - * Indicates whether the radio link on the brain is a transmitter or reciever, - * with the transmitter having double the transmitting bandwidth as the recieving + * Indicates whether the radio link on the brain is a transmitter or receiver, + * with the transmitter having double the transmitting bandwidth as the receiving * end (1040 bytes/s vs 520 bytes/s). * \param ov - * Indicates if the radio on the given port needs vexlink to override the controller radio + * Indicates if the radio on the given port needs vexlink to override the controller radio. Defualts to True. * * \return PROS_ERR if initialization fails, 1 if the initialization succeeds. + * + * \b Example: + * \code + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * \endcode */ - Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov = false); + explicit Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov = true); /** * Checks if a radio link on a port is active or not. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * * \return If a radio is connected to a port and it's connected to a link. + * + * \b Example: + * \code + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * if (link.connected()) { + * // do something + * } + * \endcode */ bool connected(); /** * Returns the bytes of data number of without protocol available to be read * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -79,26 +99,42 @@ class Link { * * \return PROS_ERR if port is not a link/radio, else the bytes available to be * read by the user. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * printf("Bytes available to read: %d", link.receivable_size()); + * } + * \endcode */ std::uint32_t raw_receivable_size(); /** * Returns the bytes of data available in transmission buffer. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * * \return PROS_ERR if port is not a link/radio, + * else the bytes available to be transmitted by the user. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * printf("Bytes available to transmit: %d", link.transmittable_size()); + * } */ std::uint32_t raw_transmittable_size(); /** * Send raw serial data through vexlink. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -114,13 +150,23 @@ class Link { * * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * std::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04}; + * link.transmit_raw(data, 4); + * } + * + * \endcode */ std::uint32_t transmit_raw(void* data, std::uint16_t data_size); /** * Receive raw serial data through vexlink. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -135,13 +181,22 @@ class Link { * * \return PROS_ERR if port is not a link, and the successfully received * data size if it succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * std::uint8_t data[4]; + * link.receive_raw(data, 4); + * } + * \endcode */ std::uint32_t receive_raw(void* dest, std::uint16_t data_size); /** * Send packeted message through vexlink, with a checksum and start byte. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -157,13 +212,22 @@ class Link { * * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * std::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04}; + * link.transmit(data, 4); + * } + * \endcode */ std::uint32_t transmit(void* data, std::uint16_t data_size); /** * Receive packeted message through vexlink, with a checksum and start byte. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -179,21 +243,40 @@ class Link { * * \return PROS_ERR if port is not a link, and the successfully received * data size if it succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * std::uint8_t data[4]; + * link.receive(data, 4); + * } + * \endcode */ std::uint32_t receive(void* dest, std::uint16_t data_size); /** * Clear the receive buffer of the link, and discarding the data. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - + * * \return PROS_ERR if port is not a link, 1 if the operation succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * link.clear_receive_buf(); + * } + * \endcode */ std::uint32_t clear_receive_buf(); + + ///@} }; } // namespace pros diff --git a/EZ-Template-Example-Project/include/pros/llemu.h b/EZ-Template-Example-Project/include/pros/llemu.h index 8a6d7570..868cd736 100644 --- a/EZ-Template-Example-Project/include/pros/llemu.h +++ b/EZ-Template-Example-Project/include/pros/llemu.h @@ -1,92 +1,27 @@ -/* - * \file pros/llemu.h - * - * Legacy LCD Emulator - * - * This file defines a high-level API for emulating the three-button, UART-based - * VEX LCD, containing a set of functions that facilitate the use of a software- - * emulated version of the classic VEX LCD module. - * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/llemu.html to learn - * more. - * - * This file should not be modified by users, since it gets replaced whenever - * a kernel upgrade occurs. - * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - #ifndef _PROS_LLEMU_H_ #define _PROS_LLEMU_H_ -#include -#include +// TODO:? Should there be weak symbols for the C api in here as well? -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wignored-qualifiers" -#include "display/lvgl.h" -#pragma GCC diagnostic pop +#include "stdint.h" -#ifdef __cplusplus -extern "C" { -namespace pros { +/******************************************************************************/ +/** 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 -typedef void (*lcd_btn_cb_fn_t)(void); - -#define LCD_BTN_LEFT 4 -#define LCD_BTN_CENTER 2 -#define LCD_BTN_RIGHT 1 - -typedef struct lcd_s { - lv_obj_t* frame; - lv_obj_t* screen; - lv_obj_t* lcd_text[8]; - lv_obj_t* btn_container; - lv_obj_t* btns[3]; // < 0 => left; 1 => center; 2 => right - lcd_btn_cb_fn_t callbacks[3]; // < 0 => left; 1 => center; 2 => right - volatile uint8_t touch_bits; // < 4 => left; 2 => center; 1 => right (no - // multitouch support) -} lcd_s_t; - #ifdef __cplusplus +extern "C" { +namespace pros { namespace c { -#endif - -/** - * Checks whether the emulated three-button LCD has already been initialized. - * - * \return True if the LCD has been initialized or false if not. - */ -bool lcd_is_initialized(void); - -/** - * 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. - */ -bool lcd_initialize(void); - -/** - * Turns 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 lcd_initialize. - * - * 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. - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_shutdown(void); +#endif//__cplusplus /** * Displays a formatted string on the emulated three-button LCD screen. @@ -106,150 +41,14 @@ bool lcd_shutdown(void); * \return True if the operation was successful, or false otherwise, setting * errno values as specified above. */ -bool lcd_print(int16_t line, const char* fmt, ...); - -/** - * 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. - */ -bool lcd_set_text(int16_t line, const char* text); - -/** - * Clears the contents 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] - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_clear(void); - -/** - * 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. - */ -bool lcd_clear_line(int16_t line); - -/** - * Registers 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. - * - * 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_register_btn0_cb(lcd_btn_cb_fn_t cb); - -/** - * Registers 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. - * - * 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_register_btn1_cb(lcd_btn_cb_fn_t cb); - -/** - * 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. - * - * 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_register_btn2_cb(lcd_btn_cb_fn_t cb); - -/** - * 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 - */ -uint8_t lcd_read_buttons(void); - -/** - * Changes the color of the LCD background to a provided color expressed in - * type lv_color_t. - * - * \param color - * A color of type lv_color_t - * - * \return void - */ -void lcd_set_background_color(lv_color_t color); - -/** - * Changes the text color of the LCD to a provided color expressed in - * type lv_color_t. - * - * \param color - * A color of type lv_color_t - * - * \return void - */ -void lcd_set_text_color(lv_color_t color); +bool __attribute__((weak)) lcd_print(int16_t line, const char* fmt, ...) { + return false; +} #ifdef __cplusplus -} // namespace c -} // namespace pros -} -#endif -#endif // _PROS_LLEMU_H_ +} // namespace c +} // namespace pros +} // extern "C" +#endif//__cplusplus + +#endif // _PROS_LLEMU_H_ diff --git a/EZ-Template-Example-Project/include/pros/llemu.hpp b/EZ-Template-Example-Project/include/pros/llemu.hpp index a4834e02..4f75d6c7 100644 --- a/EZ-Template-Example-Project/include/pros/llemu.hpp +++ b/EZ-Template-Example-Project/include/pros/llemu.hpp @@ -1,19 +1,17 @@ -/* +/** * \file pros/llemu.hpp - * + * \ingroup cpp-llemu + * * Legacy LCD Emulator * - * This file defines a high-level API for emulating the three-button, UART-based + * \details This file defines a high-level API for emulating the three-button, UART-based * VEX LCD, containing a set of functions that facilitate the use of a software- * emulated version of the classic VEX LCD module. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/llemu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -26,237 +24,115 @@ #include #include -#include "pros/llemu.h" +/******************************************************************************/ +/** 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 + +/******************************************************************************/ +/** LLEMU Weak Stubs **/ +/** **/ +/** These functions allow main.cpp to be compiled without LVGL present **/ +/******************************************************************************/ namespace pros { -namespace lcd { -/** - * Checks whether the emulated three-button LCD has already been initialized. - * - * \return True if the LCD has been initialized or false if not. - */ -bool is_initialized(void); - + /** - * 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. - */ -bool initialize(void); - -/** - * Turns 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 lcd_initialize. - * - * 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. - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool shutdown(void); - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-function" -namespace { -template -T convert_args(T arg) { - return arg; -} -const char* convert_args(const std::string& arg) { - return arg.c_str(); -} -} // namespace -#pragma GCC diagnostic pop - -/** - * 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. + * \ingroup cpp-llemu */ -template -bool print(std::int16_t line, const char* fmt, Params... args) { - return pros::c::lcd_print(line, fmt, convert_args(args)...); -} - -/** - * 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. - */ -bool set_text(std::int16_t line, std::string text); - -/** - * Clears the contents 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] - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool clear(void); - -/** - * 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. - */ -bool clear_line(std::int16_t line); - -using lcd_btn_cb_fn_t = void (*)(void); - -/** - * Registers 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t(void (*cb)(void)) - */ -void register_btn0_cb(lcd_btn_cb_fn_t cb); - -/** - * Registers 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t(void (*cb)(void)) - */ -void register_btn1_cb(lcd_btn_cb_fn_t cb); - -/** - * 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)) - */ -void register_btn2_cb(lcd_btn_cb_fn_t cb); - -/** - * 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 - */ -std::uint8_t read_buttons(void); - -/** - * Changes the color of the LCD background to a provided color expressed in - * type lv_color_t. - * - * \param color - * A color of type lv_color_t - * - * \return void - */ -void set_background_color(lv_color_t color); - -/** - * Changes the color of the LCD background to a provided color expressed in RGB - * form, with three values of type uint8_t. - * - * \param r - * A value of type uint8_t, with a range of 0 to 255, representing the - * red value of a color - * - * \param g - * A value of type uint8_t, with a range of 0 to 255, representing the - * green value of a color - * - * \param b - * A value of type uint8_t, with a range of 0 to 255, representing the - * blue value of a color - * - * \return void - */ -void set_background_color(std::uint8_t r, std::uint8_t g, std::uint8_t b); - -/** - * Changes the text color of the LCD to a provided color expressed in - * type lv_color_t. - * - * \param color - * A color of type lv_color_t - * - * \return void - */ -void set_text_color(lv_color_t color); - -/** - * Changes the text color of the LCD to a provided color expressed in RGB - * form, with three values of type uint8_t. - * - * \param r - * A value of type uint8_t, with a range of 0 to 255, representing the - * red value of a color - * - * \param g - * A value of type uint8_t, with a range of 0 to 255, representing the - * green value of a color - * - * \param b - * A value of type uint8_t, with a range of 0 to 255, representing the - * blue value of a color - * - * \return void - */ -void set_text_color(std::uint8_t r, std::uint8_t g, std::uint8_t b); - -} // namespace lcd -} // namespace pros - -#endif // _PROS_LLEMU_HPP_ +namespace lcd { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-function" + namespace { + template + 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); + + /* + * These weak symbols allow the example main.cpp in to compile even when + * the liblvgl template is missing from the project. + * + * For documentation on these functions, please see the doxygen comments for + * these functions in the libvgl llemu headers. + */ + + extern __attribute__((weak)) bool set_text(std::int16_t line, std::string text); + extern __attribute__((weak)) bool clear_line(std::int16_t line); + extern __attribute__((weak)) bool initialize(void); + extern __attribute__((weak)) std::uint8_t read_buttons(void); + extern __attribute__((weak)) void register_btn1_cb(lcd_btn_cb_fn_t cb); + extern __attribute__((weak)) bool is_initialized(void); + + /** + * \addtogroup cpp-llemu + * @{ + */ + + /* + * Note: This template resides in this file since the + */ + + /** + * 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 ...args + * Optional list of arguments for the format string + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::print(0, "My formatted text: %d!", 2); + * } + * \endcode + */ + template + 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 + +#endif // _PROS_LLEMU_HPP_ diff --git a/EZ-Template-Example-Project/include/pros/misc.h b/EZ-Template-Example-Project/include/pros/misc.h index 16cba550..677dad81 100644 --- a/EZ-Template-Example-Project/include/pros/misc.h +++ b/EZ-Template-Example-Project/include/pros/misc.h @@ -1,21 +1,22 @@ /** * \file pros/misc.h + * \ingroup c-misc * * Contains prototypes for miscellaneous functions pertaining to the controller, * battery, and competition control. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/controller.html to - * learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reservered. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-misc Miscellaneous C API + * \note Additional example code for this module can be found in its [Tutorial.](@ref controller) */ #ifndef _PROS_MISC_H_ @@ -25,63 +26,203 @@ #define NUM_V5_PORTS (22) -/******************************************************************************/ -/** V5 Competition **/ -/******************************************************************************/ -#define COMPETITION_DISABLED (1 << 0) +/** + * \ingroup c-misc + */ + +/** + * \addtogroup c-misc + * @{ + */ + +/// \name V5 Competition +//@{ + +/*#define COMPETITION_DISABLED (1 << 0) #define COMPETITION_AUTONOMOUS (1 << 1) #define COMPETITION_CONNECTED (1 << 2) +#define COMPETITION_SYSTEM (1 << 3)*/ +typedef enum { + COMPETITION_DISABLED = 1 << 0, + COMPETITION_CONNECTED = 1 << 2, + COMPETITION_AUTONOMOUS = 1 << 1, + COMPETITION_SYSTEM = 1 << 3, +} competition_status; + +#ifdef __cplusplus +extern "C" { +namespace pros { +namespace c { +#endif /** + * \fn competition_get_status(void) * Get the current status of the competition control. * * \return The competition control status as a mask of bits with * COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}. + * + * \b Example + * \code + * void initialize() { + * if (competition_get_status() & COMPETITION_CONNECTED == true) { + * // Field Control is Connected + * // Run LCD Selector code or similar + * } + * } + * \endcode */ -#ifdef __cplusplus -extern "C" { -namespace pros { -namespace c { -#endif uint8_t competition_get_status(void); + +/** + * \fn competition_is_disabled() + * + * \return True if the V5 Brain is disabled, false otherwise. + * + * \b Example + * \code + * void my_task_fn(void* ignore) { + * while (!competition_is_disabled()) { + * // Run competition tasks (like Lift Control or similar) + * } + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIO_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode + */ +uint8_t competition_is_disabled(void); + +/** + * \return True if the V5 Brain is connected to competition control, false otherwise. + * + * \b Example + * \code + * void initialize() { + * if (competition_is_connected()) { + * // Field Control is Connected + * // Run LCD Selector code or similar + * } + * } + * \endcode + */ +uint8_t competition_is_connected(void); + +/** + * \return True if the V5 Brain is in autonomous mode, false otherwise. + * + * \b Example + * \code + * void my_task_fn(void* ignore) { + * while (!competition_is_autonomous()) { + * // Wait to do anything until autonomous starts + * delay(2); + * } + * while (competition_is_autonomous()) { + * // Run whatever code is desired to just execute in autonomous + * } + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIO_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode + */ +uint8_t competition_is_autonomous(void); + +/** + * \return True if the V5 Brain is connected to VEXnet Field Controller, false otherwise. + * + * \b Example + * \code + * void initialize() { + * if (competition_is_field()) { + * // connected to VEXnet Field Controller + * } + * } + * \endcode + */ +uint8_t competition_is_field(void); + +/** + * \return True if the V5 Brain is connected to VEXnet Competition Switch, false otherwise. + * + * \b Example + * \code + * void initialize() { + * if (competition_is_switch()) { + * // connected to VEXnet Competition Switch + * } + * } + */ +uint8_t competition_is_switch(void); + #ifdef __cplusplus } } } #endif -#define competition_is_disabled() ((competition_get_status() & COMPETITION_DISABLED) != 0) -#define competition_is_connected() ((competition_get_status() & COMPETITION_CONNECTED) != 0) -#define competition_is_autonomous() ((competition_get_status() & COMPETITION_AUTONOMOUS) != 0) +///@} -/******************************************************************************/ -/** V5 Controller **/ -/******************************************************************************/ +/// \name V5 Controller +///@{ #ifdef __cplusplus extern "C" { namespace pros { #endif -typedef enum { E_CONTROLLER_MASTER = 0, E_CONTROLLER_PARTNER } controller_id_e_t; +/** + * \enum + */ +typedef enum { + /// The master controller. + E_CONTROLLER_MASTER = 0, + /// The partner controller. + E_CONTROLLER_PARTNER +} controller_id_e_t; +/** + * \enum + */ typedef enum { + /// The horizontal axis of the controller’s left analog stick. E_CONTROLLER_ANALOG_LEFT_X = 0, + /// The vertical axis of the controller’s left analog stick. E_CONTROLLER_ANALOG_LEFT_Y, + /// The horizontal axis of the controller’s right analog stick. E_CONTROLLER_ANALOG_RIGHT_X, + /// The vertical axis of the controller’s right analog stick. E_CONTROLLER_ANALOG_RIGHT_Y } controller_analog_e_t; +/** + * \enum + */ typedef enum { + /// The first trigger on the left side of the controller. E_CONTROLLER_DIGITAL_L1 = 6, + /// The second trigger on the left side of the controller. E_CONTROLLER_DIGITAL_L2, + /// The first trigger on the right side of the controller. E_CONTROLLER_DIGITAL_R1, + /// The second trigger on the right side of the controller. E_CONTROLLER_DIGITAL_R2, + /// The up arrow on the left arrow pad of the controller. E_CONTROLLER_DIGITAL_UP, + /// The down arrow on the left arrow pad of the controller. E_CONTROLLER_DIGITAL_DOWN, + /// The left arrow on the left arrow pad of the controller. E_CONTROLLER_DIGITAL_LEFT, + /// The right arrow on the left arrow pad of the controller. E_CONTROLLER_DIGITAL_RIGHT, + /// The ‘X’ button on the right button pad of the controller. E_CONTROLLER_DIGITAL_X, + /// The ‘B’ button on the right button pad of the controller. E_CONTROLLER_DIGITAL_B, + /// The ‘Y’ button on the right button pad of the controller. E_CONTROLLER_DIGITAL_Y, + /// The ‘A’ button on the right button pad of the controller. E_CONTROLLER_DIGITAL_A } controller_digital_e_t; @@ -127,48 +268,28 @@ typedef enum { #endif #endif -/* -Given an id and a port, this macro sets the port -variable based on the id and allows the mutex to take that port. - -Returns error (in the function/scope it's in) if the controller -failed to connect or an invalid id is given. -*/ +/** + * \def Given an id and a port, this macro sets the port variable based on the id and allows the mutex to take that + * port. + * + * \returns error (in the function/scope it's in) if the controller failed to connect or an invalid id is given. + */ #define CONTROLLER_PORT_MUTEX_TAKE(id, port) \ - switch (id) { \ - case E_CONTROLLER_MASTER: \ - port = V5_PORT_CONTROLLER_1; \ - break; \ - case E_CONTROLLER_PARTNER: \ - port = V5_PORT_CONTROLLER_2; \ - break; \ - default: \ - errno = EINVAL; \ - return PROS_ERR; \ - } \ - if (!internal_port_mutex_take(port)) { \ - errno = EACCES; \ - return PROS_ERR; \ - } \ -/******************************************************************************/ -/** Date and Time **/ -/******************************************************************************/ - -extern const char* baked_date; -extern const char* baked_time; - -typedef struct { - uint16_t year; // Year - 1980 - uint8_t day; - uint8_t month; // 1 = January -} date_s_t; - -typedef struct { - uint8_t hour; - uint8_t min; - uint8_t sec; - uint8_t sec_hund; // hundredths of a second -} time_s_t; + switch (id) { \ + case E_CONTROLLER_MASTER: \ + port = V5_PORT_CONTROLLER_1; \ + break; \ + case E_CONTROLLER_PARTNER: \ + port = V5_PORT_CONTROLLER_2; \ + break; \ + default: \ + errno = EINVAL; \ + return PROS_ERR; \ + } \ + if (!internal_port_mutex_take(port)) { \ + errno = EACCES; \ + return PROS_ERR; \ + } #ifdef __cplusplus namespace c { @@ -188,6 +309,16 @@ namespace c { * Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER * * \return 1 if the controller is connected, 0 otherwise + * + * \b Example + * \code + * void initialize() { + * if (competition_is_connected()) { + * // Field Control is Connected + * // Run LCD Selector code or similar + * } + * } + * \endcode */ int32_t controller_is_connected(controller_id_e_t id); @@ -210,6 +341,16 @@ int32_t controller_is_connected(controller_id_e_t id); * * \return The current reading of the analog channel: [-127, 127]. * If the controller was not connected, then 0 is returned + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * delay(2); + * } + * } + * \endcode */ int32_t controller_get_analog(controller_id_e_t id, controller_analog_e_t channel); @@ -227,6 +368,13 @@ int32_t controller_get_analog(controller_id_e_t id, controller_analog_e_t channe * Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER * * \return The controller's battery capacity + * + * \b Example + * \code + * void initialize() { + * printf("Battery Capacity: %d\n", controller_get_battery_capacity(E_CONTROLLER_MASTER)); + * } + * \endcode */ int32_t controller_get_battery_capacity(controller_id_e_t id); @@ -244,6 +392,13 @@ int32_t controller_get_battery_capacity(controller_id_e_t id); * Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER * * \return The controller's battery level + * + * \b Example + * \code + * void initialize() { + * printf("Battery Level: %d\n", controller_get_battery_level(E_CONTROLLER_MASTER)); + * } + * \endcode */ int32_t controller_get_battery_level(controller_id_e_t id); @@ -265,6 +420,22 @@ int32_t controller_get_battery_level(controller_id_e_t id); * * \return 1 if the button on the controller is pressed. * If the controller was not connected, then 0 is returned + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * if (controller_get_digital(E_CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_A)) { + * motor_set(1, 100); + * } + * else { + * motor_set(1, 0); + * } + * delay(2); + * } + * } + + * \endcode */ int32_t controller_get_digital(controller_id_e_t id, controller_digital_e_t button); @@ -294,20 +465,34 @@ int32_t controller_get_digital(controller_id_e_t id, controller_digital_e_t butt * * \return 1 if the button on the controller is pressed and had not been pressed * the last time this function was called, 0 otherwise. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * if (controller_get_digital_new_press(E_CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_A)) { + * // Toggle pneumatics or other similar actions + * } + * + * delay(2); + * } + * } + * \endcode */ int32_t controller_get_digital_new_press(controller_id_e_t id, controller_digital_e_t button); /** * Sets text to the controller LCD screen. * - * \note Controller text setting is currently in beta, so continuous, fast - * updates will not work well. + * \note Controller text setting is a slow process, so updates faster than 10ms + * when on a wired connection or 50ms over Vexnet will not be applied to the controller. * * This function uses the following values of errno when an error state is * reached: * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is * given. * EACCES - Another resource is currently trying to access the controller port. + * EAGAIN - Could not send the text to the controller. * * \param id * The ID of the controller (e.g. the master or partner controller). @@ -323,20 +508,36 @@ int32_t controller_get_digital_new_press(controller_id_e_t id, controller_digita * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * while (true) { + * if (!(count % 25)) { + * // Only print every 50ms, the controller text update rate is slow + * controller_print(E_CONTROLLER_MASTER, 0, 0, "Counter: %d", count); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ int32_t controller_print(controller_id_e_t id, uint8_t line, uint8_t col, const char* fmt, ...); /** * Sets text to the controller LCD screen. * - * \note Controller text setting is currently in beta, so continuous, fast - * updates will not work well. + * \note Controller text setting is a slow process, so updates faster than 10ms + * when on a wired connection or 50ms over Vexnet will not be applied to the controller. * * This function uses the following values of errno when an error state is * reached: * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is * given. * EACCES - Another resource is currently trying to access the controller port. + * EAGAIN - Could not send the text to the controller. * * \param id * The ID of the controller (e.g. the master or partner controller). @@ -350,6 +551,21 @@ int32_t controller_print(controller_id_e_t id, uint8_t line, uint8_t col, const * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * while (true) { + * if (!(count % 25)) { + * // Only print every 50ms, the controller text update rate is slow + * controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example text"); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ int32_t controller_set_text(controller_id_e_t id, uint8_t line, uint8_t col, const char* str); @@ -373,21 +589,30 @@ int32_t controller_set_text(controller_id_e_t id, uint8_t line, uint8_t col, con * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example"); + * delay(100); + * controller_clear_line(E_CONTROLLER_MASTER, 0); + * } + * \endcode */ int32_t controller_clear_line(controller_id_e_t id, uint8_t line); /** * Clears all of the lines on the controller screen. * - * \note Controller text setting is currently in beta, so continuous, fast - * updates will not work well. On vexOS version 1.0.0 this function will block - * for 110ms. + * \note Controller text setting is a slow process, so updates faster than 10ms + * when on a wired connection or 50ms over Vexnet will not be applied to the controller. * * This function uses the following values of errno when an error state is * reached: * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is * given. * EACCES - Another resource is currently trying to access the controller port. + * EAGAIN - Could not send the text to the controller. * * \param id * The ID of the controller (e.g. the master or partner controller). @@ -395,14 +620,23 @@ int32_t controller_clear_line(controller_id_e_t id, uint8_t line); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example"); + * delay(100); + * controller_clear(E_CONTROLLER_MASTER); + * } + * \endcode */ int32_t controller_clear(controller_id_e_t id); /** * Rumble the controller. * - * \note Controller rumble activation is currently in beta, so continuous, fast - * updates will not work well. + * \note Controller rumble activation is a slow process, so updates faster than 10ms + * when on a wired connection or 50ms over Vexnet will not be applied to the controller. * * This function uses the following values of errno when an error state is * reached: @@ -420,6 +654,21 @@ int32_t controller_clear(controller_id_e_t id); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * while (true) { + * if (!(count % 25)) { + * // Only send every 50ms, the controller update rate is slow + * controller_rumble(E_CONTROLLER_MASTER, ". - . -"); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ int32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern); @@ -431,6 +680,13 @@ int32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern); * EACCES - Another resource is currently trying to access the battery port. * * \return The current voltage of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery's Voltage: %d\n", battery_get_voltage()); + * } + * \endcode */ int32_t battery_get_voltage(void); @@ -442,6 +698,13 @@ int32_t battery_get_voltage(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current current of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery Current: %d\n", battery_get_current()); + * } + * \endcode */ int32_t battery_get_current(void); @@ -453,6 +716,13 @@ int32_t battery_get_current(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current temperature of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery's Temperature: %d\n", battery_get_temperature()); + * } + * \endcode */ double battery_get_temperature(void); @@ -464,6 +734,13 @@ double battery_get_temperature(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current capacity of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery Level: %d\n", battery_get_capacity()); + * } + * \endcode */ double battery_get_capacity(void); @@ -471,12 +748,86 @@ double battery_get_capacity(void); * Checks if the SD card is installed. * * \return 1 if the SD card is installed, 0 otherwise + * + * \b Example + * \code + * void opcontrol() { + * printf("%i", usd_is_installed()); + * } + * \endcode */ int32_t usd_is_installed(void); +/** + * Lists the files in a directory specified by the path + * Puts the list of file names (NOT DIRECTORIES) into the buffer seperated by newlines + * + * This function uses the following values of errno when an error state is + * reached: + * + * EIO - Hard error occured in the low level disk I/O layer + * EINVAL - file or directory is invalid, or length is invalid + * EBUSY - THe physical drinve cannot work + * ENOENT - cannot find the path or file + * EINVAL - the path name format is invalid + * EACCES - Access denied or directory full + * EEXIST - Access denied + * EROFS - SD card is write protected + * ENXIO - drive number is invalid or not a FAT32 drive + * ENOBUFS - drive has no work area + * ENFILE - too many open files + * + * + * + * \note use a path of "\" to list the files in the main directory NOT "/usd/" + * DO NOT PREPEND YOUR PATHS WITH "/usd/" + * + * \return 1 on success or PROS_ERR on failure setting errno + * + * \b Example + * \code + * void opcontrol() { + * char* test = (char*) malloc(128); + * pros::c::usd_list_files("/", test, 128); + * pros::delay(200); + * printf("%s\n", test); //Prints the file names in the root directory seperated by newlines + * pros::delay(100); + * pros::c::usd_list_files("/test", test, 128); + * pros::delay(200); + * printf("%s\n", test); //Prints the names of files in the folder named test seperated by newlines + * pros::delay(100); + * } + * \endcode + */ +int32_t usd_list_files(const char* path, char* buffer, int32_t len); + +/******************************************************************************/ +/** Date and Time **/ +/******************************************************************************/ + +extern const char* baked_date; +extern const char* baked_time; + +typedef struct { + uint16_t year; // Year - 1980 + uint8_t day; + uint8_t month; // 1 = January +} date_s_t; + +typedef struct { + uint8_t hour; + uint8_t min; + uint8_t sec; + uint8_t sec_hund; // hundredths of a second +} time_s_t; + +///@} + +///@} + #ifdef __cplusplus } -} +} // namespace pros } #endif diff --git a/EZ-Template-Example-Project/include/pros/misc.hpp b/EZ-Template-Example-Project/include/pros/misc.hpp index 7fcb4b54..efa4d1d8 100644 --- a/EZ-Template-Example-Project/include/pros/misc.hpp +++ b/EZ-Template-Example-Project/include/pros/misc.hpp @@ -1,33 +1,42 @@ /** * \file pros/misc.hpp + * \ingroup cpp-pros * * Contains prototypes for miscellaneous functions pertaining to the controller, * battery, and competition control. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/controller.html to - * learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reservered. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-misc Miscellaneous C++ API + * \note Additional example code for this module can be found in its [Tutorial.](@ref controller) */ #ifndef _PROS_MISC_HPP_ #define _PROS_MISC_HPP_ -#include "pros/misc.h" - #include #include +#include "pros/misc.h" + namespace pros { +inline namespace v5 { +/** + * \ingroup cpp-misc + */ class Controller { + /** + * \addtogroup cpp-misc + * ///@{ + */ public: /** * Creates a controller object for the given controller id. @@ -36,7 +45,7 @@ class Controller { * The ID of the controller (e.g. the master or partner controller). * Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER */ - Controller(controller_id_e_t id); + explicit Controller(controller_id_e_t id); /** * Checks if the controller is connected. @@ -47,6 +56,16 @@ class Controller { * port. * * \return 1 if the controller is connected, 0 otherwise + * + * \b Example + * \code + * void status_display_controller(){ + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * if(!master.is_connected()) { + * pros::lcd::print(0, "Main controller is not connected!"); + * } + * } + * \endcode */ std::int32_t is_connected(void); @@ -65,6 +84,17 @@ class Controller { * * \return The current reading of the analog channel: [-127, 127]. * If the controller was not connected, then 0 is returned + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * motor_move(1, master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * delay(2); + * } + * } + * \endcode */ std::int32_t get_analog(controller_analog_e_t channel); @@ -77,6 +107,14 @@ class Controller { * port. * * \return The controller's battery capacity + * + * \b Example + * \code + * void initialize() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * printf("Battery Capacity: %d\n", master.get_battery_capacity()); + * } + * \endcode */ std::int32_t get_battery_capacity(void); @@ -89,6 +127,14 @@ class Controller { * port. * * \return The controller's battery level + * + * \b Example + * \code + * void initialize() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * printf("Battery Level: %d\n", master.get_battery_level()); + * } + * \endcode */ std::int32_t get_battery_level(void); @@ -107,6 +153,22 @@ class Controller { * * \return 1 if the button on the controller is pressed. * If the controller was not connected, then 0 is returned + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (master.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { + * motor_set(1, 100); + * } + * else { + * motor_set(1, 0); + * } + * delay(2); + * } + * } + * \endcode */ std::int32_t get_digital(controller_digital_e_t button); @@ -132,6 +194,20 @@ class Controller { * * \return 1 if the button on the controller is pressed and had not been * pressed the last time this function was called, 0 otherwise. + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)) { + * // Toggle pneumatics or other similar actions + * } + * + * delay(2); + * } + * } + * \endcode */ std::int32_t get_digital_new_press(controller_digital_e_t button); @@ -168,6 +244,22 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (!(count % 25)) { + * // Only print every 50ms, the controller text update rate is slow + * master.print(0, 0, "Counter: %d", count); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ template std::int32_t print(std::uint8_t line, std::uint8_t col, const char* fmt, Params... args) { @@ -194,6 +286,22 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (!(count % 25)) { + * // Only print every 50ms, the controller text update rate is slow + * master.set_text(0, 0, "Example text"); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ std::int32_t set_text(std::uint8_t line, std::uint8_t col, const char* str); std::int32_t set_text(std::uint8_t line, std::uint8_t col, const std::string& str); @@ -214,6 +322,16 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * master.set_text(0, 0, "Example"); + * delay(100); + * master.clear_line(0); + * } + * \endcode */ std::int32_t clear_line(std::uint8_t line); @@ -235,6 +353,22 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (!(count % 25)) { + * // Only send every 50ms, the controller update rate is slow + * master.rumble(". - . -"); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ std::int32_t rumble(const char* rumble_pattern); @@ -252,14 +386,30 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * master.set_text(0, 0, "Example"); + * delay(100); + * master.clear(); + * } + * \endcode */ std::int32_t clear(void); private: controller_id_e_t _id; + ///@} }; +} // namespace v5 namespace battery { +/** + * \addtogroup cpp-misc + * ///@{ + */ /** * Gets the current voltage of the battery, as reported by VEXos. * @@ -268,6 +418,13 @@ namespace battery { * EACCES - Another resource is currently trying to access the battery port. * * \return The current voltage of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery Level: %.2f\n", get_capacity()); + * } + * \endcode */ double get_capacity(void); @@ -279,6 +436,13 @@ double get_capacity(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current current of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery Current: %d\n", get_current()); + * } + * \endcode */ int32_t get_current(void); @@ -290,6 +454,13 @@ int32_t get_current(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current temperature of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery's Temperature: %.2f\n", get_temperature()); + * } + * \endcode */ double get_temperature(void); @@ -301,8 +472,16 @@ double get_temperature(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current capacity of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery's Voltage: %d\n", get_voltage()); + * } + * \endcode */ int32_t get_voltage(void); +///@} } // namespace battery namespace competition { @@ -311,11 +490,27 @@ namespace competition { * * \return The competition control status as a mask of bits with * COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}. + * + * \b Example + * \code + * void status_display_task(){ + * if(!is_connected()) { + * pros::lcd::print(0, "V5 Brain is not connected!"); + * } + * if(is_autonomous()) { + * pros::lcd::print(0, "V5 Brain is in autonomous mode!"); + * } + * if(!is_disabled()) { + * pros::lcd::print(0, "V5 Brain is disabled!"); + * } + * \endcode */ std::uint8_t get_status(void); std::uint8_t is_autonomous(void); std::uint8_t is_connected(void); std::uint8_t is_disabled(void); +std::uint8_t is_field_control(void); +std::uint8_t is_competition_switch(void); } // namespace competition namespace usd { @@ -323,9 +518,60 @@ namespace usd { * Checks if the SD card is installed. * * \return 1 if the SD card is installed, 0 otherwise + * + * \b Example + * \code + * void opcontrol() { + * printf("%i", is_installed()); + * } + * \endcode */ std::int32_t is_installed(void); +/** + * Lists the files in a directory specified by the path + * Puts the list of file names (NOT DIRECTORIES) into the buffer seperated by newlines + * + * This function uses the following values of errno when an error state is + * reached: + * + * EIO - Hard error occured in the low level disk I/O layer + * EINVAL - file or directory is invalid, or length is invalid + * EBUSY - THe physical drinve cannot work + * ENOENT - cannot find the path or file + * EINVAL - the path name format is invalid + * EACCES - Access denied or directory full + * EEXIST - Access denied + * EROFS - SD card is write protected + * ENXIO - drive number is invalid or not a FAT32 drive + * ENOBUFS - drive has no work area + * ENFILE - too many open files + * + * + * + * \note use a path of "\" to list the files in the main directory NOT "/usd/" + * DO NOT PREPEND YOUR PATHS WITH "/usd/" + * + * \return 1 on success or PROS_ERR on failure setting errno + * + * \b Example + * \code + * void opcontrol() { + * char* test = (char*) malloc(128); + * pros::usd::list_files("/", test, 128); + * pros::delay(200); + * printf("%s\n", test); //Prints the file names in the root directory seperated by newlines + * pros::delay(100); + * pros::list_files("/test", test, 128); + * pros::delay(200); + * printf("%s\n", test); //Prints the names of files in the folder named test seperated by newlines + * pros::delay(100); + * } + * \endcode + */ + +std::int32_t list_files(const char* path, char* buffer, std::int32_t len); } // namespace usd + } // namespace pros #endif // _PROS_MISC_HPP_ diff --git a/EZ-Template-Example-Project/include/pros/motor_group.hpp b/EZ-Template-Example-Project/include/pros/motor_group.hpp new file mode 100644 index 00000000..33edd0f5 --- /dev/null +++ b/EZ-Template-Example-Project/include/pros/motor_group.hpp @@ -0,0 +1,2378 @@ +/** + * \file pros/motor_group.hpp + * \ingroup cpp-motor-group + * + * Contains prototypes for the V5 Motor-related functions. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/motors.html to learn + * more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-motor-group Motors C++ API + * \note Additional example code for this module can be found in its [Tutorial](@ref motors). + */ + +#ifndef _PROS_MOTOR_GROUP_HPP_ +#define _PROS_MOTOR_GROUP_HPP_ + +#include +#include + +#include "pros/abstract_motor.hpp" +#include "pros/colors.hpp" +#include "pros/device.hpp" +#include "pros/motors.h" +#include "pros/motors.hpp" +#include "rtos.hpp" + +namespace pros { +inline namespace v5 { +class MotorGroup : public virtual AbstractMotor { + /** + * \addtogroup cpp-motor-group + * @{ + */ + public: + /** + * Constructs a new MotorGroup object. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports |1-21|. + * ENODEV - The port cannot be configured as a motor + * + * \param port + * A initializer list of V5 port numbers from 1 to 21, or from -21 to -1 for reversed motors. + * A reversed motor will reverse the input or output movement functions and movement related + * telemetry in order to produce consistant behavior with non-reversed motors + * + * \param gearset = pros::v5::MotorGears::invalid + * Optional parameter for the gearset for the motor. + * Does not explicitly set the motor gearset if it is invalid or not specified + * + * \param encoder_units = pros::v5::MotorUnits::invalid + * Optional parameter for the encoder units of the motor + * Does not explicitly set the motor units if it is invalid or not specified + * + * \b Example + * \code + * void opcontrol() { + * MotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2 + * MotorGroup rotations_mg({4, 5}, pros::v5::MotorGears::blue, pros::v5::MotorUnits::rotations); + * //Creates a motor group on ports 4 and 5 with blue motors using rotaions as the encoder units + * } + * \endcode + */ + MotorGroup(const std::initializer_list, + const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid); + /** + * Constructs a new MotorGroup object. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENXIO - The given value is not within the range of V5 ports |1-21|. + * + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * \param port + * A initializer list of V5 port numbers from 1 to 21, or from -21 to -1 for reversed motors. + * A reversed motor will reverse the input or output movement functions and movement related + * telemetry in order to produce consistant behavior with non-reversed motors + * + * \param gearset = pros::v5::MotorGears::invalid + * \param gearset = pros::v5::MotorGears::green + * Optional parameter for the gearset for the motor. + * Does not explicitly set the motor gearset if it is invalid or not specified + * + * \param encoder_units = pros::v5::MotorUnits::invalid + * Optional parameter for the encoder units of the motor + * Does not explicitly set the motor units if it is invalid or not specified + * + * \b Example + * \code + * void opcontrol() { + * MotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2 with + * with both motors using the green gearset and degrees as the encoder units + * MotorGroup rotations_mg({4, 5}, pros::v5::MotorGears::blue, pros::v5::MotorUnits::rotations); + * //Creates a motor group on ports 4 and 5 with blue motors using rotaions as the encoder units + * } + * \endcode + */ + MotorGroup(const std::vector& ports, const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid); + + /** + * Constructs a new MotorGroup object from an abstract motor. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENXIO - The given value is not within the range of V5 ports |1-21|. + * + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * \param abstract_motor + * THe abstract motor to turn into a motor group + * Uses abstract_motor.get_port_all() to get the vector of ports + * + * + * \b Example + * \code + * void opcontrol() { + * MotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2 with + * with both motors using the green gearset and degrees as the encoder units + * AbstractMotor abs_mtr_group = first_mg; + * MotorGroup new_mg = (MotorGroup) abs_mtr_group; + * } + * \endcode + */ + + MotorGroup(AbstractMotor& motor_group); + + /// \name Motor movement functions + /// These functions allow programmers to make motors move + ///@{ + + /** + * Sets the voltage for the motor group from -127 to 127. + * + * This is designed to map easily to the input from the controller's analog + * stick for simple opcontrol use. The actual behavior of the motor is + * analogous to use of motor_move() + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param voltage + * The new voltage from -127 to 127 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup MotorGroup ({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t move(std::int32_t voltage) const; + + /** + * Sets the target absolute position for the motor group to move to. + * + * This movement is relative to the position of the motor when initialized or + * the position when it was most recently reset with + * pros::Motor::set_zero_position(). + * + * \note This function simply sets the target for the motor, it does not block + * program execution until the movement finishes. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - the motor group has size 0 + * + * \param position + * The absolute position to move to in the motor's encoder units + * \param velocity + * The maximum allowable velocity for the movement in RPM + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg ({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * while (!((mg.get_position() < 105) && (mg.get_position() > 95))) { + * // Continue running this loop as long as the mg is not within +-5 units of its goal + * pros::delay(2); + * } + * mg.move_absolute(100, 100); // This does not cause a movement + * while (!((mg.get_position() < 105) && (mg.get_position() > 95))) { + * pros::delay(2); + * } + * mg.tare_position(); + * mg.move_absolute(100, 100); // Moves 100 units forward + * while (!((mg.get_position() < 105) && (mg.get_position() > 95))) { + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t move_absolute(const double position, const std::int32_t velocity) const; + + /** + * Sets the relative target position for the motor group to move to. + * + * This movement is relative to the current position of each motor as given in + * pros::MotorGroup::get_position(). Providing 10.0 as the position parameter + * would result in the motor moving 10 units, no matter what the + * current position is. + * + * \note This function simply sets the target for the motor, it does not block + * program execution until the movement finishes. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param position + * The relative position to move to in the motor's encoder units + * \param velocity + * The maximum allowable velocity for the movement in RPM + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_relative(100, 100); // Moves 100 units forward + * while (!((mg.get_position() < 105) && (mg.get_position() > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * pros::delay(2); + * } + * mg.move_relative(100, 100); // Also moves 100 units forward + * while (!((mg.get_position() < 205) && (mg.get_position() > 195))) { + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t move_relative(const double position, const std::int32_t velocity) const; + + /** + * Sets the velocity for the motor group. + * + * This velocity corresponds to different actual speeds depending on the + * gearset used for the motor. This results in a range of +-100 for + * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for + * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent + * speed, as opposed to setting the motor's voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param velocity + * The new velocity from +-100, +-200, or +-600 depending on the + * motor's gearset + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_velocity(100); + * pros::delay(1000); // Move at 100 RPM for 1 second + * mg.move_velocity(0); + * } + * \endcode + */ + std::int32_t move_velocity(const std::int32_t velocity) const; + + /** + * Sets the output voltage for the motor group from -12000 to 12000 in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param voltage + * The new voltage value from -12000 to 12000 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * mg.move_voltage(12000); + * pros::delay(1000); // Move at max voltage for 1 second + * mg.move_voltage(0); + * } + * \endcode + */ + std::int32_t move_voltage(const std::int32_t voltage) const; + + /** + * Stops the motor group using the currently configured brake mode. + * + * This function sets motor velocity to zero, which will cause it to act + * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, + * this function may behave differently than calling move_absolute(0) + * or motor_move_relative(0). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * Motor motor(1); + * mg.move_voltage(12000); + * pros::delay(1000); // Move at max voltage for 1 second + * motor.brake(); + * } + * \endcode + */ + std::int32_t brake(void) const; + + /** + * Changes the output velocity for a profiled movement (move_absolute or + * move_relative). This will have no effect if the motor group is not following + * a profiled movement. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param velocity + * The new motor velocity from +-100, +-200, or +-600 depending on the + * motor's gearset + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg ({1,3}); + * mg.move_absolute(100, 100); + * pros::delay(100); + * mg.modify_profiled_velocity(0); // Stop the motor group early + * } + * \endcode + */ + std::int32_t modify_profiled_velocity(const std::int32_t velocity) const; + + /** + * Gets the target position set for a motor in the motor group, with a parameter + * for the motor index. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The target position in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); + * // get the target position from motor at index 1. (port 3) + * std::cout << "Motor Target: " << mg.get_target_position(1); + * // Prints 100 + * } + * \endcode + */ + double get_target_position(const std::uint8_t index) const; + + /** + * Gets a vector of the the target positions set for the motor group + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The Motor group is empty + * + * \return The a vector of the target positions in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); + * std::cout << "Motor Target: " << mg.get_target_position_all()[0]; + * // Prints 100 + * } + * \endcode + */ + std::vector get_target_position_all(void) const; + + /** + * Gets the velocity commanded to the motor by the user at the index specified. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * EDOM - The motor group was empty + * + * \param index Optional parameter. + * The zero indexed index of the motor in the motor group + * + * \return The commanded motor velocity from +-100, +-200, or +-600, or + * PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg ({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * // get the target velocity from motor at index 1. (port 3) + * std::cout << "Motor Velocity: " << mg.get_target_velocity(1); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_target_velocity(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the velocity commanded to the motor by the user + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - THe motor group is empty + * + * \return A vector of the commanded motor velocity from +-100, +-200, or +-600, or + * PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg ({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * std::cout << "Motor Velocity: " << mg.get_target_velocity_all(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_target_velocity_all(void) const; + + ///@} + + /// \name Motor telemetry functions + /// These functions allow programmers to collect telemetry from motors + ///@{ + + /** + * Gets the actual velocity of a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - THe motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter. + * The zero indexed index of the motor in the motor group + * + * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * while (true) { + * mg = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y); + * // get the actual velocity from motor at index 1. (port 3) + * printf("Actual velocity: %lf\n", mg.get_actual_velocity(1)); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_actual_velocity(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the the actual velocity of each motor the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - THe motor group is empty + * + * \return A vector of the each motor's actual velocity in RPM or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * while (true) { + * mg = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y); + * // get the target velocity from motor at index 1. (port 3) + * printf("Actual velocity: %lf\n", mg.get_actual_velocity(1)); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_actual_velocity_all(void) const; + + /** + * Gets the current drawn by a motor in the motor group in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter. + * The zero indexed index of the motor in the motor group + * + * \return The motor's current in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * //Print the current draw for the motor at index 1. (port 3) + * std::cout << "Motor Current Draw: " << mg.get_current_draw(1); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_current_draw(const std::uint8_t index = 0) const; + /** + * Gets a vector of the current drawn each motor in the motor group in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * + * \return A vector with each motor's current in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Current Draw: " << mg.get_current_draw_all(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_current_draw_all(void) const; + + /** + * Gets the direction of movement for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * //Print the motor direction for the motor at index 1. (port 3) + * std::cout << "Motor Direction: " << mg.get_direction(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_direction(const std::uint8_t index = 0) const; + /** + * Gets a vector of the directions of movement for each motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * \return 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Direction: " << mg.get_direction_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_direction_all(void) const; + + /** + * Gets the efficiency of a motor in the motor group in percent. + * + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's efficiency in percent or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * //Prints the efficiency of the motor at index 1 (port 3) + * std::cout << "Motor Efficiency: " << mg.get_efficiency(1); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_efficiency(const std::uint8_t index = 0) const; + /** + * Gets a vector of the efficiency of each motor in percent. + * + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - THe motor group is empty + * + * \return A vector containing each motor's efficiency in percent or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Efficiency: " << mg.get_efficiency_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_efficiency_all(void) const; + + /** + * Gets the faults experienced by a motor in the motor group. + * + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return A bitfield containing the motor's faults. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << mg.get_faults(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::uint32_t get_faults(const std::uint8_t index = 0) const; + /** + * Gets a vector of the faults experienced by each motor in the motor group. + * + * Compare these bitfields to the bitmasks in pros::motor_fault_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * + * \return A vector containing the bitfields containing each motor's faults. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << mg.get_faults_all(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_faults_all(void) const; + /** + * Gets the flags set by a motor in the motor group's operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << mg.get_faults(1); + * pros::delay(2); + * } + * } + * \endcode + */ + std::uint32_t get_flags(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the flags set by each motor in the motor groups's operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << mg.get_faults_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_flags_all(void) const; + + /** + * Gets the absolute position of a motor in the motor group in its encoder units. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << mg.get_position(1); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_position(const std::uint8_t index = 0) const; + /** + * Gets a vector of the absolute position of each motor in its encoder units. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of the motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << mg.get_position_all(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_position_all(void) const; + + /** + * Gets the power drawn by a motor in the motor group in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Power: " << mg.get_power(); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_power(const std::uint8_t index = 0) const; + /** + * Gets a vector of the power drawn by each motor in the motor group in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of each motor's power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Power: " << mg.get_power_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_power_all(void) const; + /** + * Gets the raw encoder count of a motor in the motor group at a given timestamp. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * + * \param timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The raw encoder count at the given timestamp or PROS_ERR if the + * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * std::uint32_t now = pros::millis(); + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << mg.get_raw_position(&now); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const; + /** + * Gets the raw encoder count of each motor at a given timestamp. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \return A vector of each raw encoder count at the given timestamp or PROS_ERR if the + * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * std::uint32_t now = pros::millis(); + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << mg.get_raw_position_all(&now)[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_raw_position_all(std::uint32_t* const timestamp) const; + + /** + * Gets the temperature of a motor in the motor group in degrees Celsius. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Temperature: " << mg.get_temperature(); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_temperature(const std::uint8_t index = 0) const; + /** + * Gets the temperature of each motor in the motor group in degrees Celsius. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of each motor's temperature in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Temperature: " << mg.get_temperature_all()[1]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_temperature_all(void) const; + /** + * Gets the torque generated by a motor in the motor groupin Newton Meters (Nm). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Torque: " << mg.get_torque(); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_torque(const std::uint8_t index = 0) const; + /** + * Gets a vector of the torque generated by each motor in Newton Meters (Nm). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector containing each motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Torque: " << mg.get_torque(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_torque_all(void) const; + /** + * Gets the voltage delivered to a motor in the motor group in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Voltage: " << mg.get_voltage(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_voltage(const std::uint8_t index = 0) const; + /** + * Gets a vector of the voltage delivered to each motor in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of each motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Voltage: " << mg.get_voltage_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_voltage_all(void) const; + + /** + * Checks if a motor in the motor group is drawing over its current limit. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its current limit?: " << mg.is_over_current(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t is_over_current(const std::uint8_t index = 0) const; + /** + * Checks if each motor in the motor group is drawing over its current limit. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector containing the following for each motor: 1 if the motor's current limit is being exceeded and 0 if + * the current limit is not exceeded, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its current limit?: " << motor.is_over_current_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector is_over_current_all(void) const; + + /** + * Gets the temperature limit flag for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t is_over_temp(const std::uint8_t index = 0) const; + /** + * Gets a vector with the temperature limit flag for each motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector is_over_temp_all(void) const; + + ///@} + + /// \name Motor configuration functions + /// These functions allow programmers to configure the behavior of motors + ///@{ + + /** + * Gets the brake mode that was set for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return One of MotorBrake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + MotorBrake get_brake_mode(const std::uint8_t index = 0) const; + /** + * Gets a vector with the brake mode that was set for each motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector with one of MotorBrake for each motor in the motor group, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << mg.get_brake_mode_all()[0]; + * } + * \endcode + */ + std::vector get_brake_mode_all(void) const; + + /** + * Gets the current limit for a motor in the motor group in mA. + * + * The default value is 2500 mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * while (true) { + * std::cout << "Motor Current Limit: " << mg.get_current_limit(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_current_limit(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the current limit for each motor in the motor group in mA. + * + * The default value is 2500 mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of each motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * while (true) { + * std::cout << "Motor Current Limit: " << mg.get_current_limit_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_current_limit_all(void) const; + + /** + * Gets the encoder units that were set for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return One of MotorUnits according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + MotorUnits get_encoder_units(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the encoder units that were set for each motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector with the following for each motor, One of MotorUnits according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Encoder Units: " << mg.get_encoder_units_all()[0]; + * } + * \endcode + */ + std::vector get_encoder_units_all(void) const; + + /** + * Gets the gearset that was set for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + *\param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return One of MotorGears according to what is set for the motor, + * or pros::MotorGears::invalid if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Gearing: " << mg.get_gearing(); + * } + * \endcode + */ + MotorGears get_gearing(const std::uint8_t index = 0) const; + /** + * Gets a vector of the gearset that was set for each motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * + * \return A vector with one of MotorGears according to what is set for the motor, + * or pros::MotorGears::invalid if the operation failed for each motor. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Gearing: " << mg.get_gearing_all()[0]; + * } + * \endcode + */ + std::vector get_gearing_all(void) const; + + /** + * Gets a vector with all the port numbers in the motor group. + * A port will be negative if the motor in the motor group is reversed + * + * @return a vector with all the port numbers for the motor group + */ + std::vector get_port_all(void) const; + + /** + * Gets the voltage limit of a motor in the motor group set by the user. + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + *\param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * std::cout << "Motor Voltage Limit: " << mg.get_voltage_limit(1); + * } + * \endcode + */ + std::int32_t get_voltage_limit(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the voltage limit of each motor in the motor group + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The Motor group is empty + * + * \return The motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * std::cout << "Motor Voltage Limit: " << mg.get_voltage_limit_all()[0]; + * } + * \endcode + */ + std::vector get_voltage_limit_all(void) const; + + /** + * Gets the operation direction of a motor in the motor group as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + *\param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * std::cout << "Is the motor reversed? " << motor.is_reversed(); + * // Prints "0" + * } + * \endcode + */ + std::int32_t is_reversed(const std::uint8_t index = 0) const; + /** + * Gets a vector of the operation direction of each motor in the motor group as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * EDOM - The motor group is empty + * + * \return A vector conatining the following for each motor: 1 if the motor has been reversed and 0 if the motor was + * not reversed, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * std::cout << "Is the motor reversed? " << motor.is_reversed_all()[0]; + * // Prints "0" + * } + * \endcode + */ + std::vector is_reversed_all(void) const; + + /** + * Sets one of MotorBrake to a motor in the motor group. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode(pros::MotorBrake::brake, 1); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + std::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const; + /** + * Sets one of MotorBrake to a motor in the motor group. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD, 1); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const; + /** + * Sets one of MotorBrake all the motors in the motor group. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param mode + * The MotorBrake to set for the motor + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode_all(pros::MotorBrake:brake); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + std::int32_t set_brake_mode_all(const MotorBrake mode) const; + /** + * Sets one of MotorBrake to a motor in the motor group. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param mode + * The MotorBrake to set for the motor + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const; + /** + * Sets the current limit for one motor in the motor group in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param limit + * The new current limit in mA + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * mg.set_current_limit(1000); + * while (true) { + * mg = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const; + /** + * Sets the current limit for every motor in the motor group in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group was empty + * + * \param limit + * The new current limit in mA + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * mg.set_current_limit_all(1000); + * while (true) { + * mg = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t set_current_limit_all(const std::int32_t limit) const; + /** + * Sets one of MotorUnits for one motor in the motor group's motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param units + * The new motor encoder units + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_encoder_units(E_MOTOR_ENCODER_DEGREES, 1); + * std::cout << "Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const; + /** + * Sets one of MotorUnits for one motor in the motor group's motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param units + * The new motor encoder units + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_encoder_units(E_MOTOR_ENCODER_DEGREES, 1); + * std::cout << "Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const; + /** + * Sets one of MotorUnits for every motor in the motor group's motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param units + * The new motor encoder units + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + std::int32_t set_encoder_units_all(const MotorUnits units) const; + /** + * Sets one of MotorUnits for every motor in the motor group's motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param units + * The new motor encoder units + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const; + + /** + * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * E2BIG - The size of the vector mismatches the number of motors in the motor group + * + * \note If there are more motors than gearsets passed in, + * only the first n motors will have their gearsets changed where n is the number of gearsets passed in. + * If there are more gearsets passed in than motors, then the only the first m gearsets will be used, + * where m is the number of motors. In either case, errno will be set to E2BIG, but the operation still occurs + * + * + * \param gearset + * The new geatset of the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing(pros::MotorGears::blue, 1); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing(std::vector gearsets) const; + /** + * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param gearset + * The new geatset of the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing(E_MOTOR_GEARSET_06, 1); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const; + + /** + * Sets the gear cartridge (red, green, blue) for each motor in the motor group by taking in a vector of the + * cartridges. Usable with the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * E2BIG - The size of the vector mismatches the number of motors in the motor group + * + * \note If there are more motors than gearsets passed in, + * only the first n motors will have their gearsets changed where n is the number of gearsets passed in. + * If there are more gearsets passed in than motors, then the only the first m gearsets will be used, + * where m is the number of motors. In either case, errno will be set to E2BIG, but the operation still occurs + * + * \param gearset + * The a vector containing the new geatsets of the motors + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing(pros::MotorGears::blue, 1); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing(std::vector gearsets) const; + + /** + * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param gearset + * The new geatset of the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing(E_MOTOR_GEARSET_06, 1); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const; + /** + * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param gearset + * The new geatset of the motor + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing_all(const MotorGears gearset) const; + /** + * Sets one of the gear cartridge (red, green, blue) for every motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param gearset + * The new geatset of the motor + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const; + + /** + * sets the reversal for a motor in the motor group. + * + * This will invert its movements and the values returned for its position. + * + * This function uses the following values of errno when an error state is + * reached: + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param reverse + * True reverses the motor, false is default + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * //reverse the motor at index 1 (port 3) + * mg.set_reversed(true, 1); + * std::cout << "Is this motor reversed? " << motor.is_reversed(1); + * pros::delay(100); + * // unreverse the motor at index 1 (port 3) + * mg.set_reversed(false, 1); + * std::cout << "Is this motor reversed? " << motor.is_reversed(1); + * } + * \endcode + */ + std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0); + /** + * Sets the reversal for all the motors in the motor group. + * + * This will invert its movements and the values returned for its position. + * + * This function uses the following values of errno when an error state is + * reached: + * EDOM - The motor group is empty + * + * \param reverse + * True reverses the motor, false is default + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_reversed_all(true); + * std::cout << "Is this motor reversed? " << motor.is_reversed(); + * } + * \endcode + */ + std::int32_t set_reversed_all(const bool reverse); + + /** + * Sets the voltage limit for a motor in the motor group in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param limit + * The new voltage limit in Volts + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * mg.set_voltage_limit(10000, 1); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor on at index 1 (port 3) will not output more than 10 V + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const; + + /** + * Sets the voltage limit for every motor in the motor group in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param limit + * The new voltage limit in Volts + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * mg.set_voltage_limit_all(10000); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will not output more than 10 V + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t set_voltage_limit_all(const std::int32_t limit) const; + + /** + * Sets the position for a motor in the motor group in its encoder units. + * + * This will be the future reference point for the motor's "absolute" + * position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param position + * The new reference position in its encoder units + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * mg.move_absolute(100, 100); // This does not cause a movement + * mg.set_zero_position(80); + * mg.set_zero_position(80, 1); + * mg.move_absolute(100, 100); // Moves 80 units forward + * } + * \endcode + * + */ + std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const; + /** + * Sets the position for every motor in the motor group in its encoder units. + * + * This will be the future reference point for the motor's "absolute" + * position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param position + * The new reference position in its encoder units + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * mg.move_absolute(100, 100); // This does not cause a movement + * + * mg.set_zero_position_all(80); + * mg.move_absolute(100, 100); // Moves 80 units forward + * } + * \endcode + * + */ + std::int32_t set_zero_position_all(const double position) const; + + /** + * Sets the "absolute" zero position of a motor in the motor group to its current position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * mg.move_absolute(100, 100); // This does not cause a movement + * + * mg.tare_position(); + * mg.tare_position(1); + * + * mg.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode + */ + std::int32_t tare_position(const std::uint8_t index = 0) const; + + /** + * Sets the "absolute" zero position of every motor in the motor group to its current position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * mg.move_absolute(100, 100); // This does not cause a movement + * mg.tare_position_all(); + * mg.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode + */ + std::int32_t tare_position_all(void) const; + + /** + * Returns the number of motors in the motor group + * + * \return the number of motors in the motor group + */ + std::int8_t size(void) const; + + /** + * Gets the port of a motor in the motor group via index + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The port of the motor at the specified index. + * The return value is negative if the corresponding motor is reversed + */ + std::int8_t get_port(const std::uint8_t index = 0) const; + + /** + * Appends all the motors in the other motor group reference to this motor group + * + * Maintains the order of the other motor group + * + */ + void operator+=(AbstractMotor&); + + /** + * Appends all the motors in the other motor group reference to this motor group + * + * Maintains the order of the other motor group + * + */ + void append(AbstractMotor&); + + /** + * Removes the all motors on the port (regardless of reversal) from the motor group + * + * \param port The port to remove from the motor group + * + */ + void erase_port(std::int8_t port); + + ///@} + private: + /** + * The ordered vector of ports used by the motor group + */ + std::vector _ports; + mutable pros::Mutex _MotorGroup_mutex; +}; +} // namespace v5 +} // namespace pros +#endif \ No newline at end of file diff --git a/EZ-Template-Example-Project/include/pros/motors.h b/EZ-Template-Example-Project/include/pros/motors.h index 73710924..acf61e7a 100644 --- a/EZ-Template-Example-Project/include/pros/motors.h +++ b/EZ-Template-Example-Project/include/pros/motors.h @@ -1,19 +1,20 @@ /** * \file pros/motors.h + * \ingroup c-motors * * Contains prototypes for the V5 Motor-related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/motors.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-motors Motors C API + * \note Additional example code for this module can be found in its [Tutorial](@ref motors). */ #ifndef _PROS_MOTORS_H_ @@ -28,33 +29,54 @@ namespace pros { namespace c { #endif -/******************************************************************************/ -/** Motor movement functions **/ -/** **/ -/** These functions allow programmers to make motors move **/ -/******************************************************************************/ +/** + * \ingroup c-motors + */ + +/** + * \addtogroup c-motors + * @{ + */ + +/// \name Motor movement functions +/// These functions allow programmers to make motors move +///@{ /** * Sets the voltage for the motor from -127 to 127. * * This is designed to map easily to the input from the controller's analog * stick for simple opcontrol use. The actual behavior of the motor is analogous - * to use of motor_move_voltage(), or motorSet() from the PROS 2 API. + * to use of motor_move_voltage(). * + * \note This function will not respect brake modes, and simply sets the voltage to the desired value. + * + * \note A negative port will negate the input voltage + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param voltage * The new motor voltage from -127 to 127 * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_move(uint8_t port, int32_t voltage); +int32_t motor_move(int8_t port, int32_t voltage); /** * Stops the motor using the currently configured brake mode. @@ -66,16 +88,25 @@ int32_t motor_move(uint8_t port, int32_t voltage); * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move(1, 127); + * delay(1000); + * motor_break(1); + * } + * \endcode */ -int32_t motor_brake(uint8_t port); +int32_t motor_brake(int8_t port); /** * Sets the target absolute position for the motor to move to. @@ -83,16 +114,18 @@ int32_t motor_brake(uint8_t port); * This movement is relative to the position of the motor when initialized or * the position when it was most recently reset with motor_set_zero_position(). * - * \note This function simply sets the target for the motor, it does not block - * program execution until the movement finishes. + * \note This function simply sets the target for the motor, it does not block program + * execution until the movement finishes. The example code shows how to block until a movement is finished. * + * \note A negative port number will negate the target position + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param position * The absolute position to move to in the motor's encoder units * \param velocity @@ -100,8 +133,29 @@ int32_t motor_brake(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * delay(2); + * } + * motor_move_absolute(1, 100, 100); // This will not cause a movement + * while(!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) { + * delay(2); + * } + * + * motor_tare_position(1); + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) { + * delay(2); + * } + * } + * \endcode */ -int32_t motor_move_absolute(uint8_t port, const double position, const int32_t velocity); +int32_t motor_move_absolute(int8_t port, double position, const int32_t velocity); /** * Sets the relative target position for the motor to move to. @@ -112,15 +166,18 @@ int32_t motor_move_absolute(uint8_t port, const double position, const int32_t v * is. * * \note This function simply sets the target for the motor, it does not block - * program execution until the movement finishes. + * program execution until the movement finishes. The example code shows how to + * block until a movement is finished. * + * \note A negative port will negate the target position + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param position * The relative position to move to in the motor's encoder units * \param velocity @@ -128,8 +185,24 @@ int32_t motor_move_absolute(uint8_t port, const double position, const int32_t v * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_relative(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * delay(2); + * } + * + * motor_move_relative(1, 100, 100); // Also moves 100 units forward + * while (!((motor_get_position(1) < 205) && (motor_get_position(1) > 195))) { + * delay(2); + * } + * } + * \endcode */ -int32_t motor_move_relative(uint8_t port, const double position, const int32_t velocity); +int32_t motor_move_relative(int8_t port, double position, const int32_t velocity); /** * Sets the velocity for the motor. @@ -140,146 +213,243 @@ int32_t motor_move_relative(uint8_t port, const double position, const int32_t v * is held with PID to ensure consistent speed, as opposed to setting the * motor's voltage. * + * \note A negative port will negate the velocity + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param velocity * The new motor velocity from +-100, +-200, or +-600 depending on the * motor's gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_velocity(1, 100); + * delay(1000); // Move at 100 RPM for 1 second + * motor_move_velocity(1, 0); + * } + * \endcode */ -int32_t motor_move_velocity(uint8_t port, const int32_t velocity); +int32_t motor_move_velocity(int8_t port, const int32_t velocity); /** - * Sets the output voltage for the motor from -12000 to 12000 in millivolts + * Sets the output voltage for the motor from -12000 to 12000 in millivolts. * + * \note A negative port negates the voltage + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor + * + * \note This function will not respect brake modes, and simply sets the + * voltage to the desired value. * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param voltage * The new voltage value from -12000 to 12000 * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_voltage(1, 12000); + * delay(1000); // Move at max voltage for 1 second + * motor_move_voltage(1, 0); + * } + * \endcode */ -int32_t motor_move_voltage(uint8_t port, const int32_t voltage); +int32_t motor_move_voltage(int8_t port, const int32_t voltage); /** * Changes the output velocity for a profiled movement (motor_move_absolute or * motor_move_relative). This will have no effect if the motor is not following * a profiled movement. * + * \note A negative port negates the velocity + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param velocity * The new motor velocity from +-100, +-200, or +-600 depending on the * motor's gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); + * delay(100); + * motor_modify_profiled_velocity(1, 0); // Stop the motor early + * } + * \endcode */ -int32_t motor_modify_profiled_velocity(uint8_t port, const int32_t velocity); +int32_t motor_modify_profiled_velocity(int8_t port, const int32_t velocity); /** * Gets the target position set for the motor by the user. * + * \note A negative port negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The target position in its encoder units or PROS_ERR_F if the * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); + * printf("Motor Target: %d\n", motor_get_target_position(1)); + * // Prints 100 + * } + * \endcode */ -double motor_get_target_position(uint8_t port); +double motor_get_target_position(int8_t port); /** * Gets the velocity commanded to the motor by the user. * + * \note A negative port negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The commanded motor velocity from +-100, +-200, or +-600, or PROS_ERR * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move_velocity(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Commanded Velocity: %d\n", motor_get_target_velocity(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_target_velocity(uint8_t port); +int32_t motor_get_target_velocity(int8_t port); + +///@} -/******************************************************************************/ -/** Motor telemetry functions **/ -/** **/ -/** These functions allow programmers to collect telemetry from motors **/ -/******************************************************************************/ +/// \name Motor telemetry functions +/// These functions allow programmers to collect telemetry from motors +///@{ /** * Gets the actual velocity of the motor. * + * \note A negative port negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Actual velocity: %lf\n", motor_get_actual_velocity(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_actual_velocity(uint8_t port); +double motor_get_actual_velocity(int8_t port); /** * Gets the current drawn by the motor in mA. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's current in mA or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Current Draw: %d\n", motor_get_current_draw(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_current_draw(uint8_t port); +int32_t motor_get_current_draw(int8_t port); /** * Gets the direction of movement for the motor. * + * \note A negative port number negates the return value. + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 for moving in the positive direction, -1 for moving in the * negative direction, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Direction: %d\n", motor_get_direction(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_direction(uint8_t port); +int32_t motor_get_direction(int8_t port); /** * Gets the efficiency of the motor in percent. @@ -290,90 +460,102 @@ int32_t motor_get_direction(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's efficiency in percent or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Efficiency: %d\n", motor_get_efficiency(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_efficiency(uint8_t port); +double motor_get_efficiency(int8_t port); /** * Checks if the motor is drawing over its current limit. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 if the motor's current limit is being exceeded and 0 if the current * limit is not exceeded, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Current Limit Hit?: %d\n", motor_is_over_current(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_is_over_current(uint8_t port); +int32_t motor_is_over_current(int8_t port); /** * Checks if the motor's temperature is above its limit. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 if the temperature limit is exceeded and 0 if the the temperature * is below the limit, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Temp Limit: %d\n", motor_is_over_temp(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_is_over_temp(uint8_t port); +int32_t motor_is_over_temp(int8_t port); -/** - * Checks if the motor is stopped. - * - * \note Although this function forwards data from the motor, the motor - * presently does not provide any value. This function returns PROS_ERR with - * errno set to ENOSYS. - * - * \param port - * The V5 port number from 1-21 - * - * \return 1 if the motor is not moving, 0 if the motor is moving, or PROS_ERR - * if the operation failed, setting errno - */ -int32_t motor_is_stopped(uint8_t port); -/** - * Checks if the motor is at its zero position. - * - * \note Although this function forwards data from the motor, the motor - * presently does not provide any value. This function returns PROS_ERR with - * errno set to ENOSYS. - * - * \param port - * The V5 port number from 1-21 - * - * \return 1 if the motor is at zero absolute position, 0 if the motor has - * moved from its absolute zero, or PROS_ERR if the operation failed, - * setting errno - */ -int32_t motor_get_zero_position_flag(uint8_t port); #ifdef __cplusplus } // namespace c #endif +/** + * \enum motor_fault_e_t + */ typedef enum motor_fault_e { + /// No faults E_MOTOR_FAULT_NO_FAULTS = 0x00, - E_MOTOR_FAULT_MOTOR_OVER_TEMP = 0x01, // Analogous to motor_is_over_temp() - E_MOTOR_FAULT_DRIVER_FAULT = 0x02, // Indicates a motor h-bridge fault - E_MOTOR_FAULT_OVER_CURRENT = 0x04, // Analogous to motor_is_over_current() - E_MOTOR_FAULT_DRV_OVER_CURRENT = 0x08 // Indicates an h-bridge over current + /// Analogous to motor_is_over_temp() + E_MOTOR_FAULT_MOTOR_OVER_TEMP = 0x01, + /// Indicates a motor h-bridge fault + E_MOTOR_FAULT_DRIVER_FAULT = 0x02, + /// Analogous to motor_is_over_current() + E_MOTOR_FAULT_OVER_CURRENT = 0x04, + /// Indicates an h-bridge over current + E_MOTOR_FAULT_DRV_OVER_CURRENT = 0x08 } motor_fault_e_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -410,18 +592,37 @@ namespace c { * The V5 port number from 1-21 * * \return A bitfield containing the motor's faults. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Faults: %d\n", motor_get_faults(1)); + * delay(2); + * } + * } + * \endcode */ -uint32_t motor_get_faults(uint8_t port); +uint32_t motor_get_faults(int8_t port); #ifdef __cplusplus } // namespace c #endif +/** + * \enum motor_flag_e_t + * + */ typedef enum motor_flag_e { + ///There are no flags raised E_MOTOR_FLAGS_NONE = 0x00, - E_MOTOR_FLAGS_BUSY = 0x01, // Cannot currently communicate to the motor - E_MOTOR_FLAGS_ZERO_VELOCITY = 0x02, // Analogous to motor_is_stopped() - E_MOTOR_FLAGS_ZERO_POSITION = 0x04 // Analogous to motor_get_zero_position_flag() + /// Cannot currently communicate to the motor + E_MOTOR_FLAGS_BUSY = 0x01, + /// Analogous to motor_is_stopped() + E_MOTOR_FLAGS_ZERO_VELOCITY = 0x02, + /// Analogous to motor_get_zero_position_flag() + E_MOTOR_FLAGS_ZERO_POSITION = 0x04 } motor_flag_e_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -449,26 +650,39 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Flags: %d\n", motor_get_flags(1)); + * delay(2); + * } + * } + * \endcode */ -uint32_t motor_get_flags(uint8_t port); +uint32_t motor_get_flags(int8_t port); /** * Gets the raw encoder count of the motor at a given timestamp. * + * \note A negative port value negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param[in] timestamp * A pointer to a time in milliseconds for which the encoder count * will be returned. If NULL, the timestamp at which the encoder @@ -476,72 +690,131 @@ uint32_t motor_get_flags(uint8_t port); * * \return The raw encoder count at the given timestamp or PROS_ERR if the * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * uint32_t now = millis(); + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Encoder Count: %d\n", motor_get_raw_position(1, &now)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_raw_position(uint8_t port, uint32_t* const timestamp); +int32_t motor_get_raw_position(int8_t port, uint32_t* const timestamp); /** * Gets the absolute position of the motor in its encoder units. * + * \note A negative port value negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's absolute position in its encoder units or PROS_ERR_F * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Position: %lf\n", motor_get_position(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_position(uint8_t port); +double motor_get_position(int8_t port); /** * Gets the power drawn by the motor in Watts. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's power draw in Watts or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * uint32_t now = millis(); + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Power: %lf\n", motor_get_power(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_power(uint8_t port); +double motor_get_power(int8_t port); /** * Gets the temperature of the motor in degrees Celsius. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the * operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Temperature: %lf\n", motor_get_temperature(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_temperature(uint8_t port); +double motor_get_temperature(int8_t port); /** * Gets the torque generated by the motor in Newton Meters (Nm). * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Torque: %lf\n", motor_get_torque(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_torque(uint8_t port); +double motor_get_torque(int8_t port); /** * Gets the voltage delivered to the motor in millivolts. @@ -552,60 +825,79 @@ double motor_get_torque(uint8_t port); * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Voltage: %lf\n", motor_get_voltage(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_voltage(uint8_t port); +int32_t motor_get_voltage(int8_t port); + +///@} -/******************************************************************************/ -/** Motor configuration functions **/ -/** **/ -/** These functions allow programmers to configure the behavior of motors **/ -/******************************************************************************/ +/// \name Motor configuration functions +/// These functions allow programmers to configure the behavior of motors +///@{ #ifdef __cplusplus } // namespace c #endif /** + * \enum motor_brake_mode_e_t * Indicates the current 'brake mode' of a motor. */ typedef enum motor_brake_mode_e { - E_MOTOR_BRAKE_COAST = 0, // Motor coasts when stopped, traditional behavior - E_MOTOR_BRAKE_BRAKE = 1, // Motor brakes when stopped - E_MOTOR_BRAKE_HOLD = 2, // Motor actively holds position when stopped + /// Motor coasts when stopped, traditional behavior + E_MOTOR_BRAKE_COAST = 0, + /// Motor brakes when stopped + E_MOTOR_BRAKE_BRAKE = 1, + /// Motor actively holds position when stopped + E_MOTOR_BRAKE_HOLD = 2, + /// Invalid brake mode E_MOTOR_BRAKE_INVALID = INT32_MAX } motor_brake_mode_e_t; /** + * \enum motor_encoder_units_e_t * Indicates the units used by the motor encoders. */ typedef enum motor_encoder_units_e { - E_MOTOR_ENCODER_DEGREES = 0, // Position is recorded as angle in degrees - // as a floating point number - E_MOTOR_ENCODER_ROTATIONS = 1, // Position is recorded as angle in rotations - // as a floating point number - E_MOTOR_ENCODER_COUNTS = 2, // Position is recorded as raw encoder ticks - // as a whole number + /// Position is recorded as angle in degrees as a floating point number + E_MOTOR_ENCODER_DEGREES = 0, + /// Position is recorded as angle in rotations as a floating point number + E_MOTOR_ENCODER_ROTATIONS = 1, + /// Position is recorded as raw encoder ticks as a whole number + E_MOTOR_ENCODER_COUNTS = 2, + ///Invalid motor encoder units E_MOTOR_ENCODER_INVALID = INT32_MAX } motor_encoder_units_e_t; /** + * \enum motor_gearset_e_t * Indicates the current internal gear ratio of a motor. */ typedef enum motor_gearset_e { E_MOTOR_GEARSET_36 = 0, // 36:1, 100 RPM, Red gear set - E_MOTOR_GEAR_RED = E_MOTOR_GEARSET_36, - E_MOTOR_GEAR_100 = E_MOTOR_GEARSET_36, + E_MOTOR_GEAR_RED = E_MOTOR_GEARSET_36, // 36:1, 100 RPM, Red gear set + E_MOTOR_GEAR_100 = E_MOTOR_GEARSET_36, // 36:1, 100 RPM, Red gear set E_MOTOR_GEARSET_18 = 1, // 18:1, 200 RPM, Green gear set - E_MOTOR_GEAR_GREEN = E_MOTOR_GEARSET_18, - E_MOTOR_GEAR_200 = E_MOTOR_GEARSET_18, + E_MOTOR_GEAR_GREEN = E_MOTOR_GEARSET_18, // 18:1, 200 RPM, Green gear set + E_MOTOR_GEAR_200 = E_MOTOR_GEARSET_18, // 18:1, 200 RPM, Green gear set E_MOTOR_GEARSET_06 = 2, // 6:1, 600 RPM, Blue gear set - E_MOTOR_GEAR_BLUE = E_MOTOR_GEARSET_06, - E_MOTOR_GEAR_600 = E_MOTOR_GEARSET_06, - E_MOTOR_GEARSET_INVALID = INT32_MAX + E_MOTOR_GEAR_BLUE = E_MOTOR_GEARSET_06, // 6:1, 600 RPM, Blue gear set + E_MOTOR_GEAR_600 = E_MOTOR_GEARSET_06, // 6:1, 600 RPM, Blue gear set + E_MOTOR_GEARSET_INVALID = INT32_MAX, // Error: Invalid Gearset } motor_gearset_e_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -653,35 +945,49 @@ typedef enum motor_gearset_e { #endif /** + * \struct motor_pid_full_s_t + * * Holds the information about a Motor's position or velocity PID controls. * * These values are in 4.4 format, meaning that a value of 0x20 represents 2.0, * 0x21 represents 2.0625, 0x22 represents 2.125, etc. */ typedef struct motor_pid_full_s { - uint8_t kf; // The feedforward constant - uint8_t kp; // The proportional constant - uint8_t ki; // The integral constants - uint8_t kd; // The derivative constant - uint8_t filter; // A constant used for filtering the profile acceleration - uint16_t limit; // The integral limit - uint8_t threshold; // The threshold for determining if a position movement has - // reached its goal. This has no effect for velocity PID - // calculations. - uint8_t loopspeed; // The rate at which the PID computation is run in ms + /// The feedforward constant + uint8_t kf; + /// The proportional constant + uint8_t kp; + /// The integral constants + uint8_t ki; + /// The derivative constant + uint8_t kd; + /// A constant used for filtering the profile acceleration + uint8_t filter; + /// The integral limit + uint16_t limit; + /// The threshold for determining if a position movement hasreached its goa l. This has no effect for velocity PID calculations. + uint8_t threshold; + /// The rate at which the PID computation is run in ms + uint8_t loopspeed; } motor_pid_full_s_t; /** + * \struct motor_pid_s_t + * * Holds just the constants for a Motor's position or velocity PID controls. * * These values are in 4.4 format, meaning that a value of 0x20 represents 2.0, * 0x21 represents 2.0625, 0x22 represents 2.125, etc. */ typedef struct motor_pid_s { - uint8_t kf; // The feedforward constant - uint8_t kp; // The proportional constant - uint8_t ki; // The integral constants - uint8_t kd; // The derivative constant + /// The feedforward constant + uint8_t kf; + /// The proportional constant + uint8_t kp; + /// The integral constants + uint8_t ki; + /// The derivative constant + uint8_t kd; } motor_pid_s_t; #ifdef __cplusplus @@ -695,314 +1001,239 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param position * The new reference position in its encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * delay(2); + * } + * motor_move_absolute(1, 100, 100); // This does not cause a movement + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * delay(2); + * } + * + * motor_set_zero_position(1, 80); + * motor_move_absolute(1, 100, 100); // Moves 80 units forward + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * delay(2); + * } + * } + * \endcode */ -int32_t motor_set_zero_position(uint8_t port, const double position); +int32_t motor_set_zero_position(int8_t port, const double position); /** * Sets the "absolute" zero position of the motor to its current position. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * delay(2); + * } + * motor_move_absolute(1, 100, 100); // This does not cause a movement + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * delay(2); + * } + * + * motor_tare_position(1); + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * delay(2); + * } + * } + * \endcode */ -int32_t motor_tare_position(uint8_t port); +int32_t motor_tare_position(int8_t port); /** * Sets one of motor_brake_mode_e_t to the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param mode * The motor_brake_mode_e_t to set for the motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * motor_set_brake_mode(1, E_MOTOR_BRAKE_HOLD); + * printf("Brake Mode: %d\n", motor_get_brake_mode(1)); + * } + * \endcode */ -int32_t motor_set_brake_mode(uint8_t port, const motor_brake_mode_e_t mode); +int32_t motor_set_brake_mode(int8_t port, const motor_brake_mode_e_t mode); /** * Sets the current limit for the motor in mA. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param limit * The new current limit in mA * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * motor_set_current_limit(1, 1000); + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * delay(2); + * } + * } + * \endcode */ -int32_t motor_set_current_limit(uint8_t port, const int32_t limit); +int32_t motor_set_current_limit(int8_t port, const int32_t limit); /** * Sets one of motor_encoder_units_e_t for the motor encoder. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param units * The new motor encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * motor_set_encoder_units(1, E_MOTOR_ENCODER_DEGREES); + * printf("Encoder Units: %d\n", motor_get_encoder_units(1)); + * } + * \endcode */ -int32_t motor_set_encoder_units(uint8_t port, const motor_encoder_units_e_t units); +int32_t motor_set_encoder_units(int8_t port, const motor_encoder_units_e_t units); /** * Sets one of motor_gearset_e_t for the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param gearset * The new motor gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * motor_set_gearing(1, E_MOTOR_GEARSET_06); + * printf("Brake Mode: %d\n", motor_get_gearing(1)); + * } + * \endcode */ -int32_t motor_set_gearing(uint8_t port, const motor_gearset_e_t gearset); - -/** - * Takes in floating point values and returns a properly formatted pid struct. - * The motor_pid_s_t struct is in 4.4 format, i.e. 0x20 is 2.0, 0x21 is 2.0625, - * etc. - * This function will convert the floating point values to the nearest 4.4 - * value. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant - * - * \return A motor_pid_s_t struct formatted properly in 4.4. - */ -motor_pid_s_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_convert_pid(double kf, double kp, double ki, double kd); - -/** - * Takes in floating point values and returns a properly formatted pid struct. - * The motor_pid_s_t struct is in 4.4 format, i.e. 0x20 is 2.0, 0x21 is 2.0625, - * etc. - * This function will convert the floating point values to the nearest 4.4 - * value. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant - * \param filter - * A constant used for filtering the profile acceleration - * \param limit - * The integral limit - * \param threshold - * The threshold for determining if a position movement has reached its - * goal. This has no effect for velocity PID calculations. - * \param loopspeed - * The rate at which the PID computation is run in ms - * - * \return A motor_pid_s_t struct formatted properly in 4.4. - */ -motor_pid_full_s_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_convert_pid_full(double kf, double kp, double ki, double kd, double filter, double limit, - double threshold, double loopspeed); - -/** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. - * - * Only non-zero values of the struct will change the existing motor constants. - * - * \note This feature is in beta, it is advised to use caution when modifying - * the PID values. The motor could be damaged by particularly large constants. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param pid - * The new motor PID constants - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_set_pos_pid(uint8_t port, const motor_pid_s_t pid); - -/** - * Sets one of motor_pid_full_s_t for the motor. - * - * Only non-zero values of the struct will change the existing motor constants. - * - * \note This feature is in beta, it is advised to use caution when modifying - * the PID values. The motor could be damaged by particularly large constants. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param pid - * The new motor PID constants - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_set_pos_pid_full(uint8_t port, const motor_pid_full_s_t pid); - -/** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. - * - * Only non-zero values of the struct will change the existing motor constants. - * - * \note This feature is in beta, it is advised to use caution when modifying - * the PID values. The motor could be damaged by particularly large constants. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param pid - * The new motor PID constants - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_set_vel_pid(uint8_t port, const motor_pid_s_t pid); - -/** - * Sets one of motor_pid_full_s_t for the motor. - * - * Only non-zero values of the struct will change the existing motor constants. - * - * \note This feature is in beta, it is advised to use caution when modifying - * the PID values. The motor could be damaged by particularly large constants. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param pid - * The new motor PID constants - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_set_vel_pid_full(uint8_t port, const motor_pid_full_s_t pid); - -/** - * Sets the reverse flag for the motor. - * - * This will invert its movements and the values returned for its position. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param reverse - * True reverses the motor, false is default - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t motor_set_reversed(uint8_t port, const bool reverse); +int32_t motor_set_gearing(int8_t port, const motor_gearset_e_t gearset); /** * Sets the voltage limit for the motor in Volts. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param limit * The new voltage limit in Volts * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_set_voltage_limit(1, 10000); + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * // The motor will not output more than 10 V + * delay(2); + * } + * } + * \endcode */ -int32_t motor_set_voltage_limit(uint8_t port, const int32_t limit); +int32_t motor_set_voltage_limit(int8_t port, const int32_t limit); /** * Gets the brake mode that was set for the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return One of motor_brake_mode_e_t, according to what was set for the motor, * or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * motor_set_brake_mode(1, E_MOTOR_BRAKE_HOLD); + * printf("Brake Mode: %d\n", motor_get_brake_mode(1)); + * } + * \endcode */ -motor_brake_mode_e_t motor_get_brake_mode(uint8_t port); +motor_brake_mode_e_t motor_get_brake_mode(int8_t port); /** * Gets the current limit for the motor in mA. @@ -1011,106 +1242,64 @@ motor_brake_mode_e_t motor_get_brake_mode(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's current limit in mA or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void initialize() { + * printf("Motor Current Limit: %d\n", motor_get_current_limit(1)); + * // Prints "Motor Current Limit: 2500" + * } + * \endcode */ -int32_t motor_get_current_limit(uint8_t port); +int32_t motor_get_current_limit(int8_t port); /** * Gets the encoder units that were set for the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return One of motor_encoder_units_e_t according to what is set for the motor * or E_MOTOR_ENCODER_INVALID if the operation failed. */ -motor_encoder_units_e_t motor_get_encoder_units(uint8_t port); +motor_encoder_units_e_t motor_get_encoder_units(int8_t port); /** * Gets the gearset that was set for the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return One of motor_gearset_e_t according to what is set for the motor, * or E_GEARSET_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * printf("Motor Encoder Units: %d\n", motor_get_encoder_units(1)); + * // Prints E_MOTOR_ENCODER_DEGREES by default + * } + * \endcode */ -motor_gearset_e_t motor_get_gearing(uint8_t port); - -/** - * Gets the position PID that was set for the motor. This function will return - * zero for all of the parameters if the motor_set_pos_pid() or - * motor_set_pos_pid_full() functions have not been used. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. - * - * \param port - * The V5 port number from 1-21 - * - * \return A motor_pid_full_s_t containing the position PID constants last set - * to the given motor - */ -motor_pid_full_s_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_get_pos_pid(uint8_t port); - -/** - * Gets the velocity PID that was set for the motor. This function will return - * zero for all of the parameters if the motor_set_vel_pid() or - * motor_set_vel_pid_full() functions have not been used. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. - * - * \param port - * The V5 port number from 1-21 - * - * \return A motor_pid_full_s_t containing the velocity PID constants last set - * to the given motor - */ -motor_pid_full_s_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_get_vel_pid(uint8_t port); - -/** - * Gets the operation direction of the motor as set by the user. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * - * \return 1 if the motor has been reversed and 0 if the motor was not reversed, - * or PROS_ERR if the operation failed, setting errno. - */ -int32_t motor_is_reversed(uint8_t port); +motor_gearset_e_t motor_get_gearing(int8_t port); /** * Gets the voltage limit set by the user. @@ -1120,16 +1309,28 @@ int32_t motor_is_reversed(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's voltage limit in V or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void initialize() { + * printf("Motor Voltage Limit: %d\n", motor_get_voltage_limit(1)); + * // Prints 0 by default, indicating no limit + * } + * \endcode */ -int32_t motor_get_voltage_limit(uint8_t port); +int32_t motor_get_voltage_limit(int8_t port); + +///@} + +///@} #ifdef __cplusplus } // namespace c diff --git a/EZ-Template-Example-Project/include/pros/motors.hpp b/EZ-Template-Example-Project/include/pros/motors.hpp index 10925990..b6469116 100644 --- a/EZ-Template-Example-Project/include/pros/motors.hpp +++ b/EZ-Template-Example-Project/include/pros/motors.hpp @@ -1,92 +1,91 @@ /** * \file pros/motors.hpp + * \ingroup cpp-motors * * Contains prototypes for the V5 Motor-related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/motors.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-motors Motors C++ API + * \note Additional example code for this module can be found in its [Tutorial](@ref motors). */ #ifndef _PROS_MOTORS_HPP_ #define _PROS_MOTORS_HPP_ #include -#include -#include +#include +#include "pros/abstract_motor.hpp" +#include "pros/device.hpp" #include "pros/motors.h" -#include "pros/rtos.hpp" +#include "rtos.hpp" namespace pros { -class Motor { +inline namespace v5 { + +class Motor : public AbstractMotor, public Device { public: /** - * Creates a Motor object for the given port and specifications. + * \addtogroup cpp-motors + * @{ + */ + + /** + * Constructs a new Motor object. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 - * \param gearset - * The motor's gearset - * \param reverse - * True reverses the motor, false is default - * \param encoder_units - * The motor's encoder units - */ - explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset, const bool reverse, - const motor_encoder_units_e_t encoder_units); - - explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset, const bool reverse); - - explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset); - - explicit Motor(const std::int8_t port, const bool reverse); - - explicit Motor(const std::int8_t port); - - /****************************************************************************/ - /** Motor movement functions **/ - /** **/ - /** These functions allow programmers to make motors move **/ - /****************************************************************************/ - /** - * Sets the voltage for the motor from -128 to 127. + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors. + * A reversed motor will reverse the input or output movement functions and movement related + * telemetry in order to produce consistant behavior with non-reversed motors * - * This is designed to map easily to the input from the controller's analog - * stick for simple opcontrol use. The actual behavior of the motor is - * analogous to use of pros::Motor::move(), or motorSet from the PROS 2 API. + * \param gearset = pros::v5::MotorGears::green + * Optional parameter for the gearset for the motor. + * Does not explicitly set the gearset if not specified or if the gearset is invalid * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor + * \param encoder_units = pros::v5::MotorUnits::degrees + * Optional parameter for the encoder units of the motor + * Does not explicitly set the gearset if not specified or if the gearset is invalid * - * \param voltage - * The new motor voltage from -127 to 127 + * \b Example + * \code + * void opcontrol() { + * Motor first_motor(1); //Creates a motor on port 1 without altering gearset or encoder units + * Motor reversed_motor(-2); //Creates a reversed motor on port 1 port 1 without altering gearset or encoder units + * Motor blue_motor(3, pros::v5::MotorGears::blue); //Creates a motor on port 3 with blue gear set + * Motor rotations_motor(4, pros::v5::MotorGears::green, pros::v5::MotorUnits::rotations); //port 4 w/ rotations + * + * } + * \endcode * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. */ - virtual std::int32_t operator=(std::int32_t voltage) const; + Motor(const std::int8_t port, const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid); + + Motor(const Device& device) : Motor(device.get_port()){}; + + /// \name Motor movement functions + /// These functions allow programmers to make motors move + ///@{ /** * Sets the voltage for the motor from -127 to 127. * * This is designed to map easily to the input from the controller's analog * stick for simple opcontrol use. The actual behavior of the motor is - * analogous to use of motor_move(), or motorSet() from the PROS 2 API. + * analogous to use of motor_move(). * * This function uses the following values of errno when an error state is * reached: @@ -97,8 +96,20 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor Motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t move(std::int32_t voltage) const; + std::int32_t move(std::int32_t voltage) const; /** * Sets the target absolute position for the motor to move to. @@ -110,6 +121,7 @@ class Motor { * \note This function simply sets the target for the motor, it does not block * program execution until the movement finishes. * + * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor @@ -121,16 +133,37 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * pros::delay(2); + * } + * motor.move_absolute(100, 100); // This does not cause a movement + * while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { + * pros::delay(2); + * } + * motor.tare_position(); + * motor.move_absolute(100, 100); // Moves 100 units forward + * while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t move_absolute(const double position, const std::int32_t velocity) const; + std::int32_t move_absolute(const double position, const std::int32_t velocity) const; /** * Sets the relative target position for the motor to move to. * * This movement is relative to the current position of the motor as given in * pros::Motor::motor_get_position(). Providing 10.0 as the position parameter - * would result in the motor moving clockwise 10 units, no matter what the - * current position is. + * would result in the motor moving clockwise 10 units (counter clockwise if reversed), + * no matter what the current position is. * * \note This function simply sets the target for the motor, it does not block * program execution until the movement finishes. @@ -146,8 +179,24 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_relative(100, 100); // Moves 100 units forward + * while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * pros::delay(2); + * } + * motor.move_relative(100, 100); // Also moves 100 units forward + * while (!((motor.get_position() < 205) && (motor.get_position() > 195))) { + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t move_relative(const double position, const std::int32_t velocity) const; + std::int32_t move_relative(const double position, const std::int32_t velocity) const; /** * Sets the velocity for the motor. @@ -168,8 +217,18 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_velocity(100); + * pros::delay(1000); // Move at 100 RPM for 1 second + * motor.move_velocity(0); + * } + * \endcode */ - virtual std::int32_t move_velocity(const std::int32_t velocity) const; + std::int32_t move_velocity(const std::int32_t velocity) const; /** * Sets the output voltage for the motor from -12000 to 12000 in millivolts. @@ -178,13 +237,24 @@ class Motor { * reached: * ENODEV - The port cannot be configured as a motor * + * \param port + * The V5 port number from 1-21 * \param voltage * The new voltage value from -12000 to 12000 * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor.move_voltage(12000); + * pros::delay(1000); // Move at max voltage for 1 second + * motor.move_voltage(0); + * } + * \endcode */ - virtual std::int32_t move_voltage(const std::int32_t voltage) const; + std::int32_t move_voltage(const std::int32_t voltage) const; /** * Stops the motor using the currently configured brake mode. @@ -192,7 +262,7 @@ class Motor { * This function sets motor velocity to zero, which will cause it to act * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, * this function may behave differently than calling move_absolute(0) - * or move_relative(0). + * or motor_move_relative(0). * * This function uses the following values of errno when an error state is * reached: @@ -200,13 +270,23 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * Motor motor(1); + * motor.move_voltage(12000); + * pros::delay(1000); // Move at max voltage for 1 second + * motor.brake(); + * } + * \endcode */ - virtual std::int32_t brake(void) const; + std::int32_t brake(void) const; /** - * Changes the output velocity for a profiled movement (motor_move_absolute() - * or motor_move_relative()). This will have no effect if the motor is not - * following a profiled movement. + * Changes the output velocity for a profiled movement (motor_move_absolute or + * motor_move_relative). This will have no effect if the motor is not following + * a profiled movement. * * This function uses the following values of errno when an error state is * reached: @@ -218,74 +298,195 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); + * pros::delay(100); + * motor.modify_profiled_velocity(0); // Stop the motor early + * } + * \endcode */ - virtual std::int32_t modify_profiled_velocity(const std::int32_t velocity) const; + std::int32_t modify_profiled_velocity(const std::int32_t velocity) const; + + ///@} + + /// \name Motor telemetry functions + /// These functions allow programmers to collect telemetry from motors + ///@{ /** - * Gets the target position set for the motor by the user. + * Gets the target position set for the motor by the user + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return The target position in its encoder units or PROS_ERR_F if the * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); + * std::cout << "Motor Target: " << motor.get_target_position(); + * // Prints 100 + * } + * \endcode */ - virtual double get_target_position(void) const; + double get_target_position(const std::uint8_t index = 0) const; /** - * Gets the velocity commanded to the motor by the user. + * Gets the velocity commanded to the motor by the user at the index specified. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return The commanded motor velocity from +-100, +-200, or +-600, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * std::cout << "Motor Velocity: " << motor.get_target_velocity(); + * // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_target_velocity(void) const; - - /****************************************************************************/ - /** Motor telemetry functions **/ - /** **/ - /** These functions allow programmers to collect telemetry from motors **/ - /****************************************************************************/ + std::int32_t get_target_velocity(const std::uint8_t index = 0) const; /** * Gets the actual velocity of the motor. * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * while (true) { + * motor = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y); + * printf("Actual velocity: %lf\n", motor.get_actual_velocity()); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_actual_velocity(void) const; + double get_actual_velocity(const std::uint8_t index = 0) const; /** * Gets the current drawn by the motor in mA. * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * * \return The motor's current in mA or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Current Draw: " << motor.get_current_draw(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_current_draw(void) const; + std::int32_t get_current_draw(const std::uint8_t index = 0) const; /** * Gets the direction of movement for the motor. * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * * \return 1 for moving in the positive direction, -1 for moving in the * negative direction, and PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Direction: " << motor.get_direction(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_direction(void) const; + std::int32_t get_direction(const std::uint8_t index = 0) const; /** * Gets the efficiency of the motor in percent. @@ -294,1191 +495,1932 @@ class Motor { * drawing no electrical power, and an efficiency of 0% means that the motor * is drawing power but not moving. * + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * * \return The motor's efficiency in percent or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Efficiency: " << motor.get_efficiency(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_efficiency(void) const; + double get_efficiency(const std::uint8_t index = 0) const; /** - * Checks if the motor is drawing over its current limit. + * Gets the faults experienced by the motor. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. * - * \return 1 if the motor's current limit is being exceeded and 0 if the - * current limit is not exceeded, or PROS_ERR if the operation failed, setting - * errno. - */ - virtual std::int32_t is_over_current(void) const; - - /** - * Checks if the motor is stopped. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \note Although this function forwards data from the motor, the motor - * presently does not provide any value. This function returns PROS_ERR with - * errno set to ENOSYS. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * - * \return 1 if the motor is not moving, 0 if the motor is moving, or PROS_ERR - * if the operation failed, setting errno + * + * \return A bitfield containing the motor's faults. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << motor.get_faults();pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t is_stopped(void) const; + std::uint32_t get_faults(const std::uint8_t index = 0) const; /** - * Checks if the motor is at its zero position. + * Gets the flags set by the motor's operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \note Although this function forwards data from the motor, the motor - * presently does not provide any value. This function returns PROS_ERR with - * errno set to ENOSYS. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * - * \return 1 if the motor is at zero absolute position, 0 if the motor has - * moved from its absolute zero, or PROS_ERR if the operation failed, setting - * errno + * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << motor.get_faults(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_zero_position_flag(void) const; + std::uint32_t get_flags(const std::uint8_t index = 0) const; /** - * Gets the faults experienced by the motor. + * Gets the absolute position of the motor in its encoder units. * - * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return A bitfield containing the motor's faults. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << motor.get_position(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::uint32_t get_faults(void) const; + double get_position(const std::uint8_t index = 0) const; /** - * Gets the flags set by the motor's operation. + * Gets the power drawn by the motor in Watts. * - * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return A bitfield containing the motor's flags. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Power: " << motor.get_power(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::uint32_t get_flags(void) const; + double get_power(const std::uint8_t index = 0) const; /** * Gets the raw encoder count of the motor at a given timestamp. * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param[in] timestamp + * EOVERFLOW - The index is non 0 + * + * + * \param timestamp * A pointer to a time in milliseconds for which the encoder count * will be returned. If NULL, the timestamp at which the encoder * count was read will not be supplied * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * + * * \return The raw encoder count at the given timestamp or PROS_ERR if the * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * std::uint32_t now = pros::millis(); + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << motor.get_raw_position(&now); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_raw_position(std::uint32_t* const timestamp) const; + std::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const; /** - * Gets the temperature limit flag for the motor. + * Gets the temperature of the motor in degrees Celsius. + + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return 1 if the temperature limit is exceeded and 0 if the temperature is - * below the limit, or PROS_ERR if the operation failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Temperature: " << motor.get_temperature(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t is_over_temp(void) const; + double get_temperature(const std::uint8_t index = 0) const; /** - * Gets the absolute position of the motor in its encoder units. + * Gets the torque generated by the motor in Newton Meters (Nm). + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's absolute position in its encoder units or PROS_ERR_F - * if the operation failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Torque: " << motor.get_torque(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_position(void) const; + double get_torque(const std::uint8_t index = 0) const; /** - * Gets the power drawn by the motor in Watts. + * Gets the voltage delivered to the motor in millivolts. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's power draw in Watts or PROS_ERR_F if the operation - * failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Voltage: " << motor.get_voltage(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_power(void) const; + std::int32_t get_voltage(const std::uint8_t index = 0) const; /** - * Gets the temperature of the motor in degrees Celsius. + * Checks if the motor is drawing over its current limit. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the - * operation failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its current limit?: " << motor.is_over_current(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_temperature(void) const; + std::int32_t is_over_current(const std::uint8_t index = 0) const; /** - * Gets the torque generated by the motor in Newton Meters (Nm). + * Gets the temperature limit flag for the motor. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, - * setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_torque(void) const; + std::int32_t is_over_temp(const std::uint8_t index = 0) const; + + ///@} + + /// \name Motor configuration functions + /// These functions allow programmers to configure the behavior of motors + ///@{ /** - * Gets the voltage delivered to the motor in millivolts. + * Gets the brake mode that was set for the motor. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, - * setting errno. - * + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return One of MotorBrake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - virtual std::int32_t get_voltage(void) const; - - /****************************************************************************/ - /** Motor configuration functions **/ - /** **/ - /** These functions allow programmers to configure the behavior of motors **/ - /****************************************************************************/ + MotorBrake get_brake_mode(const std::uint8_t index = 0) const; /** - * Sets the position for the motor in its encoder units. + * Gets the current limit for the motor in mA. * - * This will be the future reference point for the motor's "absolute" - * position. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param position - * The new reference position in its encoder units + * EOVERFLOW - The index is non 0 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * while (true) { + * std::cout << "Motor Current Limit: " << motor.get_current_limit(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t set_zero_position(const double position) const; + std::int32_t get_current_limit(const std::uint8_t index = 0) const; /** - * Sets the "absolute" zero position of the motor to its current position. + * Gets the encoder units that were set for the motor. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return One of MotorUnits according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - virtual std::int32_t tare_position(void) const; + MotorUnits get_encoder_units(const std::uint8_t index = 0) const; /** - * Sets one of motor_brake_mode_e_t to the motor. + * Gets the gearset that was set for the motor. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param mode - * The motor_brake_mode_e_t to set for the motor + * EOVERFLOW - The index is non 0 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return One of MotorGears according to what is set for the motor, + * or pros::MotorGears::invalid if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Gearing: " << motor.get_gearing(); + * } + * \endcode */ - virtual std::int32_t set_brake_mode(const motor_brake_mode_e_t mode) const; + MotorGears get_gearing(const std::uint8_t index = 0) const; /** - * Sets the current limit for the motor in mA. + * Gets the voltage limit set by the user. + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param limit - * The new current limit in mA + * EOVERFLOW - The index is non 0 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Motor Voltage Limit: " << motor.get_voltage_limit(); + * } + * \endcode */ - virtual std::int32_t set_current_limit(const std::int32_t limit) const; + std::int32_t get_voltage_limit(const std::uint8_t index = 0) const; /** - * Sets one of motor_encoder_units_e_t for the motor encoder. + * Gets whether the motor is reversed or not + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: - * ENODEV - The port cannot be configured as a motor * - * \param units - * The new motor encoder units + * EOVERFLOW - The index is non 0 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Is the motor reversed? " << motor.is_reversed(); + * // Prints "0" + * } + * \endcode */ - virtual std::int32_t set_encoder_units(const motor_encoder_units_e_t units) const; + std::int32_t is_reversed(const std::uint8_t index = 0) const; /** - * Sets one of motor_gearset_e_t for the motor. + * Sets one of Motor_Brake to the motor. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param gearset - * The new motor gearset + * EOVERFLOW - The index is non 0 + * + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. - */ - virtual std::int32_t set_gearing(const motor_gearset_e_t gearset) const; - - /** - * Takes in floating point values and returns a properly formatted pid struct. - * The motor_pid_s_t struct is in 4.4 format, i.e. 0x20 is 2.0, 0x21 is - * 2.0625, etc. - * This function will convert the floating point values to the nearest 4.4 - * value. - * - * \param kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant - * - * \return A motor_pid_s_t struct formatted properly in 4.4. - */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] static motor_pid_s_t - convert_pid(double kf, double kp, double ki, double kd); - - /** - * Takes in floating point values and returns a properly formatted pid struct. - * The motor_pid_s_t struct is in 4.4 format, i.e. 0x20 is 2.0, 0x21 is - * 2.0625, etc. - * This function will convert the floating point values to the nearest 4.4 - * value. - * - * \param kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant - * \param filter - * A constant used for filtering the profile acceleration - * \param limit - * The integral limit - * \param threshold - * The threshold for determining if a position movement has reached its - * goal. This has no effect for velocity PID calculations. - * \param loopspeed - * The rate at which the PID computation is run in ms * - * \return A motor_pid_s_t struct formatted properly in 4.4. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor " - "damage.")]] static motor_pid_full_s_t - convert_pid_full(double kf, double kp, double ki, double kd, double filter, double limit, double threshold, - double loopspeed); - + std::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const; /** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. - * - * Only non-zero values of the struct will change the existing motor - * constants. + * Sets one of MotorBrake to the motor. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param pid - * The new motor PID constants + * EOVERFLOW - The index is non 0 + * + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] virtual std::int32_t - set_pos_pid(const motor_pid_s_t pid) const; - + std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const; /** - * Sets one of motor_pid_full_s_t for the motor. + * Sets the current limit for the motor in mA. * - * Only non-zero values of the struct will change the existing motor - * constants. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param pid - * The new motor PID constants + * EOVERFLOW - The index is non 0 + * + * \param limit + * The new current limit in mA + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * motor.set_current_limit(1000); + * while (true) { + * motor = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * pros::delay(2); + * } + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] virtual std::int32_t - set_pos_pid_full(const motor_pid_full_s_t pid) const; + std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const; /** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. - * - * Only non-zero values of the struct will change the existing motor - * constants. + * Sets one of MotorUnits for the motor encoder. Works with the C + * enum and the C++ enum class. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * \param pid - * The new motor PID constants + * \param units + * The new motor encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_encoder_units(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] virtual std::int32_t - set_vel_pid(const motor_pid_s_t pid) const; - + std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const; /** - * Sets one of motor_pid_full_s_t for the motor. + * Sets one of MotorUnits for the motor encoder. Works with the C + * enum and the C++ enum class. * - * Only non-zero values of the struct will change the existing motor - * constants. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param pid - * The new motor PID constants + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * * \param units + * The new motor encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_encoder_units(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] virtual std::int32_t - set_vel_pid_full(const motor_pid_full_s_t pid) const; - + std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const; /** - * Sets the reverse flag for the motor. + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. * - * This will invert its movements and the values returned for its position. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param reverse - * True reverses the motor, false is default + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * \param gearset + * The new motor gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_gearing(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - virtual std::int32_t set_reversed(const bool reverse) const; + std::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const; /** - * Sets the voltage limit for the motor in Volts. + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. + + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param limit - * The new voltage limit in Volts + * EOVERFLOW - The index is non 0 + * + * \param gearset + * The new motor gearset + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_gearing(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - virtual std::int32_t set_voltage_limit(const std::int32_t limit) const; + std::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const; /** - * Gets the brake mode that was set for the motor. + * Sets the reverse flag for the motor. + * + * This will invert its movements and the values returned for its position. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: - * ENODEV - The port cannot be configured as a motor * - * \return One of motor_brake_mode_e_t, according to what was set for the - * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. - */ - virtual motor_brake_mode_e_t get_brake_mode(void) const; - - /** - * Gets the current limit for the motor in mA. + * EOVERFLOW - The index is non 0 * - * The default value is 2500 mA. + * \param reverse + * True reverses the motor, false is default direction + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_reversed(true); + * std::cout << "Is this motor reversed? " << motor.is_reversed(); + * } + * \endcode + */ + std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0); + + /** + * Sets the voltage limit for the motor in Volts. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * \return The motor's current limit in mA or PROS_ERR if the operation failed, - * setting errno. + * \param limit + * The new voltage limit in Volts + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * motor.set_voltage_limit(10000); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will not output more than 10 V + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_current_limit(void) const; + std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const; /** - * Gets the encoder units that were set for the motor. + * Sets the position for the motor in its encoder units. + * + * This will be the future reference point for the motor's "absolute" + * position. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return One of motor_encoder_units_e_t according to what is set for the - * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * EOVERFLOW - The index is non 0 + * + * \param position + * The new reference position in its encoder units + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * motor.move_absolute(100, 100); // This does not cause a movement + * + * motor.set_zero_position(80); + * motor.move_absolute(100, 100); // Moves 80 units forward + * } + * \endcode + * */ - virtual motor_encoder_units_e_t get_encoder_units(void) const; + std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const; /** - * Gets the gearset that was set for the motor. + * Sets the "absolute" zero position of the motor to its current position. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return One of motor_gearset_e_t according to what is set for the motor, - * or E_GEARSET_INVALID if the operation failed. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * motor.move_absolute(100, 100); // This does not cause a movement + * + * motor.tare_position(); + * motor.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode + */ + std::int32_t tare_position(const std::uint8_t index = 0) const; + + /** + * Gets the number of motors. + * + * \return Always returns 1 + * + */ + std::int8_t size(void) const; + + /** + * Gets all motors. + * + * \return A vector of Motor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector motor_all = pros::Motor::get_all_devices(); // All motors that are connected + * } + * \endcode + */ + static std::vector get_all_devices(); + + /** + * gets the port number of the motor + * + * \return The signed port of the motor. (negative if the motor is reversed) + * */ - virtual motor_gearset_e_t get_gearing(void) const; + std::int8_t get_port(const std::uint8_t index = 0) const; + + ///@} + /// \name Additional motor functions + /// These functions allow for motors and motor groups to be used interchangeably + ///@{ /** - * Gets the position PID that was set for the motor. This function will return - * zero for all of the parameters if the motor_set_pos_pid() or - * motor_set_pos_pid_full() functions have not been used. + * Gets a vector containing the target position set for the motor by the user * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. * - * \return A motor_pid_full_s_t containing the position PID constants last set - * to the given motor + * \return A vector containing the target position in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); + * std::cout << "Motor Target: " << motor.get_target_position_all()[0]; + * // Prints 100 + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor " - "damage.")]] virtual motor_pid_full_s_t - get_pos_pid(void) const; + std::vector get_target_position_all(void) const; /** - * Gets the velocity PID that was set for the motor. This function will return - * zero for all of the parameters if the motor_set_vel_pid() or - * motor_set_vel_pid_full() functions have not been used. + * Gets a vector containing the velocity commanded to the motor by the user * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. + * \return A vector containing the commanded motor velocity from +-100, + * +-200, or +-600, or PROS_ERR if the operation failed, setting errno. * - * \return A motor_pid_full_s_t containing the velocity PID constants last set - * to the given motor + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * std::cout << "Motor Velocity: " << motor.get_target_velocity_all()[0]; + * // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y + * pros::delay(2); + * } + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor " - "damage.")]] virtual motor_pid_full_s_t - get_vel_pid(void) const; + std::vector get_target_velocity_all(void) const; /** - * Gets the operation direction of the motor as set by the user. + * Gets a vector containing the actual velocity commanded of the motor * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * \return 1 if the motor has been reversed and 0 if the motor was not - * reversed, or PROS_ERR if the operation failed, setting errno. + * \return A vector containing the motor's actual velocity in RPM or PROS_ERR_F + * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * std::cout << "Motor Velocity: " << motor.get_actual_velocity_all()[0]; + * // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t is_reversed(void) const; + std::vector get_actual_velocity_all(void) const; /** - * Gets the voltage limit set by the user. - * - * Default value is 0V, which means that there is no software limitation - * imposed on the voltage. + * Gets a vector containing the current drawn by the motor in mA. * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's voltage limit in V or PROS_ERR if the operation failed, + * + * \return A vector containing the motor's current in mA or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Current Draw: " << motor.get_current_draw_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_voltage_limit(void) const; + std::vector get_current_draw_all(void) const; /** - * Gets the port number of the motor. + * Gets a vector containing the direction of movement for the motor. + * + * + * This function uses the following values of errno when an error state is + * reached: * - * \return The motor's port number. + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector containing 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Direction: " << motor.get_direction_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::uint8_t get_port(void) const; - - private: - const std::uint8_t _port; -}; + std::vector get_direction_all(void) const; -class Motor_Group { - public: - Motor_Group(const std::initializer_list motors); - explicit Motor_Group(const std::vector& motors); - explicit Motor_Group(const std::initializer_list motor_ports); - explicit Motor_Group(const std::vector motor_ports); // Pass by value to preserve ABI - - /****************************************************************************/ - /** Motor Group movement functions **/ - /** **/ - /** These functions allow programmers to make motor groups move **/ - /****************************************************************************/ /** - * Sets the voltage for all the motors in the motor group from -128 to 127. + * Gets a vector containing the efficiency of the motor in percent. * - * This is designed to map easily to the input from the controller's analog - * stick for simple opcontrol use. The actual behavior of the motor is - * analogous to use of pros::Motor::move() on each motor individually + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. * * This function uses the following values of errno when an error state is * reached: - * ENODEV - One of the ports cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param voltage - * The new motor voltage from -127 to 127 + * ENODEV - The port cannot be configured as a motor * - * \return 1 if the operation was successful or PROS_ERR if the operation + * + * \return A vector containing The motor's efficiency in percent or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Efficiency: " << motor.get_efficiency(); + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t operator=(std::int32_t); + std::vector get_efficiency_all(void) const; /** - * Sets the voltage for the motors in the motor group from -127 to 127. + * Gets a vector of the faults experienced by the motor. * - * This is designed to map easily to the input from the controller's analog - * stick for simple opcontrol use. The actual behavior of the motor is - * analogous to use of motor_move(), or motorSet() from the - * PROS 2 API on each motor. + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param voltage - * The new motor voltage from -127 to 127 + * \return A bitfield containing the motor's faults. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << motor.get_faults_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move(std::int32_t voltage); + std::vector get_faults_all(void) const; /** - * Sets the target absolute position for the motors to move to. + * Gets a vector of the flags set by the motor's operation. * - * This movement is relative to the position of the motors when initialized or - * the position when it was most recently reset with - * pros::Motor::set_zero_position(). + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. * - * \note This function simply sets the target for the motors, it does not block - * program execution until the movement finishes. + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << motor.get_faults_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_flags_all(void) const; + + /** + * Gets a vector containing the absolute position of the motor in its encoder units. * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * - * \param position - * The absolute position to move to in the motors' encoder units - * \param velocity - * The maximum allowable velocity for the movement in RPM + * \return A vector containing the motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. * - * \return 1 if the operation was successful or PROS_ERR if the operation + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << motor.get_position_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_position_all(void) const; + + /** + * Gets a vector containing the power drawn by the motor in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the motor's power draw in Watts or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Power: " << motor.get_power_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move_absolute(const double position, const std::int32_t velocity); + std::vector get_power_all(void) const; /** - * Sets the relative target position for the motor to move to. + * Gets a vector of the raw encoder count of the motor at a given timestamp. * - * This movement is relative to the current position of the motor as given in - * pros::Motor::motor_get_position(). Providing 10.0 as the position parameter - * would result in the motor moving clockwise 10 units, no matter what the - * current position is. * - * \note This function simply sets the target for the motor, it does not block - * program execution until the movement finishes. + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \param timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \return A vector containing the raw encoder count at the given timestamp or PROS_ERR if the + * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * std::uint32_t now = pros::millis(); + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << motor.get_raw_position(&now); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_raw_position_all(std::uint32_t* const timestamp) const; + + /** + * Gets a vector of the temperature of the motor in degrees Celsius. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param position - * The relative position to move to in the motor's encoder units - * \param velocity - * The maximum allowable velocity for the movement in RPM + * \return A vector contaioning the motor's temperature in degrees Celsius + * or PROS_ERR_F if the operation failed, setting errno. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Temperature: " << motor.get_temperature_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move_relative(const double position, const std::int32_t velocity); + std::vector get_temperature_all(void) const; /** - * Sets the velocity for the motors. + * Gets a vector of the torque generated by the motor in Newton Meters (Nm). * - * This velocity corresponds to different actual speeds depending on the - * gearset used for the motor. This results in a range of +-100 for - * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for - * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent - * speed, as opposed to setting the motor's voltage. + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Torque: " << motor.get_torque(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_torque_all(void) const; + + /** + * Gets a vector of the voltage delivered to the motor in millivolts. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param velocity - * The new motor velocity from -+-100, +-200, or +-600 depending on the - * motor's gearset * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \return A vector of the motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Voltage: " << motor.get_voltage_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move_velocity(const std::int32_t velocity); + std::vector get_voltage_all(void) const; /** - * Sets the output voltage for the motors from -12000 to 12000 in millivolts. + * Checks if the motor is drawing over its current limit. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param voltage - * The new voltage value from -12000 to 12000 + * \return A vector containing 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its current limit?: " << motor.is_over_current_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move_voltage(const std::int32_t voltage); + std::vector is_over_current_all(void) const; /** - * Stops the motor using the currently configured brake mode. - * - * This function sets motor velocity to zero, which will cause it to act - * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, - * this function may behave differently than calling move_absolute(0) - * or move_relative(0). + * Gets the temperature limit flag for the motor. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ - std::int32_t brake(void); - - /* - * Gets the voltages delivered to the motors in millivolts. + * \return A vector containing 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given - * - * \return The voltage of the motor in millivolts or PROS_ERR_F if the operation - * failed, setting errno. - * * \b Example * \code * void opcontrol() { - * pros::Motor_Group motors({1, 2}); - * std::vector voltages; + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); * while (true) { - * voltages = motors.get_voltages(); - * - * for (uint32_t i = 0; i < voltages.size(); i++) { - * printf("Voltages: %ld\n", voltages[i]); - * } - * pros::delay(20); + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp_all(); + * pros::delay(2); * } * } * \endcode - * */ - std::vector get_voltages(void); + std::vector is_over_temp_all(void) const; - /* - * Get the voltage limits of the motors set by the user. + /** + * Gets a vector containing the brake mode that was set for the motor. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given - * - * \return The voltage limit of the motor in millivolts or PROS_ERR_F if the operation - * failed, setting errno. - * + * + * \return One of Motor_Brake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * * \b Example * \code - * void opcontrol() { - * pros::Motor_Group motors({1, 2}); - * std::vector voltage_limits; - * while (true) { - * voltage_limits = motors.get_voltage_limits(); - * - * for (uint32_t i = 0; i < voltage_limits.size(); i++) { - * printf("Voltage Limits: %ld\n", voltage_limits[i]); - * } - * pros::delay(20); - * } + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); * } * \endcode */ - std::vector get_voltage_limits(void); + std::vector get_brake_mode_all(void) const; - /* - * Gets the raw encoder positions of a motor group at a given timestamp. + /** + * Gets a vector containing the current limit for the motor in mA. + * + * The default value is 2500 mA. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given - * - * \return A vector of the raw encoder positions of the motors in the motor group - * based on the timestamps passed in. If a timestamp is not found for a motor, the - * value at that index will be PROS_ERR. - * + * + * \return A vector containing the motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + * * \b Example * \code * void opcontrol() { - * pros::Motor_Group motors({1, 2}); - * std::vector timestamps; - * std::vector positions; - * std::uint32_t temp = 0; - * std::uint32_t temp2 = 0; - * timestamps.push_back(&temp); - * timestamps.push_back(&temp2); - * + * pros::Motor motor (1); * while (true) { - * positions = motors.get_raw_positions(timestamps); - * - * printf("Position: %ld, Time: %ln\n", positions[0], timestamps[0]); - * printf("Position: %ld, Time: %ln\n", positions[1], timestamps[1]); - * - * pros::delay(20); + * std::cout << "Motor Current Limit: " << motor.get_current_limit_all()[0]; + * pros::delay(2); * } * } * \endcode */ - std::vector get_raw_positions(std::vector ×tamps); - /****************************************************************************/ - /** Motor configuration functions **/ - /** **/ - /** These functions let programmers configure the behavior of motor groups **/ - /****************************************************************************/ + std::vector get_current_limit_all(void) const; /** - * Indexes Motor in the Motor_Group in the same way as an array. - * + * Gets a vector containing the encoder units that were set for the motor. + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - Out of bounds on indexing the motor groups. - * - * \param i - * The index value in the motor group. + * ENODEV - The port cannot be configured as a motor * - * \return the appropriate Motor reference or the erno if the operation - * failed - */ - pros::Motor& operator[](int i); - + * \return A vector containing One of Motor_Units according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Encoder Units: " << motor.get_encoder_units_all()[0]; + * } + * \endcode + */ + std::vector get_encoder_units_all(void) const; /** - * Indexes Motor in the Motor_Group. - * + * Gets a vector containing the gearset that was set for the motor. + * * This function uses the following values of errno when an error state is * reached: - * Throws an std::out_of_range error when indexing out of range - * - * \param i - * The index value in the motor group. + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing one of Motor_Gears according to what is set for the motor, + * or pros::Motor_Gears::invalid if the operation failed. * - * \return the appropriate Motor reference. - */ - pros::Motor& at(int i); + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Gearing: " << motor.get_gearing_all()[0]; + * } + * \endcode + */ + std::vector get_gearing_all(void) const; /** - * Indexes Motor in the Motor_Group in the same way as an array. - * - * \return the size of the vector containing motors - */ - std::int32_t size(); + * Gets returns a vector with all the port numbers in the motor group. + * + * \return A vector containing the signed port of the motor. (negative if the motor is reversed) + */ + std::vector get_port_all(void) const; /** - * Sets the position for the motor in its encoder units. + * Gets a vector of the voltage limit set by the user. * - * This will be the future reference point for the motors' "absolute" - * position. + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param position - * The new reference position in its encoder units + * \return A vector containing the motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Motor Voltage Limit: " << motor.get_voltage_limit_all()[0]; + * } + * \endcode */ - std::int32_t set_zero_position(const double position); + std::vector get_voltage_limit_all(void) const; + + /** + * Gets a vector containg whether the motor is reversed or not + * + * \return A vector containing 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Is the motor reversed? " << motor.is_reversed_all()[0]; + * // Prints "0" + * } + * \endcode + */ + std::vector is_reversed_all(void) const; + /** - * Sets one of motor_brake_mode_e_t to the motor group. + * Sets one of Motor_Brake to the motor. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * * \param mode - * The motor_brake_mode_e_t to set for the motor + * The Motor_Brake to set for the motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - std::int32_t set_brake_modes(motor_brake_mode_e_t mode); + std::int32_t set_brake_mode_all(const MotorBrake mode) const; /** - * Sets the reverse flag for all the motors in the motor group. - * - * This will invert its movements and the values returned for its position. + * Sets one of Motor_Brake to the motor. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param reverse - * True reverses the motor, false is default + * \param mode + * The Motor_Brake to set for the motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - std::int32_t set_reversed(const bool reversed); + std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const; /** - * Sets the voltage limit for all the motors in Volts. + * Sets the current limit for the motor in mA. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * * \param limit - * The new voltage limit in Volts + * The new current limit in mA * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * motor.set_current_limit_all(1000); + * while (true) { + * motor = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t set_voltage_limit(const std::int32_t limit); + std::int32_t set_current_limit_all(const std::int32_t limit) const; + /** - * Sets one of motor_gearset_e_t for all the motors in the motor group. + * Sets one of Motor_Units for the motor encoder. Works with the C + * enum and the C++ enum class. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param gearset - * The new motor gearset + * EOVERFLOW - The index is non 0 + * + * * \param units + * The new motor encoder units + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - std::int32_t set_gearing(const motor_gearset_e_t gearset); + std::int32_t set_encoder_units_all(const MotorUnits units) const; /** - * Sets one of motor_encoder_units_e_t for the all the motor encoders - * in the motor group. + * Sets one of Motor_Units for the motor encoder. Works with the C + * enum and the C++ enum class. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * * \param units * The new motor encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - std::int32_t set_encoder_units(const motor_encoder_units_e_t units); + std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const; /** - * Sets the "absolute" zero position of the motor group to its current position. + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * + * \param gearset + * The new motor gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. - */ - std::int32_t tare_position(void); - - /****************************************************************************/ - /** Motor telemetry functions **/ - /** **/ - /** These functions let programmers to collect telemetry from motor groups **/ - /****************************************************************************/ - /** - * Gets the actual velocity of each motor. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return A vector with the each motor's actual velocity in RPM in the order - * or a vector filled with PROS_ERR_F if the operation failed, setting errno. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_gearing_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - std::vector get_actual_velocities(void); + std::int32_t set_gearing_all(const MotorGears gearset) const; /** - * Gets the velocity commanded to the motor by the user. + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * \return A vector filled with The commanded motor velocities from - * +-100, +-200, or +-600, or a vector filled with PROS_ERR if the operation - * failed, setting errno. - */ - std::vector get_target_velocities(void); - - /** - * Gets the target position set for the motor by the user. + * \param gearset + * The new motor gearset * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. * - * \return A vector filled with the target position in its encoder units - * or a vector filled with PROS_ERR_F if the operation failed, setting errno. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_gearing_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - std::vector get_target_positions(void); + std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const; /** - * Gets the absolute position of the motor in its encoder units. + * Sets the reverse flag for the motor. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor + * This will invert its movements and the values returned for its position. * - * \return The motor's absolute position in its encoder units or PROS_ERR_F - * if the operation failed, setting errno. - */ - std::vector get_positions(void); - /** - * Gets the efficiency of the motors in percent. * - * An efficiency of 100% means that the motor is moving electrically while - * drawing no electrical power, and an efficiency of 0% means that the motor - * is drawing power but not moving. + * \param reverse + * True reverses the motor, false is default direction * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \return 1 * - * \return A vector filled with the motor's efficiency in percent - * or a vector filled with PROS_ERR_F if the operation failed, setting errno. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_reversed_all(true); + * std::cout << "Is this motor reversed? " << motor.is_reversed(); + * } + * \endcode */ - std::vector get_efficiencies(void); + std::int32_t set_reversed_all(const bool reverse); /** - * Checks if the motors are drawing over its current limit. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * Sets the voltage limit for the motor in Volts. * - * \return 1 if the motor's current limit is being exceeded and 0 if the - * current limit is not exceeded, or PROS_ERR if the operation failed, setting - * errno. - */ - std::vector are_over_current(void); - - /** - * Gets the temperature limit flag for the motors. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: - * ENODEV - The port cannot be configured as a motor - * - * \return A vector with for each motor a 1 if the temperature limit is - * exceeded and 0 if the temperature is below the limit, - * or a vector filled with PROS_ERR if the operation failed, setting errno. - */ - std::vector are_over_temp(void); - - /** - * Gets the brake mode that was set for the motors. * - * This function uses the following values of errno when an error state is - * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return A Vector with for each motor one of motor_brake_mode_e_t, - * according to what was set for the motor, or a vector filled with - * E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. - */ - std::vector get_brake_modes(void); - - /** - * Gets the gearset that was set for the motor. + * EOVERFLOW - The index is non 0 * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \param limit + * The new voltage limit in Volts * - * \return One of motor_gearset_e_t according to what is set for the motor, - * or E_GEARSET_INVALID if the operation failed. - */ - std::vector get_gearing(void); - - /** - * Gets the current drawn by each motor in mA. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); * - * \return A vector containing each motor's current in mA - * or a vector filled with PROS_ERR if the operation failed, setting errno. + * motor.set_voltage_limit_all(10000); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will not output more than 10 V + * pros::delay(2); + * } + * } + * \endcode */ - std::vector get_current_draws(void); + std::int32_t set_voltage_limit_all(const std::int32_t limit) const; /** - * Gets the current limit for each motor in mA. + * Sets the position for the motor in its encoder units. * - * The default value is 2500 mA. + * This will be the future reference point for the motor's "absolute" + * position. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return A vector with each motor's current limit in mA or a vector filled - * with PROS_ERR if the operation failed, setting errno. - */ - std::vector get_current_limits(void); - - /** - * Gets the port number of each motor. + * \param position + * The new reference position in its encoder units * - * \return a vector with each motor's port number. - */ - std::vector get_ports(void); - /** - * Gets the direction of movement for the motors. + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * motor.move_absolute(100, 100); // This does not cause a movement + * + * motor.set_zero_position_all(80); + * motor.move_absolute(100, 100); // Moves 80 units forward + * } + * \endcode * - * \return 1 for moving in the positive direction, -1 for moving in the - * negative direction, and PROS_ERR if the operation failed, setting errno. */ - std::vector get_directions(void); + std::int32_t set_zero_position_all(const double position) const; /** - * Gets the encoder units that were set for each motor. + * Sets the "absolute" zero position of the motor to its current position. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return A vector filled with one of motor_encoder_units_e_t for each motor - * according to what is set for the motor or a vector filled with - * E_MOTOR_ENCODER_INVALID if the operation failed. - */ - std::vector get_encoder_units(void); - - /** - * Gets the encoder units that were set for each motor. + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * motor.move_absolute(100, 100); // This does not cause a movement * - * \return The vector filled with motors' temperature in degrees Celsius or PROS_ERR_F if the - * operation failed, setting errno. + * motor.tare_position_all(); + * motor.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode */ - virtual std::vector get_temperatures(void); + std::int32_t tare_position_all(void) const; + + ///@} private: - std::vector _motors; - pros::Mutex _motor_group_mutex; - std::uint8_t _motor_count; + /** + * The port of the motor. Negative ports indicate that the motor is reversed + */ + std::int8_t _port; }; - -using MotorGroup = Motor_Group; //alias - namespace literals { +/** + * Constructs a Motor from a literal ending in _mtr + * + * \return a pros::Motor for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Motor motor = 2_mtr; //Makes an Motor object on port 2 + * } + * \endcode + */ const pros::Motor operator"" _mtr(const unsigned long long int m); +/** + * Constructs a reversed Motor from a literal ending in _rmtr + * + * \return a pros::Motor for the corresponding port that is reversed + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::motor motor = 2_rmtr; //Makes an reversed Motor object on port 2 + * } + * \endcode + */ const pros::Motor operator"" _rmtr(const unsigned long long int m); } // namespace literals +} // namespace v5 } // namespace pros #endif // _PROS_MOTORS_HPP_ diff --git a/EZ-Template-Example-Project/include/pros/optical.h b/EZ-Template-Example-Project/include/pros/optical.h index 9dd1c1b0..049c395b 100644 --- a/EZ-Template-Example-Project/include/pros/optical.h +++ b/EZ-Template-Example-Project/include/pros/optical.h @@ -1,19 +1,19 @@ /** * \file pros/optical.h + * \ingroup c-optical * * Contains prototypes for functions related to the VEX Optical sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-optical VEX Optical Sensor C API */ #ifndef _PROS_OPTICAL_H_ @@ -33,16 +33,34 @@ namespace pros { namespace c { #endif +/** + * \ingroup c-optical + */ + +/** + * \addtogroup c-optical + * @{ + */ -typedef enum optical_direction_e { - NO_GESTURE = 0, - UP = 1, - DOWN = 2, - RIGHT = 3, - LEFT = 4, +/** + * \enum optical_direction_e_t + */ +typedef enum optical_direction_e { NO_GESTURE = 0, + /// The direction indicating an upward gesture. + UP = 1, + /// The direction indicating a downward gesture. + DOWN = 2, + /// The direction indicating a rightward gesture. + RIGHT = 3, + /// The direction indicating a leftward gesture. + LEFT = 4, ERROR = PROS_ERR } optical_direction_e_t; +/** + * \struct optical_rgb_s_t + * The RGB and Brightness values for the optical sensor. + */ typedef struct optical_rgb_s { double red; double green; @@ -50,6 +68,10 @@ typedef struct optical_rgb_s { double brightness; } optical_rgb_s_t; +/** + * \struct optical_raw_s_t + * The RGB and clear values for the optical sensor. + */ typedef struct optical_raw_s { uint32_t clear; uint32_t red; @@ -57,17 +79,26 @@ typedef struct optical_raw_s { uint32_t blue; } optical_raw_s_t; +/** + * \struct optical_gesture_s_t + * This structure contains the raw gesture data. + */ typedef struct optical_gesture_s { - uint8_t udata; - uint8_t ddata; - uint8_t ldata; - uint8_t rdata; - uint8_t type; - uint8_t pad; - uint16_t count; - uint32_t time; + uint8_t udata; ///Up data + uint8_t ddata; ///Down data + uint8_t ldata; ///Left data + uint8_t rdata; ///Right data + uint8_t type; ///Type of gesture + uint8_t pad; ///Padding + uint16_t count; ///Number of gestures + uint32_t time; ///Time since gesture recognized } optical_gesture_s_t; +/** + * \name Functions + * @{ + */ + /** * Get the detected color hue * @@ -83,6 +114,18 @@ typedef struct optical_gesture_s { * The V5 Optical Sensor port number from 1-21 * \return hue value if the operation was successful or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Hue value: %lf \n", optical_get_hue(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ double optical_get_hue(uint8_t port); @@ -101,6 +144,18 @@ double optical_get_hue(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return saturation value if the operation was successful or PROS_ERR_F if * the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Saturation value: %lf \n", optical_get_saturation(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ double optical_get_saturation(uint8_t port); @@ -119,6 +174,18 @@ double optical_get_saturation(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return brightness value if the operation was successful or PROS_ERR_F if * the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Brightness value: %lf \n", optical_get_brightness(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ double optical_get_brightness(uint8_t port); @@ -137,6 +204,18 @@ double optical_get_brightness(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return poximity value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Proximity value: %d \n", optical_get_proximity(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t optical_get_proximity(uint8_t port); @@ -154,6 +233,18 @@ int32_t optical_get_proximity(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return 1 if the operation is successful or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * optical_set_led_pwm(OPTICAL_PORT, 50); + * delay(20); + * } + * } + * \endcode */ int32_t optical_set_led_pwm(uint8_t port, uint8_t value); @@ -170,6 +261,18 @@ int32_t optical_set_led_pwm(uint8_t port, uint8_t value); * The V5 Optical Sensor port number from 1-21 * \return LED pwm value that ranges from 0 to 100 if the operation was * successful or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("PWM Value: %d \n", optical_get_led_pwm(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t optical_get_led_pwm(uint8_t port); @@ -185,6 +288,23 @@ int32_t optical_get_led_pwm(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return rgb value if the operation was successful or an optical_rgb_s_t with * all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * optical_rgb_s_t RGB_values; + * void opcontrol() { + * while (true) { + * RGB_values = optical_get_rgb(OPTICAL_PORT); + * printf("Red value: %lf \n", RGB_values.red); + * printf("Green value: %lf \n", RGB_values.green); + * printf("Blue value: %lf \n", RGB_values.blue); + * printf("Brightness value: %lf \n", RGB_values.brightness); + * delay(20); + * } + * } + * \endcode */ optical_rgb_s_t optical_get_rgb(uint8_t port); @@ -200,6 +320,23 @@ optical_rgb_s_t optical_get_rgb(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return raw rgb value if the operation was successful or an optical_raw_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * optical_raw_s_t raw_values; + * void opcontrol() { + * while (true) { + * raw_values = optical_get_raw(OPTICAL_PORT); + * printf("Red value: %ld \n", raw_values.red); + * printf("Green value: %ld \n", raw_values.green); + * printf("Blue value: %ld \n", raw_values.blue); + * printf("Clear value: %ld \n", raw_values.clear); + * delay(20); + * } + * } + * \endcode */ optical_raw_s_t optical_get_raw(uint8_t port); @@ -217,6 +354,20 @@ optical_raw_s_t optical_get_raw(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return gesture value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * optical_direction_e_t gesture; + * void opcontrol() { + * while (true) { + * gesture = optical_get_gesture(OPTICAL_PORT); + * printf("Gesture value: %d \n", gesture); + * delay(20); + * } + * } + * \endcode */ optical_direction_e_t optical_get_gesture(uint8_t port); @@ -232,6 +383,26 @@ optical_direction_e_t optical_get_gesture(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return gesture value if the operation was successful or an optical_gesture_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * optical_gesture_s_t raw_gesture; + * void opcontrol() { + * while (true) { + * raw_gesture = optical_get_gesture_raw(OPTICAL_PORT); + * printf("Up data: %u \n", raw_gesture.udata); + * printf("Down data: %u \n", raw_gesture.ddata); + * printf("Left data: %u \n", raw_gesture.ldata); + * printf("Right data: %u \n", raw_gesture.rdata); + * printf("Type: %u \n", raw_gesture.type); + * printf("Count: %u \n", raw_gesture.count); + * printf("Time: %lu \n", raw_gesture.time); + * delay(20); + * } + * } + * \endcode */ optical_gesture_s_t optical_get_gesture_raw(uint8_t port); @@ -247,6 +418,18 @@ optical_gesture_s_t optical_get_gesture_raw(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return 1 if the operation is successful or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * optical_enable_gesture(OPTICAL_PORT); + * delay(20); + * } + * } + * \endcode */ int32_t optical_enable_gesture(uint8_t port); @@ -262,41 +445,24 @@ int32_t optical_enable_gesture(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return 1 if the operation is successful or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * optical_disable_gesture(OPTICAL_PORT); + * delay(20); + * } + * } + * \endcode */ int32_t optical_disable_gesture(uint8_t port); -/** - * Get integration time (update rate) of the optical sensor in milliseconds, with - * minimum time being - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as an Optical Sensor - * - * \param port - * The V5 Optical Sensor port number from 1-21 - * \return Integration time in milliseconds if the operation is successful - * or PROS_ERR if the operation failed, setting errno. - */ -double optical_get_integration_time(uint8_t port); +///@} -/** - * Set integration time (update rate) of the optical sensor in milliseconds. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as an Optical Sensor - * - * \param port - * The V5 Optical Sensor port number from 1-21 - * \param time - * The desired integration time in milliseconds - * \return 1 if the operation is successful or PROS_ERR if the operation failed, - * setting errno. - */ -int32_t optical_set_integration_time(uint8_t port, double time); +///@} #ifdef __cplusplus } diff --git a/EZ-Template-Example-Project/include/pros/optical.hpp b/EZ-Template-Example-Project/include/pros/optical.hpp index 006108d6..463daa8a 100644 --- a/EZ-Template-Example-Project/include/pros/optical.hpp +++ b/EZ-Template-Example-Project/include/pros/optical.hpp @@ -1,19 +1,19 @@ /** * \file pros/optical.hpp + * \ingroup cpp-optical * * Contains prototypes for functions related to the VEX Optical sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-optical VEX Optical Sensor C++ API */ #ifndef _PROS_OPTICAL_HPP_ @@ -22,11 +22,21 @@ #include #include +#include +#include "pros/device.hpp" #include "pros/optical.h" namespace pros { -class Optical { +inline namespace v5 { +/** + * \ingroup cpp-optical + */ +class Optical : public Device { + /** + * \addtogroup cpp-optical + * @{ + */ public: /** * Creates an Optical Sensor object for the given port. @@ -38,10 +48,30 @@ class Optical { * * \param port * The V5 port number from 1-21 + * + * \b Example: + * \code{.cpp} + * pros::Optical optical(1); + * \endcode */ - explicit Optical(const std::uint8_t port); + Optical(const std::uint8_t port); + + Optical(const Device& device) : Optical(device.get_port()){}; + - explicit Optical(std::uint8_t port, double time); + /** + * Gets all optical sensors. + * + * \return A vector of Optical sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector optical_all = pros::Optical::get_all_devices(); // All optical sensors that are connected + * } + * \endcode + */ + static std::vector get_all_devices(); /** * Get the detected color hue @@ -56,6 +86,14 @@ class Optical { * * \return hue value if the operation was successful or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * std::cout << "Hue: " << optical.get_hue() << std::endl; + * } + * \endcode */ virtual double get_hue(); @@ -72,6 +110,14 @@ class Optical { * * \return saturation value if the operation was successful or PROS_ERR_F if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * std::cout << "Saturation: " << optical.get_saturation() << std::endl; + * } + * \endcode */ virtual double get_saturation(); @@ -88,6 +134,14 @@ class Optical { * * \return brightness value if the operation was successful or PROS_ERR_F if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * std::cout << "Brightness: " << optical.get_brightness() << std::endl; + * } + * \endcode */ virtual double get_brightness(); @@ -102,8 +156,16 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return poximity value if the operation was successful or PROS_ERR if + * \return Proximity value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * std::cout << "Proximity: " << optical.get_proximity() << std::endl; + * } + * \endcode */ virtual std::int32_t get_proximity(); @@ -117,7 +179,15 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return The Error code encountered + * \return The Error code encountered or PROS_SUCCESS. + * + * \b Example: + * \code{.cpp} + * void initialize() { + * pros::Optical optical(1); + * optical.set_led_pwm(100); + * } + * \endcode */ virtual std::int32_t set_led_pwm(uint8_t value); @@ -133,6 +203,15 @@ class Optical { * * \return LED pwm value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * optical.set_led_pwm(100); + * std::cout << "LED PWM: " << optical.get_led_pwm() << std::endl; + * } + * \endcode */ virtual std::int32_t get_led_pwm(); @@ -144,8 +223,23 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return rgb value if the operation was successful or an optical_rgb_s_t + * \return rgb value if the operation was successful or an optical_rgb_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * pros::c::optical_rgb_s_t rgb = optical.get_rgb(); + * while(1) { + * std::cout << "Red: " << rgb.red << std::endl; + * std::cout << "Green: " << rgb.green << std::endl; + * std::cout << "Blue: " << rgb.blue << std::endl; + * std::cout << "Brightness: " << rgb.brightness << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual pros::c::optical_rgb_s_t get_rgb(); @@ -157,8 +251,23 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return raw rgb value if the operation was successful or an optical_raw_s_t + * \return raw rgb value if the operation was successful or an optical_raw_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * pros::c::optical_raw_s_t raw = optical.get_raw(); + * while (1) { + * std::cout << "Red: " << raw.red << std::endl; + * std::cout << "Green: " << raw.green << std::endl; + * std::cout << "Blue: " << raw.blue << std::endl; + * std::cout << "Clear: " << raw.clear << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual pros::c::optical_raw_s_t get_raw(); @@ -166,10 +275,12 @@ class Optical { * Get the most recent gesture data from the sensor * * Gestures will be cleared after 500mS - * 0 = no gesture - * 1 = up (towards cable) - * 2 = down - * 3 = right + * + * + * 0 = no gesture, + * 1 = up (towards cable), + * 2 = down, + * 3 = right, * 4 = left * * This function uses the following values of errno when an error state is @@ -179,6 +290,17 @@ class Optical { * * \return gesture value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * while(1) { + * std::cout << "Gesture: " << optical.get_gesture() << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual pros::c::optical_direction_e_t get_gesture(); @@ -190,8 +312,28 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return gesture value if the operation was successful or an optical_gesture_s_t + * \return gesture value if the operation was successful or an optical_gesture_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * optical.enable_gesture(); + * while(1) { + * pros::c::optical_gesture_s_t gesture = optical.get_gesture_raw(); + * std::cout << "Gesture raw data: " << std::endl; + * std::cout << "Up data: " << gesture.udata << std::endl; + * std::cout << "Down data: " << gesture.ddata << std::endl; + * std::cout << "Left data: " << gesture.ldata << std::endl; + * std::cout << "Right data: " << gesture.rdata << std::endl; + * std::cout << "Type: " << gesture.type << std::endl; + * std::cout << "Count: " << gesture.count << std::endl; + * std::cout << "Time: " << gesture.time << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual pros::c::optical_gesture_s_t get_gesture_raw(); @@ -204,7 +346,27 @@ class Optical { * ENODEV - The port cannot be configured as an Optical Sensor * * \return 1 if the operation is successful or PROS_ERR if the operation failed, - * setting errno. + * setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * optical.enable_gesture(); + * while(1) { + * pros::c::optical_gesture_s_t gesture = optical.get_gesture_raw(); + * std::cout << "Gesture raw data: " << std::endl; + * std::cout << "Up data: " << gesture.udata << std::endl; + * std::cout << "Down data: " << gesture.ddata << std::endl; + * std::cout << "Left data: " << gesture.ldata << std::endl; + * std::cout << "Right data: " << gesture.rdata << std::endl; + * std::cout << "Type: " << gesture.type << std::endl; + * std::cout << "Count: " << gesture.count << std::endl; + * std::cout << "Time: " << gesture.time << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual std::int32_t enable_gesture(); @@ -217,50 +379,61 @@ class Optical { * ENODEV - The port cannot be configured as an Optical Sensor * * \return 1 if the operation is successful or PROS_ERR if the operation failed, - * setting errno. - */ - virtual std::int32_t disable_gesture(); - - /** - * Set integration time (update rate) of the optical sensor in milliseconds, with - * minimum time being 3 ms and maximum time being 712 ms. Default is 100 ms, with the - * optical sensor communciating with the V5 brain every 20 ms. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as an Optical Sensor - * - * \return 1 if the operation is successful or PROS_ERR_F if the operation failed, * setting errno. - */ - double get_integration_time(); - - /** - * Get integration time (update rate) of the optical sensor in milliseconds. * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as an Optical Sensor - * - * \param time - * The desired integration time in milliseconds - * \return Integration time in milliseconds if the operation is successful - * or PROS_ERR if the operation failed, setting errno. + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * optical.enable_gesture(); + * while(1) { + * if(optical.get_gesture() != 0) { + * std::cout << "Gesture detected!"<< std::endl; + * optical.disable_gesture(); + * } + * pros::delay(20); + * } + * } + * \endcode */ - std::int32_t set_integration_time(double time); + virtual std::int32_t disable_gesture(); /** - * Gets the port number of the Optical Sensor. + * This is the overload for the << operator for printing to streams * - * \return The Optical Sensor's port number. + * Prints in format(this below is all in one line with no new line): + * Optical [port: (port number), hue: (hue), saturation: (saturation), + * brightness: (brightness), proximity: (proximity), rgb: {red, green, blue}] + * + * \b Example: + * \code{.cpp} + * pros::Optical optical(1); + * std::cout << optical << std::endl; + * \endcode */ - virtual std::uint8_t get_port(); + friend std::ostream& operator<<(std::ostream& os, pros::Optical& optical); private: - const std::uint8_t _port; + ///@} }; + +namespace literals { +/** + * Constructs a Optical sensor from a literal ending in _opt + * + * \return a pros::Optical for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Optical opt = 2_opt; //Makes an Optical object on port 2 + * } + * \endcode + */ +const pros::Optical operator"" _opt(const unsigned long long int o); +} // namespace literals +} // namespace v5 } // namespace pros #endif diff --git a/EZ-Template-Example-Project/include/pros/rotation.h b/EZ-Template-Example-Project/include/pros/rotation.h index 8daf2fd8..1c1c7317 100644 --- a/EZ-Template-Example-Project/include/pros/rotation.h +++ b/EZ-Template-Example-Project/include/pros/rotation.h @@ -1,19 +1,19 @@ /** * \file pros/rotation.h + * \ingroup c-rotation * * Contains prototypes for functions related to the VEX Rotation Sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/rotation.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-rotation VEX Rotation Sensor C API */ #ifndef _PROS_ROTATION_H_ @@ -28,6 +28,15 @@ namespace pros { namespace c { #endif +/** + * \ingroup c-rotation + */ + +/** + * \addtogroup c-rotation + * @{ + */ + #define ROTATION_MINIMUM_DATA_RATE 5 /** @@ -45,6 +54,21 @@ namespace c { * The V5 Rotation Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_reset(ROTATION_PORT); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_reset(uint8_t port); @@ -65,6 +89,16 @@ int32_t rotation_reset(uint8_t port); * \param rate The data refresh interval in milliseconds * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void initialize() { + * pros::Rotation rotation_sensor(ROTATION_PORT); + * rotation_set_data_rate(ROTATION_PORT, 5); + * } + * \endcode */ int32_t rotation_set_data_rate(uint8_t port, uint32_t rate); @@ -82,6 +116,21 @@ int32_t rotation_set_data_rate(uint8_t port, uint32_t rate); * The position in terms of ticks * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_set_position(ROTATION_PORT, 600); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_set_position(uint8_t port, uint32_t position); @@ -98,6 +147,21 @@ int32_t rotation_set_position(uint8_t port, uint32_t position); * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_reset_position(ROTATION_PORT); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_reset_position(uint8_t port); @@ -113,6 +177,18 @@ int32_t rotation_reset_position(uint8_t port); * The V5 Rotation Sensor port number from 1-21 * \return The position value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Position: %d centidegrees \n", rotation_get_position(ROTATION_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t rotation_get_position(uint8_t port); @@ -128,6 +204,18 @@ int32_t rotation_get_position(uint8_t port); * The V5 Rotation Sensor port number from 1-21 * \return The velocity value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Velocity: %d centidegrees per second \n", rotation_get_velocity(ROTATION_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t rotation_get_velocity(uint8_t port); @@ -143,6 +231,18 @@ int32_t rotation_get_velocity(uint8_t port); * The V5 Rotation Sensor port number from 1-21 * \return The angle value (0-36000) or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Angle: %d centidegrees \n", rotation_get_angle(ROTATION_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t rotation_get_angle(uint8_t port); @@ -161,6 +261,22 @@ int32_t rotation_get_angle(uint8_t port); * * \return 1 if operation succeeded or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * Rotation rotation_sensor(ROTATION_PORT); + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_set_reversed(ROTATION_PORT, true); // Reverses the Rotation Sensor on ROTATION_PORT + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_set_reversed(uint8_t port, bool value); @@ -177,6 +293,22 @@ int32_t rotation_set_reversed(uint8_t port, bool value); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * Rotation rotation_sensor(ROTATION_PORT); + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_reverse(ROTATION_PORT); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_reverse(uint8_t port); @@ -195,6 +327,23 @@ int32_t rotation_reverse(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * Rotation rotation_sensor(ROTATION_PORT); + * bool reverse_flag = true; + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_init_reverse(ROTATION_PORT, reverse_flag); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_init_reverse(uint8_t port, bool reverse_flag); @@ -211,9 +360,27 @@ int32_t rotation_init_reverse(uint8_t port, bool reverse_flag); * * \return Boolean value of if the Rotation Sensor's direction is reversed or not * or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * Rotation rotation_sensor(ROTATION_PORT); + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_get_reversed(ROTATION_PORT); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_get_reversed(uint8_t port); +///@} + #ifdef __cplusplus } //namespace C } //namespace pros diff --git a/EZ-Template-Example-Project/include/pros/rotation.hpp b/EZ-Template-Example-Project/include/pros/rotation.hpp index a063eda2..e7743aa4 100644 --- a/EZ-Template-Example-Project/include/pros/rotation.hpp +++ b/EZ-Template-Example-Project/include/pros/rotation.hpp @@ -1,35 +1,62 @@ /** * \file pros/rotation.hpp + * \ingroup cpp-rotation * * Contains prototypes for functions related to the VEX Rotation Sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/rotation.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-rotation VEX Rotation Sensor C++ API */ #ifndef _PROS_ROTATION_HPP_ #define _PROS_ROTATION_HPP_ #include +#include +#include "pros/device.hpp" #include "pros/rotation.h" namespace pros { -class Rotation { - const std::uint8_t _port; +inline namespace v5 { +/** + * \ingroup cpp-rotation + */ +class Rotation : public Device { + /** + * \addtogroup cpp-rotation + * @{ + */ public: - Rotation(const std::uint8_t port) : _port(port){}; + /** + * Constructs a new Rotation Sensor object + * + * ENXIO - The given value is not within the range of V5 ports |1-21|. + * ENODEV - The port cannot be configured as a Rotation Sensor + * + * \param port + * The V5 port number from 1 to 21, or from -21 to -1 for reversed Rotation Sensors. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); //Creates a Rotation Sensor on port 1 + * pros::Rotation reversed_rotation_sensor(-2); //Creates a reversed Rotation Sensor on port 2 + * } + * \endcode + */ + Rotation(const std::int8_t port); + + Rotation(const Device& device) : Rotation(device.get_port()){}; - Rotation(const std::uint8_t port, const bool reverse_flag); /** * Reset the Rotation Sensor @@ -44,6 +71,20 @@ class Rotation { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.reset(); + * } + * pros::delay(20); + * } + * } + * \endcode */ virtual std::int32_t reset(); @@ -67,6 +108,14 @@ class Rotation { * \param rate The data refresh interval in milliseconds * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Rotation rotation_sensor(1); + * rotation_sensor.set_data_rate(5); + * } + * \endcode */ virtual std::int32_t set_data_rate(std::uint32_t rate) const; @@ -82,11 +131,25 @@ class Rotation { * The position in terms of ticks * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.set_position(600); + * } + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t set_position(std::uint32_t position); + virtual std::int32_t set_position(std::uint32_t position) const; /** - * Reset the Rotation Sensor to a desired rotation value + * Reset the Rotation Sensor position to 0 * * This function uses the following values of errno when an error state is * reached: @@ -97,8 +160,36 @@ class Rotation { * The position in terms of ticks * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.reset_position(); + * } + * pros::delay(20); + * } + * } + * \endcode + */ + virtual std::int32_t reset_position(void) const; + + /** + * Gets all rotation sensors. + * + * \return A vector of Rotation sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector rotation_all = pros::Rotation::get_all_devices(); // All rotation sensors that are connected + * } + * \endcode */ - virtual std::int32_t reset_position(void); + static std::vector get_all_devices(); /** * Get the Rotation Sensor's current position in centidegrees @@ -110,8 +201,19 @@ class Rotation { * * \return The position value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while (true) { + * printf("Position: %d Ticks \n", rotation_sensor.get_position()); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_position(); + virtual std::int32_t get_position() const; /** * Get the Rotation Sensor's current velocity in centidegrees per second @@ -123,11 +225,21 @@ class Rotation { * * \param port * The V5 Rotation Sensor port number from 1-21 - * \return The - value or PROS_ERR_F if the operation failed, setting + * \return The velocity value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while (true) { + * printf("Velocity: %d centidegrees per second \n", rotation_sensor.get_velocity)); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_velocity(); + virtual std::int32_t get_velocity() const; /** * Get the Rotation Sensor's current position in centidegrees @@ -139,8 +251,19 @@ class Rotation { * * \return The angle value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while (true) { + * printf("Angle: %d centidegrees \n", rotation_sensor.get_angle()); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_angle(); + virtual std::int32_t get_angle() const; /** * Set the Rotation Sensor's direction reversed flag @@ -156,8 +279,22 @@ class Rotation { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.set_reversed(true); // Reverses the Rotation Sensor + * } + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t set_reversed(bool value); + virtual std::int32_t set_reversed(bool value) const; /** * Reverse the Rotation Sensor's direction. @@ -169,8 +306,22 @@ class Rotation { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.reverse(); + * } + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t reverse(); + virtual std::int32_t reverse() const; /** * Get the Rotation Sensor's reversed flag @@ -182,9 +333,62 @@ class Rotation { * * \return Reversed value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while (true) { + * printf("Reversed: %d \n", rotation_sensor.get_reversed()); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_reversed(); + virtual std::int32_t get_reversed() const; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * Rotation [port: rotation._port, position: (rotation position), velocity: (rotation velocity), + * angle: (rotation angle), reversed: (reversed boolean)] + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while(true) { + * std::cout << rotation_sensor << std::endl; + * pros::delay(20); + * } + * } + * \endcode + */ + friend std::ostream& operator<<(std::ostream& os, const pros::Rotation& rotation); + + ///@} }; + +namespace literals { +/** + * Constructs a Rotation sensor from a literal ending in _rot + * + * \return a pros::Rotation for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Rotation rotation = 2_rot; //Makes an Motor object on port 2 + * } + * \endcode + */ +const pros::Rotation operator"" _rot(const unsigned long long int r); +} // namespace literals +} // namespace v5 } // namespace pros #endif diff --git a/EZ-Template-Example-Project/include/pros/rtos.h b/EZ-Template-Example-Project/include/pros/rtos.h index c0767342..d6b9be48 100644 --- a/EZ-Template-Example-Project/include/pros/rtos.h +++ b/EZ-Template-Example-Project/include/pros/rtos.h @@ -1,22 +1,23 @@ /** * \file pros/rtos.h + * \ingroup c-rtos * * Contains declarations for the PROS RTOS kernel for use by typical VEX * programmers. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html to - * learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ + * + * \defgroup c-rtos RTOS Facilities C API + * \note Additional example code for this module can be found in its [Tutorial.](@ref multitasking) + */ #ifndef _PROS_RTOS_H_ #define _PROS_RTOS_H_ @@ -29,52 +30,117 @@ extern "C" { namespace pros { #endif -// The highest priority that can be assigned to a task. Beware of deadlock. +/// \ingroup c-rtos + +/// \addtogroup c-rtos +/// @{ + +/// \name Macros +/// @{ + +/** + * The highest priority that can be assigned to a task. + * + * A task with this priority will always run if it is available to. Beware of + * deadlocks when using this priority. + */ #define TASK_PRIORITY_MAX 16 -// The lowest priority that can be assigned to a task. -// This may cause severe performance problems and is generally not recommended. +/** + * The lowest priority that can be assigned to a task. + * + * This can cause severe performance problems and is generally not recommended + * that users use this priority. + */ #define TASK_PRIORITY_MIN 1 -// The default task priority, which should be used for most tasks. -// Default tasks such as autonomous() inherit this priority. +/** + * The default task priority, which should be used for most tasks unless you + * have a specific need for a higher or lower priority task. + * + * The default tasks, such as autonomous(), are run with this priority + */ #define TASK_PRIORITY_DEFAULT 8 -// The recommended stack size for a new task. This stack size is used for -// default tasks such as autonomous(). This equates to 32,768 bytes, or 128 -// times the default stack size for a task in PROS 2. +/** + * The recommended stack size for a new task. + * + * This stack size is used for the default tasks such as autonomous(). This + * size is 8,192 words, or 32,768 bytes. This should be enough for the majority + * of tasks + */ #define TASK_STACK_DEPTH_DEFAULT 0x2000 -// The minimal stack size for a task. This equates to 2048 bytes, or 8 times the -// default stack size for a task in PROS 2. +/** + * The minimal stack size for a task. + * + * This equates to 512 words, or 2,048 bytes. + */ #define TASK_STACK_DEPTH_MIN 0x200 -// The maximum number of characters allowed in a task's name. +/** + * The maximum number of characters allowed in a task's name. + */ #define TASK_NAME_MAX_LEN 32 -// The maximum timeout value that can be given to, for instance, a mutex grab. +/** + * The maximum timeout value that can be given to, for instance, a mutex grab. + */ #define TIMEOUT_MAX ((uint32_t)0xffffffffUL) +/// @} Name: Macros + +/// \name Typedefs +/// @{ + +/** + * An opaque type that pontis to a task handle. This is used for referencing a + * task. + */ typedef void* task_t; + +/** + * A pointer to a task's function. + * + * Such a function is called when a task starts, and exiting said function will + * terminate the task. + */ typedef void (*task_fn_t)(void*); +/// @} Name: Typedefs + + +/// \name Enumerations +/// @{ + +/** + * The state of a task. + */ typedef enum { - E_TASK_STATE_RUNNING = 0, - E_TASK_STATE_READY, - E_TASK_STATE_BLOCKED, - E_TASK_STATE_SUSPENDED, - E_TASK_STATE_DELETED, - E_TASK_STATE_INVALID + E_TASK_STATE_RUNNING = 0, /**< The task is actively executing. */ + E_TASK_STATE_READY, /**< The task exists and is available to run, but is not currently running. */ + E_TASK_STATE_BLOCKED, /**< The task is delayed or blocked by a mutex, semaphore, or I/O operation. */ + E_TASK_STATE_SUSPENDED, /**< The task is supended using task_suspend. */ + E_TASK_STATE_DELETED, /**< The task has been deleted using task_delete. */ + E_TASK_STATE_INVALID /**< The task handle does not point to a current or past task.*/ } task_state_e_t; +/** + * brief The action to take when a task is notified. + */ typedef enum { - E_NOTIFY_ACTION_NONE, - E_NOTIFY_ACTION_BITS, - E_NOTIFY_ACTION_INCR, - E_NOTIFY_ACTION_OWRITE, - E_NOTIFY_ACTION_NO_OWRITE + E_NOTIFY_ACTION_NONE, /**< The task’s notification value will not be touched.*/ + E_NOTIFY_ACTION_BITS, /**< The task’s notification value will be bitwise ORed with the new value.*/ + E_NOTIFY_ACTION_INCR, /**< The task’s notification value will be incremented by one, effectively using it as a notification counter.*/ + E_NOTIFY_ACTION_OWRITE, /**< The task’s notification value will be unconditionally set to the new value.*/ + E_NOTIFY_ACTION_NO_OWRITE /**< The task’s notification value will be set to the new value if the task does not already have a pending notification.*/ } notify_action_e_t; +/// @} Name: Enumerations + +/// \name Simple enum names +/// @{ + #ifdef PROS_USE_SIMPLE_NAMES #ifdef __cplusplus #define TASK_STATE_RUNNING pros::E_TASK_STATE_RUNNING @@ -103,10 +169,24 @@ typedef enum { #endif #endif +/// @} Name: Simple enum names + +/// \name Typedefs + +/** + * A [mutex.](@ref multitasking) + * + * A mutex is a synchronization object that can be used to protect a shared + * resource from being accessed by multiple tasks at the same time. A mutex can + * be claimed by a task, which will prevent other tasks from claiming it until + * that task releases it. + */ typedef void* mutex_t; +/// @} Name: Typedefs + /** - * Refers to the current task handle + * The task handle of the currently running task. */ #ifdef __cplusplus #define CURRENT_TASK ((pros::task_t)NULL) @@ -114,14 +194,31 @@ typedef void* mutex_t; #define CURRENT_TASK ((task_t)NULL) #endif +/// @} (add to group: c-rtos) + #ifdef __cplusplus namespace c { #endif +/// \ingroup c-rtos +/// \addtogroup c-rtos +/// @{ + /** * Gets the number of milliseconds since PROS initialized. * * \return The number of milliseconds since PROS initialized + * + * \b Example + * \code + * void opcontrol() { + * uint32_t now = millis(); + * while (true) { + * // Do opcontrol things + * task_delay_until(&now, 2); + * } + * } + * \endcode */ uint32_t millis(void); @@ -129,6 +226,17 @@ uint32_t millis(void); * Gets the number of microseconds since PROS initialized, * * \return The number of microseconds since PROS initialized + * + * \b Example + * \code + * void opcontrol() { + * uint64_t now = micros(); + * while (true) { + * // Do opcontrol things + * task_delay_until(&now, 2000); + * } + * } + * \endcode */ uint64_t micros(void); @@ -158,6 +266,19 @@ uint64_t micros(void); * \return A handle by which the newly created task can be referenced. If an * error occurred, NULL will be returned and errno can be checked for hints as * to why task_create failed. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode */ task_t task_create(task_fn_t function, void* const parameters, uint32_t prio, const uint16_t stack_depth, const char* const name); @@ -172,11 +293,26 @@ task_t task_create(task_fn_t function, void* const parameters, uint32_t prio, co * \param task * The handle of the task to be deleted. Passing NULL will cause the * calling task to be deleted. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * // Do other things + * task_delete(my_task); + * } + * \endcode */ void task_delete(task_t task); /** - * Delays a task for a given number of milliseconds. + * Delays the current task for a given number of milliseconds. * * This is not the best method to have a task execute code at predefined * intervals, as the delay time is measured from when the delay is requested. @@ -184,14 +320,44 @@ void task_delete(task_t task); * * \param milliseconds * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * // Do opcontrol things + * task_delay(2); + * } + * } + * \endcode */ void task_delay(const uint32_t milliseconds); +/** + * Delays the current task for a given number of milliseconds. + * + * This is not the best method to have a task execute code at predefined + * intervals, as the delay time is measured from when the delay is requested. + * To delay cyclically, use task_delay_until(). + * + * \param milliseconds + * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * // Do opcontrol things + * delay(2); + * } + * } + * \endcode + */ void delay(const uint32_t milliseconds); /** - * Delays a task until a specified time. This function can be used by periodic - * tasks to ensure a constant execution frequency. + * Delays the current task until a specified time. This function can be used + * by periodic tasks to ensure a constant execution frequency. * * The task will be woken up at the time *prev_time + delta, and *prev_time will * be updated to reflect the time at which the task will unblock. @@ -201,6 +367,17 @@ void delay(const uint32_t milliseconds); * typically be initialized to the return value of millis(). * \param delta * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * uint32_t now = millis(); + * while (true) { + * // Do opcontrol things + * task_delay_until(&now, 2); + * } + * } + * \endcode */ void task_delay_until(uint32_t* const prev_time, const uint32_t delta); @@ -211,6 +388,20 @@ void task_delay_until(uint32_t* const prev_time, const uint32_t delta); * The task to check * * \return The priority of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * printf("Task Priority: %d\n", task_get_priority(my_task)); + * } + * \endcode */ uint32_t task_get_priority(task_t task); @@ -225,6 +416,19 @@ uint32_t task_get_priority(task_t task); * The task to set * \param prio * The new priority of the task + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * // Do things + * } + * + * void opcontrol() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "Example Task"); + * task_set_priority(my_task, TASK_PRIORITY_DEFAULT + 1); + * } + * \endcode */ void task_set_priority(task_t task, uint32_t prio); @@ -235,6 +439,20 @@ void task_set_priority(task_t task, uint32_t prio); * The task to check * * \return The state of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * printf("Task's State: %d\n", task_get_state(my_task)); + * } + * \endcode */ task_state_e_t task_get_state(task_t task); @@ -243,6 +461,34 @@ task_state_e_t task_get_state(task_t task); * * \param task * The task to suspend + * + * \b Example + * \code + * mutex_t counter_mutex; + * int counter = 0; + * + * void my_task_fn(void* param) { + * while(true) { + * mutex_take(counter_mutex, TIMEOUT_MAX);// Mutexes are used for protecting shared resources + * counter++; + * mutex_give(counter_mutex); + * pros::delay(10); + * } + * } + * + * void opcontrol() { + * task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,; + * + * while(true) { + * mutex_take(counter_mutex, TIMEOUT_MAX); + * if(counter > 100) { + * task_suspepend(task); + * } + * mutex_give(counter_mutex); + * pros::delay(10); + * } + * } + * \endcode */ void task_suspend(task_t task); @@ -251,6 +497,39 @@ void task_suspend(task_t task); * * \param task * The task to resume + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while(true) { + * // Do stuff + * delay(10); + * } + * } + * + * task_t task; + * + * void initialize() { + * task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * + * void autonomous() { + * task_resume(task); + * + * // Run autonomous , then suspend the task so it doesn't interfere run + * + * // outside of autonomous or opcontrol + * task_suspend(task); + * } + * + * void opcontrol() { + * task_resume(task); + * // Opctonrol code here + * task_suspend(task); + * } + * + * \endcode */ void task_resume(task_t task); @@ -261,6 +540,20 @@ void task_resume(task_t task); * created may take one context switch to be counted. * * \return The number of tasks that are currently being managed by the kernel. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * printf("Number of Running Tasks: %d\n", task_get_count()); + * } + * \endcode */ uint32_t task_get_count(void); @@ -271,6 +564,20 @@ uint32_t task_get_count(void); * The task to check * * \return A pointer to the name of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * printf("Task Name: %d\n", task_get_name(my_task)); + * } + * \endcode */ char* task_get_name(task_t task); @@ -283,6 +590,21 @@ char* task_get_name(task_t task); * The name to query * * \return A task handle with a matching name, or NULL if none were found. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * // Do other things + * task_delete(task_get_by_name("My Task")); + * } + * \endcode */ task_t task_get_by_name(const char* name); @@ -291,19 +613,52 @@ task_t task_get_by_name(const char* name); * wants to tell another task about itself. * * \return The currently running task handle. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * task_t this_task = task_get_current(); + * if (task_get_state(this_take) == E_TASK_STATE_RUNNING) { + * printf("This task is currently running\n"); + * } + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode */ task_t task_get_current(); /** * Sends a simple notification to task and increments the notification counter. * - * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for - * details. - * * \param task * The task to notify * * \return Always returns true. + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * while(task_notify_take(true) == 0) { + * // Code while waiting + * } + * puts("I was unblocked!"); + * } + * + * void opcontrol() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "Notify me! Task"); + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task_notify(my_task); + * } + * } + * } + * \endcode */ uint32_t task_notify(task_t task); @@ -311,14 +666,28 @@ uint32_t task_notify(task_t task); * * Utilizes task notifications to wait until specified task is complete and deleted, * then continues to execute the program. Analogous to std::thread::join in C++. - * - * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for - * details. * * \param task - * The task to wait on. + * The handle of the task to wait on. * * \return void + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * lcd_print(1, "%s running", task_get_name(NULL)); + * task_delay(1000); + * lcd_print(2, "End of %s", task_get_name(NULL)); + * } + * + * void opcontrol() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "Example Task"); + * lcd_set_text(0, "Running task."); + * task_join(my_task); + * lcd_set_text(3, "Task completed."); + * } + * \endcode */ void task_join(task_t task); @@ -327,9 +696,6 @@ void task_join(task_t task); * retrieve the value of the notification in the target task before modifying * the notification value. * - * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for - * details. - * * \param task * The task to notify * \param value @@ -345,6 +711,37 @@ void task_join(task_t task); * For NOTIFY_ACTION_NO_WRITE: return 0 if the value could be written without * needing to overwrite, 1 otherwise. * For all other NOTIFY_ACTION values: always return 0 + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while(true) { + * // Wait until we have been notified 20 times before running the code + * if(task_notify_take(false, TIMEOUT_MAX) == 20) { + * // ... Code to do stuff here ... + * + * // Reset the notification counter + * task_notify_take(true, TIMEOUT_MAX); + * } + * delay(10); + * } + * } + * + * void opcontrol() { + * task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * + * int count = 0; + * + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task_notify_ext(task, 1, NOTIFY_ACTION_INCREMENT, &count); + * } + * + * delay(20); + * } + * } + * \endcode */ uint32_t task_notify_ext(task_t task, uint32_t value, notify_action_e_t action, uint32_t* prev_value); @@ -363,6 +760,26 @@ uint32_t task_notify_ext(task_t task, uint32_t value, notify_action_e_t action, * * \return The value of the task's notification value before it is decremented * or cleared + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * task_t current_task = task_get_current(); + * while(task_notify_take(current_task, true, TIMEOUT_MAX)) { + * puts("I was unblocked!"); + * } + * } + * + * void opcontrol() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "Notify me! Task"); + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task_notify(my_task); + * } + * } + * } + * \endcode */ uint32_t task_notify_take(bool clear_on_exit, uint32_t timeout); @@ -376,6 +793,32 @@ uint32_t task_notify_take(bool clear_on_exit, uint32_t timeout); * The task to clear * * \return False if there was not a notification waiting, true if there was + * + * \b Example + * \code + * void my_task_fn(void* param) { + * task_t task = task_get_current(); + * while(true) { + * printf("Waiting for notification...\n"); + * printf("Got a notification: %d\n", task_notify_take(task, false, TIMEOUT_MAX)); + * + * task_notify_clear(task); + * delay(10): + * } + * } + * + * void opcontrol() { + * task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task_notify(task); + * } + * delay(10); + * } + * } + * \endcode */ bool task_notify_clear(task_t task); @@ -387,6 +830,75 @@ bool task_notify_clear(task_t task); * * \return A handle to a newly created mutex. If an error occurred, NULL will be * returned and errno can be checked for hints as to why mutex_create failed. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * mutex_t odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * mutex_take(odom_mutex, MAX_DELAY); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * mutex_give(odom_mutex); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * mutex_take(odom_mutex, MAX_DELAY); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * mutex_give(odom_mutex); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * mutex_take(odom_mutex, MAX_DELAY); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * mutex_give(odom_mutex); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = mutex_create(); + * + * task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Odometry Task"); + * task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Chassis Task"); + * } + * \endcode */ mutex_t mutex_create(void); @@ -407,6 +919,75 @@ mutex_t mutex_create(void); * \return True if the mutex was successfully taken, false otherwise. If false * is returned, then errno is set with a hint about why the the mutex * couldn't be taken. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * mutex_t odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * mutex_take(odom_mutex, MAX_DELAY); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * mutex_give(odom_mutex); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * mutex_take(odom_mutex, MAX_DELAY); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * mutex_give(odom_mutex); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * mutex_take(odom_mutex, MAX_DELAY); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * mutex_give(odom_mutex); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = mutex_create(); + * + * task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Odometry Task"); + * task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Chassis Task"); + * } + * \endcode */ bool mutex_take(mutex_t mutex, uint32_t timeout); @@ -422,6 +1003,75 @@ bool mutex_take(mutex_t mutex, uint32_t timeout); * \return True if the mutex was successfully returned, false otherwise. If * false is returned, then errno is set with a hint about why the mutex * couldn't be returned. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * mutex_t odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * mutex_take(odom_mutex, MAX_DELAY); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * mutex_give(odom_mutex); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * mutex_take(odom_mutex, MAX_DELAY); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * mutex_give(odom_mutex); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * mutex_take(odom_mutex, MAX_DELAY); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * mutex_give(odom_mutex); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = mutex_create(); + * + * task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Odometry Task"); + * task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Chassis Task"); + * } + * \endcode */ bool mutex_give(mutex_t mutex); @@ -430,9 +1080,25 @@ bool mutex_give(mutex_t mutex); * * \param mutex * Mutex to unlock. + * + * \b Example + * \code + * mutex_t mutex = mutex_create(); + * // Acquire the mutex; other tasks using this command will wait until the mutex is released + * // timeout can specify the maximum time to wait, or MAX_DELAY to wait forever + * // If the timeout expires, "false" will be returned, otherwise "true" + * mutex_take(mutex, MAX_DELAY); + * // do some work + * // Release the mutex for other tasks + * mutex_give(mutex); + * // Delete the mutex + * mutex_delete(mutex); + * \endcode */ void mutex_delete(mutex_t mutex); +/// @} Add to group: c-rtos + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/EZ-Template-Example-Project/include/pros/rtos.hpp b/EZ-Template-Example-Project/include/pros/rtos.hpp index 2505f1d1..f02495c2 100644 --- a/EZ-Template-Example-Project/include/pros/rtos.hpp +++ b/EZ-Template-Example-Project/include/pros/rtos.hpp @@ -1,21 +1,22 @@ /** * \file pros/rtos.hpp + * \ingroup cpp-rtos * * Contains declarations for the PROS RTOS kernel for use by typical VEX * programmers. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html to - * learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-rtos RTOS Facilities C++ API + * \note Additional example code for this module can be found in its [Tutorial.](@ref multitasking) */ #ifndef _PROS_RTOS_HPP_ @@ -32,7 +33,15 @@ #include namespace pros { +inline namespace rtos { +/** + * \ingroup cpp-rtos + */ class Task { + /** + * \addtogroup cpp-rtos + * @{ + */ public: /** * Creates a new task and add it to the list of tasks that are ready to run. @@ -57,7 +66,18 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, (void*)"PROS"); + * } + * \endcode */ Task(task_fn_t function, void* parameters = nullptr, std::uint32_t prio = TASK_PRIORITY_DEFAULT, std::uint16_t stack_depth = TASK_STACK_DEPTH_DEFAULT, const char* name = ""); @@ -79,7 +99,18 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, (void*)"PROS", "My Task"); + * } + * \endcode */ Task(task_fn_t function, void* parameters, const char* name); @@ -101,7 +132,18 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::c::task_t my_task = pros::Task::create(my_task_fn, (void*)"PROS"); + * } + * \endcode */ template static task_t create(F&& function, std::uint32_t prio = TASK_PRIORITY_DEFAULT, @@ -127,7 +169,18 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::c::task_t my_task = pros::Task::create(my_task_fn, "My Task"); + * } + * \endcode */ template static task_t create(F&& function, const char* name) { @@ -152,7 +205,19 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * + * void initialize() { + * // Create a task function using lambdas + * auto task_fn = [](void* param) { + * printf("Hello %s\n", (char*)param); + * } + * + * pros::Task my_task(task_fn, (void*)"PROS", "My Task"); + * } + * \endcode */ template explicit Task(F&& function, std::uint32_t prio = TASK_PRIORITY_DEFAULT, @@ -179,6 +244,22 @@ class Task { * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task( + * [](void* param) { + * printf("Inside the task!\n"); + * }, + * "My Task" + * ); + * } + * \endcode */ template Task(F&& function, const char* name) @@ -190,20 +271,60 @@ class Task { * \param task * A task handle from task_create() for which to create a pros::Task * object. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::c::task_t my_task = pros::Task::create(my_task_fn, "My Task"); + * + * pros::Task my_task_cpp(my_task); + * } + * \endcode */ explicit Task(task_t task); /** * Get the currently running Task + * + * @return The currently running Task. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("The name of this task is \"%s\"\n", pros::Task::current().get_name() + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, pros::TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode */ static Task current(); /** - * Creates a new task and add it to the list of tasks that are ready to run. + * Creates a task object from the passed task handle. * * \param in * A task handle from task_create() for which to create a pros::Task * object. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("The name of this task is \"%s\"\n", pros::Task::current().get_name() + * } + * + * void initialize() { + * pros::c::task_t my_task = pros::Task::create(my_task_fn, "My Task"); + * + * pros::Task my_task_cpp = my_task; + * } + * \endcode */ Task& operator=(task_t in); @@ -213,6 +334,20 @@ class Task { * * Memory dynamically allocated by the task is not automatically freed, and * should be freed before the task is deleted. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * my_task.remove(); + * } + * \endcode */ void remove(); @@ -220,6 +355,20 @@ class Task { * Gets the priority of the specified task. * * \return The priority of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * printf("Task Priority: %d\n", my_task.get_priority()); + * } + * \endcode */ std::uint32_t get_priority(); @@ -232,6 +381,20 @@ class Task { * * \param prio * The new priority of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * Task.set_priority(pros::DEFAULT_PRIORITY + 1); + * } + * \endcode */ void set_priority(std::uint32_t prio); @@ -239,11 +402,53 @@ class Task { * Gets the state of the specified task. * * \return The state of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * printf("Task State: %d\n", my_task.get_state()); + * } + * \endcode */ std::uint32_t get_state(); /** * Suspends the specified task, making it ineligible to be scheduled. + * + * \b Example + * \code + * pros::Mutex counter_mutex; + * int counter = 0; + * + * void my_task_fn(void* param) { + * while(true) { + * counter_mutex.take(); // Mutexes are used for protecting shared resources + * counter++; + * counter_mutex.give(); + * pros::delay(10); + * } + * } + * + * void opcontrol() { + * pros::Task task(my_task_fn, "My Task"); + * + * while(true) { + * counter_mutex.take(); + * if(counter > 100) { + * task_suspepend(task); + * } + * counter_mutex.give(); + * pros::delay(10); + * } + * } + * \endcode */ void suspend(); @@ -252,6 +457,33 @@ class Task { * * \param task * The task to resume + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while(true) { + * // Do stuff + * pros::delay(10); + * } + * } + * + * pros::Task task(my_task_fn); + * + * void autonomous() { + * task.resume(); + * + * // Run autonomous , then suspend the task so it doesn't interfere run + * // outside of autonomous or opcontrol + * task.suspend(); + * } + * + * void opcontrol() { + * task.resume(); + * // Opctonrol code here + * task.suspend(); + * } + * + * \endcode */ void resume(); @@ -259,11 +491,38 @@ class Task { * Gets the name of the specified task. * * \return A pointer to the name of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * printf("Number of Running Tasks: %d\n", my_task.get_name()); + * } + * \endcode */ const char* get_name(); /** * Convert this object to a C task_t handle + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * pros::c::task_t my_task_c = (pros::c::task_t)my_task; + * } + * \endcode */ explicit operator task_t() { return task; @@ -277,6 +536,26 @@ class Task { * details. * * \return Always returns true. + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * while(pros::Task::current_task().notify_take(true) == 0) { + * // Code while waiting + * } + * puts("I was unblocked!"); + * } + * + * void opcontrol() { + * pros::Task my_task(my_task_fn); + * + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * my_task.notify(); + * } + * } + * } + * \endcode */ std::uint32_t notify(); @@ -288,6 +567,22 @@ class Task { * details. * * \return void + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * lcd_print(1, "%s running", pros::Task::current_task().get_name()); + * task_delay(1000); + * lcd_print(2, "End of %s", pros::Task::current_task().get_name()); + * } + * + * void opcontrol() { + * pros::Task my_task(my_task_fn); + * pros::lcd::set_text(0, "Running task."); + * my_task.join(); + * pros::lcd::lcd_set_text(3, "Task completed."); + * } + * \endcode */ void join(); @@ -312,6 +607,38 @@ class Task { * For NOTIFY_ACTION_NO_WRITE: return 0 if the value could be written without * needing to overwrite, 1 otherwise. * For all other NOTIFY_ACTION values: always return 0 + * + * \b Example + * \code + * void my_task_fn(void* param) { + * pros::Task task = pros::Task::current(); + * + * while(true) { + * // Wait until we have been notified 20 times before running the code + * if(task.notify_take(false, TIMEOUT_MAX) == 20) { + * // ... Code to do stuff here ... + * + * // Reset the notification counter + * task.notify_clear(); + * } + * delay(10); + * } + * } + * + * void opcontrol() { + * pros::Task task(my_task_fn); + * + * int count = 0; + * + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task.notify_ext(1, NOTIFY_ACTION_INCREMENT, &count); + * } + * + * delay(20); + * } + * } + * \endcode */ std::uint32_t notify_ext(std::uint32_t value, notify_action_e_t action, std::uint32_t* prev_value); @@ -330,6 +657,25 @@ class Task { * * \return The value of the task's notification value before it is decremented * or cleared + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * pros::Task task = pros::task::current(); + * while(task.notify_take(true, TIMEOUT_MAX)) { + * puts("I was unblocked!"); + * } + * } + * + * void opcontrol() { + * pros::Task task(my_task_fn); + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task.notify(my_task); + * } + * } + * } + * \endcode */ static std::uint32_t notify_take(bool clear_on_exit, std::uint32_t timeout); @@ -340,11 +686,34 @@ class Task { * details. * * \return False if there was not a notification waiting, true if there was + * \b Example + * \code + * void my_task_fn(void* param) { + * pros::Task task = pros::Task::current(); + * while(true) { + * printf("Waiting for notification...\n"); + * printf("Got a notification: %d\n", task.notify_take(false, TIMEOUT_MAX)); + * + * tasK_notify(task); + * delay(10): + * } + * } + * + * void opcontrol() { + * pros::Task task(my_task_fn); + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task.notify(); + * } + * delay(10); + * } + * } + * \endcode */ bool notify_clear(); /** - * Delays a task for a given number of milliseconds. + * Delays the current task for a specified number of milliseconds. * * This is not the best method to have a task execute code at predefined * intervals, as the delay time is measured from when the delay is requested. @@ -352,11 +721,20 @@ class Task { * * \param milliseconds * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * // Do opcontrol things + * pros::Task::delay(2); + * } + * \endcode */ static void delay(const std::uint32_t milliseconds); /** - * Delays a task until a specified time. This function can be used by + * Delays the current Task until a specified time. This function can be used by * periodic tasks to ensure a constant execution frequency. * * The task will be woken up at the time *prev_time + delta, and *prev_time @@ -367,6 +745,16 @@ class Task { * typically be initialized to the return value from pros::millis(). * \param delta * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * // Do opcontrol things + * pros::Task::delay(2); + * } + * } + * \endcode */ static void delay_until(std::uint32_t* const prev_time, const std::uint32_t delta); @@ -377,6 +765,19 @@ class Task { * Tasks recently created may take one context switch to be counted. * * \return The number of tasks that are currently being managed by the kernel. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void opcontrol() { + * pros::Task my_task(my_task_fn); + * printf("There are %d tasks running\n", pros::Task::get_count()); + * } + * \endcode */ static std::uint32_t get_count(); @@ -398,6 +799,23 @@ struct Clock { * Effectively a wrapper around pros::millis() * * \return The current time + * + * \b Example + * \code + * void opcontrol() { + * pros::Clock::time_point start = pros::Clock::now(); + * pros::Clock::time_point end = pros::Clock::now(); + * pros::Clock::duration duration = end - start; + * printf("Duration: %d\n", duration.count()); + * + * if(duration.count() == 500) { + * // If you see this comment in the DOCS, ping @pros in VTOW. + * // If you are the first person to do so, you will receive a free PROS + * // holo! + * printf("Duration is 500 milliseconds\n"); + * } + * } + * \endcode */ static time_point now(); }; @@ -425,7 +843,76 @@ class Mutex { * * \return True if the mutex was successfully taken, false otherwise. If false * is returned, then errno is set with a hint about why the the mutex - * couldn't be taken. + * couldn't be taken + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.take(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.give(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.take(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.give(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.take(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.give(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ bool take(); @@ -445,6 +932,75 @@ class Mutex { * \return True if the mutex was successfully taken, false otherwise. If false * is returned, then errno is set with a hint about why the the mutex * couldn't be taken. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.take(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.give(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.take(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.give(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.take(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.give(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ bool take(std::uint32_t timeout); @@ -458,6 +1014,75 @@ class Mutex { * \return True if the mutex was successfully returned, false otherwise. If * false is returned, then errno is set with a hint about why the mutex * couldn't be returned. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.take(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.give(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.take(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.give(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.take(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.give(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ bool give(); @@ -475,6 +1100,75 @@ class Mutex { * * \exception std::system_error Mutex could not be locked within TIMEOUT_MAX * milliseconds. see errno for details. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.lock(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.unlock(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.lock(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.unlock(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.lock(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.unlock(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ void lock(); @@ -488,6 +1182,75 @@ class Mutex { * * \note Consider using a std::unique_lock, std::lock_guard, or * std::scoped_lock instead of interacting with the Mutex direcly. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.lock(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.unlock(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.lock(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.unlock(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.lock(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.unlock(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ void unlock(); @@ -500,6 +1263,20 @@ class Mutex { * \see https://en.cppreference.com/w/cpp/named_req/Lockable * * \return True when lock was acquired succesfully, or false otherwise. + * + * pros::Mutex mutex; + * + * void my_task_fn(void* param) { + * while (true) { + * if(mutex.try_lock()) { + * printf("Mutex aquired successfully!\n"); + * // Do stuff that requires the protected resource here + * } + * else { + * printf("Mutex not aquired!\n"); + * } + * } + * } */ bool try_lock(); @@ -514,6 +1291,21 @@ class Mutex { * * \param rel_time Time to wait before the mutex becomes available. * \return True if the lock was acquired succesfully, otherwise false. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while (true) { + * if(mutex.try_lock_for(std::chrono::milliseconds(100))) { + * printf("Mutex aquired successfully!\n"); + * // Do stuff that requires the protected resource here + * } + * else { + * printf("Mutex not aquired after 100 milliseconds!\n"); + * } + * } + * } + * \endcode */ template bool try_lock_for(const std::chrono::duration& rel_time) { @@ -528,11 +1320,33 @@ class Mutex { * * \param abs_time Time point until which to wait for the mutex. * \return True if the lock was acquired succesfully, otherwise false. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while (true) { + * // Get the current time point + * auto now = std::chrono::system_clock::now(); + * + * // Calculate the time point 100 milliseconds from now + * auto abs_time = now + std::chrono::milliseconds(100); + * + * if(mutex.try_lock_until(abs_time)) { + * printf("Mutex aquired successfully!\n"); + * // Do stuff that requires the protected resource here + * } + * else { + * printf("Mutex not aquired after 100 milliseconds!\n"); + * } + * } + * } + * \endcode */ template bool try_lock_until(const std::chrono::time_point& abs_time) { return take(std::max(static_cast(0), (abs_time - Clock::now()).count())); } + ///@} }; template @@ -578,7 +1392,57 @@ class MutexVar { * constructor arguments. * * \param args - The arguments to provide to the Var constructor. + * The arguments to provide to the Var constructor. + * + * \b Example + * \code + * // We create a pose class to contain all our odometry data in a single + * // variable that can be protected by a MutexVar. Otherwise, we would have + * // three seperate variables which could not be protected in a single + * // MutexVar + * struct Pose { + * double x; + * double y; + * double heading; + * } + * + * pros::MutexVar odom_pose(0.0, 0.0, 0.0); + * + * void odom_task(void* param) { + * while(true) { + * Pose old_pose = *odom_pose.lock(); + * + * Pose new_pose{0.0, 0.0, 0.0}; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * + * *odom_pose.take() = new_pose; + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * + * Pose cur_pose = *odom_pose.take(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * + * \endcode */ template MutexVar(Args&&... args) : mutex(), var(std::forward(args)...) {} @@ -592,6 +1456,26 @@ class MutexVar { * * \return A std::optional which contains a MutexVarLock providing access to * the protected variable if locking is successful. + * + * \b Example + * \code + * pros::MutexVar odom_pose; + * + * void my_task(void* param) { + * while(true) { + * std::optional> cur_pose_opt = odom_pose.try_lock(100); + * + * if(cur_pose_opt.has_value()) { + * Pose* cur_pose = **cur_pose_opt; + * } + * else { + * printf("Could not lock the mutex var!"); + * } + * + * pros::delay(10); + * } + * } + * \endcode */ std::optional> try_lock(std::uint32_t timeout) { if (mutex.take(timeout)) { @@ -610,6 +1494,27 @@ class MutexVar { * * \return A std::optional which contains a MutexVarLock providing access to * the protected variable if locking is successful. + * + * \b Example + * \code + * pros::MutexVar odom_pose; + * + * void my_task(void* param) { + * while(true) { + * std::chrono::duration timeout(100); + * std::optional> cur_pose_opt = odom_pose.try_lock(timeout); + * + * if(cur_pose_opt.has_value()) { + * Pose* cur_pose = **cur_pose_opt; + * } + * else { + * printf("Could not lock the mutex var!"); + * } + * + * pros::delay(10); + * } + * } + * \endcode */ template std::optional> try_lock(const std::chrono::duration& rel_time) { @@ -620,6 +1525,22 @@ class MutexVar { * Lock the mutex-protected variable, waiting indefinitely. * * \return A MutexVarLock providing access to the protected variable. + * + * \b Example + * \code + * pros::MutexVar odom_pose; + * + * void my_task(void* param) { + * while(true) { + * pros::delay(10); + * + * pros::MutexVarLock cur_pose = odom_pose.lock(); + * Pose cur_pose = *cur_pose; + * + * // do stuff with cur_pose + * } + * } + * \endcode */ MutexVarLock lock() { while (!mutex.take(TIMEOUT_MAX)) @@ -653,6 +1574,7 @@ using pros::c::micros; * The number of milliseconds to wait (1000 milliseconds per second) */ using pros::c::delay; +} // namespace rtos } // namespace pros #endif // _PROS_RTOS_HPP_ diff --git a/EZ-Template-Example-Project/include/pros/screen.h b/EZ-Template-Example-Project/include/pros/screen.h index 5c6b538f..71c28570 100644 --- a/EZ-Template-Example-Project/include/pros/screen.h +++ b/EZ-Template-Example-Project/include/pros/screen.h @@ -1,5 +1,6 @@ /** * \file screen.h + * \ingroup c-screen * * Brain screen display and touch functions. * @@ -10,19 +11,22 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-screen Simplified Brain Screen C API + * */ #ifndef _PROS_SCREEN_H_ #define _PROS_SCREEN_H_ -#include -#include +#include +#include #define _GNU_SOURCE -#include +#include #undef _GNU_SOURCE #include -#include "pros/colors.h" // c color macros +#include "pros/colors.h" // c color macros #ifdef __cplusplus extern "C" { @@ -30,35 +34,56 @@ namespace pros { #endif /** - * ! Different font sizes that can be used in printing text. + * \ingroup c-screen + */ + +/** + * \addtogroup c-screen + * @{ + */ + +/** + * \enum text_format_e_t + * Different font sizes that can be used in printing text. */ typedef enum { - E_TEXT_SMALL = 0, ///< Small text font size - E_TEXT_MEDIUM, ///< Normal/Medium text font size - E_TEXT_LARGE, ///< Large text font size - E_TEXT_MEDIUM_CENTER, ///< Medium centered text - E_TEXT_LARGE_CENTER ///< Large centered text + /// Small text font size + E_TEXT_SMALL = 0, + /// Normal/Medium text font size + E_TEXT_MEDIUM, + /// Large text font size + E_TEXT_LARGE, + /// Medium centered text + E_TEXT_MEDIUM_CENTER, + /// Large centered text + E_TEXT_LARGE_CENTER } text_format_e_t; /** - * ! Enum indicating what the current touch status is for the touchscreen. + * \enum last_touch_e_t + * Enum indicating what the current touch status is for the touchscreen. */ typedef enum { - E_TOUCH_RELEASED = 0, ///< Last interaction with screen was a quick press - E_TOUCH_PRESSED, ///< Last interaction with screen was a release - E_TOUCH_HELD, ///< User is holding screen down - E_TOUCH_ERROR ///< An error occured while taking/returning the mutex + /// Last interaction with screen was a quick press + E_TOUCH_RELEASED = 0, + /// Last interaction with screen was a release + E_TOUCH_PRESSED, + /// User is holding screen down + E_TOUCH_HELD, + /// An error occured while taking/returning the mutex + E_TOUCH_ERROR } last_touch_e_t; /** - * ! Struct representing screen touch status, screen last x, screen last y, press count, release count. + * \struct screen_touch_status_s_t + * Struct representing screen touch status, screen last x, screen last y, press count, release count. */ typedef struct screen_touch_status_s { - last_touch_e_t touch_status; ///< Represents if the screen is being held, released, or pressed. - int16_t x; ///< Represents the x value of the location of the touch. - int16_t y; ///< Represents the y value of the location of the touch. - int32_t press_count; ///< Represents how many times the screen has be pressed. - int32_t release_count; ///< Represents how many times the user released after a touch on the screen. + last_touch_e_t touch_status; ///< Represents if the screen is being held, released, or pressed. + int16_t x; ///< Represents the x value of the location of the touch. + int16_t y; ///< Represents the y value of the location of the touch. + int32_t press_count; ///< Represents how many times the screen has be pressed. + int32_t release_count; ///< Represents how many times the user released after a touch on the screen. } screen_touch_status_s_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -89,24 +114,37 @@ typedef void (*touch_event_cb_fn_t)(); namespace c { #endif -/******************************************************************************/ -/** Screen Graphical Display Functions **/ -/** **/ -/** These functions allow programmers to display shapes on the v5 screen **/ -/******************************************************************************/ +/// \name Screen Graphical Display Functions +/// These functions allow programmers to display shapes on the v5 screen +///@{ /** * Set the pen color for subsequent graphics operations - * + * * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. * * \param color The pen color to set (it is recommended to use values * from the enum defined in colors.h) - * - * \return Returns 1 if the mutex was successfully returned, or PROS_ERR if + * + * \return Returns 1 if the mutex was successfully returned, or PROS_ERR if * there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_pen(COLOR_RED); + * } + * + * void opcontrol() { + * int iter = 0; + * while(1){ + * // This should print in red. + * screen_print(TEXT_MEDIUM, 1, "%d", iter++); + * } + * } + * \endcode */ uint32_t screen_set_pen(uint32_t color); @@ -116,12 +154,26 @@ uint32_t screen_set_pen(uint32_t color); * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * + * * \param color The background color to set (it is recommended to use values * from the enum defined in colors.h) - * - * \return Returns 1 if the mutex was successfully returned, or + * + * \return Returns 1 if the mutex was successfully returned, or * PROS_ERR if there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_eraser(COLOR_RED); + * } + * + * void opcontrol() { + * while(1){ + * // This should turn the screen red. + * screen_erase(); + * } + * } + * \endcode */ uint32_t screen_set_eraser(uint32_t color); @@ -131,10 +183,24 @@ uint32_t screen_set_eraser(uint32_t color); * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * - * \return The current pen color in the form of a value from the enum defined - * in colors.h, or PROS_ERR if there was an error taking or returning + * + * \return The current pen color in the form of a value from the enum defined + * in colors.h, or PROS_ERR if there was an error taking or returning * the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_pen(COLOR_RED); + * } + * + * void opcontrol() { + * while(1){ + * // Should print number equivalent to COLOR_RED defined in colors.h. + * screen_print(TEXT_MEDIUM, 1, "%d", screen_get_pen()); + * } + * } + * \endcode */ uint32_t screen_get_pen(void); @@ -145,9 +211,23 @@ uint32_t screen_get_pen(void); * reached: * EACCESS - Another resource is currently trying to access the screen mutex. * - * \return The current eraser color in the form of a value from the enum - * defined in colors.h, or PROS_ERR if there was an error taking or + * \return The current eraser color in the form of a value from the enum + * defined in colors.h, or PROS_ERR if there was an error taking or * returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_eraser(COLOR_RED); + * } + * + * void opcontrol() { + * while(1){ + * // Should print number equivalent to COLOR_RED defined in colors.h. + * screen_print(TEXT_MEDIUM, 1, "%d", screen_get_eraser()); + * } + * } + * \endcode */ uint32_t screen_get_eraser(void); @@ -157,9 +237,23 @@ uint32_t screen_get_eraser(void); * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_eraser(COLOR_RED); + * } + * + * void opcontrol() { + * while(1){ + * // This should turn the screen red. + * screen_erase(); + * } + * } + * \endcode */ uint32_t screen_erase(void); @@ -172,9 +266,18 @@ uint32_t screen_erase(void); * * \param start_line The line from which scrolling will start * \param lines The number of lines to scroll up - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_print(TEXT_MEDIUM, 4, "Line Here"); + * // Scroll 3 lines + * screen_scroll(4, 3); + * } + * \endcode */ uint32_t screen_scroll(int16_t start_line, int16_t lines); @@ -194,14 +297,23 @@ uint32_t screen_scroll(int16_t start_line, int16_t lines); * \param x1, y1 The (x,y) coordinates of the second corner of the * rectangular region * \param lines The number of lines to scroll upwards - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_print(TEXT_MEDIUM, 1, "Line Here"); + * // Scrolls area of screen upwards slightly. including line of text + * screen_scroll_area(0,0, 400, 200, 3); + * } + * \endcode */ uint32_t screen_scroll_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t lines); /** - * Copy a screen region (designated by a rectangle) from an off-screen buffer + * Copy a screen region (designated by a rectangle) from an off-screen buffer * to the screen * * This function uses the following values of errno when an error state is @@ -215,9 +327,20 @@ uint32_t screen_scroll_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int1 * \param buf Off-screen buffer containing screen data * \param stride Off-screen buffer width in pixels, such that image size * is stride-padding - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * uint32_t* buf = malloc(sizeof(uint32_t) * 400 * 200); + * screen_print(TEXT_MEDIUM, 1, "Line Here"); + * // Copies area of the screen including text + * screen_copy_area(0, 0, 400, 200, (uint32_t*)buf, 400 + 1); + * // Equation for stride is x2 - x1 + 1 + * } + * \endcode */ uint32_t screen_copy_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t* buf, int32_t stride); @@ -229,9 +352,21 @@ uint32_t screen_copy_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32 * EACCESS - Another resource is currently trying to access the screen mutex. * * \param x, y The (x,y) coordinates of the pixel - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * int i = 0; + * void opcontrol() { + * while(i < 200){ + * screen_draw_pixel(100,i++); + * // Draws a line at x = 100 gradually down the screen, pixel by pixel + * delay(200); + * } + * } + * \endcode */ uint32_t screen_draw_pixel(int16_t x, int16_t y); @@ -243,9 +378,24 @@ uint32_t screen_draw_pixel(int16_t x, int16_t y); * EACCESS - Another resource is currently trying to access the screen mutex. * * \param x, y The (x,y) coordinates of the erased - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Color the Screen in Red + * screen_set_pen(COLOR_RED); + * screen_fill_rect(0,0,400,200); + * int i = 0; + * while(i < 200){ + * screen_erase_pixel(100,i++); + * // Erases a line at x = 100 gradually down the screen, pixel by pixel + * delay(200); + * } + * } + * \endcode */ uint32_t screen_erase_pixel(int16_t x, int16_t y); @@ -258,9 +408,18 @@ uint32_t screen_erase_pixel(int16_t x, int16_t y); * * \param x0, y0 The (x, y) coordinates of the first point of the line * \param x1, y1 The (x, y) coordinates of the second point of the line - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_set_pen(COLOR_RED); + * // Draw line down the screen at x = 100 + * screen_draw_line(100,0,100,200); + * } + * \endcode */ uint32_t screen_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -273,9 +432,20 @@ uint32_t screen_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x0, y0 The (x, y) coordinates of the first point of the line * \param x1, y1 The (x, y) coordinates of the second point of the line - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Color the Screen in Red + * screen_set_pen(COLOR_RED); + * screen_fill_rect(0,0,400,200); + * // Erase line down the screen at x = 100 + * screen_erase_line(100,0,100,200); + * } + * \endcode */ uint32_t screen_erase_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -288,9 +458,17 @@ uint32_t screen_erase_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x0, y0 The (x,y) coordinates of the first point of the rectangle * \param x1, y1 The (x,y) coordinates of the second point of the rectangle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_set_pen(COLOR_RED); + * screen_draw_rect(1,1,480,200); + * } + * \endcode */ uint32_t screen_draw_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -303,9 +481,18 @@ uint32_t screen_draw_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x0, y0 The (x,y) coordinates of the first point of the rectangle * \param x1, y1 The (x,y) coordinates of the second point of the rectangle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Draw Box Around Half the Screen in Red + * screen_set_eraser(COLOR_RED); + * screen_erase_rect(5,5,240,200); + * } + * \endcode */ uint32_t screen_erase_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -319,9 +506,18 @@ uint32_t screen_erase_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x0, y0 The (x,y) coordinates of the first point of the rectangle * \param x1, y1 The (x,y) coordinates of the second point of the rectangle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Fill Around Half the Screen in Red + * screen_set_pen(COLOR_RED); + * screen_fill_rect(5,5,240,200); + * } + * \endcode */ uint32_t screen_fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -334,9 +530,18 @@ uint32_t screen_fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x, y The (x,y) coordinates of the center of the circle * \param r The radius of the circle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Draw a circle with radius of 100 in red + * screen_set_pen(COLOR_RED); + * screen_draw_circle(240, 200, 100); + * } + * \endcode */ uint32_t screen_draw_circle(int16_t x, int16_t y, int16_t radius); @@ -349,9 +554,20 @@ uint32_t screen_draw_circle(int16_t x, int16_t y, int16_t radius); * * \param x, y The (x,y) coordinates of the center of the circle * \param r The radius of the circle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_set_pen(COLOR_RED); + * screen_fill_rect(5,5,240,200); + * // Erase a circle with radius of 100 in COLOR_BLUE + * screen_set_pen(COLOR_BLUE); + * screen_erase_circle(240, 200, 100); + * } + * \endcode */ uint32_t screen_erase_circle(int16_t x, int16_t y, int16_t radius); @@ -365,48 +581,86 @@ uint32_t screen_erase_circle(int16_t x, int16_t y, int16_t radius); * * \param x, y The (x,y) coordinates of the center of the circle * \param r The radius of the circle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_set_pen(COLOR_RED); + * screen_fill_rect(5,5,240,200); + * // Fill a circlular area with radius of 100 in COLOR_BLUE + * screen_set_pen(COLOR_BLUE); + * screen_fill_circle(240, 200, 100); + * } + * \endcode */ uint32_t screen_fill_circle(int16_t x, int16_t y, int16_t radius); -/******************************************************************************/ -/** Screen Text Display Functions **/ -/** **/ -/** These functions allow programmers to display text on the v5 screen **/ -/******************************************************************************/ +///@} + +/// \name Screen Text Display Functions +/// These functions allow programmers to display text on the v5 screen +///@{ /** * Print a formatted string to the screen on the specified line - * + * * Will default to a medium sized font by default if invalid txt_fmt is given. - * - * \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES NOT SUPPORT SMALL) - * \param line The line number on which to print - * \param text Format string - * \param ... Optional list of arguments for the format string - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES + * NOT SUPPORT SMALL) \param line The line number on which to print \param text Format string \param ... Optional list + * of arguments for the format string + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * + * screen_set_pen(COLOR_BLUE); + * while(1){ + * // Will print seconds started since program started on line 3 + * screen_print(TEXT_MEDIUM, 3, "Seconds Passed: %3d", i++); + * delay(1000); + * } + * } + * \endcode */ uint32_t screen_print(text_format_e_t txt_fmt, const int16_t line, const char* text, ...); /** * Print a formatted string to the screen at the specified point - * + * * Will default to a medium sized font by default if invalid txt_fmt is given. - * + * * Text formats medium_center and large_center will default to medium and large respectively. - * + * * \param txt_fmt Text format enum that determines if the text is small, medium, or large. * \param x The y coordinate of the top left corner of the string * \param y The x coordinate of the top left corner of the string * \param text Format string * \param ... Optional list of arguments for the format string - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * + * screen_set_pen(COLOR_BLUE); + * while(1){ + * // Will print seconds started since program started. + * screen_print_at(TEXT_SMALL, 3, "Seconds Passed: %3d", i++); + * delay(1000); + * } + * } + * \endcode */ uint32_t screen_print_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, ...); @@ -415,21 +669,22 @@ uint32_t screen_print_at(text_format_e_t txt_fmt, const int16_t x, const int16_t * * Same as `display_printf` except that this uses a `va_list` instead of the * ellipsis operator so this can be used by other functions. - * + * * Will default to a medium sized font by default if invalid txt_fmt is given. * Exposed mostly for writing libraries and custom functions. * * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * - * \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES NOT SUPPORT SMALL) - * \param line The line number on which to print - * \param text Format string - * \param args List of arguments for the format string - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES + * NOT SUPPORT SMALL) \param line The line number on which to print \param text Format string \param args List of + * arguments for the format string + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * while taking or returning the screen mutex. + * + * */ uint32_t screen_vprintf(text_format_e_t txt_fmt, const int16_t line, const char* text, va_list args); @@ -438,40 +693,59 @@ uint32_t screen_vprintf(text_format_e_t txt_fmt, const int16_t line, const char* * * Same as `display_printf_at` except that this uses a `va_list` instead of the * ellipsis operator so this can be used by other functions. - * + * * Will default to a medium sized font by default if invalid txt_fmt is given. - * + * * Text formats medium_center and large_center will default to medium and large respectively. * Exposed mostly for writing libraries and custom functions. * * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * + * * \param txt_fmt Text format enum that determines if the text is small, medium, or large. * \param x, y The (x,y) coordinates of the top left corner of the string * \param text Format string * \param args List of arguments for the format string - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * while taking or returning the screen mutex. + * */ uint32_t screen_vprintf_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, va_list args); -/******************************************************************************/ -/** Screen Touch Functions **/ -/** **/ -/** These functions allow programmers to access **/ -/** information about screen touches **/ -/******************************************************************************/ +///@} + +/// \name Screen Touch Functions +/// These functions allow programmers to access information about screen touches +///@{ /** * Gets the touch status of the last touch of the screen. - * - * \return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE, E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD). - * This will be released by default if no action was taken. - * If an error occured, the screen_touch_status_s_t will have its last_touch_e_t - * enum specifier set to E_TOUCH_ERR, and other values set to -1. + * + * \return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE, + * E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD). This will be released by default if no action was taken. If an + * error occured, the screen_touch_status_s_t will have its last_touch_e_t enum specifier set to E_TOUCH_ERR, and other + * values set to -1. + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * screen_touch_status_s_t status; + * while(1){ + * status = screen_touch_status(); + * + * // Will print various information about the last touch + * screen_print(TEXT_MEDIUM, 1, "Touch Status (Type): %d", status.touch_status); + * screen_print(TEXT_MEDIUM, 2, "Last X: %d", status.x); + * screen_print(TEXT_MEDIUM, 3, "Last Y: %d", status.y); + * screen_print(TEXT_MEDIUM, 4, "Press Count: %d", status.press_count); + * screen_print(TEXT_MEDIUM, 5, "Release Count: %d", status.release_count); + * delay(20); + * } + * } + * \endcode */ screen_touch_status_s_t screen_touch_status(void); @@ -481,19 +755,37 @@ screen_touch_status_s_t screen_touch_status(void); * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * + * * \param cb Function pointer to callback when event type happens * \param event_type Touch event that will trigger the callback. - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * while taking or returning the screen mutex. + * + * \b Example + * \code + * touch_event_cb_fn_t changePixel(){ + * screen_touch_status_s_t status = screen_touch_status(); + * screen_draw_pixel(status.x,status.y); + * return NULL; + * } + * + * void opcontrol() { + * screen_touch_callback(changePixel(), TOUCH_PRESSED); + * while(1) delay(20); + * } + * \endcode */ uint32_t screen_touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type); +///@} + +///@} + #ifdef __cplusplus -} //namespace c -} //namespace pros +} // namespace c +} // namespace pros } -#endif +#endif -#endif +#endif diff --git a/EZ-Template-Example-Project/include/pros/screen.hpp b/EZ-Template-Example-Project/include/pros/screen.hpp index d7f6c08e..c3980e1f 100644 --- a/EZ-Template-Example-Project/include/pros/screen.hpp +++ b/EZ-Template-Example-Project/include/pros/screen.hpp @@ -1,5 +1,6 @@ /** * \file screen.hpp + * \ingroup cpp-screen * * Brain screen display and touch functions. * @@ -10,12 +11,15 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-screen Simplified Brain Screen C++ API */ #ifndef _PROS_SCREEN_HPP_ #define _PROS_SCREEN_HPP_ #include "pros/screen.h" +#include "pros/colors.hpp" #include #include @@ -37,6 +41,15 @@ const char* convert_args(const std::string& arg) { #pragma GCC diagnostic pop +/** + * \ingroup cpp-screen + */ + +/** + * \addtogroup cpp-screen + * @{ + */ + /******************************************************************************/ /** Screen Graphical Display Functions **/ /** **/ @@ -51,12 +64,59 @@ const char* convert_args(const std::string& arg) { * EACCESS - Another resource is currently trying to access the screen mutex. * * \param color The pen color to set (it is recommended to use values - * from the enum defined in colors.h) + * from the enum defined in colors.hpp) + * + * \return Returns 1 if the mutex was successfully returned, or PROS_ERR if + * there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * pros::screen::set_pen(red); + * } + * + * void opcontrol() { + * int iter = 0; + * while(1){ + * // This should print in red. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++); + * } + * } + * + * \endcode + */ + std::uint32_t set_pen(pros::Color color); + + /** + * Set the pen color for subsequent graphics operations + * + * This function uses the following values of errno when an error state is + * reached: + * EACCESS - Another resource is currently trying to access the screen mutex. + * + * \param color The pen color to set (in hex form) * * \return Returns 1 if the mutex was successfully returned, or PROS_ERR if * there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * //set pen color to red + * pros::screen::set_pen(0x00FF0000); + * } + * + * void opcontrol() { + * int iter = 0; + * while(1){ + * // This should print in red. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++); + * } + * } + * + * \endcode */ - std::uint32_t set_pen(const std::uint32_t color); + std::uint32_t set_pen(std::uint32_t color); /** * Set the eraser color for erasing and the current background. @@ -66,12 +126,58 @@ const char* convert_args(const std::string& arg) { * EACCESS - Another resource is currently trying to access the screen mutex. * * \param color The background color to set (it is recommended to use values - * from the enum defined in colors.h) + * from the enum defined in colors.hpp) * * \return Returns 1 if the mutex was successfully returned, or PROS_ERR * if there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * //set eraser color to red + * set_eraser(red); + * } + * + * void opcontrol() { + * int iter = 0; + * while(1){ + * // This should print in red. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++); + * } + * } + * + * \endcode */ - std::uint32_t set_eraser(const std::uint32_t color); + std::uint32_t set_eraser(pros::Color color); + + /** + * Set the eraser color for erasing and the current background. + * + * This function uses the following values of errno when an error state is + * reached: + * EACCESS - Another resource is currently trying to access the screen mutex. + * + * \param color The background color to set to set (in hex form) + * + * \return Returns 1 if the mutex was successfully returned, or PROS_ERR + * if there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * //set eraser color to red + * pros::screen::set_eraser(0x00FF0000); + * } + * + * void opcontrol() { + * while(1){ + * // This should turn the screen red. + * pros::screen::erase(); + * } + * } + * \endcode + */ + std::uint32_t set_eraser(std::uint32_t color); /** * Get the current pen color. @@ -83,6 +189,20 @@ const char* convert_args(const std::string& arg) { * \return The current pen color in the form of a value from the enum * defined in colors.h, or PROS_ERR if there was an error taking or * returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * pros::screen::set_pen(red); + * } + * + * void opcontrol() { + * while(1){ + * // Should print number equivalent to red defined in colors.hpp. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", get_pen()); + * } + * } + * \endcode */ std::uint32_t get_pen(); @@ -96,6 +216,20 @@ const char* convert_args(const std::string& arg) { * \return The current eraser color in the form of a value from the enum * defined in colors.h, or PROS_ERR if there was an error taking or * returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * pros::screen::set_eraser(red); + * } + * + * void opcontrol() { + * while(1){ + * // Should print number equivalent to red defined in colors.h. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", get_eraser()); + * } + * } + * \endcode */ std::uint32_t get_eraser(); @@ -108,6 +242,20 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * * \b Example + * \code + * void initialize() { + * pros::screen::set_eraser(red); + * } + * + * void opcontrol() { + * while(1){ + * // This should turn the screen red. + * pros::screen::erase(); + * } + * } + * \endcode */ std::uint32_t erase(); @@ -123,6 +271,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::print(TEXT_MEDIUM, 4, "Line Here"); + * // Scroll 3 lines + * pros::screen::scroll(4, 3); + * } + * \endcode */ std::uint32_t scroll(const std::int16_t start_line, const std::int16_t lines); @@ -145,6 +302,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::print(TEXT_MEDIUM, 1, "Line Here"); + * // Scrolls area of screen upwards slightly. including line of text + * pros::screen::scroll_area(0,0, 400, 200, 3); + * } + * \endcode */ std::uint32_t scroll_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, std::int16_t lines); @@ -166,6 +332,17 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured taking * or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * uint32_t* buf = malloc(sizeof(uint32_t) * 400 * 200); + * pros::screen::print(TEXT_MEDIUM, 1, "Line Here"); + * // Copies area of the screen including text + * pros::screen::copy_area(0, 0, 400, 200, (uint32_t*)buf, 400 + 1); + * // Equation for stride is x2 - x1 + 1 + * } + * \endcode */ std::uint32_t copy_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, uint32_t* buf, const std::int32_t stride); @@ -180,6 +357,18 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * int i = 0; + * void opcontrol() { + * while(i < 200){ + * pros::screen::draw_pixel(100,i++); + * // Draws a line at x = 100 gradually down the screen, pixel by pixel + * pros::delay(200); + * } + * } + * \endcode */ std::uint32_t draw_pixel(const std::int16_t x, const std::int16_t y); @@ -194,6 +383,21 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Color the Screen in Red + * pros::screen::set_pen(red); + * pros::screen::fill_rect(0,0,400,200); + * int i = 0; + * while(i < 200){ + * pros::screen::erase_pixel(100,i++); + * // Erases a line at x = 100 gradually down the screen, pixel by pixel + * pros::delay(200); + * } + * } + * \endcode */ std::uint32_t erase_pixel(const std::int16_t x, const std::int16_t y); @@ -209,6 +413,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::set_pen(red); + * // Draw line down the screen at x = 100 + * pros::screen::draw_line(100,0,100,200); + * } + * \endcode */ std::uint32_t draw_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -224,6 +437,17 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Color the Screen in Red + * pros::screen::set_pen(red); + * pros::screen::fill_rect(0,0,400,200); + * // Erase line down the screen at x = 100 + * pros::screen::erase_line(100,0,100,200); + * } + * \endcode */ std::uint32_t erase_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -239,6 +463,14 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::set_pen(red); + * pros::screen::draw_rect(1,1,480,200); + * } + * \endcode */ std::uint32_t draw_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -254,6 +486,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Draw Box Around Half the Screen in Red + * pros::screen::set_eraser(red); + * pros::screen::erase_rect(5,5,240,200); + * } + * \endcode */ std::uint32_t erase_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -270,6 +511,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Fill Around Half the Screen in Red + * pros::screen::set_pen(red); + * pros::screen::fill_rect(5,5,240,200); + * } + * \endcode */ std::uint32_t fill_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -285,6 +535,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Draw a circle with radius of 100 in red + * pros::screen::set_pen(red); + * pros::screen::draw_circle(240, 200, 100); + * } + * \endcode */ std::uint32_t draw_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius); @@ -300,6 +559,17 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::set_pen(red); + * pros::screen::fill_rect(5,5,240,200); + * // Erase a circle with radius of 100 in blue + * pros::screen::set_pen(blue); + * pros::screen::erase_circle(240, 200, 100); + * } + * \endcode */ std::uint32_t erase_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius); @@ -316,6 +586,17 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::set_pen(red); + * pros::screen::fill_rect(5,5,240,200); + * // Fill a circlular area with radius of 100 in blue + * pros::screen::set_pen(blue); + * pros::screen::fill_circle(240, 200, 100); + * } + * \endcode */ std::uint32_t fill_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius); @@ -336,6 +617,18 @@ const char* convert_args(const std::string& arg) { * \param y The (x,y) coordinates of the top left corner of the string * \param fmt Format string * \param ... Optional list of arguments for the format string + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * pros::screen::set_pen(blue); + * while(1){ + * // Will print seconds started since program started on line 3 + * pros::screen::print(pros::TEXT_MEDIUM, 3, "Seconds Passed: %3d", i++); + * pros::delay(1000); + * } + * } */ template void print(pros::text_format_e_t txt_fmt, const std::int16_t line, const char* text, Params... args){ @@ -361,6 +654,25 @@ const char* convert_args(const std::string& arg) { * This will be released by default if no action was taken. * If an error occured, the screen_touch_status_s_t will have its * last_touch_e_t enum specifier set to E_TOUCH_ERR, and other values set to -1. + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * pros::screen_touch_status_s_t status; + * while(1){ + * status = pros::touch_status(); + * + * // Will print various information about the last touch + * pros::screen::print(TEXT_MEDIUM, 1, "Touch Status (Type): %d", status.touch_status); + * pros::screen::print(TEXT_MEDIUM, 2, "Last X: %d", status.x); + * pros::screen::print(TEXT_MEDIUM, 3, "Last Y: %d", status.y); + * pros::screen::print(TEXT_MEDIUM, 4, "Press Count: %d", status.press_count); + * pros::screen::print(TEXT_MEDIUM, 5, "Release Count: %d", status.release_count); + * pros::delay(20); + * } + * } + * \endcode */ screen_touch_status_s_t touch_status(); @@ -376,10 +688,30 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * while taking or returning the screen mutex. + * + * \b Example + * \code + * touch_event_cb_fn_t changePixel(){ + * pros::screen_touch_status_s_t status = pros::screen::touch_status(); + * pros::screen::draw_pixel(status.x,status.y); + * return NULL; + * } + * + * void opcontrol() { + * pros::screen::touch_callback(changePixel(), TOUCH_PRESSED); + * while(1) { + * pros::delay(20); + * } + * } + * \endcode */ std::uint32_t touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type); -} //namespace screen -} //namespace pros +} // namespace screen + + +} // namespace pros +extern __attribute__((weak)) void lvgl_init() {} +///@} #endif //header guard diff --git a/EZ-Template-Example-Project/include/pros/serial.h b/EZ-Template-Example-Project/include/pros/serial.h index 357aa107..dc9ead56 100644 --- a/EZ-Template-Example-Project/include/pros/serial.h +++ b/EZ-Template-Example-Project/include/pros/serial.h @@ -1,19 +1,19 @@ /** * \file pros/serial.h + * \ingroup c-serial * * Contains prototypes for the V5 Generic Serial related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/serial.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-serial Generic Serial C API */ #ifndef _PROS_SERIAL_H_ @@ -28,11 +28,18 @@ namespace pros { namespace c { #endif -/******************************************************************************/ -/** Serial communication functions **/ -/** **/ -/** These functions allow programmers to communicate using UART over RS485 **/ -/******************************************************************************/ +/** + * \ingroup c-serial + */ + +/** + * \addtogroup c-serial + * @{ + */ + +/// \name Serial communication functions +/// These functions allow programmers to communicate using UART over RS485 +///@{ /** * Enables generic serial on the given port. @@ -50,6 +57,14 @@ namespace c { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * } + * \endcode */ int32_t serial_enable(uint8_t port); @@ -68,6 +83,18 @@ int32_t serial_enable(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * serial_write(1, "Hello World!", 12); + * delay(100); + * } + * } + * \endcode */ int32_t serial_set_baudrate(uint8_t port, int32_t baudrate); @@ -93,6 +120,19 @@ int32_t serial_set_baudrate(uint8_t port, int32_t baudrate); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * serial_flush(1); + * serial_write(1, "Hello World!", 12); + * delay(100); + * } + * } + * \endcode */ int32_t serial_flush(uint8_t port); @@ -113,6 +153,23 @@ int32_t serial_flush(uint8_t port); * * \return The number of bytes avaliable to be read or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_read_avail(1) >= 12) { + * char buffer[12]; + * serial_read(1, buffer, 12); + * printf("%s", buffer); + * } + * delay(100); + * } + * } + * \endcode + */ int32_t serial_get_read_avail(uint8_t port); @@ -132,6 +189,20 @@ int32_t serial_get_read_avail(uint8_t port); * * \return The number of bytes free or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_write_free(1) >= 12) { + * serial_write(1, "Hello World!", 12); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_get_write_free(uint8_t port); @@ -148,6 +219,22 @@ int32_t serial_get_write_free(uint8_t port); * * \return The next byte avaliable to be read, -1 if none are available, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_peek_byte(1) == 'H') { + * char buffer[12]; + * serial_read(1, buffer, 12); + * printf("%s", buffer); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_peek_byte(uint8_t port); @@ -164,6 +251,22 @@ int32_t serial_peek_byte(uint8_t port); * * \return The next byte avaliable to be read, -1 if none are available, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_read_byte(1) == 'H') { + * char buffer[12]; + * serial_read(1, buffer, 12); + * printf("%s", buffer); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_read_byte(uint8_t port); @@ -188,6 +291,22 @@ int32_t serial_read_byte(uint8_t port); * * \return The number of bytes read or PROS_ERR if the operation failed, setting * errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_read_avail(1) >= 12) { + * char buffer[12]; + * serial_read(1, buffer, 12); + * printf("%s", buffer); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_read(uint8_t port, uint8_t* buffer, int32_t length); @@ -210,6 +329,32 @@ int32_t serial_read(uint8_t port, uint8_t* buffer, int32_t length); * * \return The number of bytes written or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_write_free(1) >= 12) { + * serial_write_byte(1, 'H'); + * serial_write_byte(1, 'e'); + * serial_write_byte(1, 'l'); + * serial_write_byte(1, 'l'); + * serial_write_byte(1, 'o'); + * serial_write_byte(1, ' '); + * serial_write_byte(1, 'W'); + * serial_write_byte(1, 'o'); + * serial_write_byte(1, 'r'); + * serial_write_byte(1, 'l'); + * serial_write_byte(1, 'd'); + * serial_write_byte(1, '!'); + * serial_write_byte(1, '\n'); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_write_byte(uint8_t port, uint8_t buffer); @@ -235,9 +380,27 @@ int32_t serial_write_byte(uint8_t port, uint8_t buffer); * * \return The number of bytes written or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_write_free(1) >= 12) { + * serial_write(1, "Hello World!\n", 12); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_write(uint8_t port, uint8_t* buffer, int32_t length); +///@} + +///@} + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/EZ-Template-Example-Project/include/pros/serial.hpp b/EZ-Template-Example-Project/include/pros/serial.hpp index 60e82c1c..3880f61b 100644 --- a/EZ-Template-Example-Project/include/pros/serial.hpp +++ b/EZ-Template-Example-Project/include/pros/serial.hpp @@ -1,29 +1,39 @@ /** * \file pros/serial.hpp + * \ingroup cpp-serial * * Contains prototypes for the V5 Generic Serial related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/serial.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-serial Generic Serial C++ API */ #ifndef _PROS_SERIAL_HPP_ #define _PROS_SERIAL_HPP_ #include + +#include "pros/device.hpp" #include "pros/serial.h" namespace pros { -class Serial { +/** + * \ingroup cpp-serial + * @{ + */ +class Serial : public Device { + /** + * \addtogroup cpp-serial + * @{ + */ public: /** * Creates a Serial object for the given port and specifications. @@ -37,9 +47,30 @@ class Serial { * The V5 port number from 1-21 * \param baudrate * The baudrate to run the port at + * + * \b Example: + * \code + * pros::Serial serial(1, 9600); + * \endcode */ explicit Serial(std::uint8_t port, std::int32_t baudrate); + /** + * Creates a Serial object for the given port without a set baudrate. + * + * This function uses the following values of errno when an error state is + * reached: + * EINVAL - The given value is not within the range of V5 ports (1-21). + * EACCES - Another resource is currently trying to access the port. + * + * \param port + * The V5 port number from 1-21 + * + * \b Example: + * \code + * pros::Serial serial(1); + * \endcode + */ explicit Serial(std::uint8_t port); /******************************************************************************/ @@ -61,6 +92,12 @@ class Serial { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code + * pros::Serial serial(1); + * serial.set_baudrate(9600); + * \endcode */ virtual std::int32_t set_baudrate(std::int32_t baudrate) const; @@ -83,6 +120,12 @@ class Serial { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code + * pros::Serial serial(1); + * serial.flush(); + * \endcode */ virtual std::int32_t flush() const; @@ -100,6 +143,16 @@ class Serial { * * \return The number of bytes avaliable to be read or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * if(serial.get_read_avail() > 0) { + * std::uint8_t byte = serial.read_byte(); + * } + * } + * \endcode */ virtual std::int32_t get_read_avail() const; @@ -116,15 +169,19 @@ class Serial { * * \return The number of bytes free or PROS_ERR if the operation failed, * setting errno. - */ - virtual std::int32_t get_write_free() const; - - /** - * Gets the port number of the serial port. * - * \return The serial port's port number. + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * if(serial.get_write_free() > 0) { + * serial.write_byte(0x01); + * pros::delay(10); + * } + * } + * \endcode */ - std::uint8_t get_port() const; + virtual std::int32_t get_write_free() const; /** * Reads the next byte avaliable in the port's input buffer without removing it. @@ -136,6 +193,16 @@ class Serial { * * \return The next byte avaliable to be read, -1 if none are available, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * if(serial.peek_byte() == 0x01) { + * serial.read_byte(); + * } + * } + * \endcode */ virtual std::int32_t peek_byte() const; @@ -149,6 +216,16 @@ class Serial { * * \return The next byte avaliable to be read, -1 if none are available, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * if(serial.read_byte() == 0x01) { + * // Do something + * } + * } + * \endcode */ virtual std::int32_t read_byte() const; @@ -171,6 +248,15 @@ class Serial { * * \return The number of bytes read or PROS_ERR if the operation failed, setting * errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * std::uint8_t buffer[10]; + * serial.read(buffer, 10); + * } + * \endcode */ virtual std::int32_t read(std::uint8_t* buffer, std::int32_t length) const; @@ -191,6 +277,14 @@ class Serial { * * \return The number of bytes written or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * serial.write_byte(0x01); + * } + * \endcode */ virtual std::int32_t write_byte(std::uint8_t buffer) const; @@ -214,14 +308,36 @@ class Serial { * * \return The number of bytes written or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * std::uint8_t buffer[10]; + * serial.write(buffer, 10); + * } + * \endcode */ virtual std::int32_t write(std::uint8_t* buffer, std::int32_t length) const; private: - const std::uint8_t _port; + ///@} }; namespace literals { +/** + * Constructs a Serial device from a litteral ending in _ser + * + * \return a pros::Serial for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Serial serial = 2_ser; //Makes an Serial device object on port 2 + * } + * \endcode + */ const pros::Serial operator"" _ser(const unsigned long long int m); } // namespace literals } // namespace pros diff --git a/EZ-Template-Example-Project/include/pros/vision.h b/EZ-Template-Example-Project/include/pros/vision.h index 33918c78..dbda3fc7 100644 --- a/EZ-Template-Example-Project/include/pros/vision.h +++ b/EZ-Template-Example-Project/include/pros/vision.h @@ -1,39 +1,63 @@ /** * \file pros/vision.h + * \ingroup c-vision * * Contains prototypes for the VEX Vision Sensor-related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-vision Vision Sensor C API + * \note Additional example code for this module can be found in its [Tutorial.](@ref vision) */ #ifndef _PROS_VISION_H_ #define _PROS_VISION_H_ +/** + * \ingroup c-vision + */ + +/** + * \addtogroup c-vision + * @{ + */ + +/// \name Macros +///Parameters given by VEX +///@{ + #define VISION_OBJECT_ERR_SIG 255 -// Parameters given by VEX + +/** + * The width of the Vision Sensor’s field of view. + */ #define VISION_FOV_WIDTH 316 + +/** + * The height of the Vision Sensor’s field of view. + */ #define VISION_FOV_HEIGHT 212 +///@} + #include #ifdef __cplusplus extern "C" { namespace pros { #endif + /** - * This enumeration defines the different types of objects - * that can be detected by the Vision Sensor + * \enum vision_object_type_e_t + * This enumeration defines the different types of objects that can be detected by the Vision Sensor */ typedef enum vision_object_type { E_VISION_OBJECT_NORMAL = 0, @@ -42,8 +66,8 @@ typedef enum vision_object_type { } vision_object_type_e_t; /** - * This structure contains the parameters used by the Vision Sensor - * to detect objects. + * \struct vision_signature_s_t + * This structure contains the parameters used by the Vision Sensor to detect objects. */ typedef struct __attribute__((__packed__)) vision_signature { uint8_t id; @@ -60,39 +84,45 @@ typedef struct __attribute__((__packed__)) vision_signature { } vision_signature_s_t; /** + * \typedef vision_color_code_t * Color codes are just signatures with multiple IDs and a different type. */ typedef uint16_t vision_color_code_t; /** - * This structure contains a descriptor of an object detected - * by the Vision Sensor + * \struct vision_object_s_t + * This structure contains a descriptor of an object detected by the Vision Sensor */ typedef struct __attribute__((__packed__)) vision_object { - // Object signature + /// Object signature uint16_t signature; - // Object type, e.g. normal, color code, or line detection + /// Object type, e.g. normal, color code, or line detection vision_object_type_e_t type; - // left boundary coordinate of the object + /// Left boundary coordinate of the object int16_t left_coord; - // top boundary coordinate of the object + /// Top boundary coordinate of the object int16_t top_coord; - // width of the object + /// Width of the object int16_t width; - // height of the object + /// Height of the object int16_t height; - // Angle of a color code object in 0.1 degree units (e.g. 10 -> 1 degree, 155 - // -> 15.5 degrees) + /// Angle of a color code object in 0.1 degree units (e.g. 10 -> 1 degree, 155 -> 15.5 degrees) uint16_t angle; - - // coordinates of the middle of the object (computed from the values above) + /// Coordinates of the middle of the object (computed from the values above) int16_t x_middle_coord; + /// Coordinates of the middle of the object (computed from the values above) int16_t y_middle_coord; } vision_object_s_t; +/** + * \enum vision_zero + * This enumeration defines different zero points for returned vision objects. + */ typedef enum vision_zero { - E_VISION_ZERO_TOPLEFT = 0, // (0,0) coordinate is the top left of the FOV - E_VISION_ZERO_CENTER = 1 // (0,0) coordinate is the center of the FOV + /// (0,0) coordinate is the top left of the FOV + E_VISION_ZERO_TOPLEFT = 0, + /// (0,0) coordinate is the center of the FOV + E_VISION_ZERO_CENTER = 1 } vision_zero_e_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -115,6 +145,9 @@ typedef enum vision_zero { namespace c { #endif +/// \name Functions +///@{ + /** * Clears the vision sensor LED color, reseting it back to its default behavior, * displaying the most prominent object signature color. @@ -129,6 +162,14 @@ namespace c { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * void initialize() { + * vision_clear_led(VISION_PORT); + * } + * \endcode */ int32_t vision_clear_led(uint8_t port); @@ -155,6 +196,26 @@ int32_t vision_clear_led(uint8_t port); * Signature type * * \return A vision_signature_s_t that can be set using vision_set_signature + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * // values acquired from the vision utility + * vision_signature_s_t RED_SIG = + * vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0); + * vision_set_signature(VISION_PORT, EXAMPLE_SIG, &RED_SIG); + * while (true) { + * vision_signature_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG); + * // Gets the largest object of the EXAMPLE_SIG signature + * printf("sig: %d", rtn.signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ vision_signature_s_t vision_signature_from_utility(const int32_t id, const int32_t u_min, const int32_t u_max, const int32_t u_mean, const int32_t v_min, const int32_t v_max, @@ -184,6 +245,17 @@ vision_signature_s_t vision_signature_from_utility(const int32_t id, const int32 * The fifth signature id [1-7] to add to the color code * * \return A vision_color_code_t object containing the color code information. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * + * void opcontrol() { + * vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG); + * } + * \endcode */ vision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id1, const uint32_t sig_id2, const uint32_t sig_id3, const uint32_t sig_id4, const uint32_t sig_id5); @@ -206,6 +278,20 @@ vision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id * * \return The vision_object_s_t object corresponding to the given size id, or * PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void opcontrol() { + * while (true) { + * vision_object_s_t rtn = vision_get_by_size(VISION_PORT, 0); + * // Gets the largest object + * printf("sig: %d", rtn.signature); + * delay(2); + * } + * } + * \endcode */ vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id); @@ -230,6 +316,22 @@ vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id); * * \return The vision_object_s_t object corresponding to the given signature and * size_id, or PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * while (true) { + * vision_object_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG); + * // Gets the largest object of the EXAMPLE_SIG signature + * printf("sig: %d", rtn.signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ vision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id); @@ -252,13 +354,28 @@ vision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const * * \return The vision_object_s_t object corresponding to the given color code * and size_id, or PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * + * void opcontrol() { + * vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG); + * while (true) { + * vision_object_s_t rtn = vision_get_by_code(VISION_PORT, 0, code1); + * // Gets the largest object + * printf("sig: %d", rtn.signature); + * delay(2); + * } + * } + * \endcode */ vision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code); /** - * Gets the exposure parameter of the Vision Sensor. See - * https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html#exposure-setting - * for more detials. + * Gets the exposure parameter of the Vision Sensor. * * This function uses the following values of errno when an error state is * reached: @@ -270,6 +387,16 @@ vision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const * * \return The current exposure setting from [0,150], PROS_ERR if an error * occurred + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * if (vision_get_exposure(VISION_PORT) < 50) + * vision_set_exposure(VISION_PORT, 50); + * } + * \endcode */ int32_t vision_get_exposure(uint8_t port); @@ -286,6 +413,18 @@ int32_t vision_get_exposure(uint8_t port); * * \return The number of objects detected on the specified vision sensor. * Returns PROS_ERR if the port was invalid or an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Number of Objects Detected: %d\n", vision_get_object_count(VISION_PORT)); + * delay(2); + * } + * } + * \endcode */ int32_t vision_get_object_count(uint8_t port); @@ -301,6 +440,17 @@ int32_t vision_get_object_count(uint8_t port); * The V5 port number from 1-21 * * \return The current RGB white balance setting of the sensor + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define VISION_WHITE 0xff + * + * void initialize() { + * if (vision_get_white_balance(VISION_PORT) != VISION_WHITE) + * vision_set_white_balance(VISION_PORT, VISION_WHITE); + * } + * \endcode */ int32_t vision_get_white_balance(uint8_t port); @@ -311,6 +461,17 @@ int32_t vision_get_white_balance(uint8_t port); * The signature for which the contents will be printed * * \return 1 if no errors occured, PROS_ERR otherwise + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG); + * vision_print_signature(sig); + * } + * \endcode */ int32_t vision_print_signature(const vision_signature_s_t sig); @@ -339,6 +500,22 @@ int32_t vision_print_signature(const vision_signature_s_t sig); * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * while (true) { + * vision_read_by_size(VISION_PORT, 0, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints the signature of the largest object found + * delay(2); + * } + * } + * \endcode */ int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t object_count, vision_object_s_t* const object_arr); @@ -370,6 +547,23 @@ int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * while (true) { + * vision_read_by_sig(VISION_PORT, 0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ int32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id, const uint32_t object_count, vision_object_s_t* const object_arr); @@ -400,6 +594,25 @@ int32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG, 0, 0, 0); + * while (true) { + * vision_read_by_code(VISION_PORT, 0, code1, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints the signature of the largest object found + * delay(2); + * } + * } + * \endcode */ int32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code, const uint32_t object_count, vision_object_s_t* const object_arr); @@ -413,13 +626,24 @@ int32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_c * The signature id to read * * \return A vision_signature_s_t containing information about the signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG); + * vision_print_signature(sig); + * } + * \endcode */ vision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_id); /** * Stores the supplied object detection signature onto the vision sensor. * - * NOTE: This saves the signature in volatile memory, and the signature will be + * \note This saves the signature in volatile memory, and the signature will be * lost as soon as the sensor is powered down. * * \param port @@ -430,6 +654,18 @@ vision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_ * A pointer to the signature to save * * \return 1 if no errors occured, PROS_ERR otherwise + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG); + * sig.range = 10.0; + * vision_set_signature(VISION_PORT, EXAMPLE_SIG, &sig); + * } + * \endcode */ int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_signature_s_t* const signature_ptr); @@ -449,13 +685,20 @@ int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_si * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * vision_set_auto_white_balance(VISION_PORT, true); + * } + * \endcode */ int32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable); /** - * Sets the exposure parameter of the Vision Sensor. See - * https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html#exposure-setting - * for more detials. + * Sets the exposure parameter of the Vision Sensor. * * This function uses the following values of errno when an error state is * reached: @@ -469,6 +712,16 @@ int32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * if (vision_get_exposure(VISION_PORT) < 50) + * vision_set_exposure(VISION_PORT, 50); + * } + * \endcode */ int32_t vision_set_exposure(uint8_t port, const uint8_t exposure); @@ -487,6 +740,15 @@ int32_t vision_set_exposure(uint8_t port, const uint8_t exposure); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * vision_set_led(VISION_PORT, COLOR_BLANCHED_ALMOND); + * } + * \endcode */ int32_t vision_set_led(uint8_t port, const int32_t rgb); @@ -505,6 +767,16 @@ int32_t vision_set_led(uint8_t port, const int32_t rgb); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define VISION_WHITE 0xff + * + * void initialize() { + * vision_set_white_balance(VISION_PORT, VISION_WHITE); + * } + * \endcode */ int32_t vision_set_white_balance(uint8_t port, const int32_t rgb); @@ -527,6 +799,15 @@ int32_t vision_set_white_balance(uint8_t port, const int32_t rgb); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * vision_set_zero_point(VISION_PORT, E_VISION_ZERO_CENTER); + * } + * \endcode */ int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point); @@ -545,9 +826,22 @@ int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * vision_set_wifi_mode(VISION_PORT, 0); + * } + * \endcode */ int32_t vision_set_wifi_mode(uint8_t port, const uint8_t enable); +///@} + +///@} + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/EZ-Template-Example-Project/include/pros/vision.hpp b/EZ-Template-Example-Project/include/pros/vision.hpp index e40af9b8..ab4a61d6 100644 --- a/EZ-Template-Example-Project/include/pros/vision.hpp +++ b/EZ-Template-Example-Project/include/pros/vision.hpp @@ -1,31 +1,41 @@ /** * \file pros/vision.hpp + * \ingroup cpp-vision * * Contains prototypes for the VEX Vision Sensor-related functions in C++. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-vision Vision Sensor C++ API + * \note Additional example code for this module can be found in its [Tutorial.](@ref vision) */ #ifndef _PROS_VISION_HPP_ #define _PROS_VISION_HPP_ -#include "pros/vision.h" - #include +#include "pros/device.hpp" +#include "pros/vision.h" + namespace pros { -class Vision { +inline namespace v5 { +/** + * \ingroup cpp-vision + */ +class Vision : public Device { + /** + * \addtogroup cpp-vision + * @{ + */ public: /** * Create a Vision Sensor object on the given port. @@ -39,9 +49,18 @@ class Vision { * The V5 port number from 1-21 * \param zero_point * One of vision_zero_e_t to set the (0,0) coordinate for the FOV + * + * \b Example + * \code + * void opcontrol() { + * pros::Vision vision_sensor(1); // Creates a vision sensor on port one, with the zero point set to top left + * } + * \endcode */ Vision(std::uint8_t port, vision_zero_e_t zero_point = E_VISION_ZERO_TOPLEFT); + Vision(const Device& device) : Vision(device.get_port()){}; + /** * Clears the vision sensor LED color, reseting it back to its default * behavior, displaying the most prominent object signature color. @@ -52,6 +71,14 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Vision vision_sensor(1); + * vision_sensor.clear_led(); + * } + * \endcode */ std::int32_t clear_led(void) const; @@ -78,6 +105,27 @@ class Vision { * Signature type * * \return A vision_signature_s_t that can be set using Vision::set_signature + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * // values acquired from the vision utility + * vision_signature_s_t RED_SIG = + * vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0); + * vision_sensor.set_signature(EXAMPLE_SIG, &RED_SIG); + * while (true) { + * vision_signature_s_t rtn = vision_sensor.get_by_sig(VISION_PORT, 0, EXAMPLE_SIG); + * // Gets the largest object of the EXAMPLE_SIG signature + * printf("sig: %d", rtn.signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ static vision_signature_s_t signature_from_utility(const std::int32_t id, const std::int32_t u_min, const std::int32_t u_max, const std::int32_t u_mean, @@ -106,11 +154,37 @@ class Vision { * The fifth signature id [1-7] to add to the color code * * \return A vision_color_code_t object containing the color code information. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG); + * } + * \endcode */ vision_color_code_t create_color_code(const std::uint32_t sig_id1, const std::uint32_t sig_id2, const std::uint32_t sig_id3 = 0, const std::uint32_t sig_id4 = 0, const std::uint32_t sig_id5 = 0) const; + /** + * Gets all vision sensors. + * + * \return A vector of Vision sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector vision_all = pros::Vision::get_all_devices(); // All vision sensors that are connected + * } + * \endcode + */ + static std::vector get_all_devices(); + /** * Gets the nth largest object according to size_id. * @@ -126,6 +200,21 @@ class Vision { * * \return The vision_object_s_t object corresponding to the given size id, or * PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * while (true) { + * vision_object_s_t rtn = vision_sensor.get_by_size(0); + * // Gets the largest object + * printf("sig: %d", rtn.signature); + * delay(2); + * } + * } + * \endcode */ vision_object_s_t get_by_size(const std::uint32_t size_id) const; @@ -148,6 +237,23 @@ class Vision { * * \return The vision_object_s_t object corresponding to the given signature * and size_id, or PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * while (true) { + * vision_object_s_t rtn = vision_sensor.get_by_sig(0, EXAMPLE_SIG); + * // Gets the largest object of the EXAMPLE_SIG signature + * printf("sig: %d", rtn.signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ vision_object_s_t get_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id) const; @@ -167,13 +273,29 @@ class Vision { * * \return The vision_object_s_t object corresponding to the given color code * and size_id, or PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG); + * while (true) { + * vision_object_s_t rtn = vision_sensor.get_by_code(0, code1); + * // Gets the largest object + * printf("sig: %d", rtn.signature); + * delay(2); + * } + * } + * \endcode */ vision_object_s_t get_by_code(const std::uint32_t size_id, const vision_color_code_t color_code) const; /** - * Gets the exposure parameter of the Vision Sensor. See - * https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html#exposure-setting - * for more detials. + * Gets the exposure parameter of the Vision Sensor. * * This function uses the following values of errno when an error state is * reached: @@ -181,6 +303,17 @@ class Vision { * * \return The current exposure parameter from [0,150], * PROS_ERR if an error occurred + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * if (vision_sensor.get_exposure() < 50) + * vision_sensor.set_exposure(50); + * } + * \endcode */ std::int32_t get_exposure(void) const; @@ -193,6 +326,19 @@ class Vision { * * \return The number of objects detected on the specified vision sensor. * Returns PROS_ERR if the port was invalid or an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * while (true) { + * printf("Number of Objects Detected: %d\n", vision_sensor.get_object_count()); + * delay(2); + * } + * } + * \endcode */ std::int32_t get_object_count(void) const; @@ -207,6 +353,18 @@ class Vision { * The signature id to read * * \return A vision_signature_s_t containing information about the signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_signature_s_t sig = vision_sensor.get_signature(EXAMPLE_SIG); + * vision_sensor.print_signature(sig); + * } + * \endcode */ vision_signature_s_t get_signature(const std::uint8_t signature_id) const; @@ -218,15 +376,20 @@ class Vision { * ENODEV - The port cannot be configured as a vision sensor * * \return The current RGB white balance setting of the sensor - */ - std::int32_t get_white_balance(void) const; - - /** - * Gets the port number of the Vision Sensor. * - * \return The vision sensor's port number. + * \b Example + * \code + * #define VISION_PORT 1 + * #define VISION_WHITE 0xff + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * if (vision_sensor.get_white_balance() != VISION_WHITE) + * vision_sensor.set_white_balance(VISION_WHITE); + * } + * \endcode */ - std::uint8_t get_port(void) const; + std::int32_t get_white_balance(void) const; /** * Reads up to object_count object descriptors into object_arr. @@ -250,6 +413,23 @@ class Vision { * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * while (true) { + * vision_sensor.read_by_size(0, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints the signature of the largest object found + * delay(2); + * } + * } + * \endcode */ std::int32_t read_by_size(const std::uint32_t size_id, const std::uint32_t object_count, vision_object_s_t* const object_arr) const; @@ -280,6 +460,24 @@ class Vision { * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * while (true) { + * vision_sensor.read_by_sig(0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ std::int32_t read_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id, const std::uint32_t object_count, vision_object_s_t* const object_arr) const; @@ -308,6 +506,26 @@ class Vision { * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG, 0, 0, 0); + * while (true) { + * vision_sensor.read_by_code(0, code1, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints the signature of the largest object found + * delay(2); + * } + * } + * \endcode */ int32_t read_by_code(const std::uint32_t size_id, const vision_color_code_t color_code, const std::uint32_t object_count, vision_object_s_t* const object_arr) const; @@ -319,6 +537,18 @@ class Vision { * The signature for which the contents will be printed * * \return 1 if no errors occured, PROS_ERR otherwise + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_signature_s_t sig = visionsensor.get_signature(EXAMPLE_SIG); + * vision_print_signature(sig); + * } + * \endcode */ static std::int32_t print_signature(const vision_signature_s_t sig); @@ -334,13 +564,21 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_auto_white_balance(true); + * } + * \endcode */ std::int32_t set_auto_white_balance(const std::uint8_t enable) const; /** - * Sets the exposure parameter of the Vision Sensor. See - * https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html#exposure-setting - * for more detials. + * Sets the exposure parameter of the Vision Sensor. * * This function uses the following values of errno when an error state is * reached: @@ -351,6 +589,17 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * if (vision_sensor.get_exposure() < 50) + * vision_sensor.set_exposure(50); + * } + * \endcode */ std::int32_t set_exposure(const std::uint8_t exposure) const; @@ -366,6 +615,16 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_led(COLOR_BLANCHED_ALMOND); + * } + * \endcode */ std::int32_t set_led(const std::int32_t rgb) const; @@ -386,6 +645,19 @@ class Vision { * A pointer to the signature to save * * \return 1 if no errors occured, PROS_ERR otherwise + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_signature_s_t sig = vision_sensor.get_signature(EXAMPLE_SIG); + * sig.range = 10.0; + * vision_sensor.set_signature(EXAMPLE_SIG, &sig); + * } + * \endcode */ std::int32_t set_signature(const std::uint8_t signature_id, vision_signature_s_t* const signature_ptr) const; @@ -401,6 +673,17 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define VISION_WHITE 0xff + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_white_balance(VISION_WHITE); + * } + * \endcode */ std::int32_t set_white_balance(const std::int32_t rgb) const; @@ -420,6 +703,16 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_zero_point(E_VISION_ZERO_CENTER); + * } + * \endcode */ std::int32_t set_zero_point(vision_zero_e_t zero_point) const; @@ -435,11 +728,60 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_wifi_mode(0); + * } + * \endcode */ std::int32_t set_wifi_mode(const std::uint8_t enable) const; + /** + * Gets a vision sensor that is plugged in to the brain + * + * \note The first time this function is called it returns the vision sensor at the lowest port + * If this function is called multiple times, it will cycle through all the ports. + * For example, if you have 1 vision sensor on the robot + * this function will always return a vision sensor object for that port. + * If you have 2 vision sensors, all the odd numered calls to this function will return objects + * for the lower port number, + * all the even number calls will return vision objects for the higher port number + * + * + * This functions uses the following values of errno when an error state is + * reached: + * ENODEV - No vision sensor is plugged into the brain + * + * \return A vision object corresponding to a port that a vision sensor is connected to the brain + * If no vision sensor is plugged in, it returns a vision sensor on port PROS_ERR_BYTE + * + */ + static Vision get_vision(); + private: - std::uint8_t _port; + ///@} }; +} // namespace v5 +namespace literals { +/** + * Constructs a Vision sensor from a litteral ending in _vis + * + * \return a pros::Vision for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Vision vision = 2_vis; //Makes an Vision sensor object on port 2 + * } + * \endcode + */ +const pros::Vision operator"" _vis(const unsigned long long int m); +} // namespace literals } // namespace pros #endif // _PROS_VISION_HPP_ diff --git a/EZ-Template-Example-Project/include/subsystems.hpp b/EZ-Template-Example-Project/include/subsystems.hpp new file mode 100644 index 00000000..404e2418 --- /dev/null +++ b/EZ-Template-Example-Project/include/subsystems.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "api.h" + +// Your motors, sensors, etc. should go here. Below are examples + +// inline pros::Motor intake(1); +// inline pros::adi::DigitalIn limit_switch('A'); \ No newline at end of file diff --git a/EZ-Template-Example-Project/project.pros b/EZ-Template-Example-Project/project.pros index bf4c88d4..a728fdf3 100644 --- a/EZ-Template-Example-Project/project.pros +++ b/EZ-Template-Example-Project/project.pros @@ -5,31 +5,31 @@ "target": "v5", "templates": { "EZ-Template": { - "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\EZ-Template@3.0.1", + "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\EZ-Template@3.1.0", "metadata": { "origin": "local" }, "name": "EZ-Template", "py/object": "pros.conductor.templates.local_template.LocalTemplate", - "supported_kernels": "^3.8.3", + "supported_kernels": "^4.1.0", "system_files": [ - "include\\EZ-Template\\sdcard.hpp", - "include\\EZ-Template\\slew.hpp", "include\\EZ-Template\\drive\\drive.hpp", + "include\\EZ-Template\\sdcard.hpp", "include\\EZ-Template\\auton_selector.hpp", - "include\\EZ-Template\\auton.hpp", - "include\\EZ-Template\\util.hpp", + "include\\EZ-Template\\api.hpp", "include\\EZ-Template\\PID.hpp", + "include\\EZ-Template\\auton.hpp", "include\\EZ-Template\\piston.hpp", + "include\\EZ-Template\\slew.hpp", "firmware\\EZ-Template.a", - "include\\EZ-Template\\api.hpp" + "include\\EZ-Template\\util.hpp" ], "target": "v5", "user_files": [], - "version": "3.0.1" + "version": "3.1.0" }, "kernel": { - "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\kernel@3.8.3", + "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\kernel@4.1.0", "metadata": { "cold_addr": "58720256", "cold_output": "bin/cold.package.bin", @@ -42,296 +42,387 @@ "py/object": "pros.conductor.templates.local_template.LocalTemplate", "supported_kernels": null, "system_files": [ - "include\\display\\lv_themes\\lv_theme_mono.h", - "include\\display\\lv_themes\\lv_theme_nemo.h", - "include\\display\\lv_objx\\lv_calendar.h", - "include\\display\\lv_themes\\lv_theme_zen.h", - "include\\display\\lv_objx\\lv_spinbox.h", - "include\\pros\\screen.hpp", - "include\\display\\lv_objx\\lv_ddlist.h", - "include\\display\\lv_themes\\lv_theme.h", - "include\\display\\lv_hal\\lv_hal.h", - "include\\display\\lv_draw\\lv_draw_arc.h", - "include\\display\\lv_objx\\lv_list.h", - "include\\display\\lv_themes\\lv_themes.mk", - "include\\pros\\motors.hpp", - "include\\pros\\adi.h", - "include\\display\\lv_draw\\lv_draw.h", - "include\\pros\\colors.hpp", - "include\\display\\licence.txt", - "include\\display\\lv_draw\\lv_draw_img.h", - "include\\display\\lv_fonts\\lv_fonts.mk", - "include\\display\\lv_draw\\lv_draw_rect.h", - "include\\display\\lv_core\\lv_group.h", - "include\\display\\lv_draw\\lv_draw_label.h", - "include\\pros\\llemu.h", - "include\\pros\\error.h", - "include\\display\\lv_misc\\lv_ufs.h", - "firmware\\libm.a", - "include\\display\\lv_objx\\lv_led.h", - "include\\display\\lv_objx\\lv_btn.h", - "include\\display\\lv_misc\\lv_misc.mk", - "include\\display\\lv_objx\\lv_canvas.h", - "include\\display\\lv_objx\\lv_preload.h", - "include\\pros\\misc.hpp", - "include\\display\\lv_misc\\lv_fs.h", + "include\\pros\\rtos.hpp", + "firmware\\libpros.a", + "include\\pros\\imu.hpp", + "common.mk", "include\\pros\\rotation.hpp", - "include\\pros\\colors.h", + "include\\pros\\abstract_motor.hpp", + "include\\pros\\serial.h", "include\\pros\\vision.hpp", - "include\\display\\lv_objx\\lv_img.h", - "include\\display\\lv_fonts\\lv_font_builtin.h", - "include\\display\\lv_objx\\lv_lmeter.h", - "include\\display\\lv_misc\\lv_font.h", - "firmware\\v5.ld", - "include\\display\\lv_objx\\lv_tileview.h", - "include\\display\\lv_hal\\lv_hal_tick.h", - "include\\display\\lv_core\\lv_vdb.h", - "include\\display\\lv_core\\lv_indev.h", - "include\\pros\\vision.h", - "firmware\\v5-hot.ld", - "include\\display\\lv_objx\\lv_kb.h", - "include\\display\\lv_misc\\lv_symbol_def.h", - "firmware\\libc.a", - "include\\display\\lv_objx\\lv_label.h", - "include\\display\\lv_objx\\lv_tabview.h", - "firmware\\libpros.a", - "include\\display\\lv_misc\\lv_ll.h", - "include\\display\\lv_misc\\lv_log.h", - "include\\pros\\screen.h", - "include\\display\\lv_hal\\lv_hal.mk", - "include\\pros\\serial.hpp", - "include\\pros\\optical.hpp", - "include\\display\\lv_misc\\lv_txt.h", - "include\\display\\lv_misc\\lv_task.h", - "firmware\\v5-common.ld", - "include\\pros\\optical.h", - "include\\pros\\rtos.hpp", - "include\\display\\lv_conf_checker.h", - "include\\display\\lv_misc\\lv_math.h", - "include\\display\\lv_draw\\lv_draw_rbasic.h", - "include\\display\\lv_themes\\lv_theme_alien.h", - "include\\pros\\motors.h", + "include\\pros\\colors.h", + "include\\pros\\colors.hpp", + "include\\pros\\device.hpp", "include\\pros\\misc.h", - "include\\display\\lv_themes\\lv_theme_default.h", - "include\\pros\\gps.h", - "include\\display\\lv_misc\\lv_templ.h", - "include\\display\\lv_misc\\lv_circ.h", "include\\api.h", - "include\\display\\lv_objx\\lv_ta.h", - "include\\display\\lv_draw\\lv_draw_triangle.h", - "include\\display\\lv_misc\\lv_mem.h", - "include\\display\\lv_objx\\lv_imgbtn.h", "include\\pros\\link.h", - "include\\display\\lv_version.h", - "include\\display\\lv_conf.h", - "include\\display\\lv_objx\\lv_mbox.h", - "include\\display\\lv_misc\\lv_anim.h", - "include\\display\\lv_hal\\lv_hal_indev.h", - "include\\display\\lv_objx\\lv_btnm.h", - "include\\display\\lv_misc\\lv_color.h", - "include\\display\\lv_draw\\lv_draw_vbasic.h", - "include\\pros\\distance.hpp", - "include\\display\\lv_objx\\lv_bar.h", - "include\\display\\lv_objx\\lv_gauge.h", - "include\\display\\lv_draw\\lv_draw.mk", - "include\\display\\lvgl.h", - "include\\display\\lv_objx\\lv_slider.h", - "include\\display\\lv_objx\\lv_objx.mk", - "include\\display\\README.md", - "include\\display\\lv_core\\lv_lang.h", - "include\\display\\lv_objx\\lv_arc.h", - "include\\pros\\serial.h", - "include\\pros\\llemu.hpp", + "firmware\\v5-hot.ld", + "include\\pros\\distance.h", + "firmware\\v5-common.ld", + "include\\pros\\imu.h", + "include\\pros\\motor_group.hpp", + "include\\pros\\vision.h", + "include\\pros\\misc.hpp", + "include\\pros\\adi.h", + "include\\pros\\screen.h", + "include\\pros\\motors.h", + "include\\pros\\llemu.h", "include\\pros\\adi.hpp", - "include\\display\\lv_objx\\lv_table.h", - "include\\display\\lv_draw\\lv_draw_line.h", - "include\\display\\lv_misc\\lv_area.h", - "include\\display\\lv_core\\lv_core.mk", - "include\\display\\lv_objx\\lv_line.h", - "include\\display\\lv_hal\\lv_hal_disp.h", - "include\\display\\lv_misc\\lv_gc.h", - "include\\pros\\rotation.h", - "include\\display\\lv_themes\\lv_theme_material.h", - "include\\display\\lv_core\\lv_style.h", - "include\\display\\lv_objx\\lv_cb.h", - "include\\display\\lv_objx\\lv_chart.h", - "common.mk", + "include\\pros\\device.h", + "include\\pros\\motors.hpp", + "include\\pros\\serial.hpp", "include\\pros\\ext_adi.h", - "include\\display\\lv_objx\\lv_objx_templ.h", - "include\\display\\lv_core\\lv_refr.h", - "include\\display\\lv_core\\lv_obj.h", - "include\\pros\\api_legacy.h", + "include\\pros\\apix.h", "include\\pros\\rtos.h", - "include\\pros\\imu.h", - "include\\display\\lv_objx\\lv_win.h", - "include\\display\\lv_objx\\lv_cont.h", - "include\\display\\lv_themes\\lv_theme_templ.h", - "include\\pros\\link.hpp", - "include\\pros\\distance.h", - "include\\display\\lv_objx\\lv_roller.h", - "include\\display\\lv_objx\\lv_sw.h", - "include\\pros\\imu.hpp", + "include\\pros\\rotation.h", + "include\\pros\\llemu.hpp", + "firmware\\libc.a", + "firmware\\v5.ld", + "include\\pros\\gps.h", + "include\\pros\\optical.hpp", "include\\pros\\gps.hpp", - "include\\display\\lv_themes\\lv_theme_night.h", - "include\\pros\\apix.h", - "include\\display\\lv_objx\\lv_page.h" + "firmware\\libm.a", + "include\\pros\\distance.hpp", + "include\\pros\\link.hpp", + "include\\pros\\optical.h", + "include\\pros\\screen.hpp", + "include\\pros\\error.h" ], "target": "v5", "user_files": [ - "include\\main.h", "src\\main.c", - "include\\main.hpp", "include\\main.hh", - "src\\main.cpp", - "src\\main.cc", "Makefile", - ".gitignore" + "include\\main.h", + ".gitignore", + "src\\main.cc", + "include\\main.hpp", + "src\\main.cpp" + ], + "version": "4.1.0" + }, + "liblvgl": { + "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\liblvgl@8.3.8", + "metadata": { + "origin": "kernel-early-access-mainline" + }, + "name": "liblvgl", + "py/object": "pros.conductor.templates.local_template.LocalTemplate", + "supported_kernels": ">=4.0.0", + "system_files": [ + "include\\liblvgl\\extra\\others\\gridnav\\lv_gridnav.h", + "include\\liblvgl\\font\\lv_font_loader.h", + "include\\liblvgl\\misc\\lv_txt_ap.h", + "include\\liblvgl\\core\\lv_indev_scroll.h", + "include\\liblvgl\\misc\\lv_types.h", + "include\\liblvgl\\draw\\lv_img_decoder.h", + "include\\liblvgl\\extra\\libs\\freetype\\lv_freetype.h", + "include\\liblvgl\\extra\\widgets\\led\\lv_led.h", + "include\\liblvgl\\widgets\\lv_bar.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_rect.h", + "include\\liblvgl\\draw\\nxp\\vglite\\lv_draw_vglite_blend.h", + "include\\liblvgl\\extra\\libs\\png\\lv_png.h", + "include\\liblvgl\\misc\\lv_printf.h", + "include\\liblvgl\\extra\\themes\\lv_themes.h", + "include\\liblvgl\\draw\\lv_draw_transform.h", + "include\\liblvgl\\lv_conf_checker.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_priv.h", + "include\\liblvgl\\extra\\themes\\basic\\lv_theme_basic.h", + "include\\liblvgl\\extra\\widgets\\msgbox\\lv_msgbox.h", + "include\\liblvgl\\extra\\libs\\bmp\\lv_bmp.h", + "include\\liblvgl\\extra\\widgets\\span\\lv_span.h", + "include\\liblvgl\\misc\\lv_fs.h", + "include\\liblvgl\\misc\\lv_lru.h", + "include\\liblvgl\\core\\lv_obj_style.h", + "include\\liblvgl\\extra\\libs\\qrcode\\lv_qrcode.h", + "include\\liblvgl\\core\\lv_obj_class.h", + "include\\liblvgl\\lv_conf_internal.h", + "include\\liblvgl\\lv_conf.h", + "include\\liblvgl\\extra\\widgets\\lv_widgets.h", + "include\\liblvgl\\core\\lv_refr.h", + "include\\liblvgl\\extra\\widgets\\imgbtn\\lv_imgbtn.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_stack_blur.h", + "include\\liblvgl\\lvgl.h", + "include\\liblvgl\\misc\\lv_anim_timeline.h", + "include\\liblvgl\\extra\\widgets\\spinner\\lv_spinner.h", + "include\\liblvgl\\extra\\widgets\\animimg\\lv_animimg.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_texture_cache.h", + "include\\liblvgl\\extra\\libs\\fsdrv\\lv_fsdrv.h", + "include\\liblvgl\\draw\\nxp\\pxp\\lv_gpu_nxp_pxp.h", + "include\\liblvgl\\extra\\others\\fragment\\lv_fragment.h", + "include\\liblvgl\\extra\\widgets\\calendar\\lv_calendar_header_dropdown.h", + "include\\liblvgl\\draw\\lv_draw_triangle.h", + "include\\liblvgl\\lv_api_map.h", + "include\\liblvgl\\extra\\widgets\\chart\\lv_chart.h", + "include\\liblvgl\\extra\\widgets\\colorwheel\\lv_colorwheel.h", + "include\\liblvgl\\hal\\lv_hal_disp.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_img.h", + "include\\liblvgl\\extra\\widgets\\tileview\\lv_tileview.h", + "include\\liblvgl\\widgets\\lv_btnmatrix.h", + "include\\liblvgl\\core\\lv_obj_scroll.h", + "include\\liblvgl\\extra\\layouts\\grid\\lv_grid.h", + "include\\liblvgl\\misc\\lv_area.h", + "include\\liblvgl\\widgets\\lv_dropdown.h", + "include\\liblvgl\\hal\\lv_hal.h", + "include\\liblvgl\\draw\\nxp\\lv_gpu_nxp.h", + "include\\liblvgl\\extra\\others\\imgfont\\lv_imgfont.h", + "include\\liblvgl\\misc\\lv_txt.h", + "include\\liblvgl\\core\\lv_obj.h", + "include\\liblvgl\\widgets\\lv_objx_templ.h", + "include\\liblvgl\\core\\lv_group.h", + "firmware\\liblvgl.a", + "include\\liblvgl\\font\\lv_font.h", + "include\\liblvgl\\draw\\sw\\lv_draw_sw_blend.h", + "include\\liblvgl\\draw\\lv_draw_label.h", + "include\\liblvgl\\extra\\libs\\gif\\gifdec.h", + "include\\liblvgl\\lv_conf.old.h", + "include\\liblvgl\\hal\\lv_hal_tick.h", + "include\\liblvgl\\draw\\sw\\lv_draw_sw_dither.h", + "include\\liblvgl\\widgets\\lv_textarea.h", + "include\\liblvgl\\extra\\libs\\gif\\lv_gif.h", + "include\\liblvgl\\llemu.h", + "include\\liblvgl\\misc\\lv_async.h", + "include\\liblvgl\\draw\\sw\\lv_draw_sw.h", + "include\\liblvgl\\draw\\lv_draw_mask.h", + "include\\liblvgl\\widgets\\lv_img.h", + "include\\liblvgl\\extra\\widgets\\tabview\\lv_tabview.h", + "include\\liblvgl\\core\\lv_obj_style_gen.h", + "include\\liblvgl\\extra\\others\\ime\\lv_ime_pinyin.h", + "include\\liblvgl\\misc\\lv_log.h", + "include\\liblvgl\\font\\lv_symbol_def.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_utils.h", + "include\\liblvgl\\extra\\layouts\\flex\\lv_flex.h", + "include\\liblvgl\\misc\\lv_style_gen.h", + "include\\liblvgl\\extra\\libs\\sjpg\\tjpgd.h", + "include\\liblvgl\\draw\\lv_draw_rect.h", + "include\\liblvgl\\extra\\libs\\ffmpeg\\lv_ffmpeg.h", + "include\\liblvgl\\draw\\lv_draw_arc.h", + "include\\liblvgl\\misc\\lv_bidi.h", + "include\\liblvgl\\extra\\widgets\\win\\lv_win.h", + "include\\liblvgl\\draw\\lv_img_cache.h", + "include\\liblvgl\\core\\lv_obj_draw.h", + "include\\liblvgl\\extra\\others\\msg\\lv_msg.h", + "include\\liblvgl\\misc\\lv_ll.h", + "include\\liblvgl\\widgets\\lv_table.h", + "include\\liblvgl\\lv_conf_kconfig.h", + "include\\liblvgl\\draw\\lv_draw_layer.h", + "include\\liblvgl\\misc\\lv_assert.h", + "include\\liblvgl\\extra\\libs\\sjpg\\tjpgdcnf.h", + "include\\liblvgl\\widgets\\lv_checkbox.h", + "include\\liblvgl\\core\\lv_obj_tree.h", + "include\\liblvgl\\hal\\lv_hal_indev.h", + "include\\liblvgl\\widgets\\lv_label.h", + "include\\liblvgl\\misc\\lv_mem.h", + "include\\liblvgl\\widgets\\lv_btn.h", + "include\\liblvgl\\core\\lv_theme.h", + "include\\liblvgl\\font\\lv_font_fmt_txt.h", + "include\\liblvgl\\extra\\others\\snapshot\\lv_snapshot.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_layer.h", + "include\\liblvgl\\extra\\libs\\qrcode\\qrcodegen.h", + "include\\liblvgl\\draw\\sw\\lv_draw_sw_gradient.h", + "include\\liblvgl\\misc\\lv_utils.h", + "include\\liblvgl\\draw\\nxp\\pxp\\lv_draw_pxp_blend.h", + "include\\liblvgl\\misc\\lv_style.h", + "include\\liblvgl\\widgets\\lv_line.h", + "include\\liblvgl\\widgets\\lv_slider.h", + "include\\liblvgl\\extra\\widgets\\meter\\lv_meter.h", + "include\\liblvgl\\draw\\arm2d\\lv_gpu_arm2d.h", + "include\\liblvgl\\extra\\libs\\rlottie\\lv_rlottie.h", + "include\\liblvgl\\extra\\others\\lv_others.h", + "include\\liblvgl\\extra\\layouts\\lv_layouts.h", + "include\\liblvgl\\extra\\widgets\\calendar\\lv_calendar_header_arrow.h", + "include\\liblvgl\\draw\\swm341_dma2d\\lv_gpu_swm341_dma2d.h", + "include\\liblvgl\\draw\\stm32_dma2d\\lv_gpu_stm32_dma2d.h", + "include\\liblvgl\\misc\\lv_anim.h", + "include\\liblvgl\\extra\\widgets\\calendar\\lv_calendar.h", + "include\\liblvgl\\misc\\lv_templ.h", + "include\\liblvgl\\extra\\widgets\\spinbox\\lv_spinbox.h", + "include\\liblvgl\\extra\\lv_extra.h", + "include\\liblvgl\\draw\\lv_draw_img.h", + "include\\liblvgl\\draw\\lv_img_buf.h", + "include\\liblvgl\\extra\\libs\\sjpg\\lv_sjpg.h", + "include\\liblvgl\\extra\\libs\\lv_libs.h", + "include\\liblvgl\\draw\\nxp\\vglite\\lv_draw_vglite_rect.h", + "include\\liblvgl\\llemu.hpp", + "include\\liblvgl\\draw\\lv_draw.h", + "include\\liblvgl\\extra\\themes\\mono\\lv_theme_mono.h", + "include\\liblvgl\\core\\lv_event.h", + "include\\liblvgl\\widgets\\lv_canvas.h", + "include\\liblvgl\\extra\\others\\monkey\\lv_monkey.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_mask.h", + "include\\liblvgl\\draw\\nxp\\vglite\\lv_draw_vglite_arc.h", + "include\\liblvgl\\draw\\nxp\\pxp\\lv_gpu_nxp_pxp_osa.h", + "include\\liblvgl\\core\\lv_disp.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_composite.h", + "include\\liblvgl\\widgets\\lv_switch.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl.h", + "include\\liblvgl\\core\\lv_indev.h", + "include\\liblvgl\\misc\\lv_timer.h", + "include\\liblvgl\\draw\\nxp\\vglite\\lv_gpu_nxp_vglite.h", + "include\\liblvgl\\extra\\widgets\\menu\\lv_menu.h", + "include\\liblvgl\\misc\\lv_math.h", + "include\\liblvgl\\misc\\lv_color.h", + "include\\liblvgl\\draw\\lv_draw_line.h", + "include\\liblvgl\\misc\\lv_gc.h", + "include\\liblvgl\\core\\lv_obj_pos.h", + "include\\liblvgl\\widgets\\lv_arc.h", + "include\\liblvgl\\extra\\themes\\default\\lv_theme_default.h", + "include\\liblvgl\\extra\\widgets\\list\\lv_list.h", + "include\\liblvgl\\widgets\\lv_roller.h", + "include\\liblvgl\\extra\\libs\\png\\lodepng.h", + "include\\liblvgl\\misc\\lv_tlsf.h", + "include\\liblvgl\\extra\\widgets\\keyboard\\lv_keyboard.h" ], - "version": "3.8.3" + "target": "v5", + "user_files": [], + "version": "8.3.8" }, "okapilib": { - "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\okapilib@4.8.0", + "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\okapilib@5.0.0", "metadata": { - "origin": "pros-mainline" + "origin": "kernel-early-access-mainline" }, "name": "okapilib", "py/object": "pros.conductor.templates.local_template.LocalTemplate", - "supported_kernels": "^3.3.1", + "supported_kernels": "^4.0.3", "system_files": [ - "include/okapi/api/odometry/odomMath.hpp", - "include/okapi/squiggles/physicalmodel/physicalmodel.hpp", - "include/okapi/api/chassis/model/threeEncoderXDriveModel.hpp", - "include/okapi/api/chassis/model/hDriveModel.hpp", - "include/okapi/api/chassis/model/readOnlyChassisModel.hpp", - "include/okapi/api/device/button/buttonBase.hpp", - "include/okapi/api/units/QAngularJerk.hpp", - "include/okapi/api/control/iterative/iterativeController.hpp", - "include/okapi/api/control/controllerInput.hpp", - "include/okapi/squiggles/math/quinticpolynomial.hpp", - "include/okapi/api/device/rotarysensor/continuousRotarySensor.hpp", - "include/okapi/api/control/async/asyncPositionController.hpp", + "include/okapi/api/units/QFrequency.hpp", + "include/okapi/api/control/iterative/iterativePosPidController.hpp", + "include/okapi/impl/util/configurableTimeUtilFactory.hpp", "include/okapi/api/filter/passthroughFilter.hpp", - "include/okapi/api/device/rotarysensor/rotarySensor.hpp", - "include/okapi/api/odometry/stateMode.hpp", - "include/okapi/impl/device/controller.hpp", - "include/okapi/api/units/QTime.hpp", - "include/okapi/api/control/util/controllerRunner.hpp", - "include/okapi/api/units/QTorque.hpp", - "include/okapi/impl/device/rotarysensor/IMU.hpp", - "include/okapi/api/control/util/pidTuner.hpp", - "include/okapi/impl/util/timeUtilFactory.hpp", - "include/okapi/api/device/motor/abstractMotor.hpp", - "include/okapi/impl/device/button/controllerButton.hpp", - "include/okapi/impl/device/rotarysensor/integratedEncoder.hpp", - "include/okapi/impl/device/rotarysensor/adiEncoder.hpp", - "include/okapi/api/filter/composableFilter.hpp", - "include/okapi/api/chassis/model/xDriveModel.hpp", + "include/okapi/api/coreProsAPI.hpp", + "include/okapi/squiggles/math/quinticpolynomial.hpp", + "firmware/okapilib.a", + "include/okapi/api/util/abstractTimer.hpp", + "include/okapi/impl/control/async/asyncMotionProfileControllerBuilder.hpp", "include/okapi/squiggles/geometry/pose.hpp", - "include/okapi/api/odometry/twoEncoderOdometry.hpp", - "include/okapi/api/util/timeUtil.hpp", - "firmware/squiggles.mk", - "include/okapi/api/control/async/asyncPosPidController.hpp", - "include/okapi/impl/control/util/controllerRunnerFactory.hpp", - "include/okapi/impl/chassis/controller/chassisControllerBuilder.hpp", - "include/okapi/api/control/closedLoopController.hpp", - "include/okapi/squiggles/math/utils.hpp", + "include/okapi/api/control/util/pathfinderUtil.hpp", + "include/okapi/squiggles/constraints.hpp", + "include/okapi/api/chassis/model/threeEncoderSkidSteerModel.hpp", + "include/okapi/api/control/iterative/iterativeMotorVelocityController.hpp", "include/okapi/api/control/async/asyncVelIntegratedController.hpp", - "include/okapi/api/units/QLength.hpp", - "include/okapi/impl/device/motor/motor.hpp", - "include/okapi/api/odometry/odometry.hpp", "include/okapi/api/units/RQuantity.hpp", "include/okapi/api/units/QArea.hpp", - "include/okapi/api/filter/filter.hpp", - "include/okapi/api/device/button/abstractButton.hpp", - "include/okapi/api/units/QPressure.hpp", - "include/okapi/api/control/async/asyncLinearMotionProfileController.hpp", - "include/okapi/api/control/util/flywheelSimulator.hpp", - "include/okapi/api/util/logging.hpp", - "include/okapi/api/chassis/model/threeEncoderSkidSteerModel.hpp", - "include/okapi/api/filter/emaFilter.hpp", - "include/okapi/impl/device/controllerUtil.hpp", - "include/okapi/api/util/mathUtil.hpp", - "include/okapi/api/filter/averageFilter.hpp", - "include/okapi/api/control/iterative/iterativeVelocityController.hpp", - "include/okapi/api/odometry/point.hpp", + "include/okapi/api/units/QAngularJerk.hpp", + "include/okapi/api/odometry/twoEncoderOdometry.hpp", + "include/okapi/api/chassis/model/skidSteerModel.hpp", + "include/okapi/impl/util/timeUtilFactory.hpp", + "include/okapi/impl/device/rotarysensor/rotationSensor.hpp", "include/okapi/api/control/async/asyncController.hpp", - "include/okapi/impl/control/async/asyncMotionProfileControllerBuilder.hpp", - "include/okapi/api/coreProsAPI.hpp", - "include/okapi/api/units/QSpeed.hpp", - "include/okapi/impl/control/util/pidTunerFactory.hpp", - "include/okapi/api/units/QAngle.hpp", - "include/okapi/api/control/async/asyncVelocityController.hpp", + "include/okapi/api/chassis/model/chassisModel.hpp", + "include/okapi/api/chassis/controller/odomChassisController.hpp", + "include/okapi/api/control/iterative/iterativePositionController.hpp", "include/okapi/api/odometry/threeEncoderOdometry.hpp", - "include/okapi/api/filter/velMath.hpp", - "include/okapi/api/control/async/asyncPosIntegratedController.hpp", - "include/okapi/squiggles/constraints.hpp", - "include/okapi/api/filter/filteredControllerInput.hpp", + "include/okapi/impl/device/controllerUtil.hpp", + "include/okapi/api/device/rotarysensor/rotarySensor.hpp", "include/okapi/api/chassis/controller/chassisControllerPid.hpp", - "include/okapi/api/control/iterative/iterativePositionController.hpp", + "include/okapi/impl/device/controller.hpp", + "include/okapi/squiggles/physicalmodel/physicalmodel.hpp", + "include/okapi/api/control/iterative/iterativeVelPidController.hpp", + "include/okapi/impl/device/distanceSensor.hpp", + "include/okapi/impl/filter/velMathFactory.hpp", + "include/okapi/api/chassis/controller/chassisControllerIntegrated.hpp", + "include/okapi/squiggles/math/utils.hpp", + "include/okapi/api/util/abstractRate.hpp", + "include/okapi/api/util/supplier.hpp", + "include/okapi/api/chassis/controller/chassisController.hpp", + "include/okapi/api/odometry/stateMode.hpp", + "include/okapi/impl/util/timer.hpp", + "include/okapi/api/filter/ekfFilter.hpp", + "include/okapi/impl/chassis/controller/chassisControllerBuilder.hpp", + "include/okapi/api/units/QVolume.hpp", + "include/okapi/api/chassis/controller/chassisScales.hpp", + "firmware/squiggles.mk", + "include/okapi/impl/device/motor/motor.hpp", + "include/okapi/api/odometry/odomMath.hpp", + "include/okapi/api/chassis/model/threeEncoderXDriveModel.hpp", + "include/okapi/api/control/async/asyncMotionProfileController.hpp", + "include/okapi/api/chassis/model/hDriveModel.hpp", + "include/okapi/api/units/QJerk.hpp", + "include/okapi/impl/util/rate.hpp", "include/okapi/api/control/offsettableControllerInput.hpp", - "include/okapi/squiggles/squiggles.hpp", + "include/okapi/squiggles/geometry/profilepoint.hpp", + "include/okapi/impl/device/rotarysensor/potentiometer.hpp", "include/okapi/api/units/QAngularSpeed.hpp", - "include/okapi/api/control/iterative/iterativePosPidController.hpp", + "include/okapi/squiggles/spline.hpp", + "include/okapi/api/odometry/odometry.hpp", + "include/okapi/api/util/timeUtil.hpp", + "include/okapi/squiggles/geometry/controlvector.hpp", + "include/okapi/api/control/util/flywheelSimulator.hpp", + "include/okapi/api/control/util/pidTuner.hpp", + "include/okapi/impl/device/motor/adiMotor.hpp", + "include/okapi/api/chassis/model/xDriveModel.hpp", + "include/okapi/api/units/QSpeed.hpp", + "include/okapi/api/odometry/point.hpp", + "include/okapi/api/filter/composableFilter.hpp", + "include/okapi/impl/device/adiUltrasonic.hpp", + "include/okapi/api/filter/averageFilter.hpp", + "include/okapi/api/units/QAngularAcceleration.hpp", + "include/okapi/api/device/rotarysensor/continuousRotarySensor.hpp", + "include/okapi/api/control/util/controllerRunner.hpp", + "include/okapi/api/device/button/buttonBase.hpp", + "include/okapi/squiggles/squiggles.hpp", "include/okapi/squiggles/physicalmodel/tankmodel.hpp", - "include/okapi/impl/util/rate.hpp", - "include/okapi/api/filter/medianFilter.hpp", - "include/okapi/impl/device/rotarysensor/potentiometer.hpp", - "include/okapi/api/control/iterative/iterativeVelPidController.hpp", - "include/okapi/squiggles/geometry/profilepoint.hpp", - "include/okapi/impl/device/button/adiButton.hpp", - "include/okapi/impl/control/async/asyncVelControllerBuilder.hpp", - "include/okapi/api/filter/demaFilter.hpp", - "include/okapi/api/units/RQuantityName.hpp", - "include/okapi/api/control/util/pathfinderUtil.hpp", - "include/okapi/api/util/abstractTimer.hpp", - "include/okapi/api.hpp", - "include/okapi/impl/control/async/asyncPosControllerBuilder.hpp", - "include/okapi/api/chassis/controller/chassisScales.hpp", "include/okapi/api/units/QMass.hpp", - "include/okapi/impl/device/rotarysensor/adiGyro.hpp", - "include/okapi/impl/util/configurableTimeUtilFactory.hpp", - "include/okapi/api/control/util/settledUtil.hpp", + "include/okapi/api/util/mathUtil.hpp", + "include/okapi/api/control/controllerOutput.hpp", + "include/okapi/impl/control/util/pidTunerFactory.hpp", + "include/okapi/api/filter/emaFilter.hpp", "include/okapi/impl/control/iterative/iterativeControllerFactory.hpp", - "include/okapi/impl/util/timer.hpp", + "include/okapi/api/filter/filter.hpp", + "include/okapi/api/control/controllerInput.hpp", + "include/okapi/api/units/QForce.hpp", + "include/okapi/impl/device/rotarysensor/IMU.hpp", + "include/okapi/api/control/async/asyncLinearMotionProfileController.hpp", + "include/okapi/impl/device/button/controllerButton.hpp", + "include/okapi/squiggles/io.hpp", "include/okapi/api/chassis/controller/defaultOdomChassisController.hpp", - "include/okapi/impl/device/motor/motorGroup.hpp", + "include/okapi/api/control/closedLoopController.hpp", + "include/okapi/api/control/iterative/iterativeVelocityController.hpp", + "include/okapi/impl/control/util/controllerRunnerFactory.hpp", + "include/okapi/api/units/RQuantityName.hpp", + "include/okapi/api/filter/filteredControllerInput.hpp", + "include/okapi/impl/control/async/asyncVelControllerBuilder.hpp", + "include/okapi/api/units/QAcceleration.hpp", "include/okapi/api/control/async/asyncWrapper.hpp", - "include/okapi/squiggles/io.hpp", - "include/okapi/api/filter/ekfFilter.hpp", - "include/okapi/api/control/async/asyncMotionProfileController.hpp", - "include/okapi/squiggles/geometry/controlvector.hpp", - "include/okapi/impl/device/distanceSensor.hpp", - "include/okapi/api/control/controllerOutput.hpp", - "include/okapi/api/units/QVolume.hpp", - "include/okapi/squiggles/spline.hpp", - "include/okapi/api/units/QJerk.hpp", - "include/okapi/api/chassis/controller/chassisController.hpp", + "include/okapi/api/util/logging.hpp", + "include/okapi/api/units/QTime.hpp", + "include/okapi/api/control/async/asyncPositionController.hpp", + "include/okapi/impl/device/button/adiButton.hpp", + "include/okapi/api/units/QPressure.hpp", + "include/okapi/impl/device/rotarysensor/adiEncoder.hpp", + "include/okapi/impl/device/motor/motorGroup.hpp", + "include/okapi/api/units/QLength.hpp", + "include/okapi/api.hpp", + "include/okapi/api/units/QAngle.hpp", + "include/okapi/impl/control/async/asyncPosControllerBuilder.hpp", + "include/okapi/api/filter/medianFilter.hpp", + "include/okapi/api/control/async/asyncPosPidController.hpp", + "include/okapi/api/control/async/asyncVelPidController.hpp", + "include/okapi/api/control/async/asyncVelocityController.hpp", + "include/okapi/impl/device/rotarysensor/adiGyro.hpp", + "include/okapi/impl/device/rotarysensor/integratedEncoder.hpp", + "include/okapi/api/device/button/abstractButton.hpp", "include/okapi/squiggles/physicalmodel/passthroughmodel.hpp", - "include/okapi/api/units/QAngularAcceleration.hpp", - "include/okapi/api/chassis/controller/chassisControllerIntegrated.hpp", - "include/okapi/impl/device/adiUltrasonic.hpp", + "include/okapi/api/filter/demaFilter.hpp", + "include/okapi/api/device/motor/abstractMotor.hpp", "include/okapi/impl/device/opticalSensor.hpp", - "include/okapi/api/units/QForce.hpp", - "include/okapi/api/util/supplier.hpp", - "include/okapi/api/chassis/controller/odomChassisController.hpp", - "include/okapi/impl/filter/velMathFactory.hpp", - "include/okapi/api/control/iterative/iterativeMotorVelocityController.hpp", - "include/okapi/api/control/async/asyncVelPidController.hpp", + "include/okapi/api/control/async/asyncPosIntegratedController.hpp", + "include/okapi/api/filter/velMath.hpp", + "include/okapi/api/control/iterative/iterativeController.hpp", "include/okapi/api/odometry/odomState.hpp", - "include/okapi/api/chassis/model/chassisModel.hpp", - "include/okapi/api/units/QFrequency.hpp", - "include/okapi/impl/device/rotarysensor/rotationSensor.hpp", - "include/okapi/api/util/abstractRate.hpp", - "include/okapi/impl/device/motor/adiMotor.hpp", - "include/okapi/api/units/QAcceleration.hpp", - "include/okapi/api/chassis/model/skidSteerModel.hpp", - "firmware/okapilib.a" + "include/okapi/api/chassis/model/readOnlyChassisModel.hpp", + "include/okapi/api/control/util/settledUtil.hpp", + "include/okapi/api/units/QTorque.hpp" ], "target": "v5", "user_files": [], - "version": "4.8.0" + "version": "5.0.0" } }, - "upload_options": {} + "upload_options": { + "description": "making code ez" + }, + "use_early_access": false } } \ No newline at end of file diff --git a/EZ-Template-Example-Project/src/autons.cpp b/EZ-Template-Example-Project/src/autons.cpp index 65715767..2ccdb230 100644 --- a/EZ-Template-Example-Project/src/autons.cpp +++ b/EZ-Template-Example-Project/src/autons.cpp @@ -1,12 +1,12 @@ #include "main.h" ///// -// For installation, upgrading, documentations and tutorials, check out our website! +// For installation, upgrading, documentations, and tutorials, check out our website! // https://ez-robotics.github.io/EZ-Template/ ///// // These are out of 127 -const int DRIVE_SPEED = 110; +const int DRIVE_SPEED = 110; const int TURN_SPEED = 90; const int SWING_SPEED = 90; @@ -14,19 +14,22 @@ const int SWING_SPEED = 90; // Constants /// void default_constants() { - chassis.pid_heading_constants_set(3, 0, 20); - chassis.pid_drive_constants_set(10, 0, 100); - chassis.pid_turn_constants_set(3, 0, 20); - chassis.pid_swing_constants_set(5, 0, 30); + chassis.pid_heading_constants_set(11, 0, 20); + chassis.pid_drive_constants_set(20, 0, 100); + chassis.pid_turn_constants_set(3, 0.05, 20, 15); + chassis.pid_swing_constants_set(6, 0, 65); - chassis.pid_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms); - chassis.pid_swing_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms); - chassis.pid_drive_exit_condition_set(300_ms, 1_in, 500_ms, 3_in, 750_ms, 750_ms); + chassis.pid_turn_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms); + chassis.pid_swing_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms); + chassis.pid_drive_exit_condition_set(80_ms, 1_in, 250_ms, 3_in, 500_ms, 500_ms); + + chassis.pid_turn_chain_constant_set(3_deg); + chassis.pid_swing_chain_constant_set(5_deg); + chassis.pid_drive_chain_constant_set(3_in); chassis.slew_drive_constants_set(7_in, 80); } - /// // Drive Example /// @@ -34,7 +37,7 @@ void drive_example() { // The first parameter is target inches // The second parameter is max speed the robot will drive at // The third parameter is a boolean (true or false) for enabling/disabling a slew at the start of drive motions - // for slew, only enable it when the drive distance is greater then the slew distance + a few inches + // for slew, only enable it when the drive distance is greater than the slew distance + a few inches chassis.pid_drive_set(24_in, DRIVE_SPEED, true); chassis.pid_wait(); @@ -50,7 +53,7 @@ void drive_example() { // Turn Example /// void turn_example() { - // The first parameter is target degrees + // The first parameter is the target in degrees // The second parameter is max speed the robot will drive at chassis.pid_turn_set(90_deg, TURN_SPEED); @@ -89,10 +92,10 @@ void drive_and_turn() { void wait_until_change_speed() { // pid_wait_until will wait until the robot gets to a desired position - // When the robot gets to 6 inches, the robot will travel the remaining distance at a max speed of 30 - chassis.pid_drive_set(24_in, DRIVE_SPEED, true); + // When the robot gets to 6 inches slowly, the robot will travel the remaining distance at full speed + chassis.pid_drive_set(24_in, 30, true); chassis.pid_wait_until(6_in); - chassis.pid_speed_max_set(30); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 30 speed + chassis.pid_speed_max_set(DRIVE_SPEED); // After driving 6 inches at 30 speed, the robot will go the remaining distance at DRIVE_SPEED chassis.pid_wait(); chassis.pid_turn_set(45_deg, TURN_SPEED); @@ -104,10 +107,10 @@ void wait_until_change_speed() { chassis.pid_turn_set(0_deg, TURN_SPEED); chassis.pid_wait(); - // When the robot gets to -6 inches, the robot will travel the remaining distance at a max speed of 30 - chassis.pid_drive_set(-24_in, DRIVE_SPEED, true); + // When the robot gets to -6 inches slowly, the robot will travel the remaining distance at full speed + chassis.pid_drive_set(-24_in, 30, true); chassis.pid_wait_until(-6_in); - chassis.pid_speed_max_set(30); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 30 speed + chassis.pid_speed_max_set(DRIVE_SPEED); // After driving 6 inches at 30 speed, the robot will go the remaining distance at DRIVE_SPEED chassis.pid_wait(); } @@ -116,8 +119,8 @@ void wait_until_change_speed() { /// void swing_example() { // The first parameter is ez::LEFT_SWING or ez::RIGHT_SWING - // The second parameter is target degrees - // The third parameter is speed of the moving side of the drive + // The second parameter is the target in degrees + // The third parameter is the speed of the moving side of the drive // The fourth parameter is the speed of the still side of the drive, this allows for wider arcs chassis.pid_swing_set(ez::LEFT_SWING, 45_deg, SWING_SPEED, 45); @@ -133,6 +136,30 @@ void swing_example() { chassis.pid_wait(); } +/// +// Motion Chaining +/// +void motion_chaining() { + // Motion chaining is where motions all try to blend together instead of individual movements. + // This works by exiting while the robot is still moving a little bit. + // To use this, replace pid_wait with pid_wait_quick_chain. + chassis.pid_drive_set(24_in, DRIVE_SPEED, true); + chassis.pid_wait(); + + chassis.pid_turn_set(45_deg, TURN_SPEED); + chassis.pid_wait_quick_chain(); + + chassis.pid_turn_set(-45_deg, TURN_SPEED); + chassis.pid_wait_quick_chain(); + + chassis.pid_turn_set(0_deg, TURN_SPEED); + chassis.pid_wait(); + + // Your final motion should still be a normal pid_wait + chassis.pid_drive_set(-24_in, DRIVE_SPEED, true); + chassis.pid_wait(); +} + /// // Auto that tests everything /// @@ -158,7 +185,7 @@ void combining_movements() { /// void tug(int attempts) { for (int i = 0; i < attempts - 1; i++) { - // Attempt to drive backwards + // Attempt to drive backward printf("i - %i", i); chassis.pid_drive_set(-12_in, 127); chassis.pid_wait(); @@ -169,15 +196,15 @@ void tug(int attempts) { chassis.pid_drive_set(-2_in, 20); pros::delay(1000); } - // If robot successfully drove back, return + // If the robot successfully drove back, return else { return; } } } -// If there is no interference, robot will drive forward and turn 90 degrees. -// If interfered, robot will drive forward and then attempt to drive backwards. +// If there is no interference, the robot will drive forward and turn 90 degrees. +// If interfered, the robot will drive forward and then attempt to drive backward. void interfered_example() { chassis.pid_drive_set(24_in, DRIVE_SPEED, true); chassis.pid_wait(); diff --git a/EZ-Template-Example-Project/src/main.cpp b/EZ-Template-Example-Project/src/main.cpp index c836f129..176091e4 100644 --- a/EZ-Template-Example-Project/src/main.cpp +++ b/EZ-Template-Example-Project/src/main.cpp @@ -1,38 +1,19 @@ #include "main.h" ///// -// For installation, upgrading, documentations and tutorials, check out our website! +// For installation, upgrading, documentations, and tutorials, check out our website! // https://ez-robotics.github.io/EZ-Template/ ///// - // Chassis constructor -ez::Drive chassis ( - // Left Chassis Ports (negative port will reverse it!) - // the first port is used as the sensor - {1, 2, 3} - - // Right Chassis Ports (negative port will reverse it!) - // the first port is used as the sensor - ,{-4, -5, -6} - - // IMU Port - ,7 - - // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!) - ,3.25 - - // Cartridge RPM - ,600 - - // External Gear Ratio (MUST BE DECIMAL) This is WHEEL GEAR / MOTOR GEAR - // eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 84/36 which is 2.333 - // eg. if your drive is 60:36 where the 36t is powered, your RATIO would be 60/36 which is 0.6 - // eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 36/60 which is 0.6 - ,1.6667 -); - +ez::Drive chassis( + // These are your drive motors, the first motor is used for sensing! + {1, 2, 3}, // Left Chassis Ports (negative port will reverse it!) + {-4, -5, -6}, // Right Chassis Ports (negative port will reverse it!) + 7, // IMU Port + 4.125, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!) + 343); // Wheel RPM /** * Runs initialization code. This occurs as soon as the program is started. @@ -43,28 +24,31 @@ ez::Drive chassis ( void initialize() { // Print our branding over your terminal :D ez::ez_template_print(); - - pros::delay(500); // Stop the user from doing anything while legacy ports configure + + pros::delay(500); // Stop the user from doing anything while legacy ports configure // Configure your chassis controls - chassis.opcontrol_curve_buttons_toggle(true); // Enables modifying the controller curve with buttons on the joysticks - chassis.opcontrol_drive_activebrake_set(0); // Sets the active brake kP. We recommend 2. - chassis.opcontrol_curve_default_set(0, 0); // Defaults for curve. If using tank, only the first parameter is used. (Comment this line out if you have an SD card!) - default_constants(); // Set the drive to your own constants from autons.cpp! + chassis.opcontrol_curve_buttons_toggle(true); // Enables modifying the controller curve with buttons on the joysticks + chassis.opcontrol_drive_activebrake_set(0); // Sets the active brake kP. We recommend ~2. 0 will disable. + chassis.opcontrol_curve_default_set(0, 0); // Defaults for curve. If using tank, only the first parameter is used. (Comment this line out if you have an SD card!) + + // Set the drive to your own constants from autons.cpp! + default_constants(); // These are already defaulted to these buttons, but you can change the left/right curve buttons here! - // chassis.opcontrol_curve_buttons_left_set (pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT); // If using tank, only the left side is used. - // chassis.opcontrol_curve_buttons_right_set(pros::E_CONTROLLER_DIGITAL_Y, pros::E_CONTROLLER_DIGITAL_A); + // chassis.opcontrol_curve_buttons_left_set(pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT); // If using tank, only the left side is used. + // chassis.opcontrol_curve_buttons_right_set(pros::E_CONTROLLER_DIGITAL_Y, pros::E_CONTROLLER_DIGITAL_A); // Autonomous Selector using LLEMU ez::as::auton_selector.autons_add({ - Auton("Example Drive\n\nDrive forward and come back.", drive_example), - Auton("Example Turn\n\nTurn 3 times.", turn_example), - Auton("Drive and Turn\n\nDrive forward, turn, come back. ", drive_and_turn), - Auton("Drive and Turn\n\nSlow down during drive.", wait_until_change_speed), - Auton("Swing Example\n\nSwing in an 'S' curve", swing_example), - Auton("Combine all 3 movements", combining_movements), - Auton("Interference\n\nAfter driving forward, robot performs differently if interfered or not.", interfered_example), + Auton("Example Drive\n\nDrive forward and come back.", drive_example), + Auton("Example Turn\n\nTurn 3 times.", turn_example), + Auton("Drive and Turn\n\nDrive forward, turn, come back. ", drive_and_turn), + Auton("Drive and Turn\n\nSlow down during drive.", wait_until_change_speed), + Auton("Swing Example\n\nSwing in an 'S' curve", swing_example), + Auton("Motion Chaining\n\nDrive forward, turn, and come back, but blend everything together :D", motion_chaining), + Auton("Combine all 3 movements", combining_movements), + Auton("Interference\n\nAfter driving forward, robot performs differently if interfered or not.", interfered_example), }); // Initialize chassis and auton selector @@ -73,8 +57,6 @@ void initialize() { master.rumble("."); } - - /** * Runs while the robot is in the disabled state of Field Management System or * the VEX Competition Switch, following either autonomous or opcontrol. When @@ -84,8 +66,6 @@ void disabled() { // . . . } - - /** * Runs after initialize(), and before autonomous when connected to the Field * Management System or the VEX Competition Switch. This is intended for @@ -99,8 +79,6 @@ void competition_initialize() { // . . . } - - /** * Runs the user autonomous code. This function will be started in its own task * with the default priority and stack size whenever the robot is enabled via @@ -113,22 +91,13 @@ void competition_initialize() { * from where it left off. */ void autonomous() { - chassis.pid_targets_reset(); // Resets PID targets to 0 - chassis.drive_imu_reset(); // Reset gyro position to 0 - chassis.drive_sensor_reset(); // Reset drive sensors to 0 - chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency - - // ez::as::auton_selector.selected_auton_call(); // Calls selected auton from autonomous selector - int dist = 48; - chassis.pid_drive_set(dist, 127, true); - chassis.pid_wait_until(dist - 5); - - int dist2 = -(dist-6); - chassis.pid_drive_set(dist2, 127, true); - chassis.pid_wait_until(dist2 + 5); -} - + chassis.pid_targets_reset(); // Resets PID targets to 0 + chassis.drive_imu_reset(); // Reset gyro position to 0 + chassis.drive_sensor_reset(); // Reset drive sensors to 0 + chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency + ez::as::auton_selector.selected_auton_call(); // Calls selected auton from autonomous selector +} /** * Runs the operator control code. This function will be started in its own task @@ -145,37 +114,40 @@ void autonomous() { */ void opcontrol() { // This is preference to what you like to drive on - chassis.drive_brake_set(MOTOR_BRAKE_COAST); - + pros::motor_brake_mode_e_t driver_preference_brake = MOTOR_BRAKE_COAST; + + chassis.drive_brake_set(driver_preference_brake); + while (true) { - // PID Tuner // After you find values that you're happy with, you'll have to set them in auton.cpp - if (!pros::competition::is_connected()) { + if (!pros::competition::is_connected()) { // Enable / Disable PID Tuner - // When enabled: + // When enabled: // * use A and Y to increment / decrement the constants // * use the arrow keys to navigate the constants - if (master.get_digital_new_press(DIGITAL_X)) + if (master.get_digital_new_press(DIGITAL_X)) chassis.pid_tuner_toggle(); - + // Trigger the selected autonomous routine - if (master.get_digital_new_press(DIGITAL_B)) + if (master.get_digital(DIGITAL_B) && master.get_digital(DIGITAL_DOWN)) { autonomous(); + chassis.drive_brake_set(driver_preference_brake); + } - chassis.pid_tuner_iterate(); // Allow PID Tuner to iterate - } + chassis.pid_tuner_iterate(); // Allow PID Tuner to iterate + } - chassis.opcontrol_tank(); // Tank control - // chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade - // chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade - // chassis.opcontrol_arcade_flipped(ez::SPLIT); // Flipped split arcade - // chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade + chassis.opcontrol_tank(); // Tank control + // chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade + // chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade + // chassis.opcontrol_arcade_flipped(ez::SPLIT); // Flipped split arcade + // chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade // . . . // Put more user control code here! // . . . - pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME + pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME } -} +} \ No newline at end of file diff --git a/EZ-Template@3.0.1.zip b/EZ-Template@3.0.1.zip deleted file mode 100644 index 31e8046b..00000000 Binary files a/EZ-Template@3.0.1.zip and /dev/null differ diff --git a/EZ-Template@3.1.0.zip b/EZ-Template@3.1.0.zip new file mode 100644 index 00000000..8185d1fb Binary files /dev/null and b/EZ-Template@3.1.0.zip differ diff --git a/Makefile b/Makefile index 78588c4e..aaa9bd78 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ EXCLUDE_COLD_LIBRARIES:= IS_LIBRARY:=1 # TODO: CHANGE THIS! LIBNAME:=EZ-Template -VERSION:=3.0.1 +VERSION:=3.1.0 # EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c # this line excludes opcontrol.c and similar files EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/autons $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext))) diff --git a/README.md b/README.md index 83b2e89b..dfc30e08 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ ## Features - Simple to setup -- PID for driving, turning, and swing turns +- PID for driving, turning, swing turns, and arcs +- Easy to use PID tuner - Speed ramp-up for driving - Asynchronous PID with blocking functions until settled and until a specific position has come - Joystick input curves @@ -20,12 +21,19 @@ - 3 wire encoder and rotation sensor support - Add / remove motors from the drive dynamically to allow for PTO use - Exposed PID class for use with your other subsystems +- Exposed slew class for gradual speed ramp-up for your other subsystems -## [Installation and Upgrading](https://ez-robotics.github.io/EZ-Template/tutorials/installation) -Installation and Upgrading tutorials can be foud [here](https://ez-robotics.github.io/EZ-Template/tutorials/installation). +## [Discord Server](https://discord.gg/EHjXBcK2Gy) +Need extra assistance using EZ-Template? Feel free to join our [Discord Server](https://discord.gg/EHjXBcK2Gy)! + +## [Installation](https://ez-robotics.github.io/EZ-Template/tutorials/installation) +Installation tutorials can be found [here](https://ez-robotics.github.io/EZ-Template/tutorials/installation). + +## [Upgrading](https://ez-robotics.github.io/EZ-Template/tutorials/installation) +Upgrading tutorials can be found [here](https://ez-robotics.github.io/EZ-Template/tutorials/upgrading). ## [Tutorials](https://ez-robotics.github.io/EZ-Template/category/tutorials) -Tutorials on how to use and install EZ-Template can be found [here](https://ez-robotics.github.io/EZ-Template/category/tutorials). +Tutorials on how to use and install EZ-Template can be found [here](https://ez-robotics.github.io/EZ-Template/category/tutorials). ## [Docs](https://ez-robotics.github.io/EZ-Template/category/docs) Documentation on how to use EZ-Template functions can be found [here](https://ez-robotics.github.io/EZ-Template/category/docs). diff --git a/common.mk b/common.mk index 10ab5d38..33efe871 100644 --- a/common.mk +++ b/common.mk @@ -5,11 +5,24 @@ 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 := $() $() COMMA := , +C_STANDARD?=gnu11 +CXX_STANDARD?=gnu++20 + DEPDIR := .d $(shell mkdir -p $(DEPDIR)) DEPFLAGS = -MT $$@ -MMD -MP -MF $(DEPDIR)/$$*.Td @@ -24,8 +37,8 @@ wlprefix=-Wl,$(subst $(SPACE),$(COMMA),$1) LNK_FLAGS=--gc-sections --start-group $(strip $(LIBRARIES)) -lgcc -lstdc++ --end-group -T$(FWDIR)/v5-common.ld ASMFLAGS=$(MFLAGS) $(WARNFLAGS) -CFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=gnu11 -CXXFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=gnu++17 +CFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(C_STANDARD) +CXXFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(CXX_STANDARD) LDFLAGS=$(MFLAGS) $(WARNFLAGS) -nostdlib $(GCCFLAGS) SIZEFLAGS=-d --common NUMFMTFLAGS=--to=iec --format %.2f --suffix=B diff --git a/firmware/liblvgl.a b/firmware/liblvgl.a new file mode 100644 index 00000000..81e5f1a9 Binary files /dev/null and b/firmware/liblvgl.a differ diff --git a/firmware/libpros.a b/firmware/libpros.a index 3dbfc1b7..43f4e941 100644 Binary files a/firmware/libpros.a and b/firmware/libpros.a differ diff --git a/firmware/okapilib.a b/firmware/okapilib.a index ae1c4df5..d8d44809 100644 Binary files a/firmware/okapilib.a and b/firmware/okapilib.a differ diff --git a/include/EZ-Template/PID.hpp b/include/EZ-Template/PID.hpp index b0e6e266..29605362 100644 --- a/include/EZ-Template/PID.hpp +++ b/include/EZ-Template/PID.hpp @@ -97,10 +97,21 @@ class PID { * Computes PID. * * \param current - * Current sensor library. + * Current sensor value. */ double compute(double current); + /** + * Computes PID, but you set the error yourself. This function ignores target. + * Current is only used here for calculative derivative. + * + * \param err + * Error in PID, you need to calculate this yourself. + * \param current + * Current sensor value. + */ + double compute_error(double err, double current); + /** * Returns target value. */ @@ -126,6 +137,58 @@ class PID { */ exit_condition_ exit; + /** + * Updates a secondary sensor for velocity exiting. Ideal use is IMU during normal drive motions. + * + * \param secondary_sensor + * double for a secondary sensor. + */ + void velocity_sensor_secondary_set(double secondary_sensor); + + /** + * Returns the updated secondary sensor for velocity exiting. + */ + double velocity_sensor_secondary_get(); + + /** + * Boolean for if the secondary sensor will be updated or not. True uses this sensor, false does not. + * + * \param toggle + * True uses this sensor, false does not. + */ + void velocity_sensor_secondary_toggle_set(bool toggle); + + /** + * Returns the boolean for if the secondary sensor will be updated or not. True uses this sensor, false does not. + */ + bool velocity_sensor_secondary_toggle_get(); + + /** + * Sets the threshold that the main sensor will return 0 velocity within + * + * \param zero + * a small double + */ + void velocity_sensor_main_exit_set(double zero); + + /** + * Returns the threshold that the main sensor will return 0 velocity within + */ + double velocity_sensor_main_exit_get(); + + /** + * Sets the threshold that the secondary sensor will return 0 velocity within + * + * \param zero + * a small double + */ + void velocity_sensor_secondary_exit_set(double zero); + + /** + * Returns the threshold that the secondary sensor will return 0 velocity within + */ + double velocity_sensor_secondary_exit_get(); + /** * Iterative exit condition for PID. * @@ -180,26 +243,37 @@ class PID { */ bool i_reset_get(); + /** + * Resets all timers for exit conditions. + */ + void timers_reset(); + /** * PID variables. */ - double output; - double cur; - double error; - double target; - double prev_error; - double integral; - double derivative; - long time; - long prev_time; + double output = 0.0; + double cur = 0.0; + double error = 0.0; + double target = 0.0; + double prev_error = 0.0; + double prev_current = 0.0; + double integral = 0.0; + double derivative = 0.0; + long time = 0; + long prev_time = 0; private: - int i = 0, j = 0, k = 0, l = 0; + double velocity_zero_main = 0.05; + double velocity_zero_secondary = 0.1; + int i = 0, j = 0, k = 0, l = 0, m = 0; bool is_mA = false; - void timers_reset(); + double second_sensor = 0.0; + std::string name; bool name_active = false; void exit_condition_print(ez::exit_output exit_type); bool reset_i_sgn = true; + double raw_compute(); + bool use_second_sensor = false; }; }; // namespace ez \ No newline at end of file diff --git a/include/EZ-Template/drive/drive.hpp b/include/EZ-Template/drive/drive.hpp index 0fddb2eb..582792d2 100644 --- a/include/EZ-Template/drive/drive.hpp +++ b/include/EZ-Template/drive/drive.hpp @@ -66,12 +66,12 @@ class Drive { /** * Left tracking wheel. */ - pros::ADIEncoder left_tracker; + pros::adi::Encoder left_tracker; /** * Right tracking wheel. */ - pros::ADIEncoder right_tracker; + pros::adi::Encoder right_tracker; /** * Left rotation tracker. @@ -249,7 +249,7 @@ class Drive { * \param ratio * External gear ratio, wheel gear / motor gear. */ - Drive(std::vector left_motor_ports, std::vector right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio); + Drive(std::vector left_motor_ports, std::vector right_motor_ports, int imu_port, double wheel_diameter, double ticks, double ratio = 1.0); /** * Creates a Drive Controller using encoders plugged into the brain. @@ -641,7 +641,7 @@ class Drive { void drive_sensor_reset(); /** - * Resets the current gyro value. Defaults to 0, recommended to run at the start of your autonomous routine. + * Resets the current imu value. Defaults to 0, recommended to run at the start of your autonomous routine. * * \param new_heading * New heading value. @@ -649,10 +649,28 @@ class Drive { void drive_imu_reset(double new_heading = 0); /** - * Returns the current gyro value. + * Returns the current imu rotation value. */ double drive_imu_get(); + /** + * Returns the current imu accel x + accel y value. + */ + double drive_imu_accel_get(); + + /** + * Sets a new imu scaling factor. This value is multiplied by the imu to change its output. + * + * \param scaler + * Factor to scale the imu by. + */ + void drive_imu_scaler_set(double scaler); + + /** + * Returns the current imu scaling factor. + */ + double drive_imu_scaler_get(); + /** * Calibrates the IMU, recommended to run in initialize(). * @@ -834,12 +852,12 @@ class Drive { void pid_targets_reset(); /** - * Sets heading of gyro and target of PID, okapi angle. + * Sets heading of imo and target of PID, okapi angle. */ void drive_angle_set(okapi::QAngle p_angle); /** - * Sets heading of gyro and target of PID, takes double as an angle. + * Sets heading of imo and target of PID, takes double as an angle. */ void drive_angle_set(double angle); @@ -872,6 +890,19 @@ class Drive { */ void pid_wait_until(double target); + /** + * Lock the code in a while loop until the robot has settled. + * Wrapper for pid_wait_until(target), target is your previously input target + */ + void pid_wait_quick(); + + /** + * Lock the code in a while loop until the robot has settled. + * This also adds distance to target, and then exits with pid_wait_quick + * This will exit the motion while carrying momentum into the next motion. + */ + void pid_wait_quick_chain(); + /** * Autonomous interference detection. Returns true when interfered, and false when nothing happened. */ @@ -885,6 +916,24 @@ class Drive { */ void drive_ratio_set(double ratio); + /** + * @brief Set the cartridge/wheel rpm of the robot + * + * @param rpm + * rpm of the cartridge or wheel + */ + void drive_rpm_set(double rpm); + + /** + * Returns the ratio of the drive. + */ + double drive_ratio_get(); + + /** + * Returns the current cartridge / wheel rpm. + */ + double drive_rpm_get(); + /** * Changes max speed during a drive motion. * @@ -918,6 +967,29 @@ class Drive { */ PID::Constants pid_turn_constants_get(); + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets turning constants. + * + * \param input + * okapi angle unit + */ + void pid_turn_chain_constant_set(okapi::QAngle input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets turning constants. + * + * \param input + * angle in degrees + */ + void pid_turn_chain_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for turning. + */ + double pid_turn_chain_constant_get(); + /** * @brief Set the swing pid constants object * @@ -978,6 +1050,70 @@ class Drive { */ PID::Constants pid_swing_constants_backward_get(); + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets forward and backwards swing constants. + * + * \param input + * okapi angle unit + */ + void pid_swing_chain_constant_set(okapi::QAngle input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets forward swing constants. + * + * \param input + * okapi angle unit + */ + void pid_swing_chain_forward_constant_set(okapi::QAngle input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets backward swing constants. + * + * \param input + * okapi angle unit + */ + void pid_swing_chain_backward_constant_set(okapi::QAngle input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets forward and backwards swing constants. + * + * \param input + * angle in degrees + */ + void pid_swing_chain_constant_set(double input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets forward constants. + * + * \param input + * angle in degrees + */ + void pid_swing_chain_forward_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for swinging forward. + */ + double pid_swing_chain_forward_constant_get(); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets backwards swing constants. + * + * \param input + * angle in degrees + */ + void pid_swing_chain_backward_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for swinging backward. + */ + double pid_swing_chain_backward_constant_get(); + /** * @brief Set the heading pid constants object * @@ -1058,6 +1194,70 @@ class Drive { */ PID::Constants pid_drive_constants_backward_get(); + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets forward and backwards driving constants. + * + * \param input + * okapi length unit + */ + void pid_drive_chain_constant_set(okapi::QLength input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets forward driving constants. + * + * \param input + * okapi length unit + */ + void pid_drive_chain_forward_constant_set(okapi::QLength input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets backward driving constants. + * + * \param input + * okapi length unit + */ + void pid_drive_chain_backward_constant_set(okapi::QLength input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This sets forward and backwards driving constants. + * + * \param input + * distance in inches + */ + void pid_drive_chain_constant_set(double input); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets forward driving constants. + * + * \param input + * distance in inches + */ + void pid_drive_chain_forward_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for driving forward. + */ + double pid_drive_chain_forward_constant_get(); + + /** + * Sets the amount that the PID will overshoot target by to maintain momentum into the next motion. + * This only sets backward driving constants. + * + * \param input + * distance in inches + */ + void pid_drive_chain_backward_constant_set(double input); + + /** + * Returns the amount that the PID will overshoot target by to maintain momentum into the next motion for driving backward. + */ + double pid_drive_chain_backward_constant_get(); + /** * Sets minimum power for swings when kI and startI are enabled. * @@ -1097,8 +1297,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. In okapi units. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. In okapi units. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_drive_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QLength p_small_error, okapi::QTime p_big_exit_time, okapi::QLength p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout); + void pid_drive_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QLength p_small_error, okapi::QTime p_big_exit_time, okapi::QLength p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu = true); /** * Set's constants for turn exit conditions. @@ -1113,8 +1315,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. In okapi units. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. In okapi units. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_turn_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout); + void pid_turn_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu = true); /** * Set's constants for swing exit conditions. @@ -1129,8 +1333,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. In okapi units. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. In okapi units. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_swing_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout); + void pid_swing_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu = true); /** * Set's constants for drive exit conditions. @@ -1145,8 +1351,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_drive_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout); + void pid_drive_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu = true); /** * Set's constants for turn exit conditions. @@ -1161,8 +1369,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_turn_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout); + void pid_turn_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu = true); /** * Set's constants for swing exit conditions. @@ -1177,8 +1387,10 @@ class Drive { * Sets big_error. Timer will start when error is within this. * \param p_velocity_exit_time * Sets velocity_exit_time. Timer will start when velocity is 0. + * \param use_imu + * Adds the Imu for velocity calculation in conjunction with the main sensor. */ - void pid_swing_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout); + void pid_swing_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu = true); /** * Returns current tick_per_inch() @@ -1294,6 +1506,18 @@ class Drive { double pid_tuner_increment_start_i_get(); private: // !Auton + double chain_target_start = 0.0; + double chain_sensor_start = 0.0; + double drive_forward_motion_chain_scale = 0.0; + double drive_backward_motion_chain_scale = 0.0; + double swing_forward_motion_chain_scale = 0.0; + double swing_backward_motion_chain_scale = 0.0; + double turn_motion_chain_scale = 0.0; + double used_motion_chain_scale = 0.0; + bool motion_chain_backward = false; + + double IMU_SCALER = 1.0; + bool drive_toggle = true; bool print_toggle = true; int swing_min = 0; diff --git a/include/EZ-Template/piston.hpp b/include/EZ-Template/piston.hpp index 0ecb75a7..ec091ea8 100644 --- a/include/EZ-Template/piston.hpp +++ b/include/EZ-Template/piston.hpp @@ -14,7 +14,7 @@ class Piston { /** * Piston used throughout. */ - pros::ADIDigitalOut piston; + pros::adi::DigitalOut piston; /** * Piston constructor. This class keeps track of piston state. The starting position of your piston is FALSE. diff --git a/include/EZ-Template/sdcard.hpp b/include/EZ-Template/sdcard.hpp index d6c9be8c..ea8d5427 100644 --- a/include/EZ-Template/sdcard.hpp +++ b/include/EZ-Template/sdcard.hpp @@ -51,8 +51,8 @@ inline bool auton_selector_running; extern bool turn_off; -extern pros::ADIDigitalIn* limit_switch_left; -extern pros::ADIDigitalIn* limit_switch_right; +extern pros::adi::DigitalIn* limit_switch_left; +extern pros::adi::DigitalIn* limit_switch_right; /** * Initialize two limitswithces to change pages on the lcd * @@ -61,7 +61,7 @@ extern pros::ADIDigitalIn* limit_switch_right; * @param right_limit_port * port for the right limit switch */ -void limit_switch_lcd_initialize(pros::ADIDigitalIn* right_limit, pros::ADIDigitalIn* left_limit = nullptr); +void limit_switch_lcd_initialize(pros::adi::DigitalIn* right_limit, pros::adi::DigitalIn* left_limit = nullptr); /** * pre_auto_task diff --git a/include/EZ-Template/slew.hpp b/include/EZ-Template/slew.hpp index 047c34ca..53e1fa21 100644 --- a/include/EZ-Template/slew.hpp +++ b/include/EZ-Template/slew.hpp @@ -76,6 +76,19 @@ class slew { */ double output(); + /** + * Sets the max speed the slew can be + * + * \param speed + * maximum speed + */ + void speed_max_set(double speed); + + /** + * Returns the max speed the slew can be + */ + double speed_max_get(); + private: int sign = 0; double error = 0; diff --git a/include/api.h b/include/api.h index 6b09de1d..b97e65d6 100644 --- a/include/api.h +++ b/include/api.h @@ -39,13 +39,15 @@ #include #endif /* __cplusplus */ -#define PROS_VERSION_MAJOR 3 -#define PROS_VERSION_MINOR 8 -#define PROS_VERSION_PATCH 3 -#define PROS_VERSION_STRING "3.8.3" +#define PROS_VERSION_MAJOR 4 +#define PROS_VERSION_MINOR 1 + +#define PROS_VERSION_PATCH 0 +#define PROS_VERSION_STRING "4.1.0" #include "pros/adi.h" #include "pros/colors.h" +#include "pros/device.h" #include "pros/distance.h" #include "pros/error.h" #include "pros/ext_adi.h" @@ -63,12 +65,15 @@ #ifdef __cplusplus #include "pros/adi.hpp" +#include "pros/colors.hpp" +#include "pros/device.hpp" #include "pros/distance.hpp" #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" #include "pros/optical.hpp" #include "pros/rotation.hpp" diff --git a/include/autons.hpp b/include/autons.hpp index 6d96879f..654902d8 100644 --- a/include/autons.hpp +++ b/include/autons.hpp @@ -9,6 +9,7 @@ void turn_example(); void drive_and_turn(); void wait_until_change_speed(); void swing_example(); +void motion_chaining(); void combining_movements(); void interfered_example(); diff --git a/include/display/README.md b/include/display/README.md deleted file mode 100644 index afdfdeb5..00000000 --- a/include/display/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# Littlev Graphics Libraray - -![LittlevGL cover](http://www.gl.littlev.hu/home/main_cover_small.png) - -LittlevGL provides everything you need to create a Graphical User Interface (GUI) on embedded systems with easy-to-use graphical elements, beautiful visual effects and low memory footprint. - -Homepage: https://littlevgl.com - -### Table Of Content -* [Key features](#key-features) -* [Porting](#porting) -* [Project set-up](#project-set-up) -* [PC simulator](#pc-simulator) -* [Screenshots](#screenshots) -* [Contributing](#contributing) -* [Donate](#donate) - -## Key features -* Powerful building blocks buttons, charts, lists, sliders, images etc -* Advanced graphics with animations, anti-aliasing, opacity, smooth scrolling -* Various input devices touch pad, mouse, keyboard, encoder, buttons etc -* Multi language support with UTF-8 decoding -* Fully customizable graphical elements -* Hardware independent to use with any microcontroller or display -* Scalable to operate with few memory (50 kB Flash, 10 kB RAM) -* OS, External memory and GPU supported but not required -* Single frame buffer operation even with advances graphical effects -* Written in C for maximal compatibility -* Simulator to develop on PC without embedded hardware -* Tutorials, examples, themes for rapid development -* Documentation and API references online - -## Porting -In the most sime case you need 4 things: -1. Call `lv_tick_inc(1)` in every millisecods in a Timer or Task -2. Register a function which can **copy a pixel array** to an area of the screen -3. Register a function which can **read an input device**. (E.g. touch pad) -4. Call `lv_task_handler()` periodically in every few milliseconds -For more information visit https://littlevgl.com/porting - -## Project set-up -1. **Clone** or [Download](https://littlevgl.com/download) the lvgl repository: `git clone https://github.com/littlevgl/lvgl.git` -2. **Create project** with your preferred IDE and add the *lvgl* folder -3. Copy **lvgl/lv_conf_templ.h** as **lv_conf.h** next to the *lvgl* folder -4. In the lv_conf.h delete the first `#if 0` and its `#endif`. Let the default configurations at first. -5. In your *main.c*: #include "lvgl/lvgl.h" -6. In your *main function*: - * lvgl_init(); - * tick, display and input device initialization (see above) -7. To **test** create a label: `lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);` -8. In the main *while(1)* call `lv_task_handler();` and make a few milliseconds delay (e.g. `my_delay_ms(5);`) -9. Compile the code and load it to your embedded hardware - -## PC Simulator -If you don't have got an embedded hardware you can test the graphics library in a PC simulator. The simulator uses [SDL2](https://www.libsdl.org/) to emulate a display on your monitor and a touch pad with your mouse. - -There is a pre-configured PC project for **Eclipse CDT** in this repository: https://github.com/littlevgl/pc_simulator - -## Screenshots -![TFT material](http://www.gl.littlev.hu/github_res/tft_material.png) -![TFT zen](http://www.gl.littlev.hu/github_res/tft_zen.png) -![TFT alien](http://www.gl.littlev.hu/github_res/tft_alien.png) -![TFT night](http://www.gl.littlev.hu/github_res/tft_night.png) - -## Contributing -See [CONTRIBUTING.md](https://github.com/littlevgl/lvgl/blob/master/docs/CONTRIBUTING.md) - -## Donate -If you are pleased with the graphics library, found it useful or be happy with the support you got, please help its further development: - -[![Donate](https://littlevgl.com/donate_dir/donate_btn.png)](https://littlevgl.com/donate) diff --git a/include/display/licence.txt b/include/display/licence.txt deleted file mode 100644 index beaef1d2..00000000 --- a/include/display/licence.txt +++ /dev/null @@ -1,8 +0,0 @@ -MIT licence -Copyright (c) 2016 Gábor Kiss-Vámosi - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/include/display/lv_core/lv_core.mk b/include/display/lv_core/lv_core.mk deleted file mode 100644 index 9992e3fe..00000000 --- a/include/display/lv_core/lv_core.mk +++ /dev/null @@ -1,12 +0,0 @@ -CSRCS += lv_group.c -CSRCS += lv_indev.c -CSRCS += lv_obj.c -CSRCS += lv_refr.c -CSRCS += lv_style.c -CSRCS += lv_vdb.c -CSRCS += lv_lang.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_core -VPATH += :$(LVGL_DIR)/lvgl/lv_core - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core" diff --git a/include/display/lv_core/lv_group.h b/include/display/lv_core/lv_group.h deleted file mode 100644 index 4fb6043b..00000000 --- a/include/display/lv_core/lv_group.h +++ /dev/null @@ -1,247 +0,0 @@ -/** - * @file lv_group.h - * - */ - -#ifndef LV_GROUP_H -#define LV_GROUP_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include "lv_obj.h" - -/********************* - * DEFINES - *********************/ -/*Predefined keys to control the focused object via lv_group_send(group, c)*/ -/*For compatibility in signal function define the keys regardless to LV_GROUP*/ -#define LV_GROUP_KEY_UP 17 /*0x11*/ -#define LV_GROUP_KEY_DOWN 18 /*0x12*/ -#define LV_GROUP_KEY_RIGHT 19 /*0x13*/ -#define LV_GROUP_KEY_LEFT 20 /*0x14*/ -#define LV_GROUP_KEY_ESC 27 /*0x1B*/ -#define LV_GROUP_KEY_DEL 127 /*0x7F*/ -#define LV_GROUP_KEY_BACKSPACE 8 /*0x08*/ -#define LV_GROUP_KEY_ENTER 10 /*0x0A, '\n'*/ -#define LV_GROUP_KEY_NEXT 9 /*0x09, '\t'*/ -#define LV_GROUP_KEY_PREV 11 /*0x0B, '*/ - -#if USE_LV_GROUP != 0 -/********************** - * TYPEDEFS - **********************/ -struct _lv_group_t; - -typedef void (*lv_group_style_mod_func_t)(lv_style_t *); -typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *); - -typedef struct _lv_group_t -{ - lv_ll_t obj_ll; /*Linked list to store the objects in the group */ - lv_obj_t ** obj_focus; /*The object in focus*/ - lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/ - lv_group_style_mod_func_t style_mod_edit;/*A function which modifies the style of the focused object*/ - lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/ - lv_style_t style_tmp; /*Stores the modified style of the focused object */ - uint8_t frozen :1; /*1: can't focus to new object*/ - uint8_t editing :1; /*1: Edit mode, 0: Navigate mode*/ - uint8_t click_focus :1; /*1: If an object in a group is clicked by an indev then it will be focused */ - uint8_t refocus_policy :1; /*1: Focus prev if focused on deletion. 0: Focus prev if focused on deletion.*/ - uint8_t wrap :1; /*1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end of list.*/ -} lv_group_t; - -typedef enum _lv_group_refocus_policy_t { - LV_GROUP_REFOCUS_POLICY_NEXT = 0, - LV_GROUP_REFOCUS_POLICY_PREV = 1 -} lv_group_refocus_policy_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a new object group - * @return pointer to the new object group - */ -lv_group_t * lv_group_create(void); - -/** - * Delete a group object - * @param group pointer to a group - */ -void lv_group_del(lv_group_t * group); - -/** - * Add an object to a group - * @param group pointer to a group - * @param obj pointer to an object to add - */ -void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj); - -/** - * Remove an object from its group - * @param obj pointer to an object to remove - */ -void lv_group_remove_obj(lv_obj_t * obj); - -/** - * Focus on an object (defocus the current) - * @param obj pointer to an object to focus on - */ -void lv_group_focus_obj(lv_obj_t * obj); - -/** - * Focus the next object in a group (defocus the current) - * @param group pointer to a group - */ -void lv_group_focus_next(lv_group_t * group); - -/** - * Focus the previous object in a group (defocus the current) - * @param group pointer to a group - */ -void lv_group_focus_prev(lv_group_t * group); - -/** - * Do not let to change the focus from the current object - * @param group pointer to a group - * @param en true: freeze, false: release freezing (normal mode) - */ -void lv_group_focus_freeze(lv_group_t * group, bool en); - -/** - * Send a control character to the focuses object of a group - * @param group pointer to a group - * @param c a character (use LV_GROUP_KEY_.. to navigate) - * @return result of focused object in group. - */ -lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c); - -/** - * Set a function for a group which will modify the object's style if it is in focus - * @param group pointer to a group - * @param style_mod_func the style modifier function pointer - */ -void lv_group_set_style_mod_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func); - -/** - * Set a function for a group which will modify the object's style if it is in focus in edit mode - * @param group pointer to a group - * @param style_mod_func the style modifier function pointer - */ -void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func); - -/** - * Set a function for a group which will be called when a new object is focused - * @param group pointer to a group - * @param focus_cb the call back function or NULL if unused - */ -void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb); - -/** - * Set whether the next or previous item in a group is focused if the currently focussed obj is deleted. - * @param group pointer to a group - * @param new refocus policy enum - */ -void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy); - -/** - * Manually set the current mode (edit or navigate). - * @param group pointer to group - * @param edit: true: edit mode; false: navigate mode - */ -void lv_group_set_editing(lv_group_t * group, bool edit); - -/** - * Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked. - * @param group pointer to group - * @param en: true: enable `click_focus` - */ -void lv_group_set_click_focus(lv_group_t * group, bool en); - -/** - * Set whether focus next/prev will allow wrapping from first->last or last->first object. - * @param group pointer to group - * @param en: true: wrapping enabled; false: wrapping disabled - */ -void lv_group_set_wrap(lv_group_t * group, bool en); - -/** - * Modify a style with the set 'style_mod' function. The input style remains unchanged. - * @param group pointer to group - * @param style pointer to a style to modify - * @return a copy of the input style but modified with the 'style_mod' function - */ -lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style); - -/** - * Get the focused object or NULL if there isn't one - * @param group pointer to a group - * @return pointer to the focused object - */ -lv_obj_t * lv_group_get_focused(const lv_group_t * group); - -/** - * Get a the style modifier function of a group - * @param group pointer to a group - * @return pointer to the style modifier function - */ -lv_group_style_mod_func_t lv_group_get_style_mod_cb(const lv_group_t * group); - -/** - * Get a the style modifier function of a group in edit mode - * @param group pointer to a group - * @return pointer to the style modifier function - */ -lv_group_style_mod_func_t lv_group_get_style_mod_edit_cb(const lv_group_t * group); - -/** - * Get the focus callback function of a group - * @param group pointer to a group - * @return the call back function or NULL if not set - */ -lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group); - -/** - * Get the current mode (edit or navigate). - * @param group pointer to group - * @return true: edit mode; false: navigate mode - */ -bool lv_group_get_editing(const lv_group_t * group); - -/** - * Get the `click_focus` attribute. - * @param group pointer to group - * @return true: `click_focus` is enabled; false: disabled - */ -bool lv_group_get_click_focus(const lv_group_t * group); - -/** - * Get whether focus next/prev will allow wrapping from first->last or last->first object. - * @param group pointer to group - * @param en: true: wrapping enabled; false: wrapping disabled - */ -bool lv_group_get_wrap(lv_group_t * group); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_GROUP != 0*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_GROUP_H*/ diff --git a/include/display/lv_core/lv_indev.h b/include/display/lv_core/lv_indev.h deleted file mode 100644 index b066246b..00000000 --- a/include/display/lv_core/lv_indev.h +++ /dev/null @@ -1,157 +0,0 @@ -/** - * @file lv_indev_proc.h - * - */ - -#ifndef LV_INDEV_H -#define LV_INDEV_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_obj.h" -#include "display/lv_hal/lv_hal_indev.h" -#include "display/lv_core/lv_group.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the display input device subsystem - */ -void lv_indev_init(void); - -/** - * Get the currently processed input device. Can be used in action functions too. - * @return pointer to the currently processed input device or NULL if no input device processing right now - */ -lv_indev_t * lv_indev_get_act(void); - - -/** - * Get the type of an input device - * @param indev pointer to an input device - * @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`) - */ -lv_hal_indev_type_t lv_indev_get_type(const lv_indev_t * indev); - -/** - * Reset one or all input devices - * @param indev pointer to an input device to reset or NULL to reset all of them - */ -void lv_indev_reset(lv_indev_t * indev); - -/** - * Reset the long press state of an input device - * @param indev_proc pointer to an input device - */ -void lv_indev_reset_lpr(lv_indev_t * indev); - -/** - * Enable input devices device by type - * @param type Input device type - * @param enable true: enable this type; false: disable this type - */ -void lv_indev_enable(lv_hal_indev_type_t type, bool enable); - -/** - * Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON) - * @param indev pointer to an input device - * @param cur_obj pointer to an object to be used as cursor - */ -void lv_indev_set_cursor(lv_indev_t *indev, lv_obj_t *cur_obj); - -#if USE_LV_GROUP -/** - * Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD) - * @param indev pointer to an input device - * @param group point to a group - */ -void lv_indev_set_group(lv_indev_t *indev, lv_group_t *group); -#endif - -/** - * Set the an array of points for LV_INDEV_TYPE_BUTTON. - * These points will be assigned to the buttons to press a specific point on the screen - * @param indev pointer to an input device - * @param group point to a group - */ -void lv_indev_set_button_points(lv_indev_t *indev, const lv_point_t *points); - -/** - * Set feedback callback for indev. - * @param indev pointer to an input device - * @param feedback feedback callback - */ -void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback); - -/** - * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) - * @param indev pointer to an input device - * @param point pointer to a point to store the result - */ -void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point); - -/** - * Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD) - * @param indev pointer to an input device - * @return the last pressed key (0 on error) - */ -uint32_t lv_indev_get_key(const lv_indev_t * indev); - -/** - * Check if there is dragging with an input device or not (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) - * @param indev pointer to an input device - * @return true: drag is in progress - */ -bool lv_indev_is_dragging(const lv_indev_t * indev); - -/** - * Get the vector of dragging of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) - * @param indev pointer to an input device - * @param point pointer to a point to store the vector - */ -void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point); -/** - * Get elapsed time since last press - * @param indev pointer to an input device (NULL to get the overall smallest inactivity) - * @return Elapsed ticks (milliseconds) since last press - */ -uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev); - -/** - * Get feedback callback for indev. - * @param indev pointer to an input device - * @return feedback callback - */ -lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev); - -/** - * Do nothing until the next release - * @param indev pointer to an input device - */ -void lv_indev_wait_release(lv_indev_t * indev); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_INDEV_H*/ diff --git a/include/display/lv_core/lv_lang.h b/include/display/lv_core/lv_lang.h deleted file mode 100644 index efbdd0a8..00000000 --- a/include/display/lv_core/lv_lang.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @file lv_lang.h - * - */ - -#ifndef LV_LANG_H -#define LV_LANG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_MULTI_LANG - -#include - -/********************* - * DEFINES - *********************/ -#define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Change the language - * @param lang_id the id of the - */ -void lv_lang_set(uint8_t lang_id); - -/** - * Set a function to get the texts of the set languages from a `txt_id` - * @param fp a function pointer to get the texts - */ -void lv_lang_set_text_func(const void * (*fp)(uint16_t)); - -/** - * Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language - * @param txt_id an ID of the text to get - * @return the `txt_id` txt on the set language - */ -const void * lv_lang_get_text(uint16_t txt_id); - -/** - * Return with ID of the currently selected language - * @return pointer to the active screen object (loaded by 'lv_scr_load()') - */ -uint8_t lv_lang_act(void); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_MULTI_LANG*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LANG_H*/ diff --git a/include/display/lv_core/lv_obj.h b/include/display/lv_core/lv_obj.h deleted file mode 100644 index 02378a51..00000000 --- a/include/display/lv_core/lv_obj.h +++ /dev/null @@ -1,841 +0,0 @@ -/** - * @file lv_obj.h - * - */ - -#ifndef LV_OBJ_H -#define LV_OBJ_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include "lv_style.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_misc/lv_mem.h" -#include "display/lv_misc/lv_ll.h" -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_log.h" - -/********************* - * DEFINES - *********************/ - -/*Error check of lv_conf.h*/ -#if LV_HOR_RES == 0 || LV_VER_RES == 0 -#error "LittlevGL: LV_HOR_RES and LV_VER_RES must be greater than 0" -#endif - -#if LV_ANTIALIAS > 1 -#error "LittlevGL: LV_ANTIALIAS can be only 0 or 1" -#endif - -#if LV_VDB_SIZE == 0 && LV_ANTIALIAS != 0 -#error "LittlevGL: If LV_VDB_SIZE == 0 the anti-aliasing must be disabled" -#endif - -#if LV_VDB_SIZE > 0 && LV_VDB_SIZE < LV_HOR_RES -#error "LittlevGL: Small Virtual Display Buffer (lv_conf.h: LV_VDB_SIZE >= LV_HOR_RES)" -#endif - -#if LV_VDB_SIZE == 0 && USE_LV_REAL_DRAW == 0 -#error "LittlevGL: If LV_VDB_SIZE = 0 Real drawing function are required (lv_conf.h: USE_LV_REAL_DRAW 1)" -#endif - - -#define LV_ANIM_IN 0x00 /*Animation to show an object. 'OR' it with lv_anim_builtin_t*/ -#define LV_ANIM_OUT 0x80 /*Animation to hide an object. 'OR' it with lv_anim_builtin_t*/ -#define LV_ANIM_DIR_MASK 0x80 /*ANIM_IN/ANIM_OUT mask*/ - -#define LV_MAX_ANCESTOR_NUM 8 - -/********************** - * TYPEDEFS - **********************/ - -struct _lv_obj_t; - -enum -{ - LV_DESIGN_DRAW_MAIN, - LV_DESIGN_DRAW_POST, - LV_DESIGN_COVER_CHK, -}; -typedef uint8_t lv_design_mode_t; - -typedef bool (* lv_design_func_t) (struct _lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode); - -enum -{ - LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action function or an operation was failed*/ - LV_RES_OK, /*The object is valid (no deleted) after the action*/ -}; -typedef uint8_t lv_res_t; - -enum -{ - /*General signals*/ - LV_SIGNAL_CLEANUP, - LV_SIGNAL_CHILD_CHG, - LV_SIGNAL_CORD_CHG, - LV_SIGNAL_STYLE_CHG, - LV_SIGNAL_REFR_EXT_SIZE, - LV_SIGNAL_LANG_CHG, - LV_SIGNAL_GET_TYPE, - - _LV_SIGNAL_FEEDBACK_SECTION_START, - /*Input device related*/ - LV_SIGNAL_PRESSED, - LV_SIGNAL_PRESSING, - LV_SIGNAL_PRESS_LOST, - LV_SIGNAL_RELEASED, - LV_SIGNAL_LONG_PRESS, - LV_SIGNAL_LONG_PRESS_REP, - LV_SIGNAL_DRAG_BEGIN, - LV_SIGNAL_DRAG_END, - - /*Group related*/ - LV_SIGNAL_FOCUS, - LV_SIGNAL_DEFOCUS, - LV_SIGNAL_CONTROLL, - _LV_SIGNAL_FEEDBACK_SECTION_END, - LV_SIGNAL_GET_EDITABLE, -}; -typedef uint8_t lv_signal_t; - -typedef lv_res_t (* lv_signal_func_t) (struct _lv_obj_t * obj, lv_signal_t sign, void * param); - -enum -{ - LV_ALIGN_CENTER = 0, - LV_ALIGN_IN_TOP_LEFT, - LV_ALIGN_IN_TOP_MID, - LV_ALIGN_IN_TOP_RIGHT, - LV_ALIGN_IN_BOTTOM_LEFT, - LV_ALIGN_IN_BOTTOM_MID, - LV_ALIGN_IN_BOTTOM_RIGHT, - LV_ALIGN_IN_LEFT_MID, - LV_ALIGN_IN_RIGHT_MID, - LV_ALIGN_OUT_TOP_LEFT, - LV_ALIGN_OUT_TOP_MID, - LV_ALIGN_OUT_TOP_RIGHT, - LV_ALIGN_OUT_BOTTOM_LEFT, - LV_ALIGN_OUT_BOTTOM_MID, - LV_ALIGN_OUT_BOTTOM_RIGHT, - LV_ALIGN_OUT_LEFT_TOP, - LV_ALIGN_OUT_LEFT_MID, - LV_ALIGN_OUT_LEFT_BOTTOM, - LV_ALIGN_OUT_RIGHT_TOP, - LV_ALIGN_OUT_RIGHT_MID, - LV_ALIGN_OUT_RIGHT_BOTTOM, -}; -typedef uint8_t lv_align_t; - -#if LV_OBJ_REALIGN -typedef struct { - const struct _lv_obj_t * base; - lv_coord_t xofs; - lv_coord_t yofs; - lv_align_t align; - uint8_t auto_realign :1; - uint8_t origo_align :1; /*1: the oigo (center of the object) was aligned with `lv_obj_align_origo`*/ -}lv_reailgn_t; -#endif - - -typedef struct _lv_obj_t -{ - struct _lv_obj_t * par; /*Pointer to the parent object*/ - lv_ll_t child_ll; /*Linked list to store the children objects*/ - - lv_area_t coords; /*Coordinates of the object (x1, y1, x2, y2)*/ - - lv_signal_func_t signal_func; /*Object type specific signal function*/ - lv_design_func_t design_func; /*Object type specific design function*/ - - void * ext_attr; /*Object type specific extended data*/ - lv_style_t * style_p; /*Pointer to the object's style*/ - -#if LV_OBJ_FREE_PTR != 0 - void * free_ptr; /*Application specific pointer (set it freely)*/ -#endif - -#if USE_LV_GROUP != 0 - void * group_p; /*Pointer to the group of the object*/ -#endif - /*Attributes and states*/ - uint8_t click :1; /*1: Can be pressed by an input device*/ - uint8_t drag :1; /*1: Enable the dragging*/ - uint8_t drag_throw :1; /*1: Enable throwing with drag*/ - uint8_t drag_parent :1; /*1: Parent will be dragged instead*/ - uint8_t hidden :1; /*1: Object is hidden*/ - uint8_t top :1; /*1: If the object or its children is clicked it goes to the foreground*/ - uint8_t opa_scale_en :1; /*1: opa_scale is set*/ - uint8_t protect; /*Automatically happening actions can be prevented. 'OR'ed values from `lv_protect_t`*/ - lv_opa_t opa_scale; /*Scale down the opacity by this factor. Effects all children as well*/ - - lv_coord_t ext_size; /*EXTtend the size of the object in every direction. E.g. for shadow drawing*/ -#if LV_OBJ_REALIGN - lv_reailgn_t realign; -#endif - -#ifdef LV_OBJ_FREE_NUM_TYPE - LV_OBJ_FREE_NUM_TYPE free_num; /*Application specific identifier (set it freely)*/ -#endif -} lv_obj_t; - -typedef lv_res_t (*lv_action_t) (struct _lv_obj_t * obj); - -/*Protect some attributes (max. 8 bit)*/ -enum -{ - LV_PROTECT_NONE = 0x00, - LV_PROTECT_CHILD_CHG = 0x01, /*Disable the child change signal. Used by the library*/ - LV_PROTECT_PARENT = 0x02, /*Prevent automatic parent change (e.g. in lv_page)*/ - LV_PROTECT_POS = 0x04, /*Prevent automatic positioning (e.g. in lv_cont layout)*/ - LV_PROTECT_FOLLOW = 0x08, /*Prevent the object be followed in automatic ordering (e.g. in lv_cont PRETTY layout)*/ - LV_PROTECT_PRESS_LOST= 0x10, /*If the `indev` was pressing this object but swiped out while pressing do not search other object.*/ - LV_PROTECT_CLICK_FOCUS= 0x20,/*Prevent focusing the object by clicking on it*/ -}; -typedef uint8_t lv_protect_t; - - -/*Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/ -typedef struct { - const char * type[LV_MAX_ANCESTOR_NUM]; /*[0]: the actual type, [1]: ancestor, [2] #1's ancestor ... [x]: "lv_obj" */ -} lv_obj_type_t; - -enum -{ - LV_ANIM_NONE = 0, - LV_ANIM_FLOAT_TOP, /*Float from/to the top*/ - LV_ANIM_FLOAT_LEFT, /*Float from/to the left*/ - LV_ANIM_FLOAT_BOTTOM, /*Float from/to the bottom*/ - LV_ANIM_FLOAT_RIGHT, /*Float from/to the right*/ - LV_ANIM_GROW_H, /*Grow/shrink horizontally*/ - LV_ANIM_GROW_V, /*Grow/shrink vertically*/ -}; -typedef uint8_t lv_anim_builtin_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init. the 'lv' library. - */ -void lv_init(void); - -/*-------------------- - * Create and delete - *-------------------*/ - -/** - * Create a basic object - * @param parent pointer to a parent object. - * If NULL then a screen will be created - * @param copy pointer to a base object, if not NULL then the new object will be copied from it - * @return pointer to the new object - */ -lv_obj_t * lv_obj_create(lv_obj_t * parent,const lv_obj_t * copy); - -/** - * Delete 'obj' and all of its children - * @param obj pointer to an object to delete - * @return LV_RES_INV because the object is deleted - */ -lv_res_t lv_obj_del(lv_obj_t * obj); - -/** - * Delete all children of an object - * @param obj pointer to an object - */ -void lv_obj_clean(lv_obj_t *obj); - -/** - * Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task' - * @param obj pointer to an object - */ -void lv_obj_invalidate(const lv_obj_t * obj); - -/*===================== - * Setter functions - *====================*/ - -/*-------------- - * Screen set - *--------------*/ - -/** - * Load a new screen - * @param scr pointer to a screen - */ -void lv_scr_load(lv_obj_t * scr); - -/*-------------------- - * Parent/children set - *--------------------*/ - -/** - * Set a new parent for an object. Its relative position will be the same. - * @param obj pointer to an object. Can't be a screen. - * @param parent pointer to the new parent object. (Can't be NULL) - */ -void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent); - -/*-------------------- - * Coordinate set - * ------------------*/ - -/** - * Set relative the position of an object (relative to the parent) - * @param obj pointer to an object - * @param x new distance from the left side of the parent - * @param y new distance from the top of the parent - */ -void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y); - -/** - * Set the x coordinate of a object - * @param obj pointer to an object - * @param x new distance from the left side from the parent - */ -void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x); - -/** - * Set the y coordinate of a object - * @param obj pointer to an object - * @param y new distance from the top of the parent - */ -void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y); - -/** - * Set the size of an object - * @param obj pointer to an object - * @param w new width - * @param h new height - */ -void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h); - -/** - * Set the width of an object - * @param obj pointer to an object - * @param w new width - */ -void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w); - -/** - * Set the height of an object - * @param obj pointer to an object - * @param h new height - */ -void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h); - -/** - * Align an object to an other object. - * @param obj pointer to an object to align - * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. - * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment - */ -void lv_obj_align(lv_obj_t * obj,const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod); - -/** - * Align an object to an other object. - * @param obj pointer to an object to align - * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. - * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment - */ -void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod); - -/** - * Realign the object based on the last `lv_obj_align` parameters. - * @param obj pointer to an object - */ -void lv_obj_realign(lv_obj_t * obj); - -/** - * Enable the automatic realign of the object when its size has changed based on the last `lv_obj_align` parameters. - * @param obj pointer to an object - * @param en true: enable auto realign; false: disable auto realign - */ -void lv_obj_set_auto_realign(lv_obj_t * obj, bool en); - -/*--------------------- - * Appearance set - *--------------------*/ - -/** - * Set a new style for an object - * @param obj pointer to an object - * @param style_p pointer to the new style - */ -void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style); - -/** - * Notify an object about its style is modified - * @param obj pointer to an object - */ -void lv_obj_refresh_style(lv_obj_t * obj); - -/** - * Notify all object if a style is modified - * @param style pointer to a style. Only the objects with this style will be notified - * (NULL to notify all objects) - */ -void lv_obj_report_style_mod(lv_style_t * style); - -/*----------------- - * Attribute set - *----------------*/ - -/** - * Hide an object. It won't be visible and clickable. - * @param obj pointer to an object - * @param en true: hide the object - */ -void lv_obj_set_hidden(lv_obj_t * obj, bool en); - -/** - * Enable or disable the clicking of an object - * @param obj pointer to an object - * @param en true: make the object clickable - */ -void lv_obj_set_click(lv_obj_t * obj, bool en); - -/** - * Enable to bring this object to the foreground if it - * or any of its children is clicked - * @param obj pointer to an object - * @param en true: enable the auto top feature - */ -void lv_obj_set_top(lv_obj_t * obj, bool en); - -/** - * Enable the dragging of an object - * @param obj pointer to an object - * @param en true: make the object dragable - */ -void lv_obj_set_drag(lv_obj_t * obj, bool en); - -/** - * Enable the throwing of an object after is is dragged - * @param obj pointer to an object - * @param en true: enable the drag throw - */ -void lv_obj_set_drag_throw(lv_obj_t * obj, bool en); - -/** - * Enable to use parent for drag related operations. - * If trying to drag the object the parent will be moved instead - * @param obj pointer to an object - * @param en true: enable the 'drag parent' for the object - */ -void lv_obj_set_drag_parent(lv_obj_t * obj, bool en); - -/** - * Set editable parameter Used by groups and keyboard/encoder control. - * Editable object has something inside to choose (the elements of a list) - * @param obj pointer to an object - * @param en true: enable editing - */ -//void lv_obj_set_editable(lv_obj_t * obj, bool en); - -/** - * Set the opa scale enable parameter (required to set opa_scale with `lv_obj_set_opa_scale()`) - * @param obj pointer to an object - * @param en true: opa scaling is enabled for this object and all children; false: no opa scaling - */ -void lv_obj_set_opa_scale_enable(lv_obj_t * obj, bool en); - -/** - * Set the opa scale of an object - * @param obj pointer to an object - * @param opa_scale a factor to scale down opacity [0..255] - */ -void lv_obj_set_opa_scale(lv_obj_t * obj, lv_opa_t opa_scale); - -/** - * Set a bit or bits in the protect filed - * @param obj pointer to an object - * @param prot 'OR'-ed values from `lv_protect_t` - */ -void lv_obj_set_protect(lv_obj_t * obj, uint8_t prot); - -/** - * Clear a bit or bits in the protect filed - * @param obj pointer to an object - * @param prot 'OR'-ed values from `lv_protect_t` - */ -void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot); - -/** - * Set the signal function of an object. - * Always call the previous signal function in the new. - * @param obj pointer to an object - * @param fp the new signal function - */ -void lv_obj_set_signal_func(lv_obj_t * obj, lv_signal_func_t fp); - -/** - * Set a new design function for an object - * @param obj pointer to an object - * @param fp the new design function - */ -void lv_obj_set_design_func(lv_obj_t * obj, lv_design_func_t fp); - -/*---------------- - * Other set - *--------------*/ - -/** - * Allocate a new ext. data for an object - * @param obj pointer to an object - * @param ext_size the size of the new ext. data - * @return pointer to the allocated ext - */ -void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size); - -/** - * Send a 'LV_SIGNAL_REFR_EXT_SIZE' signal to the object - * @param obj pointer to an object - */ -void lv_obj_refresh_ext_size(lv_obj_t * obj); - -#ifdef LV_OBJ_FREE_NUM_TYPE -/** - * Set an application specific number for an object. - * It can help to identify objects in the application. - * @param obj pointer to an object - * @param free_num the new free number - */ -void lv_obj_set_free_num(lv_obj_t * obj, LV_OBJ_FREE_NUM_TYPE free_num); -#endif - -#if LV_OBJ_FREE_PTR != 0 -/** - * Set an application specific pointer for an object. - * It can help to identify objects in the application. - * @param obj pointer to an object - * @param free_p the new free pinter - */ -void lv_obj_set_free_ptr(lv_obj_t * obj, void * free_p); -#endif - -#if USE_LV_ANIMATION -/** - * Animate an object - * @param obj pointer to an object to animate - * @param type type of animation from 'lv_anim_builtin_t'. 'OR' it with ANIM_IN or ANIM_OUT - * @param time time of animation in milliseconds - * @param delay delay before the animation in milliseconds - * @param cb a function to call when the animation is ready - */ -void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint16_t delay, void (*cb) (lv_obj_t *)); -#endif - -/*======================= - * Getter functions - *======================*/ - -/*------------------ - * Screen get - *-----------------*/ - -/** - * Return with a pointer to the active screen - * @return pointer to the active screen object (loaded by 'lv_scr_load()') - */ -lv_obj_t * lv_scr_act(void); - -/** - * Return with the top layer. (Same on every screen and it is above the normal screen layer) - * @return pointer to the top layer object (transparent screen sized lv_obj) - */ -lv_obj_t * lv_layer_top(void); - -/** - * Return with the system layer. (Same on every screen and it is above the all other layers) - * It is used for example by the cursor - * @return pointer to the system layer object (transparent screen sized lv_obj) - */ -lv_obj_t * lv_layer_sys(void); - -/** - * Return with the screen of an object - * @param obj pointer to an object - * @return pointer to a screen - */ -lv_obj_t * lv_obj_get_screen(const lv_obj_t * obj); - -/*--------------------- - * Parent/children get - *--------------------*/ - -/** - * Returns with the parent of an object - * @param obj pointer to an object - * @return pointer to the parent of 'obj' - */ -lv_obj_t * lv_obj_get_parent(const lv_obj_t * obj); - -/** - * Iterate through the children of an object (start from the "youngest, lastly created") - * @param obj pointer to an object - * @param child NULL at first call to get the next children - * and the previous return value later - * @return the child after 'act_child' or NULL if no more child - */ -lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child); - -/** - * Iterate through the children of an object (start from the "oldest", firstly created) - * @param obj pointer to an object - * @param child NULL at first call to get the next children - * and the previous return value later - * @return the child after 'act_child' or NULL if no more child - */ -lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child); - -/** - * Count the children of an object (only children directly on 'obj') - * @param obj pointer to an object - * @return children number of 'obj' - */ -uint16_t lv_obj_count_children(const lv_obj_t * obj); - -/*--------------------- - * Coordinate get - *--------------------*/ - -/** - * Copy the coordinates of an object to an area - * @param obj pointer to an object - * @param cords_p pointer to an area to store the coordinates - */ -void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p); - -/** - * Get the x coordinate of object - * @param obj pointer to an object - * @return distance of 'obj' from the left side of its parent - */ -lv_coord_t lv_obj_get_x(const lv_obj_t * obj); - -/** - * Get the y coordinate of object - * @param obj pointer to an object - * @return distance of 'obj' from the top of its parent - */ -lv_coord_t lv_obj_get_y(const lv_obj_t * obj); - -/** - * Get the width of an object - * @param obj pointer to an object - * @return the width - */ -lv_coord_t lv_obj_get_width(const lv_obj_t * obj); - -/** - * Get the height of an object - * @param obj pointer to an object - * @return the height - */ -lv_coord_t lv_obj_get_height(const lv_obj_t * obj); - -/** - * Get the extended size attribute of an object - * @param obj pointer to an object - * @return the extended size attribute - */ -lv_coord_t lv_obj_get_ext_size(const lv_obj_t * obj); - -/** - * Get the automatic realign property of the object. - * @param obj pointer to an object - * @return true: auto realign is enabled; false: auto realign is disabled - */ -bool lv_obj_get_auto_realign(lv_obj_t * obj); - -/*----------------- - * Appearance get - *---------------*/ - -/** - * Get the style pointer of an object (if NULL get style of the parent) - * @param obj pointer to an object - * @return pointer to a style - */ -lv_style_t * lv_obj_get_style(const lv_obj_t * obj); - -/*----------------- - * Attribute get - *----------------*/ - -/** - * Get the hidden attribute of an object - * @param obj pointer to an object - * @return true: the object is hidden - */ -bool lv_obj_get_hidden(const lv_obj_t * obj); - -/** - * Get the click enable attribute of an object - * @param obj pointer to an object - * @return true: the object is clickable - */ -bool lv_obj_get_click(const lv_obj_t * obj); - -/** - * Get the top enable attribute of an object - * @param obj pointer to an object - * @return true: the auto top feature is enabled - */ -bool lv_obj_get_top(const lv_obj_t * obj); - -/** - * Get the drag enable attribute of an object - * @param obj pointer to an object - * @return true: the object is dragable - */ -bool lv_obj_get_drag(const lv_obj_t * obj); - -/** - * Get the drag throw enable attribute of an object - * @param obj pointer to an object - * @return true: drag throw is enabled - */ -bool lv_obj_get_drag_throw(const lv_obj_t * obj); - -/** - * Get the drag parent attribute of an object - * @param obj pointer to an object - * @return true: drag parent is enabled - */ -bool lv_obj_get_drag_parent(const lv_obj_t * obj); - - -/** - * Get the opa scale enable parameter - * @param obj pointer to an object - * @return true: opa scaling is enabled for this object and all children; false: no opa scaling - */ -lv_opa_t lv_obj_get_opa_scale_enable(const lv_obj_t * obj); - -/** - * Get the opa scale parameter of an object - * @param obj pointer to an object - * @return opa scale [0..255] - */ -lv_opa_t lv_obj_get_opa_scale(const lv_obj_t * obj); - -/** - * Get the protect field of an object - * @param obj pointer to an object - * @return protect field ('OR'ed values of `lv_protect_t`) - */ -uint8_t lv_obj_get_protect(const lv_obj_t * obj); - -/** - * Check at least one bit of a given protect bitfield is set - * @param obj pointer to an object - * @param prot protect bits to test ('OR'ed values of `lv_protect_t`) - * @return false: none of the given bits are set, true: at least one bit is set - */ -bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot); - -/** - * Get the signal function of an object - * @param obj pointer to an object - * @return the signal function - */ -lv_signal_func_t lv_obj_get_signal_func(const lv_obj_t * obj); - -/** - * Get the design function of an object - * @param obj pointer to an object - * @return the design function - */ -lv_design_func_t lv_obj_get_design_func(const lv_obj_t * obj); - -/*------------------ - * Other get - *-----------------*/ - -/** - * Get the ext pointer - * @param obj pointer to an object - * @return the ext pointer but not the dynamic version - * Use it as ext->data1, and NOT da(ext)->data1 - */ -void * lv_obj_get_ext_attr(const lv_obj_t * obj); - -/** - * Get object's and its ancestors type. Put their name in `type_buf` starting with the current type. - * E.g. buf.type[0]="lv_btn", buf.type[1]="lv_cont", buf.type[2]="lv_obj" - * @param obj pointer to an object which type should be get - * @param buf pointer to an `lv_obj_type_t` buffer to store the types - */ -void lv_obj_get_type(lv_obj_t * obj, lv_obj_type_t * buf); - -#ifdef LV_OBJ_FREE_NUM_TYPE -/** - * Get the free number - * @param obj pointer to an object - * @return the free number - */ -LV_OBJ_FREE_NUM_TYPE lv_obj_get_free_num(const lv_obj_t * obj); -#endif - -#if LV_OBJ_FREE_PTR != 0 -/** - * Get the free pointer - * @param obj pointer to an object - * @return the free pointer - */ -void * lv_obj_get_free_ptr(const lv_obj_t * obj); -#endif - -#if USE_LV_GROUP -/** - * Get the group of the object - * @param obj pointer to an object - * @return the pointer to group of the object - */ -void * lv_obj_get_group(const lv_obj_t * obj); - - -/** - * Tell whether the object is the focused object of a group or not. - * @param obj pointer to an object - * @return true: the object is focused, false: the object is not focused or not in a group - */ -bool lv_obj_is_focused(const lv_obj_t * obj); - -#endif - - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_OBJ_H*/ diff --git a/include/display/lv_core/lv_refr.h b/include/display/lv_core/lv_refr.h deleted file mode 100644 index 75b22d01..00000000 --- a/include/display/lv_core/lv_refr.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - * @file lv_refr.h - * - */ - -#ifndef LV_REFR_H -#define LV_REFR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_obj.h" -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ - -/********************** - * STATIC VARIABLES - **********************/ - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/** - * Initialize the screen refresh subsystem - */ -void lv_refr_init(void); - -/** - * Redraw the invalidated areas now. - * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can - * prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar) - * this function can be called when the screen should be updated. - */ -void lv_refr_now(void); - -/** - * Invalidate an area - * @param area_p pointer to area which should be invalidated - */ -void lv_inv_area(const lv_area_t * area_p); - -/** - * Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels - * @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num)) - */ -void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)); - -/** - * Called when an area is invalidated to modify the coordinates of the area. - * Special display controllers may require special coordinate rounding - * @param cb pointer to the a function which will modify the area - */ -void lv_refr_set_round_cb(void(*cb)(lv_area_t*)); - -/** - * Get the number of areas in the buffer - * @return number of invalid areas - */ -uint16_t lv_refr_get_buf_size(void); - -/** - * Pop (delete) the last 'num' invalidated areas from the buffer - * @param num number of areas to delete - */ -void lv_refr_pop_from_buf(uint16_t num); -/********************** - * STATIC FUNCTIONS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_REFR_H*/ diff --git a/include/display/lv_core/lv_style.h b/include/display/lv_core/lv_style.h deleted file mode 100644 index 4206ada3..00000000 --- a/include/display/lv_core/lv_style.h +++ /dev/null @@ -1,199 +0,0 @@ -/** - * @file lv_style.h - * - */ - -#ifndef LV_STYLE_H -#define LV_STYLE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_misc/lv_font.h" -#include "display/lv_misc/lv_anim.h" - -/********************* - * DEFINES - *********************/ -#define LV_RADIUS_CIRCLE (LV_COORD_MAX) /*A very big radius to always draw as circle*/ - -/********************** - * TYPEDEFS - **********************/ - -/*Border types (Use 'OR'ed values)*/ -enum -{ - LV_BORDER_NONE = 0x00, - LV_BORDER_BOTTOM = 0x01, - LV_BORDER_TOP = 0x02, - LV_BORDER_LEFT = 0x04, - LV_BORDER_RIGHT = 0x08, - LV_BORDER_FULL = 0x0F, - LV_BORDER_INTERNAL = 0x10, /*FOR matrix-like objects (e.g. Button matrix)*/ -}; -typedef uint8_t lv_border_part_t; - -/*Shadow types*/ -enum -{ - LV_SHADOW_BOTTOM = 0, - LV_SHADOW_FULL, -}; -typedef uint8_t lv_shadow_type_t; - -typedef struct -{ - uint8_t glass :1; /*1: Do not inherit this style*/ - - struct { - lv_color_t main_color; - lv_color_t grad_color; /*`grad_color` will be removed in v6.0, use `aux_color` instead*/ - lv_coord_t radius; - lv_opa_t opa; - - struct { - lv_color_t color; - lv_coord_t width; - lv_border_part_t part; - lv_opa_t opa; - } border; - - struct { - lv_color_t color; - lv_coord_t width; - lv_shadow_type_t type; - } shadow; - - struct { - lv_coord_t ver; - lv_coord_t hor; - lv_coord_t inner; - } padding; - - uint8_t empty :1; /*Transparent background (border still drawn)*/ - } body; - - - struct { - lv_color_t color; - const lv_font_t * font; - lv_coord_t letter_space; - lv_coord_t line_space; - lv_opa_t opa; - } text; - - struct { - lv_color_t color; - lv_opa_t intense; - lv_opa_t opa; - } image; - - struct { - lv_color_t color; - lv_coord_t width; - lv_opa_t opa; - uint8_t rounded :1; /*1: rounded line endings*/ - } line; -} lv_style_t; - -#if USE_LV_ANIMATION -typedef struct { - const lv_style_t * style_start; /*Pointer to the starting style*/ - const lv_style_t * style_end; /*Pointer to the destination style*/ - lv_style_t * style_anim; /*Pointer to a style to animate*/ - lv_anim_cb_t end_cb; /*Call it when the animation is ready (NULL if unused)*/ - int16_t time; /*Animation time in ms*/ - int16_t act_time; /*Current time in animation. Set to negative to make delay.*/ - uint16_t playback_pause; /*Wait before play back*/ - uint16_t repeat_pause; /*Wait before repeat*/ - uint8_t playback :1; /*When the animation is ready play it back*/ - uint8_t repeat :1; /*Repeat the animation infinitely*/ -} lv_style_anim_t; - -/* Example initialization -lv_style_anim_t a; -a.style_anim = &style_to_anim; -a.style_start = &style_1; -a.style_end = &style_2; -a.act_time = 0; -a.time = 1000; -a.playback = 0; -a.playback_pause = 0; -a.repeat = 0; -a.repeat_pause = 0; -a.end_cb = NULL; -lv_style_anim_create(&a); - */ -#endif - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init the basic styles - */ -void lv_style_init (void); - -/** - * Copy a style to an other - * @param dest pointer to the destination style - * @param src pointer to the source style - */ -void lv_style_copy(lv_style_t * dest, const lv_style_t * src); - - -/** - * Mix two styles according to a given ratio - * @param start start style - * @param end end style - * @param res store the result style here - * @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style - */ -void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio); - -#if USE_LV_ANIMATION - -/** - * Create an animation from a pre-configured 'lv_style_anim_t' variable - * @param anim pointer to a pre-configured 'lv_style_anim_t' variable (will be copied) - * @return pointer to a descriptor. Really this variable will be animated. (Can be used in `lv_anim_del(dsc, NULL)`) - */ -void * lv_style_anim_create(lv_style_anim_t * anim); -#endif - -/************************* - * GLOBAL VARIABLES - *************************/ -extern lv_style_t lv_style_scr; -extern lv_style_t lv_style_transp; -extern lv_style_t lv_style_transp_fit; -extern lv_style_t lv_style_transp_tight; -extern lv_style_t lv_style_plain; -extern lv_style_t lv_style_plain_color; -extern lv_style_t lv_style_pretty; -extern lv_style_t lv_style_pretty_color; -extern lv_style_t lv_style_btn_rel; -extern lv_style_t lv_style_btn_pr; -extern lv_style_t lv_style_btn_tgl_rel; -extern lv_style_t lv_style_btn_tgl_pr; -extern lv_style_t lv_style_btn_ina; - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_STYLE_H*/ diff --git a/include/display/lv_core/lv_vdb.h b/include/display/lv_core/lv_vdb.h deleted file mode 100644 index 32aac5df..00000000 --- a/include/display/lv_core/lv_vdb.h +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @file lv_vdb.h - * - */ - -#ifndef LV_VDB_H -#define LV_VDB_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if LV_VDB_SIZE != 0 - -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" - -/********************* - * DEFINES - *********************/ -/*Can be used in `lv_conf.h` the set an invalid address for the VDB. It should be replaced later by a valid address using `lv_vdb_set_adr()`*/ -#define LV_VDB_ADR_INV 8 /*8 is still too small to be valid but it's aligned on 64 bit machines as well*/ - -#ifndef LV_VDB_PX_BPP -#define LV_VDB_PX_BPP LV_COLOR_SIZE /* Default is LV_COLOR_SIZE */ -#endif - - -#if LV_VDB_TRUE_DOUBLE_BUFFERED && (LV_VDB_SIZE != LV_HOR_RES * LV_VER_RES || LV_VDB_DOUBLE == 0) -#error "With LV_VDB_TRUE_DOUBLE_BUFFERED: (LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES and LV_VDB_DOUBLE = 1 is required" -#endif - - -/* The size of VDB in bytes. - * (LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3): just divide by 8 to convert bits to bytes - * (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0): add an extra byte to round up. - * E.g. if LV_VDB_SIZE = 10 and LV_VDB_PX_BPP = 1 -> 10 bits -> 2 bytes*/ -#define LV_VDB_SIZE_IN_BYTES ((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0) - -/********************** - * TYPEDEFS - **********************/ - -typedef struct -{ - lv_area_t area; - lv_color_t *buf; -} lv_vdb_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode - * @return pointer to a 'vdb' variable - */ -lv_vdb_t * lv_vdb_get(void); - -/** - * Flush the content of the vdb - */ -void lv_vdb_flush(void); - -/** - * Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`. - * It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES` - * @param buf1 address of the VDB. - * @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0` - */ -void lv_vdb_set_adr(void * buf1, void * buf2); - -/** - * Call in the display driver's 'disp_flush' function when the flushing is finished - */ -void lv_flush_ready(void); - -/** - * Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1` - * @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB - */ -lv_vdb_t * lv_vdb_get_active(void); - -/** - * Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1` - * @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB - */ -lv_vdb_t * lv_vdb_get_inactive(void); - -/** - * Whether the flushing is in progress or not - * @return true: flushing is in progress; false: flushing ready - */ -bool lv_vdb_is_flushing(void); - -/********************** - * MACROS - **********************/ - -#else /*LV_VDB_SIZE != 0*/ - -/*Just for compatibility*/ -void lv_flush_ready(void); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_VDB_H*/ diff --git a/include/display/lv_draw/lv_draw.h b/include/display/lv_draw/lv_draw.h deleted file mode 100644 index 55038836..00000000 --- a/include/display/lv_draw/lv_draw.h +++ /dev/null @@ -1,115 +0,0 @@ -/** - * @file lv_draw.h - * - */ - -#ifndef LV_DRAW_H -#define LV_DRAW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include "display/lv_core/lv_style.h" -#include "display/lv_misc/lv_txt.h" - -/********************* - * DEFINES - *********************/ -/*If image pixels contains alpha we need to know how much byte is a pixel*/ -#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8 -# define LV_IMG_PX_SIZE_ALPHA_BYTE 2 -#elif LV_COLOR_DEPTH == 16 -# define LV_IMG_PX_SIZE_ALPHA_BYTE 3 -#elif LV_COLOR_DEPTH == 32 -# define LV_IMG_PX_SIZE_ALPHA_BYTE 4 -#endif - -/********************** - * TYPEDEFS - **********************/ - -enum { - LV_IMG_SRC_VARIABLE, - LV_IMG_SRC_FILE, - LV_IMG_SRC_SYMBOL, - LV_IMG_SRC_UNKNOWN, -}; -typedef uint8_t lv_img_src_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -#if LV_ANTIALIAS != 0 - -/** - * Get the opacity of a pixel based it's position in a line segment - * @param seg segment length - * @param px_id position of of a pixel which opacity should be get [0..seg-1] - * @param base_opa the base opacity - * @return the opacity of the given pixel - */ -lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa); - -/** - * Add a vertical anti-aliasing segment (pixels with decreasing opacity) - * @param x start point x coordinate - * @param y start point y coordinate - * @param length length of segment (negative value to start from 0 opacity) - * @param mask draw only in this area - * @param color color of pixels - * @param opa maximum opacity - */ -void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); - -/** - * Add a horizontal anti-aliasing segment (pixels with decreasing opacity) - * @param x start point x coordinate - * @param y start point y coordinate - * @param length length of segment (negative value to start from 0 opacity) - * @param mask draw only in this area - * @param color color of pixels - * @param opa maximum opacity - */ -void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); -#endif - -/********************** - * GLOBAL VARIABLES - **********************/ -extern void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); -extern void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); -extern void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa); -extern void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p, - const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, - lv_color_t recolor, lv_opa_t recolor_opa); - -/********************** - * MACROS - **********************/ - -/********************** - * POST INCLUDES - *********************/ -#include "lv_draw_rect.h" -#include "lv_draw_label.h" -#include "lv_draw_img.h" -#include "lv_draw_line.h" -#include "lv_draw_triangle.h" - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_H*/ diff --git a/include/display/lv_draw/lv_draw.mk b/include/display/lv_draw/lv_draw.mk deleted file mode 100644 index a384eefe..00000000 --- a/include/display/lv_draw/lv_draw.mk +++ /dev/null @@ -1,14 +0,0 @@ -CSRCS += lv_draw_vbasic.c -CSRCS += lv_draw_rbasic.c -CSRCS += lv_draw.c -CSRCS += lv_draw_rect.c -CSRCS += lv_draw_label.c -CSRCS += lv_draw_line.c -CSRCS += lv_draw_img.c -CSRCS += lv_draw_arc.c -CSRCS += lv_draw_triangle.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_draw -VPATH += :$(LVGL_DIR)/lvgl/lv_draw - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw" diff --git a/include/display/lv_draw/lv_draw_arc.h b/include/display/lv_draw/lv_draw_arc.h deleted file mode 100644 index 203eabe6..00000000 --- a/include/display/lv_draw/lv_draw_arc.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file lv_draw_arc.h - * - */ - -#ifndef LV_DRAW_ARC_H -#define LV_DRAW_ARC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Draw an arc. (Can draw pie too with great thickness.) - * @param center_x the x coordinate of the center of the arc - * @param center_y the y coordinate of the center of the arc - * @param radius the radius of the arc - * @param mask the arc will be drawn only in this mask - * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) - * @param end_angle the end angle of the arc - * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) - * @param opa_scale scale down all opacities by the factor - */ -void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask, - uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_ARC*/ diff --git a/include/display/lv_draw/lv_draw_img.h b/include/display/lv_draw/lv_draw_img.h deleted file mode 100644 index ff779580..00000000 --- a/include/display/lv_draw/lv_draw_img.h +++ /dev/null @@ -1,167 +0,0 @@ -/** - * @file lv_draw_img.h - * - */ - -#ifndef LV_DRAW_IMG_H -#define LV_DRAW_IMG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ -#define LV_IMG_DECODER_OPEN_FAIL ((void*)(-1)) - -/********************** - * TYPEDEFS - **********************/ -struct _lv_img_t; - -typedef struct { - - /* The first 8 bit is very important to distinguish the different source types. - * For more info see `lv_img_get_src_type()` in lv_img.c */ - uint32_t cf :5; /* Color format: See `lv_img_color_format_t`*/ - uint32_t always_zero :3; /*It the upper bits of the first byte. Always zero to look like a non-printable character*/ - - uint32_t reserved :2; /*Reserved to be used later*/ - - uint32_t w:11; /*Width of the image map*/ - uint32_t h:11; /*Height of the image map*/ -} lv_img_header_t; - -/*Image color format*/ -enum { - LV_IMG_CF_UNKOWN = 0, - - LV_IMG_CF_RAW, /*Contains the file as it is. Needs custom decoder function*/ - LV_IMG_CF_RAW_ALPHA, /*Contains the file as it is. The image has alpha. Needs custom decoder function*/ - LV_IMG_CF_RAW_CHROMA_KEYED, /*Contains the file as it is. The image is chroma keyed. Needs custom decoder function*/ - - LV_IMG_CF_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/ - LV_IMG_CF_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/ - LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/ - - LV_IMG_CF_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/ - LV_IMG_CF_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/ - LV_IMG_CF_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/ - LV_IMG_CF_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/ - - LV_IMG_CF_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/ - LV_IMG_CF_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/ - LV_IMG_CF_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/ - LV_IMG_CF_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/ -}; -typedef uint8_t lv_img_cf_t; - -/* Image header it is compatible with - * the result image converter utility*/ -typedef struct -{ - lv_img_header_t header; - uint32_t data_size; - const uint8_t * data; -} lv_img_dsc_t; - -/* Decoder function definitions */ - - -/** - * Get info from an image and store in the `header` - * @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type) - * @param header store the info here - * @return LV_RES_OK: info written correctly; LV_RES_INV: failed - */ -typedef lv_res_t (*lv_img_decoder_info_f_t)(const void * src, lv_img_header_t * header); - -/** - * Open an image for decoding. Prepare it as it is required to read it later - * @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type) - * @param style the style of image (maybe it will be required to determine a color or something) - * @return there are 3 possible return values: - * 1) buffer with the decoded image - * 2) if can decode the whole image NULL. decoder_read_line will be called to read the image line-by-line - * 3) LV_IMG_DECODER_OPEN_FAIL if the image format is unknown to the decoder or an error occurred - */ -typedef const uint8_t * (*lv_img_decoder_open_f_t)(const void * src, const lv_style_t * style); - -/** - * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`. - * Required only if the "open" function can't return with the whole decoded pixel array. - * @param x start x coordinate - * @param y startt y coordinate - * @param len number of pixels to decode - * @param buf a buffer to store the decoded pixels - * @return LV_RES_OK: ok; LV_RES_INV: failed - */ -typedef lv_res_t (*lv_img_decoder_read_line_f_t)(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); - -/** - * Close the pending decoding. Free resources etc. - */ -typedef void (*lv_img_decoder_close_f_t)(void); - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Draw an image - * @param coords the coordinates of the image - * @param mask the image will be drawn only in this area - * @param src pointer to a lv_color_t array which contains the pixels of the image - * @param style style of the image - * @param opa_scale scale down all opacities by the factor - */ -void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask, - const void * src, const lv_style_t * style, lv_opa_t opa_scale); - - -/** - * Get the type of an image source - * @param src pointer to an image source: - * - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code) - * - a path to a file (e.g. "S:/folder/image.bin") - * - or a symbol (e.g. SYMBOL_CLOSE) - * @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN - */ -lv_img_src_t lv_img_src_get_type(const void * src); - -/** - * Set custom decoder functions. See the typdefs of the function typed above for more info about them - * @param info_fp info get function - * @param open_fp open function - * @param read_fp read line function - * @param close_fp clode function - */ -void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp, - lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp); - -lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header); - -uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf); - -bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf); - -bool lv_img_color_format_has_alpha(lv_img_cf_t cf); - - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TEMPL_H*/ diff --git a/include/display/lv_draw/lv_draw_label.h b/include/display/lv_draw/lv_draw_label.h deleted file mode 100644 index 8798573d..00000000 --- a/include/display/lv_draw/lv_draw_label.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file lv_draw_label.h - * - */ - -#ifndef LV_DRAW_LABEL_H -#define LV_DRAW_LABEL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Write a text - * @param coords coordinates of the label - * @param mask the label will be drawn only in this area - * @param style pointer to a style - * @param opa_scale scale down all opacities by the factor - * @param txt 0 terminated text to write - * @param flag settings for the text from 'txt_flag_t' enum - * @param offset text offset in x and y direction (NULL if unused) - * - */ -void lv_draw_label(const lv_area_t * coords,const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale, - const char * txt, lv_txt_flag_t flag, lv_point_t * offset); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_LABEL_H*/ diff --git a/include/display/lv_draw/lv_draw_line.h b/include/display/lv_draw/lv_draw_line.h deleted file mode 100644 index 4269475e..00000000 --- a/include/display/lv_draw/lv_draw_line.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file lv_draw_line.h - * - */ - -#ifndef LV_DRAW_LINE_H -#define LV_DRAW_LINE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Draw a line - * @param point1 first point of the line - * @param point2 second point of the line - * @param mask the line will be drawn only on this area - * @param style pointer to a line's style - * @param opa_scale scale down all opacities by the factor - */ -void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, - const lv_style_t * style, lv_opa_t opa_scale); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_LINE_H*/ diff --git a/include/display/lv_draw/lv_draw_rbasic.h b/include/display/lv_draw/lv_draw_rbasic.h deleted file mode 100644 index 403cb806..00000000 --- a/include/display/lv_draw/lv_draw_rbasic.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * @file lv_draw_rbasic..h - * - */ - -#ifndef LV_DRAW_RBASIC_H -#define LV_DRAW_RBASIC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_REAL_DRAW != 0 - -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_misc/lv_font.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); - -/** - * Fill an area on the display - * @param cords_p coordinates of the area to fill - * @param mask_p fill only o this mask - * @param color fill color - * @param opa opacity (ignored, only for compatibility with lv_vfill) - */ -void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p, - lv_color_t color, lv_opa_t opa); - -/** - * Draw a letter to the display - * @param pos_p left-top coordinate of the latter - * @param mask_p the letter will be drawn only on this area - * @param font_p pointer to font - * @param letter a letter to draw - * @param color color of letter - * @param opa opacity of letter (ignored, only for compatibility with lv_vletter) - */ -void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p, - const lv_font_t * font_p, uint32_t letter, - lv_color_t color, lv_opa_t opa); - -/** - * When the letter is ant-aliased it needs to know the background color - * @param bg_color the background color of the currently drawn letter - */ -void lv_rletter_set_background(lv_color_t color); - - -/** - * Draw a color map to the display (image) - * @param cords_p coordinates the color map - * @param mask_p the map will drawn only on this area - * @param map_p pointer to a lv_color_t array - * @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap') - * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels - * @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it) - * @param recolor mix the pixels with this color - * @param recolor_opa the intense of recoloring - */ -void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p, - const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, - lv_color_t recolor, lv_opa_t recolor_opa); -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_REAL_DRAW*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_RBASIC_H*/ diff --git a/include/display/lv_draw/lv_draw_rect.h b/include/display/lv_draw/lv_draw_rect.h deleted file mode 100644 index 933590ca..00000000 --- a/include/display/lv_draw/lv_draw_rect.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @file lv_draw_rect.h - * - */ - -#ifndef LV_DRAW_RECT_H -#define LV_DRAW_RECT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Draw a rectangle - * @param coords the coordinates of the rectangle - * @param mask the rectangle will be drawn only in this mask - * @param style pointer to a style - * @param opa_scale scale down all opacities by the factor - */ -void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_RECT_H*/ diff --git a/include/display/lv_draw/lv_draw_vbasic.h b/include/display/lv_draw/lv_draw_vbasic.h deleted file mode 100644 index 82d4b7a1..00000000 --- a/include/display/lv_draw/lv_draw_vbasic.h +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @file lv_draw_vbasic.h - * - */ - -#ifndef LV_DRAW_VBASIC_H -#define LV_DRAW_VBASIC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if LV_VDB_SIZE != 0 - -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_misc/lv_font.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); -/** - * Fill an area in the Virtual Display Buffer - * @param cords_p coordinates of the area to fill - * @param mask_p fill only o this mask - * @param color fill color - * @param opa opacity of the area (0..255) - */ -void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p, - lv_color_t color, lv_opa_t opa); - -/** - * Draw a letter in the Virtual Display Buffer - * @param pos_p left-top coordinate of the latter - * @param mask_p the letter will be drawn only on this area - * @param font_p pointer to font - * @param letter a letter to draw - * @param color color of letter - * @param opa opacity of letter (0..255) - */ -void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p, - const lv_font_t * font_p, uint32_t letter, - lv_color_t color, lv_opa_t opa); - -/** - * Draw a color map to the display (image) - * @param cords_p coordinates the color map - * @param mask_p the map will drawn only on this area (truncated to VDB area) - * @param map_p pointer to a lv_color_t array - * @param opa opacity of the map - * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels - * @param alpha_byte true: extra alpha byte is inserted for every pixel - * @param recolor mix the pixels with this color - * @param recolor_opa the intense of recoloring - */ -void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p, - const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, - lv_color_t recolor, lv_opa_t recolor_opa); - -/********************** - * MACROS - **********************/ - -#endif /*LV_VDB_SIZE != 0*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_RBASIC_H*/ diff --git a/include/display/lv_fonts/lv_font_builtin.h b/include/display/lv_fonts/lv_font_builtin.h deleted file mode 100644 index 5687fa1f..00000000 --- a/include/display/lv_fonts/lv_font_builtin.h +++ /dev/null @@ -1,150 +0,0 @@ -/** - * @file lv_font_builtin.h - * - */ - -#ifndef LV_FONT_BUILTIN_H -#define LV_FONT_BUILTIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include "display/lv_misc/lv_font.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the built-in fonts - */ -void lv_font_builtin_init(void); - -/********************** - * MACROS - **********************/ - -/********************** - * FONT DECLARATIONS - **********************/ - -/*10 px */ -#if USE_LV_FONT_DEJAVU_10 -LV_FONT_DECLARE(lv_font_dejavu_10); -#endif - -#if USE_LV_FONT_DEJAVU_10_LATIN_SUP -LV_FONT_DECLARE(lv_font_dejavu_10_latin_sup); -#endif - -#if USE_LV_FONT_DEJAVU_10_CYRILLIC -LV_FONT_DECLARE(lv_font_dejavu_10_cyrillic); -#endif - -#if USE_LV_FONT_SYMBOL_10 -LV_FONT_DECLARE(lv_font_symbol_10); -#endif - -/*20 px */ -#if USE_LV_FONT_DEJAVU_20 -LV_FONT_DECLARE(lv_font_dejavu_20); -#endif - -#if USE_LV_FONT_DEJAVU_20_LATIN_SUP -LV_FONT_DECLARE(lv_font_dejavu_20_latin_sup); -#endif - -#if USE_LV_FONT_DEJAVU_20_CYRILLIC -LV_FONT_DECLARE(lv_font_dejavu_20_cyrillic); -#endif - -#if USE_LV_FONT_SYMBOL_20 -LV_FONT_DECLARE(lv_font_symbol_20); -#endif - -/*30 px */ -#if USE_LV_FONT_DEJAVU_30 -LV_FONT_DECLARE(lv_font_dejavu_30); -#endif - -#if USE_LV_FONT_DEJAVU_30_LATIN_SUP -LV_FONT_DECLARE(lv_font_dejavu_30_latin_sup); -#endif - -#if USE_LV_FONT_DEJAVU_30_CYRILLIC -LV_FONT_DECLARE(lv_font_dejavu_30_cyrillic); -#endif - -#if USE_LV_FONT_SYMBOL_30 -LV_FONT_DECLARE(lv_font_symbol_30); -#endif - -/*40 px */ -#if USE_LV_FONT_DEJAVU_40 -LV_FONT_DECLARE(lv_font_dejavu_40); -#endif - -#if USE_LV_FONT_DEJAVU_40_LATIN_SUP -LV_FONT_DECLARE(lv_font_dejavu_40_latin_sup); -#endif - -#if USE_LV_FONT_DEJAVU_40_CYRILLIC -LV_FONT_DECLARE(lv_font_dejavu_40_cyrillic); -#endif - -#if USE_LV_FONT_SYMBOL_40 -LV_FONT_DECLARE(lv_font_symbol_40); -#endif - -#if USE_LV_FONT_MONOSPACE_8 -LV_FONT_DECLARE(lv_font_monospace_8); -#endif - -#if USE_PROS_FONT_DEJAVU_MONO_10 -LV_FONT_DECLARE(pros_font_dejavu_mono_10); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_10_LATIN_SUP -LV_FONT_DECLARE(pros_font_dejavu_mono_10_latin_sup); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_20 -LV_FONT_DECLARE(pros_font_dejavu_mono_20); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_20_LATIN_SUP -LV_FONT_DECLARE(pros_font_dejavu_mono_20_latin_sup); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_30 -LV_FONT_DECLARE(pros_font_dejavu_mono_30); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_30_LATIN_SUP -LV_FONT_DECLARE(pros_font_dejavu_mono_30_latin_sup); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_40 -LV_FONT_DECLARE(pros_font_dejavu_mono_40); -#endif -#if USE_PROS_FONT_DEJAVU_MONO_40_LATIN_SUP -LV_FONT_DECLARE(pros_font_dejavu_mono_40_latin_sup); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_FONT_BUILTIN_H*/ diff --git a/include/display/lv_fonts/lv_fonts.mk b/include/display/lv_fonts/lv_fonts.mk deleted file mode 100644 index f124b559..00000000 --- a/include/display/lv_fonts/lv_fonts.mk +++ /dev/null @@ -1,23 +0,0 @@ -CSRCS += lv_font_builtin.c -CSRCS += lv_font_dejavu_10.c -CSRCS += lv_font_dejavu_20.c -CSRCS += lv_font_dejavu_30.c -CSRCS += lv_font_dejavu_40.c -CSRCS += lv_font_dejavu_10_cyrillic.c -CSRCS += lv_font_dejavu_20_cyrillic.c -CSRCS += lv_font_dejavu_30_cyrillic.c -CSRCS += lv_font_dejavu_40_cyrillic.c -CSRCS += lv_font_dejavu_10_latin_sup.c -CSRCS += lv_font_dejavu_20_latin_sup.c -CSRCS += lv_font_dejavu_30_latin_sup.c -CSRCS += lv_font_dejavu_40_latin_sup.c -CSRCS += lv_font_symbol_10.c -CSRCS += lv_font_symbol_20.c -CSRCS += lv_font_symbol_30.c -CSRCS += lv_font_symbol_40.c -CSRCS += lv_font_monospace_8.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_fonts -VPATH += :$(LVGL_DIR)/lvgl/lv_fonts - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_fonts" diff --git a/include/display/lv_hal/lv_hal.mk b/include/display/lv_hal/lv_hal.mk deleted file mode 100644 index 83f4bf17..00000000 --- a/include/display/lv_hal/lv_hal.mk +++ /dev/null @@ -1,8 +0,0 @@ -CSRCS += lv_hal_disp.c -CSRCS += lv_hal_indev.c -CSRCS += lv_hal_tick.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_hal -VPATH += :$(LVGL_DIR)/lvgl/lv_hal - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal" diff --git a/include/display/lv_hal/lv_hal_disp.h b/include/display/lv_hal/lv_hal_disp.h deleted file mode 100644 index 273f3314..00000000 --- a/include/display/lv_hal/lv_hal_disp.h +++ /dev/null @@ -1,174 +0,0 @@ -/** - * @file hal_disp.h - * - * @description Display Driver HAL interface header file - * - */ - -#ifndef HAL_DISP_H -#define HAL_DISP_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include -#include -#include "lv_hal.h" -#include "display/lv_misc/lv_color.h" -#include "display/lv_misc/lv_area.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/** - * Display Driver structure to be registered by HAL - */ -typedef struct _disp_drv_t { - /*Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has to be called when finished*/ - void (*disp_flush)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); - - /*Fill an area with a color on the display*/ - void (*disp_fill)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); - - /*Write pixel map (e.g. image) to the display*/ - void (*disp_map)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p); - - /*Optional interface functions to use GPU*/ -#if USE_LV_GPU - /*Blend two memories using opacity (GPU only)*/ - void (*mem_blend)(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa); - - /*Fill a memory with a color (GPU only)*/ - void (*mem_fill)(lv_color_t * dest, uint32_t length, lv_color_t color); -#endif - -#if LV_VDB_SIZE - /*Optional: Set a pixel in a buffer according to the requirements of the display*/ - void (*vdb_wr)(uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa); -#endif -} lv_disp_drv_t; - -typedef struct _disp_t { - lv_disp_drv_t driver; - struct _disp_t *next; -} lv_disp_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize a display driver with default values. - * It is used to surly have known values in the fields ant not memory junk. - * After it you can set the fields. - * @param driver pointer to driver variable to initialize - */ -void lv_disp_drv_init(lv_disp_drv_t *driver); - -/** - * Register an initialized display driver. - * Automatically set the first display as active. - * @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable) - * @return pointer to the new display or NULL on error - */ -lv_disp_t * lv_disp_drv_register(lv_disp_drv_t *driver); - -/** - * Set the active display - * @param disp pointer to a display (return value of 'lv_disp_register') - */ -void lv_disp_set_active(lv_disp_t * disp); - -/** - * Get a pointer to the active display - * @return pointer to the active display - */ -lv_disp_t * lv_disp_get_active(void); - -/** - * Get the next display. - * @param disp pointer to the current display. NULL to initialize. - * @return the next display or NULL if no more. Give the first display when the parameter is NULL - */ -lv_disp_t * lv_disp_next(lv_disp_t * disp); - -/** - * Fill a rectangular area with a color on the active display - * @param x1 left coordinate of the rectangle - * @param x2 right coordinate of the rectangle - * @param y1 top coordinate of the rectangle - * @param y2 bottom coordinate of the rectangle - * @param color_p pointer to an array of colors - */ -void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p); - -/** - * Fill a rectangular area with a color on the active display - * @param x1 left coordinate of the rectangle - * @param x2 right coordinate of the rectangle - * @param y1 top coordinate of the rectangle - * @param y2 bottom coordinate of the rectangle - * @param color fill color - */ -void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color); - -/** - * Put a color map to a rectangular area on the active display - * @param x1 left coordinate of the rectangle - * @param x2 right coordinate of the rectangle - * @param y1 top coordinate of the rectangle - * @param y2 bottom coordinate of the rectangle - * @param color_map pointer to an array of colors - */ -void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map); - -#if USE_LV_GPU -/** - * Blend pixels to a destination memory from a source memory - * In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available) - * @param dest a memory address. Blend 'src' here. - * @param src pointer to pixel map. Blend it to 'dest'. - * @param length number of pixels in 'src' - * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) - */ -void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa); - -/** - * Fill a memory with a color (GPUs may support it) - * In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available) - * @param dest a memory address. Copy 'src' here. - * @param src pointer to pixel map. Copy it to 'dest'. - * @param length number of pixels in 'src' - * @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover) - */ -void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color); -/** - * Shows if memory blending (by GPU) is supported or not - * @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver - */ -bool lv_disp_is_mem_blend_supported(void); - -/** - * Shows if memory fill (by GPU) is supported or not - * @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver - */ -bool lv_disp_is_mem_fill_supported(void); -#endif -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/include/display/lv_hal/lv_hal_indev.h b/include/display/lv_hal/lv_hal_indev.h deleted file mode 100644 index 0252dc47..00000000 --- a/include/display/lv_hal/lv_hal_indev.h +++ /dev/null @@ -1,166 +0,0 @@ -/** - * @file hal_indev.h - * - * @description Input Device HAL interface layer header file - * - */ - -#ifndef HAL_INDEV_H -#define HAL_INDEV_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include -#include -#include "lv_hal.h" -#include "display/lv_misc/lv_area.h" -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Possible input device types*/ -enum { - LV_INDEV_TYPE_NONE, /*Show uninitialized state*/ - LV_INDEV_TYPE_POINTER, /*Touch pad, mouse, external button*/ - LV_INDEV_TYPE_KEYPAD, /*Keypad or keyboard*/ - LV_INDEV_TYPE_BUTTON, /*External (hardware button) which is assinged to a specific point of the screen*/ - LV_INDEV_TYPE_ENCODER, /*Encoder with only Left, Right turn and a Button*/ -}; -typedef uint8_t lv_hal_indev_type_t; - -/*States for input devices*/ -enum { - LV_INDEV_STATE_REL = 0, - LV_INDEV_STATE_PR -}; -typedef uint8_t lv_indev_state_t; - -/*Data type when an input device is read */ -typedef struct { - union { - lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/ - uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ - uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/ - int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/ - }; - void *user_data; /*'lv_indev_drv_t.priv' for this driver*/ - lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ -} lv_indev_data_t; - -/*Initialized by the user and registered by 'lv_indev_add()'*/ -typedef struct { - lv_hal_indev_type_t type; /*Input device type*/ - bool (*read)(lv_indev_data_t *data); /*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/ - void *user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/ -} lv_indev_drv_t; - -struct _lv_obj_t; - -/*Run time data of input devices*/ -typedef struct _lv_indev_proc_t { - lv_indev_state_t state; - union { - struct { /*Pointer and button data*/ - lv_point_t act_point; - lv_point_t last_point; - lv_point_t vect; - lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DRAG_LIMIT*/ - struct _lv_obj_t * act_obj; - struct _lv_obj_t * last_obj; - - /*Flags*/ - uint8_t drag_range_out :1; - uint8_t drag_in_prog :1; - uint8_t wait_unil_release :1; - }; - struct { /*Keypad data*/ - lv_indev_state_t last_state; - uint32_t last_key; - }; - }; - - uint32_t pr_timestamp; /*Pressed time stamp*/ - uint32_t longpr_rep_timestamp; /*Long press repeat time stamp*/ - - /*Flags*/ - uint8_t long_pr_sent :1; - uint8_t reset_query :1; - uint8_t disabled :1; -} lv_indev_proc_t; - -struct _lv_indev_t; - -typedef void (*lv_indev_feedback_t)(struct _lv_indev_t *, lv_signal_t); - -struct _lv_obj_t; -struct _lv_group_t; - -/*The main input device descriptor with driver, runtime data ('proc') and some additional information*/ -typedef struct _lv_indev_t { - lv_indev_drv_t driver; - lv_indev_proc_t proc; - lv_indev_feedback_t feedback; - uint32_t last_activity_time; - union { - struct _lv_obj_t *cursor; /*Cursor for LV_INPUT_TYPE_POINTER*/ - struct _lv_group_t *group; /*Keypad destination group*/ - const lv_point_t * btn_points; /*Array points assigned to the button ()screen will be pressed here by the buttons*/ - - }; - struct _lv_indev_t *next; -} lv_indev_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize an input device driver with default values. - * It is used to surly have known values in the fields ant not memory junk. - * After it you can set the fields. - * @param driver pointer to driver variable to initialize - */ -void lv_indev_drv_init(lv_indev_drv_t *driver); - -/** - * Register an initialized input device driver. - * @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable) - * @return pointer to the new input device or NULL on error - */ -lv_indev_t * lv_indev_drv_register(lv_indev_drv_t *driver); - -/** - * Get the next input device. - * @param indev pointer to the current input device. NULL to initialize. - * @return the next input devise or NULL if no more. Gives the first input device when the parameter is NULL - */ -lv_indev_t * lv_indev_next(lv_indev_t * indev); - -/** - * Read data from an input device. - * @param indev pointer to an input device - * @param data input device will write its data here - * @return false: no more data; true: there more data to read (buffered) - */ -bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t *data); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/include/display/lv_misc/lv_anim.h b/include/display/lv_misc/lv_anim.h deleted file mode 100644 index b3b8553b..00000000 --- a/include/display/lv_misc/lv_anim.h +++ /dev/null @@ -1,177 +0,0 @@ -/** - * @file anim.h - * - */ - -#ifndef ANIM_H -#define ANIM_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_ANIMATION - -#include -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -struct _lv_anim_t; - -typedef int32_t(*lv_anim_path_t)(const struct _lv_anim_t*); - -typedef void (*lv_anim_fp_t)(void *, int32_t); -typedef void (*lv_anim_cb_t)(void *); - -typedef struct _lv_anim_t -{ - void * var; /*Variable to animate*/ - lv_anim_fp_t fp; /*Animator function*/ - lv_anim_cb_t end_cb; /*Call it when the animation is ready*/ - lv_anim_path_t path; /*An array with the steps of animations*/ - int32_t start; /*Start value*/ - int32_t end; /*End value*/ - uint16_t time; /*Animation time in ms*/ - int16_t act_time; /*Current time in animation. Set to negative to make delay.*/ - uint16_t playback_pause; /*Wait before play back*/ - uint16_t repeat_pause; /*Wait before repeat*/ - uint8_t playback :1; /*When the animation is ready play it back*/ - uint8_t repeat :1; /*Repeat the animation infinitely*/ - /*Animation system use these - user shouldn't set*/ - uint8_t playback_now :1; /*Play back is in progress*/ - uint32_t has_run :1; /*Indicates the animation has run it this round*/ -} lv_anim_t; - -/*Example initialization -lv_anim_t a; -a.var = obj; -a.start = lv_obj_get_height(obj); -a.end = new_height; -a.fp = (lv_anim_fp_t)lv_obj_set_height; -a.path = lv_anim_path_linear; -a.end_cb = NULL; -a.act_time = 0; -a.time = 200; -a.playback = 0; -a.playback_pause = 0; -a.repeat = 0; -a.repeat_pause = 0; -lv_anim_create(&a); - */ -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init. the animation module - */ -void lv_anim_init(void); - -/** - * Create an animation - * @param anim_p an initialized 'anim_t' variable. Not required after call. - */ -void lv_anim_create(lv_anim_t * anim_p); - -/** - * Delete an animation for a variable with a given animatior function - * @param var pointer to variable - * @param fp a function pointer which is animating 'var', - * or NULL to ignore it and delete all animation with 'var - * @return true: at least 1 animation is deleted, false: no animation is deleted - */ -bool lv_anim_del(void * var, lv_anim_fp_t fp); - -/** - * Get the number of currently running animations - * @return the number of running animations - */ -uint16_t lv_anim_count_running(void); - -/** - * Calculate the time of an animation with a given speed and the start and end values - * @param speed speed of animation in unit/sec - * @param start start value of the animation - * @param end end value of the animation - * @return the required time [ms] for the animation with the given parameters - */ -uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end); - -/** - * Calculate the current value of an animation applying linear characteristic - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_linear(const lv_anim_t *a); - -/** - * Calculate the current value of an animation slowing down the start phase - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_ease_in(const lv_anim_t * a); - -/** - * Calculate the current value of an animation slowing down the end phase - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_ease_out(const lv_anim_t * a); - -/** - * Calculate the current value of an animation applying an "S" characteristic (cosine) - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_ease_in_out(const lv_anim_t *a); - -/** - * Calculate the current value of an animation with overshoot at the end - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_overshoot(const lv_anim_t * a); - -/** - * Calculate the current value of an animation with 3 bounces - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_bounce(const lv_anim_t * a); - -/** - * Calculate the current value of an animation applying step characteristic. - * (Set end value on the end of the animation) - * @param a pointer to an animation - * @return the current value to set - */ -int32_t lv_anim_path_step(const lv_anim_t *a); -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_ANIMATION == 0*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_ANIM_H*/ - diff --git a/include/display/lv_misc/lv_area.h b/include/display/lv_misc/lv_area.h deleted file mode 100644 index fc8b7dec..00000000 --- a/include/display/lv_misc/lv_area.h +++ /dev/null @@ -1,169 +0,0 @@ -/** - * @file lv_area.h - * - */ - -#ifndef LV_AREA_H -#define LV_AREA_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#include -#include -#include - -/********************* - * DEFINES - *********************/ -#define LV_COORD_MAX (16383) /*To avoid overflow don't let the max [-32,32k] range */ -#define LV_COORD_MIN (-16384) - -/********************** - * TYPEDEFS - **********************/ -typedef int16_t lv_coord_t; - -typedef struct -{ - lv_coord_t x; - lv_coord_t y; -} lv_point_t; - -typedef struct -{ - lv_coord_t x1; - lv_coord_t y1; - lv_coord_t x2; - lv_coord_t y2; -} lv_area_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize an area - * @param area_p pointer to an area - * @param x1 left coordinate of the area - * @param y1 top coordinate of the area - * @param x2 right coordinate of the area - * @param y2 bottom coordinate of the area - */ -void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2); - -/** - * Copy an area - * @param dest pointer to the destination area - * @param src pointer to the source area - */ -inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src) -{ - memcpy(dest, src, sizeof(lv_area_t)); -} - -/** - * Get the width of an area - * @param area_p pointer to an area - * @return the width of the area (if x1 == x2 -> width = 1) - */ -static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p) -{ - return area_p->x2 - area_p->x1 + 1; -} - -/** - * Get the height of an area - * @param area_p pointer to an area - * @return the height of the area (if y1 == y2 -> height = 1) - */ -static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p) -{ - return area_p->y2 - area_p->y1 + 1; -} - -/** - * Set the width of an area - * @param area_p pointer to an area - * @param w the new width of the area (w == 1 makes x1 == x2) - */ -void lv_area_set_width(lv_area_t * area_p, lv_coord_t w); - -/** - * Set the height of an area - * @param area_p pointer to an area - * @param h the new height of the area (h == 1 makes y1 == y2) - */ -void lv_area_set_height(lv_area_t * area_p, lv_coord_t h); - -/** - * Set the position of an area (width and height will be kept) - * @param area_p pointer to an area - * @param x the new x coordinate of the area - * @param y the new y coordinate of the area - */ -void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y); - -/** - * Return with area of an area (x * y) - * @param area_p pointer to an area - * @return size of area - */ -uint32_t lv_area_get_size(const lv_area_t * area_p); - -/** - * Get the common parts of two areas - * @param res_p pointer to an area, the result will be stored her - * @param a1_p pointer to the first area - * @param a2_p pointer to the second area - * @return false: the two area has NO common parts, res_p is invalid - */ -bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); - -/** - * Join two areas into a third which involves the other two - * @param res_p pointer to an area, the result will be stored here - * @param a1_p pointer to the first area - * @param a2_p pointer to the second area - */ -void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); - -/** - * Check if a point is on an area - * @param a_p pointer to an area - * @param p_p pointer to a point - * @return false:the point is out of the area - */ -bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p); - -/** - * Check if two area has common parts - * @param a1_p pointer to an area. - * @param a2_p pointer to an other area - * @return false: a1_p and a2_p has no common parts - */ -bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p); - -/** - * Check if an area is fully on an other - * @param ain_p pointer to an area which could be on aholder_p - * @param aholder pointer to an area which could involve ain_p - * @return - */ -bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif diff --git a/include/display/lv_misc/lv_circ.h b/include/display/lv_misc/lv_circ.h deleted file mode 100644 index f2065f71..00000000 --- a/include/display/lv_misc/lv_circ.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @file lv_circ.h - * - */ - -#ifndef LV_CIRC_H -#define LV_CIRC_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#include -#include "lv_area.h" - -/********************* - * DEFINES - *********************/ -#define LV_CIRC_OCT1_X(p) (p.x) -#define LV_CIRC_OCT1_Y(p) (p.y) -#define LV_CIRC_OCT2_X(p) (p.y) -#define LV_CIRC_OCT2_Y(p) (p.x) -#define LV_CIRC_OCT3_X(p) (-p.y) -#define LV_CIRC_OCT3_Y(p) (p.x) -#define LV_CIRC_OCT4_X(p) (-p.x) -#define LV_CIRC_OCT4_Y(p) (p.y) -#define LV_CIRC_OCT5_X(p) (-p.x) -#define LV_CIRC_OCT5_Y(p) (-p.y) -#define LV_CIRC_OCT6_X(p) (-p.y) -#define LV_CIRC_OCT6_Y(p) (-p.x) -#define LV_CIRC_OCT7_X(p) (p.y) -#define LV_CIRC_OCT7_Y(p) (-p.x) -#define LV_CIRC_OCT8_X(p) (p.x) -#define LV_CIRC_OCT8_Y(p) (-p.y) - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the circle drawing - * @param c pointer to a point. The coordinates will be calculated here - * @param tmp point to a variable. It will store temporary data - * @param radius radius of the circle - */ -void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius); - -/** - * Test the circle drawing is ready or not - * @param c same as in circ_init - * @return true if the circle is not ready yet - */ -bool lv_circ_cont(lv_point_t * c); - -/** - * Get the next point from the circle - * @param c same as in circ_init. The next point stored here. - * @param tmp same as in circ_init. - */ -void lv_circ_next(lv_point_t * c, lv_coord_t * tmp); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif diff --git a/include/display/lv_misc/lv_color.h b/include/display/lv_misc/lv_color.h deleted file mode 100644 index e2da8133..00000000 --- a/include/display/lv_misc/lv_color.h +++ /dev/null @@ -1,445 +0,0 @@ -/** - * @file lv_color.h - * - */ - -#ifndef LV_COLOR_H -#define LV_COLOR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -/*Error checking*/ -#if LV_COLOR_DEPTH == 24 -#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)" -#endif - -#if LV_COLOR_DEPTH != 32 && LV_COLOR_SCREEN_TRANSP != 0 -#error "LV_COLOR_SCREEN_TRANSP requires LV_COLOR_DEPTH == 32. Set it in lv_conf.h" -#endif - -#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0 -#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h" -#endif - - -#include - -/********************* - * DEFINES - *********************/ -#define LV_COLOR_WHITE LV_COLOR_MAKE(0xFF,0xFF,0xFF) -#define LV_COLOR_SILVER LV_COLOR_MAKE(0xC0,0xC0,0xC0) -#define LV_COLOR_GRAY LV_COLOR_MAKE(0x80,0x80,0x80) -#define LV_COLOR_BLACK LV_COLOR_MAKE(0x00,0x00,0x00) -#define LV_COLOR_RED LV_COLOR_MAKE(0xFF,0x00,0x00) -#define LV_COLOR_MAROON LV_COLOR_MAKE(0x80,0x00,0x00) -#define LV_COLOR_YELLOW LV_COLOR_MAKE(0xFF,0xFF,0x00) -#define LV_COLOR_OLIVE LV_COLOR_MAKE(0x80,0x80,0x00) -#define LV_COLOR_LIME LV_COLOR_MAKE(0x00,0xFF,0x00) -#define LV_COLOR_GREEN LV_COLOR_MAKE(0x00,0x80,0x00) -#define LV_COLOR_CYAN LV_COLOR_MAKE(0x00,0xFF,0xFF) -#define LV_COLOR_AQUA LV_COLOR_CYAN -#define LV_COLOR_TEAL LV_COLOR_MAKE(0x00,0x80,0x80) -#define LV_COLOR_BLUE LV_COLOR_MAKE(0x00,0x00,0xFF) -#define LV_COLOR_NAVY LV_COLOR_MAKE(0x00,0x00,0x80) -#define LV_COLOR_MAGENTA LV_COLOR_MAKE(0xFF,0x00,0xFF) -#define LV_COLOR_PURPLE LV_COLOR_MAKE(0x80,0x00,0x80) -#define LV_COLOR_ORANGE LV_COLOR_MAKE(0xFF,0xA5,0x00) - -enum { - LV_OPA_TRANSP = 0, - LV_OPA_0 = 0, - LV_OPA_10 = 25, - LV_OPA_20 = 51, - LV_OPA_30 = 76, - LV_OPA_40 = 102, - LV_OPA_50 = 127, - LV_OPA_60 = 153, - LV_OPA_70 = 178, - LV_OPA_80 = 204, - LV_OPA_90 = 229, - LV_OPA_100 = 255, - LV_OPA_COVER = 255, -}; - -#define LV_OPA_MIN 16 /*Opacities below this will be transparent*/ -#define LV_OPA_MAX 251 /*Opacities above this will fully cover*/ - -#if LV_COLOR_DEPTH == 1 -#define LV_COLOR_SIZE 8 -#elif LV_COLOR_DEPTH == 8 -#define LV_COLOR_SIZE 8 -#elif LV_COLOR_DEPTH == 16 -#define LV_COLOR_SIZE 16 -#elif LV_COLOR_DEPTH == 32 -#define LV_COLOR_SIZE 32 -#else -#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!" -#endif - -/********************** - * TYPEDEFS - **********************/ - -typedef union -{ - uint8_t blue :1; - uint8_t green :1; - uint8_t red :1; - uint8_t full :1; -} lv_color1_t; - -typedef union -{ - struct - { - uint8_t blue :2; - uint8_t green :3; - uint8_t red :3; - }; - uint8_t full; -} lv_color8_t; - -typedef union -{ - struct - { -#if LV_COLOR_16_SWAP == 0 - uint16_t blue :5; - uint16_t green :6; - uint16_t red :5; -#else - uint16_t green_h :3; - uint16_t red :5; - uint16_t blue :5; - uint16_t green_l :3; -#endif - }; - uint16_t full; -} lv_color16_t; - -typedef union -{ - struct - { - uint8_t blue; - uint8_t green; - uint8_t red; - uint8_t alpha; - }; - uint32_t full; -} lv_color32_t; - -#if LV_COLOR_DEPTH == 1 -typedef uint8_t lv_color_int_t; -typedef lv_color1_t lv_color_t; -#elif LV_COLOR_DEPTH == 8 -typedef uint8_t lv_color_int_t; -typedef lv_color8_t lv_color_t; -#elif LV_COLOR_DEPTH == 16 -typedef uint16_t lv_color_int_t; -typedef lv_color16_t lv_color_t; -#elif LV_COLOR_DEPTH == 32 -typedef uint32_t lv_color_int_t; -typedef lv_color32_t lv_color_t; -#else -#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!" -#endif - -typedef uint8_t lv_opa_t; - -typedef struct -{ - uint16_t h; - uint8_t s; - uint8_t v; -} lv_color_hsv_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/*In color conversations: - * - When converting to bigger color type the LSB weight of 1 LSB is calculated - * E.g. 16 bit Red has 5 bits - * 8 bit Red has 2 bits - * ---------------------- - * 8 bit red LSB = (2^5 - 1) / (2^2 - 1) = 31 / 3 = 10 - * - * - When calculating to smaller color type simply shift out the LSBs - * E.g. 8 bit Red has 2 bits - * 16 bit Red has 5 bits - * ---------------------- - * Shift right with 5 - 3 = 2 - */ - -static inline uint8_t lv_color_to1(lv_color_t color) -{ -#if LV_COLOR_DEPTH == 1 - return color.full; -#elif LV_COLOR_DEPTH == 8 - if((color.red & 0x4) || - (color.green & 0x4) || - (color.blue & 0x2)) { - return 1; - } else { - return 0; - } -#elif LV_COLOR_DEPTH == 16 -# if LV_COLOR_16_SWAP == 0 - if((color.red & 0x10) || - (color.green & 0x20) || - (color.blue & 0x10)) { - return 1; -# else - if((color.red & 0x10) || - (color.green_h & 0x20) || - (color.blue & 0x10)) { - return 1; -# endif - } else { - return 0; - } -#elif LV_COLOR_DEPTH == 32 - if((color.red & 0x80) || - (color.green & 0x80) || - (color.blue & 0x80)) { - return 1; - } else { - return 0; - } -#endif -} - -static inline uint8_t lv_color_to8(lv_color_t color) -{ -#if LV_COLOR_DEPTH == 1 - if(color.full == 0) return 0; - else return 0xFF; -#elif LV_COLOR_DEPTH == 8 - return color.full; -#elif LV_COLOR_DEPTH == 16 - -# if LV_COLOR_16_SWAP == 0 - lv_color8_t ret; - ret.red = color.red >> 2; /* 5 - 3 = 2*/ - ret.green = color.green >> 3; /* 6 - 3 = 3*/ - ret.blue = color.blue >> 3; /* 5 - 2 = 3*/ - return ret.full; -# else - lv_color8_t ret; - ret.red = color.red >> 2; /* 5 - 3 = 2*/ - ret.green = color.green_h; /* 6 - 3 = 3*/ - ret.blue = color.blue >> 3; /* 5 - 2 = 3*/ - return ret.full; -# endif -#elif LV_COLOR_DEPTH == 32 - lv_color8_t ret; - ret.red = color.red >> 5; /* 8 - 3 = 5*/ - ret.green = color.green >> 5; /* 8 - 3 = 5*/ - ret.blue = color.blue >> 6; /* 8 - 2 = 6*/ - return ret.full; -#endif -} - -static inline uint16_t lv_color_to16(lv_color_t color) -{ -#if LV_COLOR_DEPTH == 1 - if(color.full == 0) return 0; - else return 0xFFFF; -#elif LV_COLOR_DEPTH == 8 - lv_color16_t ret; -# if LV_COLOR_16_SWAP == 0 - ret.red = color.red * 4; /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/ - ret.green = color.green * 9; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/ - ret.blue = color.blue * 10; /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/ -# else - ret.red = color.red * 4; - uint8_t g_tmp = color.green * 9; - ret.green_h = (g_tmp & 0x1F) >> 3; - ret.green_l = g_tmp & 0x07; - ret.blue = color.blue * 10; -# endif - return ret.full; -#elif LV_COLOR_DEPTH == 16 - return color.full; -#elif LV_COLOR_DEPTH == 32 - lv_color16_t ret; -# if LV_COLOR_16_SWAP == 0 - ret.red = color.red >> 3; /* 8 - 5 = 3*/ - ret.green = color.green >> 2; /* 8 - 6 = 2*/ - ret.blue = color.blue >> 3; /* 8 - 5 = 3*/ -# else - ret.red = color.red >> 3; - ret.green_h = (color.green & 0xE0) >> 5; - ret.green_l = (color.green & 0x1C) >> 2; - ret.blue = color.blue >> 3; -# endif - return ret.full; -#endif -} - -static inline uint32_t lv_color_to32(lv_color_t color) -{ -#if LV_COLOR_DEPTH == 1 - if(color.full == 0) return 0; - else return 0xFFFFFFFF; -#elif LV_COLOR_DEPTH == 8 - lv_color32_t ret; - ret.red = color.red * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ - ret.green = color.green * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ - ret.blue = color.blue * 85; /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/ - ret.alpha = 0xFF; - return ret.full; -#elif LV_COLOR_DEPTH == 16 -# if LV_COLOR_16_SWAP == 0 - lv_color32_t ret; - ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ - ret.green = color.green * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/ - ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ - ret.alpha = 0xFF; - return ret.full; -# else - lv_color32_t ret; - ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ - ret.green = ((color.green_h << 3) + color.green_l) * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/ - ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/ - ret.alpha = 0xFF; - return ret.full; -# endif -#elif LV_COLOR_DEPTH == 32 - return color.full; -#endif -} - -static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix) -{ - lv_color_t ret; -#if LV_COLOR_DEPTH != 1 - /*LV_COLOR_DEPTH == 8, 16 or 32*/ - ret.red = (uint16_t)((uint16_t) c1.red * mix + (c2.red * (255 - mix))) >> 8; -# if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP - /*If swapped Green is in 2 parts*/ - uint16_t g_1 = (c1.green_h << 3) + c1.green_l; - uint16_t g_2 = (c2.green_h << 3) + c2.green_l; - uint16_t g_out = (uint16_t)((uint16_t) g_1 * mix + (g_2 * (255 - mix))) >> 8; - ret.green_h = g_out >> 3; - ret.green_l = g_out & 0x7; -# else - ret.green = (uint16_t)((uint16_t) c1.green * mix + (c2.green * (255 - mix))) >> 8; -# endif - ret.blue = (uint16_t)((uint16_t) c1.blue * mix + (c2.blue * (255 - mix))) >> 8; -# if LV_COLOR_DEPTH == 32 - ret.alpha = 0xFF; -# endif -#else - /*LV_COLOR_DEPTH == 1*/ - ret.full = mix > LV_OPA_50 ? c1.full : c2.full; -#endif - - return ret; -} - -/** - * Get the brightness of a color - * @param color a color - * @return the brightness [0..255] - */ -static inline uint8_t lv_color_brightness(lv_color_t color) -{ - lv_color32_t c32; - c32.full = lv_color_to32(color); - uint16_t bright = 3 * c32.red + c32.blue + 4 * c32.green; - return (uint16_t) bright >> 3; -} - -/* The most simple macro to create a color from R,G and B values - * The order of bit field is different on Big-endian and Little-endian machines*/ -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#if LV_COLOR_DEPTH == 1 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(b8 >> 7 | g8 >> 7 | r8 >> 7)}) -#elif LV_COLOR_DEPTH == 8 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 6, g8 >> 5, r8 >> 5}}) -#elif LV_COLOR_DEPTH == 16 -# if LV_COLOR_16_SWAP == 0 -# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 3, g8 >> 2, r8 >> 3}}) -# else -# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{g8 >> 5, r8 >> 3, b8 >> 3, (g8 >> 2) & 0x7}}) -# endif -#elif LV_COLOR_DEPTH == 32 -#ifdef __cplusplus -# define LV_COLOR_MAKE(r8, g8, b8) lv_color_t{b8, g8, r8, 0xff} -#else -# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/ -#endif -#endif -#else -#if LV_COLOR_DEPTH == 1 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(r8 >> 7 | g8 >> 7 | b8 >> 7)}) -#elif LV_COLOR_DEPTH == 8 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 6, g8 >> 5, b8 >> 5}}) -#elif LV_COLOR_DEPTH == 16 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 3, g8 >> 2, b8 >> 3}}) -#elif LV_COLOR_DEPTH == 32 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{0xff, r8, g8, b8}}) /*Fix 0xff alpha*/ -#endif -#endif - - -#define LV_COLOR_HEX(c) LV_COLOR_MAKE((uint8_t) ((uint32_t)((uint32_t)c >> 16) & 0xFF), \ - (uint8_t) ((uint32_t)((uint32_t)c >> 8) & 0xFF), \ - (uint8_t) ((uint32_t) c & 0xFF)) - -/*Usage LV_COLOR_HEX3(0x16C) which means LV_COLOR_HEX(0x1166CC)*/ -#define LV_COLOR_HEX3(c) LV_COLOR_MAKE((uint8_t) (((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), \ - (uint8_t) ((uint32_t)(c & 0xF0) | ((c & 0xF0) >> 4)), \ - (uint8_t) ((uint32_t)(c & 0xF) | ((c & 0xF) << 4))) - -static inline lv_color_t lv_color_hex(uint32_t c){ - return LV_COLOR_HEX(c); -} - -static inline lv_color_t lv_color_hex3(uint32_t c){ - return LV_COLOR_HEX3(c); -} - - -/** - * Convert a HSV color to RGB - * @param h hue [0..359] - * @param s saturation [0..100] - * @param v value [0..100] - * @return the given RGB color in RGB (with LV_COLOR_DEPTH depth) - */ -lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v); - -/** - * Convert an RGB color to HSV - * @param r red - * @param g green - * @param b blue - * @return the given RGB color n HSV - */ -lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r, uint8_t g, uint8_t b); - - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*USE_COLOR*/ diff --git a/include/display/lv_misc/lv_font.h b/include/display/lv_misc/lv_font.h deleted file mode 100644 index 0b1675c5..00000000 --- a/include/display/lv_misc/lv_font.h +++ /dev/null @@ -1,192 +0,0 @@ -/** - * @file lv_font.h - * - */ - -#ifndef LV_FONT_H -#define LV_FONT_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include - -#include "lv_symbol_def.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -typedef struct -{ - uint32_t w_px :8; - uint32_t glyph_index :24; -} lv_font_glyph_dsc_t; - -typedef struct -{ - uint32_t unicode :21; - uint32_t glyph_dsc_index :11; -} lv_font_unicode_map_t; - -typedef struct _lv_font_struct -{ - uint32_t unicode_first; - uint32_t unicode_last; - const uint8_t * glyph_bitmap; - const lv_font_glyph_dsc_t * glyph_dsc; - const uint32_t * unicode_list; - const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's bitmap from a font*/ - int16_t (*get_width)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's with with a given font*/ - struct _lv_font_struct * next_page; /*Pointer to a font extension*/ - uint32_t h_px :8; - uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/ - uint32_t monospace :8; /*Fix width (0: normal width)*/ - uint16_t glyph_cnt; /*Number of glyphs (letters) in the font*/ -} lv_font_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the fonts - */ -void lv_font_init(void); - -/** - * Add a font to an other to extend the character set. - * @param child the font to add - * @param parent this font will be extended. Using it later will contain the characters from `child` - */ -void lv_font_add(lv_font_t *child, lv_font_t *parent); - -/** - * Remove a font from a character set. - * @param child the font to remove - * @param parent remove `child` from here - */ -void lv_font_remove(lv_font_t * child, lv_font_t * parent); - -/** - * Tells if font which contains `letter` is monospace or not - * @param font_p point to font - * @param letter an UNICODE character code - * @return true: the letter is monospace; false not monospace - */ -bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter); - -/** - * Return with the bitmap of a font. - * @param font_p pointer to a font - * @param letter an UNICODE character code - * @return pointer to the bitmap of the letter - */ -const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter); - -/** - * Get the width of a letter in a font. If `monospace` is set then return with it. - * @param font_p pointer to a font - * @param letter an UNICODE character code - * @return the width of a letter - */ -uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter); - - -/** - * Get the width of the letter without overwriting it with the `monospace` attribute - * @param font_p pointer to a font - * @param letter an UNICODE character code - * @return the width of a letter - */ -uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter); - -/** - * Get the height of a font - * @param font_p pointer to a font - * @return the height of a font - */ -static inline uint8_t lv_font_get_height(const lv_font_t * font_p) -{ - return font_p->h_px; -} - -/** - * Get the bit-per-pixel of font - * @param font pointer to font - * @param letter a letter from font (font extensions can have different bpp) - * @return bpp of the font (or font extension) - */ -uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter); - -/** - * Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range - * @param font pointer to font - * @param unicode_letter an unicode letter which bitmap should be get - * @return pointer to the bitmap or NULL if not found - */ -const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter); - -/** - * Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse) - * @param font pointer to font - * @param unicode_letter an unicode letter which bitmap should be get - * @return pointer to the bitmap or NULL if not found - */ -const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter); -/** - * Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range - * @param font pointer to font - * @param unicode_letter an unicode letter which width should be get - * @return width of the gylph or -1 if not found - */ -int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter); - -/** - * Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse) - * @param font pointer to font - * @param unicode_letter an unicode letter which width should be get - * @return width of the glyph or -1 if not found - */ -int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter); - -/********************** - * MACROS - **********************/ - -#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name - - -/********************** - * ADD BUILT IN FONTS - **********************/ -#include "display/lv_fonts/lv_font_builtin.h" - -/*Declare the custom (user defined) fonts*/ -#ifdef LV_FONT_CUSTOM_DECLARE -LV_FONT_CUSTOM_DECLARE -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*USE_FONT*/ - diff --git a/include/display/lv_misc/lv_fs.h b/include/display/lv_misc/lv_fs.h deleted file mode 100644 index 845b4794..00000000 --- a/include/display/lv_misc/lv_fs.h +++ /dev/null @@ -1,277 +0,0 @@ -/** - * @file lv_fs.h - * - */ - -#ifndef LV_FS_H -#define LV_FS_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_FILESYSTEM - -#include -#include -#include "lv_mem.h" - -/********************* - * DEFINES - *********************/ -#define LV_FS_MAX_FN_LENGTH 64 - -/********************** - * TYPEDEFS - **********************/ -enum -{ - LV_FS_RES_OK = 0, - LV_FS_RES_HW_ERR, /*Low level hardware error*/ - LV_FS_RES_FS_ERR, /*Error in the file system structure */ - LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/ - LV_FS_RES_FULL, /*Disk full*/ - LV_FS_RES_LOCKED, /*The file is already opened*/ - LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/ - LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/ - LV_FS_RES_TOUT, /*Process time outed*/ - LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/ - LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/ - LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/ - LV_FS_RES_UNKNOWN, /*Other unknown error*/ -}; -typedef uint8_t lv_fs_res_t; - -struct __lv_fs_drv_t; - -typedef struct -{ - void * file_d; - struct __lv_fs_drv_t* drv; -} lv_fs_file_t; - - -typedef struct -{ - void * dir_d; - struct __lv_fs_drv_t * drv; -} lv_fs_dir_t; - -enum -{ - LV_FS_MODE_WR = 0x01, - LV_FS_MODE_RD = 0x02, -}; -typedef uint8_t lv_fs_mode_t; - -typedef struct __lv_fs_drv_t -{ - char letter; - uint16_t file_size; - uint16_t rddir_size; - bool (*ready) (void); - - lv_fs_res_t (*open) (void * file_p, const char * path, lv_fs_mode_t mode); - lv_fs_res_t (*close) (void * file_p); - lv_fs_res_t (*remove) (const char * fn); - lv_fs_res_t (*read) (void * file_p, void * buf, uint32_t btr, uint32_t * br); - lv_fs_res_t (*write) (void * file_p, const void * buf, uint32_t btw, uint32_t * bw); - lv_fs_res_t (*seek) (void * file_p, uint32_t pos); - lv_fs_res_t (*tell) (void * file_p, uint32_t * pos_p); - lv_fs_res_t (*trunc) (void * file_p); - lv_fs_res_t (*size) (void * file_p, uint32_t * size_p); - lv_fs_res_t (*rename) (const char * oldname, const char * newname); - lv_fs_res_t (*free) (uint32_t * total_p, uint32_t * free_p); - - lv_fs_res_t (*dir_open) (void * rddir_p, const char * path); - lv_fs_res_t (*dir_read) (void * rddir_p, char * fn); - lv_fs_res_t (*dir_close) (void * rddir_p); -} lv_fs_drv_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the File system interface - */ -void lv_fs_init(void); - -/** - * Add a new drive - * @param drv_p pointer to an lv_fs_drv_t structure which is inited with the - * corresponding function pointers. The data will be copied so the variable can be local. - */ -void lv_fs_add_drv(lv_fs_drv_t * drv_p); - -/** - * Test if a drive is rady or not. If the `ready` function was not initialized `true` will be returned. - * @param letter letter of the drive - * @return true: drive is ready; false: drive is not ready - */ -bool lv_fs_is_ready(char letter); - -/** - * Open a file - * @param file_p pointer to a lv_fs_file_t variable - * @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt) - * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_open (lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode); - -/** - * Close an already opened file - * @param file_p pointer to a lv_fs_file_t variable - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_close (lv_fs_file_t * file_p); - -/** - * Delete a file - * @param path path of the file to delete - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_remove (const char * path); - -/** - * Read from a file - * @param file_p pointer to a lv_fs_file_t variable - * @param buf pointer to a buffer where the read bytes are stored - * @param btr Bytes To Read - * @param br the number of real read bytes (Bytes Read). NULL if unused. - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_read (lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br); - -/** - * Write into a file - * @param file_p pointer to a lv_fs_file_t variable - * @param buf pointer to a buffer with the bytes to write - * @param btr Bytes To Write - * @param br the number of real written bytes (Bytes Written). NULL if unused. - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_write (lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw); - -/** - * Set the position of the 'cursor' (read write pointer) in a file - * @param file_p pointer to a lv_fs_file_t variable - * @param pos the new position expressed in bytes index (0: start of file) - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_seek (lv_fs_file_t * file_p, uint32_t pos); - -/** - * Give the position of the read write pointer - * @param file_p pointer to a lv_fs_file_t variable - * @param pos_p pointer to store the position of the read write pointer - * @return LV_FS_RES_OK or any error from 'fs_res_t' - */ -lv_fs_res_t lv_fs_tell (lv_fs_file_t * file_p, uint32_t * pos); - -/** - * Truncate the file size to the current position of the read write pointer - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open ) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_trunc (lv_fs_file_t * file_p); - -/** - * Give the size of a file bytes - * @param file_p pointer to a lv_fs_file_t variable - * @param size pointer to a variable to store the size - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_size (lv_fs_file_t * file_p, uint32_t * size); - -/** - * Rename a file - * @param oldname path to the file - * @param newname path with the new name - * @return LV_FS_RES_OK or any error from 'fs_res_t' - */ -lv_fs_res_t lv_fs_rename (const char * oldname, const char * newname); - -/** - * Initialize a 'fs_dir_t' variable for directory reading - * @param rddir_p pointer to a 'fs_read_dir_t' variable - * @param path path to a directory - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path); - -/** - * Read the next filename form a directory. - * The name of the directories will begin with '/' - * @param rddir_p pointer to an initialized 'fs_rdir_t' variable - * @param fn pointer to a buffer to store the filename - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_dir_read (lv_fs_dir_t * rddir_p, char * fn); - -/** - * Close the directory reading - * @param rddir_p pointer to an initialized 'fs_dir_t' variable - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_dir_close (lv_fs_dir_t * rddir_p); - -/** - * Get the free and total size of a driver in kB - * @param letter the driver letter - * @param total_p pointer to store the total size [kB] - * @param free_p pointer to store the free size [kB] - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_fs_free (char letter, uint32_t * total_p, uint32_t * free_p); - -/** - * Fill a buffer with the letters of existing drivers - * @param buf buffer to store the letters ('\0' added after the last letter) - * @return the buffer - */ -char * lv_fs_get_letters(char * buf); - -/** - * Return with the extension of the filename - * @param fn string with a filename - * @return pointer to the beginning extension or empty string if no extension - */ -const char * lv_fs_get_ext(const char * fn); - -/** - * Step up one level - * @param path pointer to a file name - * @return the truncated file name - */ -char * lv_fs_up(char * path); - -/** - * Get the last element of a path (e.g. U:/folder/file -> file) - * @param buf buffer to store the letters ('\0' added after the last letter) - * @return pointer to the beginning of the last element in the path - */ -const char * lv_fs_get_last(const char * path); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_FILESYSTEM*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_FS_H*/ diff --git a/include/display/lv_misc/lv_gc.h b/include/display/lv_misc/lv_gc.h deleted file mode 100644 index e3d0d8ac..00000000 --- a/include/display/lv_misc/lv_gc.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @file lv_gc.h - * - */ - -#ifndef LV_GC_H -#define LV_GC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include "lv_mem.h" -#include "lv_ll.h" - -/********************* - * DEFINES - *********************/ - -#define LV_GC_ROOTS(prefix) \ - prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \ - prefix lv_ll_t _lv_scr_ll; /*Linked list of screens*/ \ - prefix lv_ll_t _lv_drv_ll;\ - prefix lv_ll_t _lv_file_ll;\ - prefix lv_ll_t _lv_anim_ll;\ - prefix void * _lv_def_scr;\ - prefix void * _lv_act_scr;\ - prefix void * _lv_top_layer;\ - prefix void * _lv_sys_layer;\ - prefix void * _lv_task_act;\ - prefix void * _lv_indev_list;\ - prefix void * _lv_disp_list;\ - - -#define LV_NO_PREFIX -#define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX) - -#if LV_ENABLE_GC == 1 -# if LV_MEM_CUSTOM != 1 -# error "GC requires CUSTOM_MEM" -# endif /* LV_MEM_CUSTOM */ -#else /* LV_ENABLE_GC */ -# define LV_GC_ROOT(x) x - LV_GC_ROOTS(extern) -#endif /* LV_ENABLE_GC */ - - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_GC_H*/ diff --git a/include/display/lv_misc/lv_log.h b/include/display/lv_misc/lv_log.h deleted file mode 100644 index adcb846d..00000000 --- a/include/display/lv_misc/lv_log.h +++ /dev/null @@ -1,86 +0,0 @@ -/** - * @file lv_log.h - * - */ - -#ifndef LV_LOG_H -#define LV_LOG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif -#include - -/********************* - * DEFINES - *********************/ - -/*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/ - -#define LV_LOG_LEVEL_TRACE 0 /*A lot of logs to give detailed information*/ -#define LV_LOG_LEVEL_INFO 1 /*Log important events*/ -#define LV_LOG_LEVEL_WARN 2 /*Log if something unwanted happened but didn't caused problem*/ -#define LV_LOG_LEVEL_ERROR 3 /*Only critical issue, when the system may fail*/ -#define _LV_LOG_LEVEL_NUM 4 - -typedef int8_t lv_log_level_t; - -#if USE_LV_LOG -/********************** - * TYPEDEFS - **********************/ - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Register custom print (or anything else) function to call when log is added - * @param f a function pointer: - * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` - */ -void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)); - -/** - * Add a log - * @param level the level of log. (From `lv_log_level_t` enum) - * @param file name of the file when the log added - * @param line line number in the source code where the log added - * @param dsc description of the log - */ -void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc); - -/********************** - * MACROS - **********************/ - -#define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc); -#define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc); -#define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc); -#define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc); - -#else /*USE_LV_LOG*/ - -/*Do nothing if `USE_LV_LOG 0`*/ -#define lv_log_add(level, file, line, dsc) {;} -#define LV_LOG_TRACE(dsc) {;} -#define LV_LOG_INFO(dsc) {;} -#define LV_LOG_WARN(dsc) {;} -#define LV_LOG_ERROR(dsc) {;} -#endif /*USE_LV_LOG*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LOG_H*/ diff --git a/include/display/lv_misc/lv_math.h b/include/display/lv_misc/lv_math.h deleted file mode 100644 index a0229eb1..00000000 --- a/include/display/lv_misc/lv_math.h +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @file math_base.h - * - */ - -#ifndef LV_MATH_H -#define LV_MATH_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#include - -/********************* - * DEFINES - *********************/ -#define LV_MATH_MIN(a,b) ((a) < (b) ? (a) : (b)) -#define LV_MATH_MAX(a,b) ((a) > (b) ? (a) : (b)) -#define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x))) - -#define LV_TRIGO_SIN_MAX 32767 -#define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/ - -#define LV_BEZIER_VAL_MAX 1024 /*Max time in Bezier functions (not [0..1] to use integers) */ -#define LV_BEZIER_VAL_SHIFT 10 /*log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -/** - * Convert a number to string - * @param num a number - * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) - * @return same as `buf` (just for convenience) - */ -char * lv_math_num_to_str(int32_t num, char * buf); - -/** - * Return with sinus of an angle - * @param angle - * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 - */ -int16_t lv_trigo_sin(int16_t angle); - -/** - * Calculate a value of a Cubic Bezier function. - * @param t time in range of [0..LV_BEZIER_VAL_MAX] - * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] - * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] - * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] - * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] - * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] - */ -int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/include/display/lv_misc/lv_mem.h b/include/display/lv_misc/lv_mem.h deleted file mode 100644 index 77429018..00000000 --- a/include/display/lv_misc/lv_mem.h +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @file lv_mem.h - * - */ - -#ifndef LV_MEM_H -#define LV_MEM_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include "lv_log.h" - -/********************* - * DEFINES - *********************/ -// Check windows -#ifdef __WIN64 -# define LV_MEM_ENV64 -#endif - -// Check GCC -#ifdef __GNUC__ -# if defined(__x86_64__) || defined(__ppc64__) -# define LV_MEM_ENV64 -# endif -#endif - -/********************** - * TYPEDEFS - **********************/ - -typedef struct -{ - uint32_t total_size; - uint32_t free_cnt; - uint32_t free_size; - uint32_t free_biggest_size; - uint32_t used_cnt; - uint8_t used_pct; - uint8_t frag_pct; -} lv_mem_monitor_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Initiaize the dyn_mem module (work memory and other variables) - */ -void lv_mem_init(void); - -/** - * Allocate a memory dynamically - * @param size size of the memory to allocate in bytes - * @return pointer to the allocated memory - */ -void * lv_mem_alloc(uint32_t size); - -/** - * Free an allocated data - * @param data pointer to an allocated memory - */ -void lv_mem_free(const void * data); - -/** - * Reallocate a memory with a new size. The old content will be kept. - * @param data pointer to an allocated memory. - * Its content will be copied to the new memory block and freed - * @param new_size the desired new size in byte - * @return pointer to the new memory - */ -void * lv_mem_realloc(void * data_p, uint32_t new_size); - -/** - * Join the adjacent free memory blocks - */ -void lv_mem_defrag(void); - -/** - * Give information about the work memory of dynamic allocation - * @param mon_p pointer to a dm_mon_p variable, - * the result of the analysis will be stored here - */ -void lv_mem_monitor(lv_mem_monitor_t * mon_p); - -/** - * Give the size of an allocated memory - * @param data pointer to an allocated memory - * @return the size of data memory in bytes - */ -uint32_t lv_mem_get_size(const void * data); - - -/********************** - * MACROS - **********************/ - -/** - * Halt on NULL pointer - * p pointer to a memory - */ -#if USE_LV_LOG == 0 -# define lv_mem_assert(p) {if(p == NULL) while(1); } -#else -# define lv_mem_assert(p) {if(p == NULL) {LV_LOG_ERROR("Out of memory!"); while(1); }} -#endif -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_MEM_H*/ - diff --git a/include/display/lv_misc/lv_misc.mk b/include/display/lv_misc/lv_misc.mk deleted file mode 100644 index 470f1230..00000000 --- a/include/display/lv_misc/lv_misc.mk +++ /dev/null @@ -1,19 +0,0 @@ -CSRCS += lv_font.c -CSRCS += lv_circ.c -CSRCS += lv_area.c -CSRCS += lv_task.c -CSRCS += lv_fs.c -CSRCS += lv_anim.c -CSRCS += lv_mem.c -CSRCS += lv_ll.c -CSRCS += lv_color.c -CSRCS += lv_txt.c -CSRCS += lv_ufs.c -CSRCS += lv_math.c -CSRCS += lv_log.c -CSRCS += lv_gc.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_misc -VPATH += :$(LVGL_DIR)/lvgl/lv_misc - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc" diff --git a/include/display/lv_misc/lv_symbol_def.h b/include/display/lv_misc/lv_symbol_def.h deleted file mode 100644 index 6ba6241c..00000000 --- a/include/display/lv_misc/lv_symbol_def.h +++ /dev/null @@ -1,207 +0,0 @@ -#ifndef LV_SYMBOL_DEF_H -#define LV_SYMBOL_DEF_H - -#ifdef __cplusplus -extern "C" { -#endif -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -/* - * With no UTF-8 support (192- 255) (192..241 is used) - * - * With UTF-8 support (in Supplemental Private Use Area-A): 0xF800 .. 0xF831 - * - Basic symbols: 0xE000..0xE01F - * - File symbols: 0xE020..0xE03F - * - Feedback symbols: 0xE040..0xE05F - * - Reserved: 0xE060..0xE07F - */ - -#if LV_TXT_UTF8 == 0 -#define LV_SYMBOL_GLYPH_FIRST 0xC0 -#define SYMBOL_AUDIO _SYMBOL_VALUE1(C0) -#define SYMBOL_VIDEO _SYMBOL_VALUE1(C1) -#define SYMBOL_LIST _SYMBOL_VALUE1(C2) -#define SYMBOL_OK _SYMBOL_VALUE1(C3) -#define SYMBOL_CLOSE _SYMBOL_VALUE1(C4) -#define SYMBOL_POWER _SYMBOL_VALUE1(C5) -#define SYMBOL_SETTINGS _SYMBOL_VALUE1(C6) -#define SYMBOL_TRASH _SYMBOL_VALUE1(C7) -#define SYMBOL_HOME _SYMBOL_VALUE1(C8) -#define SYMBOL_DOWNLOAD _SYMBOL_VALUE1(C9) -#define SYMBOL_DRIVE _SYMBOL_VALUE1(CA) -#define SYMBOL_REFRESH _SYMBOL_VALUE1(CB) -#define SYMBOL_MUTE _SYMBOL_VALUE1(CC) -#define SYMBOL_VOLUME_MID _SYMBOL_VALUE1(CD) -#define SYMBOL_VOLUME_MAX _SYMBOL_VALUE1(CE) -#define SYMBOL_IMAGE _SYMBOL_VALUE1(CF) -#define SYMBOL_EDIT _SYMBOL_VALUE1(D0) -#define SYMBOL_PREV _SYMBOL_VALUE1(D1) -#define SYMBOL_PLAY _SYMBOL_VALUE1(D2) -#define SYMBOL_PAUSE _SYMBOL_VALUE1(D3) -#define SYMBOL_STOP _SYMBOL_VALUE1(D4) -#define SYMBOL_NEXT _SYMBOL_VALUE1(D5) -#define SYMBOL_EJECT _SYMBOL_VALUE1(D6) -#define SYMBOL_LEFT _SYMBOL_VALUE1(D7) -#define SYMBOL_RIGHT _SYMBOL_VALUE1(D8) -#define SYMBOL_PLUS _SYMBOL_VALUE1(D9) -#define SYMBOL_MINUS _SYMBOL_VALUE1(DA) -#define SYMBOL_WARNING _SYMBOL_VALUE1(DB) -#define SYMBOL_SHUFFLE _SYMBOL_VALUE1(DC) -#define SYMBOL_UP _SYMBOL_VALUE1(DD) -#define SYMBOL_DOWN _SYMBOL_VALUE1(DE) -#define SYMBOL_LOOP _SYMBOL_VALUE1(DF) -#define SYMBOL_DIRECTORY _SYMBOL_VALUE1(E0) -#define SYMBOL_UPLOAD _SYMBOL_VALUE1(E1) -#define SYMBOL_CALL _SYMBOL_VALUE1(E2) -#define SYMBOL_CUT _SYMBOL_VALUE1(E3) -#define SYMBOL_COPY _SYMBOL_VALUE1(E4) -#define SYMBOL_SAVE _SYMBOL_VALUE1(E5) -#define SYMBOL_CHARGE _SYMBOL_VALUE1(E6) -#define SYMBOL_BELL _SYMBOL_VALUE1(E7) -#define SYMBOL_KEYBOARD _SYMBOL_VALUE1(E8) -#define SYMBOL_GPS _SYMBOL_VALUE1(E9) -#define SYMBOL_FILE _SYMBOL_VALUE1(EA) -#define SYMBOL_WIFI _SYMBOL_VALUE1(EB) -#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE1(EC) -#define SYMBOL_BATTERY_3 _SYMBOL_VALUE1(ED) -#define SYMBOL_BATTERY_2 _SYMBOL_VALUE1(EE) -#define SYMBOL_BATTERY_1 _SYMBOL_VALUE1(EF) -#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE1(F0) -#define SYMBOL_BLUETOOTH _SYMBOL_VALUE1(F1) -#define LV_SYMBOL_GLYPH_LAST 0xF1 -#define SYMBOL_DUMMY _SYMBOL_VALUE1(FF) /*Invalid symbol. If written before a string then `lv_img` will show it as a label*/ - -#else -#define LV_SYMBOL_GLYPH_FIRST 0xF800 -#define SYMBOL_AUDIO _SYMBOL_VALUE3(EF,A0,80) -#define SYMBOL_VIDEO _SYMBOL_VALUE3(EF,A0,81) -#define SYMBOL_LIST _SYMBOL_VALUE3(EF,A0,82) -#define SYMBOL_OK _SYMBOL_VALUE3(EF,A0,83) -#define SYMBOL_CLOSE _SYMBOL_VALUE3(EF,A0,84) -#define SYMBOL_POWER _SYMBOL_VALUE3(EF,A0,85) -#define SYMBOL_SETTINGS _SYMBOL_VALUE3(EF,A0,86) -#define SYMBOL_TRASH _SYMBOL_VALUE3(EF,A0,87) -#define SYMBOL_HOME _SYMBOL_VALUE3(EF,A0,88) -#define SYMBOL_DOWNLOAD _SYMBOL_VALUE3(EF,A0,89) -#define SYMBOL_DRIVE _SYMBOL_VALUE3(EF,A0,8A) -#define SYMBOL_REFRESH _SYMBOL_VALUE3(EF,A0,8B) -#define SYMBOL_MUTE _SYMBOL_VALUE3(EF,A0,8C) -#define SYMBOL_VOLUME_MID _SYMBOL_VALUE3(EF,A0,8D) -#define SYMBOL_VOLUME_MAX _SYMBOL_VALUE3(EF,A0,8E) -#define SYMBOL_IMAGE _SYMBOL_VALUE3(EF,A0,8F) -#define SYMBOL_EDIT _SYMBOL_VALUE3(EF,A0,90) -#define SYMBOL_PREV _SYMBOL_VALUE3(EF,A0,91) -#define SYMBOL_PLAY _SYMBOL_VALUE3(EF,A0,92) -#define SYMBOL_PAUSE _SYMBOL_VALUE3(EF,A0,93) -#define SYMBOL_STOP _SYMBOL_VALUE3(EF,A0,94) -#define SYMBOL_NEXT _SYMBOL_VALUE3(EF,A0,95) -#define SYMBOL_EJECT _SYMBOL_VALUE3(EF,A0,96) -#define SYMBOL_LEFT _SYMBOL_VALUE3(EF,A0,97) -#define SYMBOL_RIGHT _SYMBOL_VALUE3(EF,A0,98) -#define SYMBOL_PLUS _SYMBOL_VALUE3(EF,A0,99) -#define SYMBOL_MINUS _SYMBOL_VALUE3(EF,A0,9A) -#define SYMBOL_WARNING _SYMBOL_VALUE3(EF,A0,9B) -#define SYMBOL_SHUFFLE _SYMBOL_VALUE3(EF,A0,9C) -#define SYMBOL_UP _SYMBOL_VALUE3(EF,A0,9D) -#define SYMBOL_DOWN _SYMBOL_VALUE3(EF,A0,9E) -#define SYMBOL_LOOP _SYMBOL_VALUE3(EF,A0,9F) -#define SYMBOL_DIRECTORY _SYMBOL_VALUE3(EF,A0,A0) -#define SYMBOL_UPLOAD _SYMBOL_VALUE3(EF,A0,A1) -#define SYMBOL_CALL _SYMBOL_VALUE3(EF,A0,A2) -#define SYMBOL_CUT _SYMBOL_VALUE3(EF,A0,A3) -#define SYMBOL_COPY _SYMBOL_VALUE3(EF,A0,A4) -#define SYMBOL_SAVE _SYMBOL_VALUE3(EF,A0,A5) -#define SYMBOL_CHARGE _SYMBOL_VALUE3(EF,A0,A6) -#define SYMBOL_BELL _SYMBOL_VALUE3(EF,A0,A7) -#define SYMBOL_KEYBOARD _SYMBOL_VALUE3(EF,A0,A8) -#define SYMBOL_GPS _SYMBOL_VALUE3(EF,A0,A9) -#define SYMBOL_FILE _SYMBOL_VALUE3(EF,A0,AA) -#define SYMBOL_WIFI _SYMBOL_VALUE3(EF,A0,AB) -#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE3(EF,A0,AC) -#define SYMBOL_BATTERY_3 _SYMBOL_VALUE3(EF,A0,AD) -#define SYMBOL_BATTERY_2 _SYMBOL_VALUE3(EF,A0,AE) -#define SYMBOL_BATTERY_1 _SYMBOL_VALUE3(EF,A0,AF) -#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE3(EF,A0,B0) -#define SYMBOL_BLUETOOTH _SYMBOL_VALUE3(EF,A0,B1) -#define LV_SYMBOL_GLYPH_LAST 0xF831 -#define SYMBOL_DUMMY _SYMBOL_VALUE3(EF,A3,BF) /*Invalid symbol at (U+F831). If written before a string then `lv_img` will show it as a label*/ -#endif - -#define _SYMBOL_VALUE1(x) (0x ## x) -#define _SYMBOL_VALUE3(x, y, z) (0x ## z ## y ## x) -#define _SYMBOL_NUMSTR(sym) LV_ ## sym ## _NUMSTR = sym - -enum -{ - _SYMBOL_NUMSTR(SYMBOL_AUDIO), - _SYMBOL_NUMSTR(SYMBOL_VIDEO), - _SYMBOL_NUMSTR(SYMBOL_LIST), - _SYMBOL_NUMSTR(SYMBOL_OK), - _SYMBOL_NUMSTR(SYMBOL_CLOSE), - _SYMBOL_NUMSTR(SYMBOL_POWER), - _SYMBOL_NUMSTR(SYMBOL_SETTINGS), - _SYMBOL_NUMSTR(SYMBOL_TRASH), - _SYMBOL_NUMSTR(SYMBOL_HOME), - _SYMBOL_NUMSTR(SYMBOL_DOWNLOAD), - _SYMBOL_NUMSTR(SYMBOL_DRIVE), - _SYMBOL_NUMSTR(SYMBOL_REFRESH), - _SYMBOL_NUMSTR(SYMBOL_MUTE), - _SYMBOL_NUMSTR(SYMBOL_VOLUME_MID), - _SYMBOL_NUMSTR(SYMBOL_VOLUME_MAX), - _SYMBOL_NUMSTR(SYMBOL_IMAGE), - _SYMBOL_NUMSTR(SYMBOL_EDIT), - _SYMBOL_NUMSTR(SYMBOL_PREV), - _SYMBOL_NUMSTR(SYMBOL_PLAY), - _SYMBOL_NUMSTR(SYMBOL_PAUSE), - _SYMBOL_NUMSTR(SYMBOL_STOP), - _SYMBOL_NUMSTR(SYMBOL_NEXT), - _SYMBOL_NUMSTR(SYMBOL_EJECT), - _SYMBOL_NUMSTR(SYMBOL_LEFT), - _SYMBOL_NUMSTR(SYMBOL_RIGHT), - _SYMBOL_NUMSTR(SYMBOL_PLUS), - _SYMBOL_NUMSTR(SYMBOL_MINUS), - _SYMBOL_NUMSTR(SYMBOL_WARNING), - _SYMBOL_NUMSTR(SYMBOL_SHUFFLE), - _SYMBOL_NUMSTR(SYMBOL_UP), - _SYMBOL_NUMSTR(SYMBOL_DOWN), - _SYMBOL_NUMSTR(SYMBOL_LOOP), - _SYMBOL_NUMSTR(SYMBOL_DIRECTORY), - _SYMBOL_NUMSTR(SYMBOL_UPLOAD), - _SYMBOL_NUMSTR(SYMBOL_CALL), - _SYMBOL_NUMSTR(SYMBOL_CUT), - _SYMBOL_NUMSTR(SYMBOL_COPY), - _SYMBOL_NUMSTR(SYMBOL_SAVE), - _SYMBOL_NUMSTR(SYMBOL_CHARGE), - _SYMBOL_NUMSTR(SYMBOL_BELL), - _SYMBOL_NUMSTR(SYMBOL_KEYBOARD), - _SYMBOL_NUMSTR(SYMBOL_GPS), - _SYMBOL_NUMSTR(SYMBOL_FILE), - _SYMBOL_NUMSTR(SYMBOL_WIFI), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_FULL), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_3), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_2), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_1), - _SYMBOL_NUMSTR(SYMBOL_BATTERY_EMPTY), - _SYMBOL_NUMSTR(SYMBOL_BLUETOOTH), - _SYMBOL_NUMSTR(SYMBOL_DUMMY), -}; - -#undef _SYMBOL_VALUE1 -#undef _SYMBOL_VALUE3 - -#define _SYMBOL_STR_(x) #x -#define _SYMBOL_STR(x) _SYMBOL_STR_(x) -#define _SYMBOL_CHAR(c) \x ## c -#define _SYMBOL_VALUE1(x) _SYMBOL_STR(_SYMBOL_CHAR(x)) -#define _SYMBOL_VALUE3(x, y, z) _SYMBOL_STR(_SYMBOL_CHAR(x)_SYMBOL_CHAR(y)_SYMBOL_CHAR(z)) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /*LV_SYMBOL_DEF_H*/ diff --git a/include/display/lv_misc/lv_task.h b/include/display/lv_misc/lv_task.h deleted file mode 100644 index 6cac3efd..00000000 --- a/include/display/lv_misc/lv_task.h +++ /dev/null @@ -1,149 +0,0 @@ -/** - * @file lv_task.c - * An 'lv_task' is a void (*fp) (void* param) type function which will be called periodically. - * A priority (5 levels + disable) can be assigned to lv_tasks. - */ - -#ifndef LV_TASK_H -#define LV_TASK_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include -#include "lv_mem.h" -#include "lv_ll.h" - -/********************* - * DEFINES - *********************/ -#ifndef LV_ATTRIBUTE_TASK_HANDLER -#define LV_ATTRIBUTE_TASK_HANDLER -#endif -/********************** - * TYPEDEFS - **********************/ -/** - * Possible priorities for lv_tasks - */ -enum -{ - LV_TASK_PRIO_OFF = 0, - LV_TASK_PRIO_LOWEST, - LV_TASK_PRIO_LOW, - LV_TASK_PRIO_MID, - LV_TASK_PRIO_HIGH, - LV_TASK_PRIO_HIGHEST, - LV_TASK_PRIO_NUM, -}; -typedef uint8_t lv_task_prio_t; - -/** - * Descriptor of a lv_task - */ -typedef struct -{ - uint32_t period; - uint32_t last_run; - void (*task) (void*); - void * param; - uint8_t prio:3; - uint8_t once:1; -} lv_task_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Init the lv_task module - */ -void lv_task_init(void); - -/** - * Call it periodically to handle lv_tasks. - */ -LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void); - -/** - * Create a new lv_task - * @param task a function which is the task itself - * @param period call period in ms unit - * @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped) - * @param param free parameter - * @return pointer to the new task - */ -lv_task_t* lv_task_create(void (*task) (void *), uint32_t period, lv_task_prio_t prio, void * param); - -/** - * Delete a lv_task - * @param lv_task_p pointer to task created by lv_task_p - */ -void lv_task_del(lv_task_t* lv_task_p); - -/** - * Set new priority for a lv_task - * @param lv_task_p pointer to a lv_task - * @param prio the new priority - */ -void lv_task_set_prio(lv_task_t* lv_task_p, lv_task_prio_t prio); - -/** - * Set new period for a lv_task - * @param lv_task_p pointer to a lv_task - * @param period the new period - */ -void lv_task_set_period(lv_task_t* lv_task_p, uint32_t period); - -/** - * Make a lv_task ready. It will not wait its period. - * @param lv_task_p pointer to a lv_task. - */ -void lv_task_ready(lv_task_t* lv_task_p); - - -/** - * Delete the lv_task after one call - * @param lv_task_p pointer to a lv_task. - */ -void lv_task_once(lv_task_t * lv_task_p); - -/** - * Reset a lv_task. - * It will be called the previously set period milliseconds later. - * @param lv_task_p pointer to a lv_task. - */ -void lv_task_reset(lv_task_t* lv_task_p); - -/** - * Enable or disable the whole lv_task handling - * @param en: true: lv_task handling is running, false: lv_task handling is suspended - */ -void lv_task_enable(bool en); - -/** - * Get idle percentage - * @return the lv_task idle in percentage - */ -uint8_t lv_task_get_idle(void); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/include/display/lv_misc/lv_txt.h b/include/display/lv_misc/lv_txt.h deleted file mode 100644 index 2e98b60e..00000000 --- a/include/display/lv_misc/lv_txt.h +++ /dev/null @@ -1,198 +0,0 @@ -/** - * @file lv_text.h - * - */ - -#ifndef LV_TXT_H -#define LV_TXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include -#include "lv_area.h" -#include "lv_font.h" -#include "lv_area.h" - -/********************* - * DEFINES - *********************/ -#define LV_TXT_COLOR_CMD "#" - -/********************** - * TYPEDEFS - **********************/ -enum -{ - LV_TXT_FLAG_NONE = 0x00, - LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/ - LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width to avoid automatic word wrapping*/ - LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/ - LV_TXT_FLAG_RIGHT = 0x08, /*Align the text to the right*/ -}; -typedef uint8_t lv_txt_flag_t; - -enum -{ - LV_TXT_CMD_STATE_WAIT, /*Waiting for command*/ - LV_TXT_CMD_STATE_PAR, /*Processing the parameter*/ - LV_TXT_CMD_STATE_IN, /*Processing the command*/ -}; -typedef uint8_t lv_txt_cmd_state_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Get size of a text - * @param size_res pointer to a 'point_t' variable to store the result - * @param text pointer to a text - * @param font pinter to font of the text - * @param letter_space letter space of the text - * @param line_space line space of the text - * @param flags settings for the text from 'txt_flag_t' enum - * @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks - */ -void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, - lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag); - -/** - * Get the next line of text. Check line length and break chars too. - * @param txt a '\0' terminated string - * @param font pointer to a font - * @param letter_space letter space - * @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks - * @param flags settings for the text from 'txt_flag_type' enum - * @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different) - */ -uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, - lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag); - -/** - * Give the length of a text with a given font - * @param txt a '\0' terminate string - * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8) - * @param font pointer to a font - * @param letter_space letter space - * @param flags settings for the text from 'txt_flag_t' enum - * @return length of a char_num long text - */ -lv_coord_t lv_txt_get_width(const char * txt, uint16_t length, - const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag); - - -/** - * Check next character in a string and decide if te character is part of the command or not - * @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing - * @param c the current character - * @return true: the character is part of a command and should not be written, - * false: the character should be written - */ -bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c); - -/** - * Insert a string into an other - * @param txt_buf the original text (must be big enough for the result text) - * @param pos position to insert (0: before the original text, 1: after the first char etc.) - * @param ins_txt text to insert - */ -void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt); - -/** - * Delete a part of a string - * @param txt string to modify - * @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.) - * @param len number of characters to delete - */ -void lv_txt_cut(char * txt, uint32_t pos, uint32_t len); - -/*************************************************************** - * GLOBAL FUNCTION POINTERS FOR CAHRACTER ENCODING INTERFACE - ***************************************************************/ - -/** - * Give the size of an encoded character - * @param str pointer to a character in a string - * @return length of the encoded character (1,2,3 ...). O in invalid - */ -extern uint8_t (*lv_txt_encoded_size)(const char *); - - -/** - * Convert an Unicode letter to encoded - * @param letter_uni an Unicode letter - * @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü') - */ -extern uint32_t (*lv_txt_unicode_to_encoded)(uint32_t ); - -/** - * Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format. - * @param c a wide character - * @return `c` in the encoded format - */ -extern uint32_t (*lv_txt_encoded_conv_wc) (uint32_t c); - -/** - * Decode the next encoded character from a string. - * @param txt pointer to '\0' terminated string - * @param i start index in 'txt' where to start. - * After the call it will point to the next encoded char in 'txt'. - * NULL to use txt[0] as index - * @return the decoded Unicode character or 0 on invalid data code - */ -extern uint32_t (*lv_txt_encoded_next)(const char *, uint32_t * ); - -/** - * Get the previous encoded character form a string. - * @param txt pointer to '\0' terminated string - * @param i_start index in 'txt' where to start. After the call it will point to the previous encoded char in 'txt'. - * @return the decoded Unicode character or 0 on invalid data - */ -extern uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *); - -/** - * Convert a letter index (in an the encoded text) to byte index. - * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long - * @param txt a '\0' terminated UTF-8 string - * @param enc_id letter index - * @return byte index of the 'enc_id'th letter - */ -extern uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t); - -/** - * Convert a byte index (in an encoded text) to character index. - * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long - * @param txt a '\0' terminated UTF-8 string - * @param byte_id byte index - * @return character index of the letter at 'byte_id'th position - */ -extern uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t); - -/** - * Get the number of characters (and NOT bytes) in a string. - * E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes) - * @param txt a '\0' terminated char string - * @return number of characters - */ -extern uint32_t (*lv_txt_get_encoded_length)(const char *); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*USE_TXT*/ diff --git a/include/display/lv_misc/lv_ufs.h b/include/display/lv_misc/lv_ufs.h deleted file mode 100644 index d30cbe0f..00000000 --- a/include/display/lv_misc/lv_ufs.h +++ /dev/null @@ -1,214 +0,0 @@ -/** - * @file lv_ufs.h - * Implementation of RAM file system which do NOT support directories. - * The API is compatible with the lv_fs_int module. - */ - -#ifndef LV_UFS_H -#define LV_UFS_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_FILESYSTEM - -#include -#include "lv_fs.h" -#include "lv_mem.h" - -/********************* - * DEFINES - *********************/ -#define UFS_LETTER 'U' - -/********************** - * TYPEDEFS - **********************/ -/*Description of a file entry */ -typedef struct -{ - char * fn_d; - void * data_d; - uint32_t size; /*Data length in bytes*/ - uint16_t oc; /*Open Count*/ - uint8_t const_data :1; -} lv_ufs_ent_t; - -/*File descriptor, used to handle opening an entry more times simultaneously - Contains unique informations about the specific opening*/ -typedef struct -{ - lv_ufs_ent_t* ent; /*Pointer to the entry*/ - uint32_t rwp; /*Read Write Pointer*/ - uint8_t ar :1; /*1: Access for read is enabled */ - uint8_t aw :1; /*1: Access for write is enabled */ -} lv_ufs_file_t; - -/* Read directory descriptor. - * It is used to to iterate through the entries in a directory*/ -typedef struct -{ - lv_ufs_ent_t * last_ent; -} lv_ufs_dir_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a driver for ufs and initialize it. - */ -void lv_ufs_init(void); - -/** - * Give the state of the ufs - * @return true if ufs is initialized and can be used else false - */ -bool lv_ufs_ready(void); - -/** - * Open a file in ufs - * @param file_p pointer to a lv_ufs_file_t variable - * @param fn name of the file. There are no directories so e.g. "myfile.txt" - * @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD) - * @return LV_FS_RES_OK: no error, the file is opened - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode); - -/** - * Create a file with a constant data - * @param fn name of the file (directories are not supported) - * @param const_p pointer to a constant data - * @param len length of the data pointed by 'const_p' in bytes - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len); - -/** - * Close an opened file - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_close (void * file_p); - -/** - * Remove a file. The file can not be opened. - * @param fn '\0' terminated string - * @return LV_FS_RES_OK: no error, the file is removed - * LV_FS_RES_DENIED: the file was opened, remove failed - */ -lv_fs_res_t lv_ufs_remove(const char * fn); - -/** - * Read data from an opened file - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @param buf pointer to a memory block where to store the read data - * @param btr number of Bytes To Read - * @param br the real number of read bytes (Byte Read) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br); - -/** - * Write data to an opened file - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open) - * @param buf pointer to a memory block which content will be written - * @param btw the number Bytes To Write - * @param bw The real number of written bytes (Byte Written) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw); - -/** - * Set the read write pointer. Also expand the file size if necessary. - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @param pos the new position of read write pointer - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos); - -/** - * Give the position of the read write pointer - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @param pos_p pointer to to store the result - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p); - -/** - * Truncate the file size to the current position of the read write pointer - * @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_trunc (void * file_p); - -/** - * Give the size of the file in bytes - * @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open ) - * @param size_p pointer to store the size - * @return LV_FS_RES_OK: no error, the file is read - * any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p); - -/** - * Initialize a lv_ufs_read_dir_t variable to directory reading - * @param rddir_p pointer to a 'ufs_read_dir_t' variable - * @param path uFS doesn't support folders so it has to be "" - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path); - -/** - * Read the next file name - * @param dir_p pointer to an initialized 'ufs_read_dir_t' variable - * @param fn pointer to buffer to sore the file name - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn); - -/** - * Close the directory reading - * @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable - * @return LV_FS_RES_OK or any error from lv_fs_res_t enum - */ -lv_fs_res_t lv_ufs_dir_close(void * rddir_p); - -/** - * Give the size of a drive - * @param total_p pointer to store the total size [kB] - * @param free_p pointer to store the free site [kB] - * @return LV_FS_RES_OK or any error from 'fs_res_t' - */ -lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_FILESYSTEM*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/include/display/lv_objx/lv_arc.h b/include/display/lv_objx/lv_arc.h deleted file mode 100644 index 4f82e0d8..00000000 --- a/include/display/lv_objx/lv_arc.h +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @file lv_arc.h - * - */ - - -#ifndef LV_ARC_H -#define LV_ARC_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_ARC != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of arc*/ -typedef struct { - /*New data for this type */ - lv_coord_t angle_start; - lv_coord_t angle_end; -} lv_arc_ext_t; - - -/*Styles*/ -enum { - LV_ARC_STYLE_MAIN, -}; -typedef uint8_t lv_arc_style_t; - - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a arc objects - * @param par pointer to an object, it will be the parent of the new arc - * @param copy pointer to a arc object, if not NULL then the new object will be copied from it - * @return pointer to the created arc - */ -lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc. - * @param arc pointer to an arc object - * @param start the start angle [0..360] - * @param end the end angle [0..360] - */ -void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end); - -/** - * Set a style of a arc. - * @param arc pointer to arc object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_arc_set_style(lv_obj_t * arc, lv_arc_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the start angle of an arc. - * @param arc pointer to an arc object - * @return the start angle [0..360] - */ -uint16_t lv_arc_get_angle_start(lv_obj_t * arc); - -/** - * Get the end angle of an arc. - * @param arc pointer to an arc object - * @return the end angle [0..360] - */ -uint16_t lv_arc_get_angle_end(lv_obj_t * arc); - -/** - * Get style of a arc. - * @param arc pointer to arc object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_arc_get_style(const lv_obj_t * arc, lv_arc_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_ARC*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_ARC_H*/ diff --git a/include/display/lv_objx/lv_bar.h b/include/display/lv_objx/lv_bar.h deleted file mode 100644 index 3938aa28..00000000 --- a/include/display/lv_objx/lv_bar.h +++ /dev/null @@ -1,160 +0,0 @@ -/** - * @file lv_bar.h - * - */ - -#ifndef LV_BAR_H -#define LV_BAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_BAR != 0 - -#include "display/lv_core/lv_obj.h" -#include "lv_cont.h" -#include "lv_btn.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of bar*/ -typedef struct -{ - /*No inherited ext*/ /*Ext. of ancestor*/ - /*New data for this type */ - int16_t cur_value; /*Current value of the bar*/ - int16_t min_value; /*Minimum value of the bar*/ - int16_t max_value; /*Maximum value of the bar*/ - uint8_t sym :1; /*Symmetric: means the center is around zero value*/ - lv_style_t *style_indic; /*Style of the indicator*/ -} lv_bar_ext_t; - -enum { - LV_BAR_STYLE_BG, - LV_BAR_STYLE_INDIC, -}; -typedef uint8_t lv_bar_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a bar objects - * @param par pointer to an object, it will be the parent of the new bar - * @param copy pointer to a bar object, if not NULL then the new object will be copied from it - * @return pointer to the created bar - */ -lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new value on the bar - * @param bar pointer to a bar object - * @param value new value - */ -void lv_bar_set_value(lv_obj_t * bar, int16_t value); - -/** - * Set a new value with animation on the bar - * @param bar pointer to a bar object - * @param value new value - * @param anim_time animation time in milliseconds - */ -void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time); - - -/** - * Set minimum and the maximum values of a bar - * @param bar pointer to the bar object - * @param min minimum value - * @param max maximum value - */ -void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max); - -/** - * Make the bar symmetric to zero. The indicator will grow from zero instead of the minimum position. - * @param bar pointer to a bar object - * @param en true: enable disable symmetric behavior; false: disable - */ -void lv_bar_set_sym(lv_obj_t * bar, bool en); - -/** - * Set a style of a bar - * @param bar pointer to a bar object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_bar_set_style(lv_obj_t *bar, lv_bar_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a bar - * @param bar pointer to a bar object - * @return the value of the bar - */ -int16_t lv_bar_get_value(const lv_obj_t * bar); - -/** - * Get the minimum value of a bar - * @param bar pointer to a bar object - * @return the minimum value of the bar - */ -int16_t lv_bar_get_min_value(const lv_obj_t * bar); - -/** - * Get the maximum value of a bar - * @param bar pointer to a bar object - * @return the maximum value of the bar - */ -int16_t lv_bar_get_max_value(const lv_obj_t * bar); - -/** - * Get whether the bar is symmetric or not. - * @param bar pointer to a bar object - * @return true: symmetric is enabled; false: disable - */ -bool lv_bar_get_sym(lv_obj_t * bar); - -/** - * Get a style of a bar - * @param bar pointer to a bar object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_bar_get_style(const lv_obj_t *bar, lv_bar_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_BAR*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_BAR_H*/ diff --git a/include/display/lv_objx/lv_btn.h b/include/display/lv_objx/lv_btn.h deleted file mode 100644 index 805b5d78..00000000 --- a/include/display/lv_objx/lv_btn.h +++ /dev/null @@ -1,279 +0,0 @@ -/** - * @file lv_btn.h - * - */ - -#ifndef LV_BTN_H -#define LV_BTN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_BTN != 0 - -/*Testing of dependencies*/ -#if USE_LV_CONT == 0 -#error "lv_btn: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " -#endif - -#include "lv_cont.h" -#include "display/lv_core/lv_indev.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/* Button states - * It can be used not only by buttons but other button-like objects too*/ -enum -{ - LV_BTN_STATE_REL, - LV_BTN_STATE_PR, - LV_BTN_STATE_TGL_REL, - LV_BTN_STATE_TGL_PR, - LV_BTN_STATE_INA, - LV_BTN_STATE_NUM, -}; -typedef uint8_t lv_btn_state_t; - -enum -{ - LV_BTN_ACTION_CLICK, - LV_BTN_ACTION_PR, - LV_BTN_ACTION_LONG_PR, - LV_BTN_ACTION_LONG_PR_REPEAT, - LV_BTN_ACTION_NUM, -}; -typedef uint8_t lv_btn_action_t; - - -/*Data of button*/ -typedef struct -{ - lv_cont_ext_t cont; /*Ext. of ancestor*/ - /*New data for this type */ - lv_action_t actions[LV_BTN_ACTION_NUM]; - lv_style_t * styles[LV_BTN_STATE_NUM]; /*Styles in each state*/ - lv_btn_state_t state; /*Current state of the button from 'lv_btn_state_t' enum*/ -#if LV_BTN_INK_EFFECT - uint16_t ink_in_time; /*[ms] Time of ink fill effect (0: disable ink effect)*/ - uint16_t ink_wait_time; /*[ms] Wait before the ink disappears */ - uint16_t ink_out_time; /*[ms] Time of ink disappearing*/ -#endif - uint8_t toggle :1; /*1: Toggle enabled*/ - uint8_t long_pr_action_executed :1; /*1: Long press action executed (Handled by the library)*/ -} lv_btn_ext_t; - -/*Styles*/ -enum { - LV_BTN_STYLE_REL, - LV_BTN_STYLE_PR, - LV_BTN_STYLE_TGL_REL, - LV_BTN_STYLE_TGL_PR, - LV_BTN_STYLE_INA, -}; -typedef uint8_t lv_btn_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a button objects - * @param par pointer to an object, it will be the parent of the new button - * @param copy pointer to a button object, if not NULL then the new object will be copied from it - * @return pointer to the created button - */ -lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Enable the toggled states. On release the button will change from/to toggled state. - * @param btn pointer to a button object - * @param tgl true: enable toggled states, false: disable - */ -void lv_btn_set_toggle(lv_obj_t * btn, bool tgl); - -/** - * Set the state of the button - * @param btn pointer to a button object - * @param state the new state of the button (from lv_btn_state_t enum) - */ -void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); - -/** - * Toggle the state of the button (ON->OFF, OFF->ON) - * @param btn pointer to a button object - */ -void lv_btn_toggle(lv_obj_t * btn); - -/** - * Set a function to call when a button event happens - * @param btn pointer to a button object - * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) - */ -void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action); - -/** - * Set the layout on a button - * @param btn pointer to a button object - * @param layout a layout from 'lv_cont_layout_t' - */ -static inline void lv_btn_set_layout(lv_obj_t * btn, lv_layout_t layout) -{ - lv_cont_set_layout(btn, layout); -} - -/** - * Enable the horizontal or vertical fit. - * The button size will be set to involve the children horizontally or vertically. - * @param btn pointer to a button object - * @param hor_en true: enable the horizontal fit - * @param ver_en true: enable the vertical fit - */ -static inline void lv_btn_set_fit(lv_obj_t * btn, bool hor_en, bool ver_en) -{ - lv_cont_set_fit(btn, hor_en, ver_en); -} - -/** - * Set time of the ink effect (draw a circle on click to animate in the new state) - * @param btn pointer to a button object - * @param time the time of the ink animation - */ -void lv_btn_set_ink_in_time(lv_obj_t * btn, uint16_t time); - -/** - * Set the wait time before the ink disappears - * @param btn pointer to a button object - * @param time the time of the ink animation - */ -void lv_btn_set_ink_wait_time(lv_obj_t * btn, uint16_t time); - -/** - * Set time of the ink out effect (animate to the released state) - * @param btn pointer to a button object - * @param time the time of the ink animation - */ -void lv_btn_set_ink_out_time(lv_obj_t * btn, uint16_t time); - -/** - * Set a style of a button. - * @param btn pointer to button object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_btn_set_style(lv_obj_t * btn, lv_btn_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the current state of the button - * @param btn pointer to a button object - * @return the state of the button (from lv_btn_state_t enum) - */ -lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn); - -/** - * Get the toggle enable attribute of the button - * @param btn pointer to a button object - * @return ture: toggle enabled, false: disabled - */ -bool lv_btn_get_toggle(const lv_obj_t * btn); - -/** - * Get the release action of a button - * @param btn pointer to a button object - * @return pointer to the release action function - */ -lv_action_t lv_btn_get_action(const lv_obj_t * btn, lv_btn_action_t type); - -/** - * Get the layout of a button - * @param btn pointer to button object - * @return the layout from 'lv_cont_layout_t' - */ -static inline lv_layout_t lv_btn_get_layout(const lv_obj_t * btn) -{ - return lv_cont_get_layout(btn); -} - -/** - * Get horizontal fit enable attribute of a button - * @param btn pointer to a button object - * @return true: horizontal fit is enabled; false: disabled - */ -static inline bool lv_btn_get_hor_fit(const lv_obj_t * btn) -{ - return lv_cont_get_hor_fit(btn); -} - -/** - * Get vertical fit enable attribute of a container - * @param btn pointer to a button object - * @return true: vertical fit is enabled; false: disabled - */ -static inline bool lv_btn_get_ver_fit(const lv_obj_t * btn) -{ - return lv_cont_get_ver_fit(btn); -} - -/** - * Get time of the ink in effect (draw a circle on click to animate in the new state) - * @param btn pointer to a button object - * @return the time of the ink animation - */ -uint16_t lv_btn_get_ink_in_time(const lv_obj_t * btn); - -/** - * Get the wait time before the ink disappears - * @param btn pointer to a button object - * @return the time of the ink animation - */ -uint16_t lv_btn_get_ink_wait_time(const lv_obj_t * btn); - -/** - * Get time of the ink out effect (animate to the releases state) - * @param btn pointer to a button object - * @return the time of the ink animation - */ -uint16_t lv_btn_get_ink_out_time(const lv_obj_t * btn); - -/** - * Get style of a button. - * @param btn pointer to button object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_btn_get_style(const lv_obj_t * btn, lv_btn_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_BUTTON*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_BTN_H*/ diff --git a/include/display/lv_objx/lv_btnm.h b/include/display/lv_objx/lv_btnm.h deleted file mode 100644 index 89c066a4..00000000 --- a/include/display/lv_objx/lv_btnm.h +++ /dev/null @@ -1,197 +0,0 @@ -/** - * @file lv_btnm.h - * - */ - - -#ifndef LV_BTNM_H -#define LV_BTNM_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_BTNM != 0 - -#include "display/lv_core/lv_obj.h" -#include "lv_label.h" -#include "lv_btn.h" - -/********************* - * DEFINES - *********************/ - -/*Control byte*/ -#define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/ -#define LV_BTNM_CTRL_MASK 0xC0 -#define LV_BTNM_WIDTH_MASK 0x07 -#define LV_BTNM_HIDE_MASK 0x08 -#define LV_BTNM_REPEAT_DISABLE_MASK 0x10 -#define LV_BTNM_INACTIVE_MASK 0x20 - - -#define LV_BTNM_PR_NONE 0xFFFF -/********************** - * TYPEDEFS - **********************/ - -/* Type of callback function which is called when a button is released or long pressed on the button matrix - * Parameters: button matrix, text of the released button - * return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/ -typedef lv_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt); - -/*Data of button matrix*/ -typedef struct -{ - /*No inherited ext.*/ /*Ext. of ancestor*/ - /*New data for this type */ - const char ** map_p; /*Pointer to the current map*/ - lv_area_t *button_areas; /*Array of areas of buttons*/ - lv_btnm_action_t action; /*A function to call when a button is releases*/ - lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/ - uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/ - uint16_t btn_id_pr; /*Index of the currently pressed button (in `button_areas`) or LV_BTNM_PR_NONE*/ - uint16_t btn_id_tgl; /*Index of the currently toggled button (in `button_areas`) or LV_BTNM_PR_NONE */ - uint8_t toggle :1; /*Enable toggling*/ - uint8_t recolor :1; /*Enable button recoloring*/ -} lv_btnm_ext_t; - -enum { - LV_BTNM_STYLE_BG, - LV_BTNM_STYLE_BTN_REL, - LV_BTNM_STYLE_BTN_PR, - LV_BTNM_STYLE_BTN_TGL_REL, - LV_BTNM_STYLE_BTN_TGL_PR, - LV_BTNM_STYLE_BTN_INA, -}; -typedef uint8_t lv_btnm_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a button matrix objects - * @param par pointer to an object, it will be the parent of the new button matrix - * @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it - * @return pointer to the created button matrix - */ -lv_obj_t * lv_btnm_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new map. Buttons will be created/deleted according to the map. - * @param btnm pointer to a button matrix object - * @param map pointer a string array. The last string has to be: "". - * Use "\n" to begin a new line. - * The first byte can be a control data: - * - bit 7: always 1 - * - bit 6: always 0 - * - bit 5: inactive (disabled) - * - bit 4: no repeat (on long press) - * - bit 3: hidden - * - bit 2..0: button relative width - * Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press - */ -void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); - -/** - * Set a new callback function for the buttons (It will be called when a button is released) - * @param btnm: pointer to button matrix object - * @param action pointer to a callback function - */ -void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t action); - -/** - * Enable or disable button toggling - * @param btnm pointer to button matrix object - * @param en true: enable toggling; false: disable toggling - * @param id index of the currently toggled button (ignored if 'en' == false) - */ -void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id); - -/** - * Set a style of a button matrix - * @param btnm pointer to a button matrix object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_btnm_set_style(lv_obj_t *btnm, lv_btnm_style_t type, lv_style_t *style); - -/** - * Set whether recoloring is enabled - * @param btnm pointer to button matrix object - * @param en whether recoloring is enabled - */ -void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the current map of a button matrix - * @param btnm pointer to a button matrix object - * @return the current map - */ -const char ** lv_btnm_get_map(const lv_obj_t * btnm); - -/** - * Get a the callback function of the buttons on a button matrix - * @param btnm: pointer to button matrix object - * @return pointer to the callback function - */ -lv_btnm_action_t lv_btnm_get_action(const lv_obj_t * btnm); - -/** - * Get the pressed button - * @param btnm pointer to button matrix object - * @return index of the currently pressed button (LV_BTNM_PR_NONE: if unset) - */ -uint16_t lv_btnm_get_pressed(const lv_obj_t * btnm); - -/** - * Get the toggled button - * @param btnm pointer to button matrix object - * @return index of the currently toggled button (LV_BTNM_PR_NONE: if unset) - */ -uint16_t lv_btnm_get_toggled(const lv_obj_t * btnm); - -/** - * Get a style of a button matrix - * @param btnm pointer to a button matrix object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_btnm_get_style(const lv_obj_t *btnm, lv_btnm_style_t type); - -/** - * Find whether recoloring is enabled - * @param btnm pointer to button matrix object - * @return whether recoloring is enabled - */ -bool lv_btnm_get_recolor(const lv_obj_t * btnm); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_BTNM*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_BTNM_H*/ diff --git a/include/display/lv_objx/lv_calendar.h b/include/display/lv_objx/lv_calendar.h deleted file mode 100644 index 3ef4b025..00000000 --- a/include/display/lv_objx/lv_calendar.h +++ /dev/null @@ -1,246 +0,0 @@ -/** - * @file lv_calendar.h - * - */ - -#ifndef LV_CALENDAR_H -#define LV_CALENDAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CALENDAR != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -typedef struct { - uint16_t year; - int8_t month; - int8_t day; -} lv_calendar_date_t; - -enum -{ - LV_CALENDAR_ACTION_CLICK, - LV_CALENDAR_ACTION_PR, - LV_CALENDAR_ACTION_LONG_PR, - LV_CALENDAR_ACTION_LONG_PR_REPEAT, - LV_CALENDAR_ACTION_NUM, -}; -typedef uint8_t lv_calendar_action_t; - -/*Data of calendar*/ -typedef struct { - /*None*/ /*Ext. of ancestor*/ - /*New data for this type */ - lv_calendar_date_t today; /*Date of today*/ - lv_calendar_date_t showed_date; /*Currently visible month (day is ignored)*/ - lv_calendar_date_t * highlighted_dates; /*Apply different style on these days (pointer to an array defined by the user)*/ - uint8_t highlighted_dates_num; /*Number of elements in `highlighted_days`*/ - int8_t btn_pressing; /*-1: prev month pressing, +1 next month pressing on the header*/ - lv_calendar_date_t pressed_date; - const char ** day_names; /*Pointer to an array with the name of the days (NULL: use default names)*/ - const char ** month_names; /*Pointer to an array with the name of the month (NULL. use default names)*/ - lv_action_t actions[LV_CALENDAR_ACTION_NUM]; - - /*Styles*/ - lv_style_t * style_header; - lv_style_t * style_header_pr; - lv_style_t * style_day_names; - lv_style_t * style_highlighted_days; - lv_style_t * style_inactive_days; - lv_style_t * style_week_box; - lv_style_t * style_today_box; -} lv_calendar_ext_t; - -/*Styles*/ -enum { - LV_CALENDAR_STYLE_BG, /*Also the style of the "normal" date numbers*/ - LV_CALENDAR_STYLE_HEADER, - LV_CALENDAR_STYLE_HEADER_PR, - LV_CALENDAR_STYLE_DAY_NAMES, - LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS, - LV_CALENDAR_STYLE_INACTIVE_DAYS, - LV_CALENDAR_STYLE_WEEK_BOX, - LV_CALENDAR_STYLE_TODAY_BOX, -}; -typedef uint8_t lv_calendar_style_t; - - - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a calendar objects - * @param par pointer to an object, it will be the parent of the new calendar - * @param copy pointer to a calendar object, if not NULL then the new object will be copied from it - * @return pointer to the created calendar - */ -lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - - -/*===================== - * Setter functions - *====================*/ -/** - * Set a function to call when a calendar event happens - * @param calendar pointer to a calendar object - * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) - */ -void lv_calendar_set_action(lv_obj_t * calendar, lv_calendar_action_t type, lv_action_t action); - -/** - * Set the today's date - * @param calendar pointer to a calendar object - * @param today pointer to an `lv_calendar_date_t` variable containing the date of today. The value will be saved it can be local variable too. - */ -void lv_calendar_set_today_date(lv_obj_t * calendar, lv_calendar_date_t * today); - -/** - * Set the currently showed - * @param calendar pointer to a calendar object - * @param showed pointer to an `lv_calendar_date_t` variable containing the date to show. The value will be saved it can be local variable too. - */ -void lv_calendar_set_showed_date(lv_obj_t * calendar, lv_calendar_date_t * showed); - -/** - * Set the the highlighted dates - * @param calendar pointer to a calendar object - * @param highlighted pointer to an `lv_calendar_date_t` array containing the dates. ONLY A POINTER WILL BE SAVED! CAN'T BE LOCAL ARRAY. - * @param date_num number of dates in the array - */ -void lv_calendar_set_highlighted_dates(lv_obj_t * calendar, lv_calendar_date_t * highlighted, uint16_t date_num); - - -/** - * Set the name of the days - * @param calendar pointer to a calendar object - * @param day_names pointer to an array with the names. E.g. `const char * days[7] = {"Sun", "Mon", ...}` - * Only the pointer will be saved so this variable can't be local which will be destroyed later. - */ -void lv_calendar_set_day_names(lv_obj_t * calendar, const char ** day_names); - -/** - * Set the name of the month - * @param calendar pointer to a calendar object - * @param day_names pointer to an array with the names. E.g. `const char * days[12] = {"Jan", "Feb", ...}` - * Only the pointer will be saved so this variable can't be local which will be destroyed later. - */ -void lv_calendar_set_month_names(lv_obj_t * calendar, const char ** day_names); - -/** - * Set a style of a calendar. - * @param calendar pointer to calendar object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_calendar_set_style(lv_obj_t * calendar, lv_calendar_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ -/** - * Get the action of a calendar - * @param calendar pointer to a calendar object - * @return pointer to the action function - */ -lv_action_t lv_calendar_get_action(const lv_obj_t * calendar, lv_calendar_action_t type); - -/** - * Get the today's date - * @param calendar pointer to a calendar object - * @return return pointer to an `lv_calendar_date_t` variable containing the date of today. - */ -lv_calendar_date_t * lv_calendar_get_today_date(const lv_obj_t * calendar); - -/** - * Get the currently showed - * @param calendar pointer to a calendar object - * @return pointer to an `lv_calendar_date_t` variable containing the date is being shown. - */ -lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar); - -/** - * Get the the pressed date. - * @param calendar pointer to a calendar object - * @return pointer to an `lv_calendar_date_t` variable containing the pressed date. - */ -lv_calendar_date_t * lv_calendar_get_pressed_date(const lv_obj_t * calendar); - -/** - * Get the the highlighted dates - * @param calendar pointer to a calendar object - * @return pointer to an `lv_calendar_date_t` array containing the dates. - */ -lv_calendar_date_t * lv_calendar_get_highlighted_dates(const lv_obj_t * calendar); - -/** - * Get the number of the highlighted dates - * @param calendar pointer to a calendar object - * @return number of highlighted days - */ -uint16_t lv_calendar_get_highlighted_dates_num(const lv_obj_t * calendar); - - -/** - * Get the name of the days - * @param calendar pointer to a calendar object - * @return pointer to the array of day names - */ -const char ** lv_calendar_get_day_names(const lv_obj_t * calendar); - -/** - * Get the name of the month - * @param calendar pointer to a calendar object - * @return pointer to the array of month names - */ -const char ** lv_calendar_get_month_names(const lv_obj_t * calendar); - -/** - * Get style of a calendar. - * @param calendar pointer to calendar object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_calendar_get_style(const lv_obj_t * calendar, lv_calendar_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CALENDAR*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CALENDAR_H*/ diff --git a/include/display/lv_objx/lv_canvas.h b/include/display/lv_objx/lv_canvas.h deleted file mode 100644 index 14d6e87b..00000000 --- a/include/display/lv_objx/lv_canvas.h +++ /dev/null @@ -1,229 +0,0 @@ -/** - * @file lv_canvas.h - * - */ - -#ifndef LV_CANVAS_H -#define LV_CANVAS_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CANVAS != 0 - -#include "display/lv_core/lv_obj.h" -#include "display/lv_objx/lv_img.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of canvas*/ -typedef struct { - lv_img_ext_t img; /*Ext. of ancestor*/ - /*New data for this type */ - lv_img_dsc_t dsc; -} lv_canvas_ext_t; - - -/*Styles*/ -enum { - LV_CANVAS_STYLE_MAIN, -}; -typedef uint8_t lv_canvas_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a canvas object - * @param par pointer to an object, it will be the parent of the new canvas - * @param copy pointer to a canvas object, if not NULL then the new object will be copied from it - * @return pointer to the created canvas - */ -lv_obj_t * lv_canvas_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a buffer for the canvas. - * @param buf a buffer where the content of the canvas will be. - * The required size is (lv_img_color_format_get_px_size(cf) * w * h) / 8) - * It can be allocated with `lv_mem_alloc()` or - * it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or - * it can be an address in RAM or external SRAM - * @param canvas pointer to a canvas object - * @param w width of the canvas - * @param h height of the canvas - * @param cf color format. The following formats are supported: - * LV_IMG_CF_TRUE_COLOR, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, LV_IMG_CF_INDEXES_1/2/4/8BIT - */ -void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); - -/** - * Set the color of a pixel on the canvas - * @param canvas - * @param x x coordinate of the point to set - * @param y x coordinate of the point to set - * @param c color of the point - */ -void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c); - -/** - * Set a style of a canvas. - * @param canvas pointer to canvas object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, lv_style_t * style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the color of a pixel on the canvas - * @param canvas - * @param x x coordinate of the point to set - * @param y x coordinate of the point to set - * @return color of the point - */ -lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y); - -/** - * Get style of a canvas. - * @param canvas pointer to canvas object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type); - -/*===================== - * Other functions - *====================*/ - -/** - * Copy a buffer to the canvas - * @param canvas pointer to a canvas object - * @param to_copy buffer to copy. The color format has to match with the canvas's buffer color format - * @param w width of the buffer to copy - * @param h height of the buffer to copy - * @param x left side of the destination position - * @param y top side of the destination position - */ -void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y); - -/** - * Multiply a buffer with the canvas - * @param canvas pointer to a canvas object - * @param to_copy buffer to copy (multiply). LV_IMG_CF_TRUE_COLOR_ALPHA is not supported - * @param w width of the buffer to copy - * @param h height of the buffer to copy - * @param x left side of the destination position - * @param y top side of the destination position - */ -void lv_canvas_mult_buf(lv_obj_t * canvas, void * to_copy, lv_coord_t w, lv_coord_t h, lv_coord_t x, lv_coord_t y); - -/** - * Draw circle function of the canvas - * @param canvas pointer to a canvas object - * @param x0 x coordinate of the circle - * @param y0 y coordinate of the circle - * @param radius radius of the circle - * @param color border color of the circle - */ -void lv_canvas_draw_circle(lv_obj_t * canvas, lv_coord_t x0, lv_coord_t y0, lv_coord_t radius, lv_color_t color); - -/** - * Draw line function of the canvas - * @param canvas pointer to a canvas object - * @param point1 start point of the line - * @param point2 end point of the line - * @param color color of the line - * - * NOTE: The lv_canvas_draw_line function originates from https://github.com/jb55/bresenham-line.c. - */ -void lv_canvas_draw_line(lv_obj_t * canvas, lv_point_t point1, lv_point_t point2, lv_color_t color); - -/** - * Draw triangle function of the canvas - * @param canvas pointer to a canvas object - * @param points edge points of the triangle - * @param color line color of the triangle - */ -void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color); - -/** - * Draw rectangle function of the canvas - * @param canvas pointer to a canvas object - * @param points edge points of the rectangle - * @param color line color of the rectangle - */ -void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color); - -/** - * Draw polygon function of the canvas - * @param canvas pointer to a canvas object - * @param points edge points of the polygon - * @param size edge count of the polygon - * @param color line color of the polygon - */ -void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color); - -/** - * Fill polygon function of the canvas - * @param canvas pointer to a canvas object - * @param points edge points of the polygon - * @param size edge count of the polygon - * @param boundary_color line color of the polygon - * @param fill_color fill color of the polygon - */ -void lv_canvas_fill_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t boundary_color, lv_color_t fill_color); -/** - * Boundary fill function of the canvas - * @param canvas pointer to a canvas object - * @param x x coordinate of the start position (seed) - * @param y y coordinate of the start position (seed) - * @param boundary_color edge/boundary color of the area - * @param fill_color fill color of the area - */ -void lv_canvas_boundary_fill4(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t boundary_color, lv_color_t fill_color); - -/** - * Flood fill function of the canvas - * @param canvas pointer to a canvas object - * @param x x coordinate of the start position (seed) - * @param y y coordinate of the start position (seed) - * @param fill_color fill color of the area - * @param bg_color background color of the area - */ -void lv_canvas_flood_fill(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t fill_color, lv_color_t bg_color); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CANVAS*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CANVAS_H*/ diff --git a/include/display/lv_objx/lv_cb.h b/include/display/lv_objx/lv_cb.h deleted file mode 100644 index 5c550b6f..00000000 --- a/include/display/lv_objx/lv_cb.h +++ /dev/null @@ -1,174 +0,0 @@ -/** - * @file lv_cb.h - * - */ - -#ifndef LV_CB_H -#define LV_CB_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CB != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTN == 0 -#error "lv_cb: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_cb: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_btn.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of check box*/ -typedef struct -{ - lv_btn_ext_t bg_btn; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * bullet; /*Pointer to button*/ - lv_obj_t * label; /*Pointer to label*/ -} lv_cb_ext_t; - -enum { - LV_CB_STYLE_BG, - LV_CB_STYLE_BOX_REL, - LV_CB_STYLE_BOX_PR, - LV_CB_STYLE_BOX_TGL_REL, - LV_CB_STYLE_BOX_TGL_PR, - LV_CB_STYLE_BOX_INA, -}; -typedef uint8_t lv_cb_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a check box objects - * @param par pointer to an object, it will be the parent of the new check box - * @param copy pointer to a check box object, if not NULL then the new object will be copied from it - * @return pointer to the created check box - */ -lv_obj_t * lv_cb_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the text of a check box - * @param cb pointer to a check box - * @param txt the text of the check box - */ -void lv_cb_set_text(lv_obj_t * cb, const char * txt); - -/** - * Set the state of the check box - * @param cb pointer to a check box object - * @param checked true: make the check box checked; false: make it unchecked - */ -static inline void lv_cb_set_checked(lv_obj_t * cb, bool checked) -{ - lv_btn_set_state(cb, checked ? LV_BTN_STATE_TGL_REL : LV_BTN_STATE_REL); -} - -/** - * Make the check box inactive (disabled) - * @param cb pointer to a check box object - */ -static inline void lv_cb_set_inactive(lv_obj_t * cb) -{ - lv_btn_set_state(cb, LV_BTN_STATE_INA); -} - -/** - * Set a function to call when the check box is clicked - * @param cb pointer to a check box object - */ -static inline void lv_cb_set_action(lv_obj_t * cb, lv_action_t action) -{ - lv_btn_set_action(cb, LV_BTN_ACTION_CLICK, action); -} - - -/** - * Set a style of a check box - * @param cb pointer to check box object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_cb_set_style(lv_obj_t * cb, lv_cb_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the text of a check box - * @param cb pointer to check box object - * @return pointer to the text of the check box - */ -const char * lv_cb_get_text(const lv_obj_t * cb); - -/** - * Get the current state of the check box - * @param cb pointer to a check box object - * @return true: checked; false: not checked - */ -static inline bool lv_cb_is_checked(const lv_obj_t * cb) -{ - return lv_btn_get_state(cb) == LV_BTN_STATE_REL ? false : true; -} - -/** - * Get the action of a check box - * @param cb pointer to a button object - * @return pointer to the action function - */ -static inline lv_action_t lv_cb_get_action(const lv_obj_t * cb) -{ - return lv_btn_get_action(cb, LV_BTN_ACTION_CLICK); -} - - -/** - * Get a style of a button - * @param cb pointer to check box object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_cb_get_style(const lv_obj_t * cb, lv_cb_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CB*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CB_H*/ diff --git a/include/display/lv_objx/lv_chart.h b/include/display/lv_objx/lv_chart.h deleted file mode 100644 index 92637e89..00000000 --- a/include/display/lv_objx/lv_chart.h +++ /dev/null @@ -1,262 +0,0 @@ -/** - * @file lv_chart.h - * - */ - -#ifndef LV_CHART_H -#define LV_CHART_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CHART != 0 - -#include "display/lv_core/lv_obj.h" -#include "lv_line.h" - -/********************* - * DEFINES - *********************/ -#define LV_CHART_POINT_DEF (LV_COORD_MIN) - -/********************** - * TYPEDEFS - **********************/ -typedef struct -{ - lv_coord_t * points; - lv_color_t color; - uint16_t start_point; -} lv_chart_series_t; - -/*Data of chart */ -typedef struct -{ - /*No inherited ext*/ /*Ext. of ancestor*/ - /*New data for this type */ - lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/ - lv_coord_t ymin; /*y min value (used to scale the data)*/ - lv_coord_t ymax; /*y max value (used to scale the data)*/ - uint8_t hdiv_cnt; /*Number of horizontal division lines*/ - uint8_t vdiv_cnt; /*Number of vertical division lines*/ - uint16_t point_cnt; /*Point number in a data line*/ - uint8_t type :4; /*Line, column or point chart (from 'lv_chart_type_t')*/ - struct { - lv_coord_t width; /*Line width or point radius*/ - uint8_t num; /*Number of data lines in dl_ll*/ - lv_opa_t opa; /*Opacity of data lines*/ - lv_opa_t dark; /*Dark level of the point/column bottoms*/ - } series; -} lv_chart_ext_t; - -/*Chart types*/ -enum -{ - LV_CHART_TYPE_LINE = 0x01, /*Connect the points with lines*/ - LV_CHART_TYPE_COLUMN = 0x02, /*Draw columns*/ - LV_CHART_TYPE_POINT = 0x04, /*Draw circles on the points*/ - LV_CHART_TYPE_VERTICAL_LINE = 0x08, /*Draw vertical lines on points (useful when chart width == point count)*/ -}; -typedef uint8_t lv_chart_type_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a chart background objects - * @param par pointer to an object, it will be the parent of the new chart background - * @param copy pointer to a chart background object, if not NULL then the new object will be copied from it - * @return pointer to the created chart background - */ -lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Allocate and add a data series to the chart - * @param chart pointer to a chart object - * @param color color of the data series - * @return pointer to the allocated data series - */ -lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color); - -/** - * Clear the point of a serie - * @param chart pointer to a chart object - * @param serie pointer to the chart's serie to clear - */ -void lv_chart_clear_serie(lv_obj_t * chart, lv_chart_series_t * serie); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the number of horizontal and vertical division lines - * @param chart pointer to a graph background object - * @param hdiv number of horizontal division lines - * @param vdiv number of vertical division lines - */ -void lv_chart_set_div_line_count(lv_obj_t * chart, uint8_t hdiv, uint8_t vdiv); - -/** - * Set the minimal and maximal y values - * @param chart pointer to a graph background object - * @param ymin y minimum value - * @param ymax y maximum value - */ -void lv_chart_set_range(lv_obj_t * chart, lv_coord_t ymin, lv_coord_t ymax); - -/** - * Set a new type for a chart - * @param chart pointer to a chart object - * @param type new type of the chart (from 'lv_chart_type_t' enum) - */ -void lv_chart_set_type(lv_obj_t * chart, lv_chart_type_t type); - -/** - * Set the number of points on a data line on a chart - * @param chart pointer r to chart object - * @param point_cnt new number of points on the data lines - */ -void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt); - -/** - * Set the opacity of the data series - * @param chart pointer to a chart object - * @param opa opacity of the data series - */ -void lv_chart_set_series_opa(lv_obj_t * chart, lv_opa_t opa); - -/** - * Set the line width or point radius of the data series - * @param chart pointer to a chart object - * @param width the new width - */ -void lv_chart_set_series_width(lv_obj_t * chart, lv_coord_t width); - -/** - * Set the dark effect on the bottom of the points or columns - * @param chart pointer to a chart object - * @param dark_eff dark effect level (LV_OPA_TRANSP to turn off) - */ -void lv_chart_set_series_darking(lv_obj_t * chart, lv_opa_t dark_eff); - -/** - * Initialize all data points with a value - * @param chart pointer to chart object - * @param ser pointer to a data series on 'chart' - * @param y the new value for all points - */ -void lv_chart_init_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y); - -/** - * Set the value s of points from an array - * @param chart pointer to chart object - * @param ser pointer to a data series on 'chart' - * @param y_array array of 'lv_coord_t' points (with 'points count' elements ) - */ -void lv_chart_set_points(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t * y_array); - -/** - * Shift all data right and set the most right data on a data line - * @param chart pointer to chart object - * @param ser pointer to a data series on 'chart' - * @param y the new value of the most right data - */ -void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y); - -/** - * Set the style of a chart - * @param chart pointer to a chart object - * @param style pointer to a style - */ -static inline void lv_chart_set_style(lv_obj_t *chart, lv_style_t *style) -{ - lv_obj_set_style(chart, style); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the type of a chart - * @param chart pointer to chart object - * @return type of the chart (from 'lv_chart_t' enum) - */ -lv_chart_type_t lv_chart_get_type(const lv_obj_t * chart); - -/** - * Get the data point number per data line on chart - * @param chart pointer to chart object - * @return point number on each data line - */ -uint16_t lv_chart_get_point_cnt(const lv_obj_t * chart); - -/** - * Get the opacity of the data series - * @param chart pointer to chart object - * @return the opacity of the data series - */ -lv_opa_t lv_chart_get_series_opa(const lv_obj_t * chart); - -/** - * Get the data series width - * @param chart pointer to chart object - * @return the width the data series (lines or points) - */ -lv_coord_t lv_chart_get_series_width(const lv_obj_t * chart); - -/** - * Get the dark effect level on the bottom of the points or columns - * @param chart pointer to chart object - * @return dark effect level (LV_OPA_TRANSP to turn off) - */ -lv_opa_t lv_chart_get_series_darking(const lv_obj_t * chart); - -/** - * Get the style of an chart object - * @param chart pointer to an chart object - * @return pointer to the chart's style - */ -static inline lv_style_t* lv_chart_get_style(const lv_obj_t *chart) -{ - return lv_obj_get_style(chart); -} - -/*===================== - * Other functions - *====================*/ - -/** - * Refresh a chart if its data line has changed - * @param chart pointer to chart object - */ -void lv_chart_refresh(lv_obj_t * chart); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CHART*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CHART_H*/ diff --git a/include/display/lv_objx/lv_cont.h b/include/display/lv_objx/lv_cont.h deleted file mode 100644 index 3f4923dc..00000000 --- a/include/display/lv_objx/lv_cont.h +++ /dev/null @@ -1,163 +0,0 @@ -/** - * @file lv_cont.h - * - */ - -#ifndef LV_CONT_H -#define LV_CONT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_CONT != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Layout options*/ -enum -{ - LV_LAYOUT_OFF = 0, - LV_LAYOUT_CENTER, - LV_LAYOUT_COL_L, /*Column left align*/ - LV_LAYOUT_COL_M, /*Column middle align*/ - LV_LAYOUT_COL_R, /*Column right align*/ - LV_LAYOUT_ROW_T, /*Row top align*/ - LV_LAYOUT_ROW_M, /*Row middle align*/ - LV_LAYOUT_ROW_B, /*Row bottom align*/ - LV_LAYOUT_PRETTY, /*Put as many object as possible in row and begin a new row*/ - LV_LAYOUT_GRID, /*Align same-sized object into a grid*/ -}; -typedef uint8_t lv_layout_t; - -typedef struct -{ - /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/ - /*New data for this type */ - uint8_t layout :4; /*A layout from 'lv_cont_layout_t' enum*/ - uint8_t hor_fit :1; /*1: Enable horizontal fit to involve all children*/ - uint8_t ver_fit :1; /*1: Enable horizontal fit to involve all children*/ -} lv_cont_ext_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a container objects - * @param par pointer to an object, it will be the parent of the new container - * @param copy pointer to a container object, if not NULL then the new object will be copied from it - * @return pointer to the created container - */ -lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a layout on a container - * @param cont pointer to a container object - * @param layout a layout from 'lv_cont_layout_t' - */ -void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout); - - -/** - * Enable the horizontal or vertical fit. - * The container size will be set to involve the children horizontally or vertically. - * @param cont pointer to a container object - * @param hor_en true: enable the horizontal fit - * @param ver_en true: enable the vertical fit - */ -void lv_cont_set_fit(lv_obj_t * cont, bool hor_en, bool ver_en); - -/** - * Set the style of a container - * @param cont pointer to a container object - * @param style pointer to the new style - */ -static inline void lv_cont_set_style(lv_obj_t *cont, lv_style_t * style) -{ - lv_obj_set_style(cont, style); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the layout of a container - * @param cont pointer to container object - * @return the layout from 'lv_cont_layout_t' - */ -lv_layout_t lv_cont_get_layout(const lv_obj_t * cont); - -/** - * Get horizontal fit enable attribute of a container - * @param cont pointer to a container object - * @return true: horizontal fit is enabled; false: disabled - */ -bool lv_cont_get_hor_fit(const lv_obj_t * cont); - -/** - * Get vertical fit enable attribute of a container - * @param cont pointer to a container object - * @return true: vertical fit is enabled; false: disabled - */ -bool lv_cont_get_ver_fit(const lv_obj_t * cont); - - -/** - * Get that width reduced by the horizontal padding. Useful if a layout is used. - * @param cont pointer to a container object - * @return the width which still fits into the container - */ -lv_coord_t lv_cont_get_fit_width(lv_obj_t * cont); - -/** - * Get that height reduced by the vertical padding. Useful if a layout is used. - * @param cont pointer to a container object - * @return the height which still fits into the container - */ -lv_coord_t lv_cont_get_fit_height(lv_obj_t * cont); - -/** - * Get the style of a container - * @param cont pointer to a container object - * @return pointer to the container's style - */ -static inline lv_style_t * lv_cont_get_style(const lv_obj_t *cont) -{ - return lv_obj_get_style(cont); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_CONT*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_CONT_H*/ diff --git a/include/display/lv_objx/lv_ddlist.h b/include/display/lv_objx/lv_ddlist.h deleted file mode 100644 index cd9de975..00000000 --- a/include/display/lv_objx/lv_ddlist.h +++ /dev/null @@ -1,265 +0,0 @@ -/** - * @file lv_ddlist.h - * - */ - -#ifndef LV_DDLIST_H -#define LV_DDLIST_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_DDLIST != 0 - -/*Testing of dependencies*/ -#if USE_LV_PAGE == 0 -#error "lv_ddlist: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_ddlist: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "display/lv_objx/lv_page.h" -#include "display/lv_objx/lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of drop down list*/ -typedef struct -{ - lv_page_ext_t page; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t *label; /*Label for the options*/ - lv_style_t * sel_style; /*Style of the selected option*/ - lv_action_t action; /*Pointer to function to call when an option is selected*/ - uint16_t option_cnt; /*Number of options*/ - uint16_t sel_opt_id; /*Index of the current option*/ - uint16_t sel_opt_id_ori; /*Store the original index on focus*/ - uint16_t anim_time; /*Open/Close animation time [ms]*/ - uint8_t opened :1; /*1: The list is opened (handled by the library)*/ - uint8_t draw_arrow :1; /*1: Draw arrow*/ - - lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/ -} lv_ddlist_ext_t; - -enum { - LV_DDLIST_STYLE_BG, - LV_DDLIST_STYLE_SEL, - LV_DDLIST_STYLE_SB, -}; -typedef uint8_t lv_ddlist_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ -/** - * Create a drop down list objects - * @param par pointer to an object, it will be the parent of the new drop down list - * @param copy pointer to a drop down list object, if not NULL then the new object will be copied from it - * @return pointer to the created drop down list - */ -lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set arrow draw in a drop down list - * @param ddlist pointer to drop down list object - * @param en enable/disable a arrow draw. E.g. "true" for draw. - */ -void lv_ddlist_set_draw_arrow(lv_obj_t * ddlist, bool en); - -/** - * Set the options in a drop down list from a string - * @param ddlist pointer to drop down list object - * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" - */ -void lv_ddlist_set_options(lv_obj_t * ddlist, const char * options); - -/** - * Set the selected option - * @param ddlist pointer to drop down list object - * @param sel_opt id of the selected option (0 ... number of option - 1); - */ -void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt); - -/** - * Set a function to call when a new option is chosen - * @param ddlist pointer to a drop down list - * @param action pointer to a call back function - */ -void lv_ddlist_set_action(lv_obj_t * ddlist, lv_action_t action); - -/** - * Set the fix height for the drop down list - * If 0 then the opened ddlist will be auto. sized else the set height will be applied. - * @param ddlist pointer to a drop down list - * @param h the height when the list is opened (0: auto size) - */ -void lv_ddlist_set_fix_height(lv_obj_t * ddlist, lv_coord_t h); - -/** - * Enable or disable the horizontal fit to the content - * @param ddlist pointer to a drop down list - * @param en true: enable auto fit; false: disable auto fit - */ -void lv_ddlist_set_hor_fit(lv_obj_t * ddlist, bool en); - -/** - * Set the scroll bar mode of a drop down list - * @param ddlist pointer to a drop down list object - * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum - */ -static inline void lv_ddlist_set_sb_mode(lv_obj_t * ddlist, lv_sb_mode_t mode) -{ - lv_page_set_sb_mode(ddlist, mode); -} - -/** - * Set the open/close animation time. - * @param ddlist pointer to a drop down list - * @param anim_time: open/close animation time [ms] - */ -void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time); - - -/** - * Set a style of a drop down list - * @param ddlist pointer to a drop down list object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style); - -/** - * Set the alignment of the labels in a drop down list - * @param ddlist pointer to a drop down list object - * @param align alignment of labels - */ -void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get arrow draw in a drop down list - * @param ddlist pointer to drop down list object - */ -bool lv_ddlist_get_draw_arrow(lv_obj_t * ddlist); - -/** - * Get the options of a drop down list - * @param ddlist pointer to drop down list object - * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") - */ -const char * lv_ddlist_get_options(const lv_obj_t * ddlist); - -/** - * Get the selected option - * @param ddlist pointer to drop down list object - * @return id of the selected option (0 ... number of option - 1); - */ -uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist); - -/** - * Get the current selected option as a string - * @param ddlist pointer to ddlist object - * @param buf pointer to an array to store the string - */ -void lv_ddlist_get_selected_str(const lv_obj_t * ddlist, char * buf); - -/** - * Get the "option selected" callback function - * @param ddlist pointer to a drop down list - * @return pointer to the call back function - */ -lv_action_t lv_ddlist_get_action(const lv_obj_t * ddlist); - -/** - * Get the fix height value. - * @param ddlist pointer to a drop down list object - * @return the height if the ddlist is opened (0: auto size) - */ -lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t * ddlist); - -/** - * Get the scroll bar mode of a drop down list - * @param ddlist pointer to a drop down list object - * @return scrollbar mode from 'lv_page_sb_mode_t' enum - */ -static inline lv_sb_mode_t lv_ddlist_get_sb_mode(const lv_obj_t * ddlist) -{ - return lv_page_get_sb_mode(ddlist); -} - -/** - * Get the open/close animation time. - * @param ddlist pointer to a drop down list - * @return open/close animation time [ms] - */ -uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist); - -/** - * Get a style of a drop down list - * @param ddlist pointer to a drop down list object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_ddlist_get_style(const lv_obj_t *ddlist, lv_ddlist_style_t type); - -/** - * Get the alignment of the labels in a drop down list - * @param ddlist pointer to a drop down list object - * @return alignment of labels - */ -lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist); - -/*===================== - * Other functions - *====================*/ - -/** - * Open the drop down list with or without animation - * @param ddlist pointer to drop down list object - * @param anim_en true: use animation; false: not use animations - */ -void lv_ddlist_open(lv_obj_t * ddlist, bool anim_en); - -/** - * Close (Collapse) the drop down list - * @param ddlist pointer to drop down list object - * @param anim_en true: use animation; false: not use animations - */ -void lv_ddlist_close(lv_obj_t * ddlist, bool anim_en); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_DDLIST*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DDLIST_H*/ diff --git a/include/display/lv_objx/lv_gauge.h b/include/display/lv_objx/lv_gauge.h deleted file mode 100644 index 3f269cd0..00000000 --- a/include/display/lv_objx/lv_gauge.h +++ /dev/null @@ -1,222 +0,0 @@ -/** - * @file lv_gauge.h - * - */ - -#ifndef LV_GAUGE_H -#define LV_GAUGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_GAUGE != 0 - -/*Testing of dependencies*/ -#if USE_LV_LMETER == 0 -#error "lv_gauge: lv_lmeter is required. Enable it in lv_conf.h (USE_LV_LMETER 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_lmeter.h" -#include "lv_label.h" -#include "lv_line.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of gauge*/ -typedef struct -{ - lv_lmeter_ext_t lmeter; /*Ext. of ancestor*/ - /*New data for this type */ - int16_t * values; /*Array of the set values (for needles) */ - const lv_color_t * needle_colors; /*Color of the needles (lv_color_t my_colors[needle_num])*/ - uint8_t needle_count; /*Number of needles*/ - uint8_t label_count; /*Number of labels on the scale*/ -} lv_gauge_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a gauge objects - * @param par pointer to an object, it will be the parent of the new gauge - * @param copy pointer to a gauge object, if not NULL then the new object will be copied from it - * @return pointer to the created gauge - */ -lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the number of needles - * @param gauge pointer to gauge object - * @param needle_cnt new count of needles - * @param colors an array of colors for needles (with 'num' elements) - */ -void lv_gauge_set_needle_count(lv_obj_t * gauge, uint8_t needle_cnt, const lv_color_t * colors); - -/** - * Set the value of a needle - * @param gauge pointer to a gauge - * @param needle_id the id of the needle - * @param value the new value - */ -void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int16_t value); - -/** - * Set minimum and the maximum values of a gauge - * @param gauge pointer to he gauge object - * @param min minimum value - * @param max maximum value - */ -static inline void lv_gauge_set_range(lv_obj_t *gauge, int16_t min, int16_t max) -{ - lv_lmeter_set_range(gauge, min, max); -} - -/** - * Set a critical value on the scale. After this value 'line.color' scale lines will be drawn - * @param gauge pointer to a gauge object - * @param value the critical value - */ -static inline void lv_gauge_set_critical_value(lv_obj_t * gauge, int16_t value) -{ - lv_lmeter_set_value(gauge, value); -} - -/** - * Set the scale settings of a gauge - * @param gauge pointer to a gauge object - * @param angle angle of the scale (0..360) - * @param line_cnt count of scale lines. - * The get a given "subdivision" lines between label, `line_cnt` = (sub_div + 1) * (label_cnt - 1) + 1 - * @param label_cnt count of scale labels. - */ -void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t line_cnt, uint8_t label_cnt); - -/** - * Set the styles of a gauge - * @param gauge pointer to a gauge object - * @param bg set the style of the gauge - * */ -static inline void lv_gauge_set_style(lv_obj_t *gauge, lv_style_t *bg) -{ - lv_obj_set_style(gauge, bg); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a needle - * @param gauge pointer to gauge object - * @param needle the id of the needle - * @return the value of the needle [min,max] - */ -int16_t lv_gauge_get_value(const lv_obj_t * gauge, uint8_t needle); - -/** - * Get the count of needles on a gauge - * @param gauge pointer to gauge - * @return count of needles - */ -uint8_t lv_gauge_get_needle_count(const lv_obj_t * gauge); - -/** - * Get the minimum value of a gauge - * @param gauge pointer to a gauge object - * @return the minimum value of the gauge - */ -static inline int16_t lv_gauge_get_min_value(const lv_obj_t * lmeter) -{ - return lv_lmeter_get_min_value(lmeter); -} - -/** - * Get the maximum value of a gauge - * @param gauge pointer to a gauge object - * @return the maximum value of the gauge - */ -static inline int16_t lv_gauge_get_max_value(const lv_obj_t * lmeter) -{ - return lv_lmeter_get_max_value(lmeter); -} - -/** - * Get a critical value on the scale. - * @param gauge pointer to a gauge object - * @return the critical value - */ -static inline int16_t lv_gauge_get_critical_value(const lv_obj_t * gauge) -{ - return lv_lmeter_get_value(gauge); -} - -/** - * Set the number of labels (and the thicker lines too) - * @param gauge pointer to a gauge object - * @return count of labels - */ -uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge); - -/** - * Get the scale number of a gauge - * @param gauge pointer to a gauge object - * @return number of the scale units - */ -static inline uint8_t lv_gauge_get_line_count(const lv_obj_t * gauge) -{ - return lv_lmeter_get_line_count(gauge); -} - -/** - * Get the scale angle of a gauge - * @param gauge pointer to a gauge object - * @return angle of the scale - */ -static inline uint16_t lv_gauge_get_scale_angle(const lv_obj_t * gauge) -{ - return lv_lmeter_get_scale_angle(gauge); -} - -/** - * Get the style of a gauge - * @param gauge pointer to a gauge object - * @return pointer to the gauge's style - */ -static inline lv_style_t * lv_gauge_get_style(const lv_obj_t *gauge) -{ - return lv_obj_get_style(gauge); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_GAUGE*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_GAUGE_H*/ diff --git a/include/display/lv_objx/lv_img.h b/include/display/lv_objx/lv_img.h deleted file mode 100644 index 03eca247..00000000 --- a/include/display/lv_objx/lv_img.h +++ /dev/null @@ -1,195 +0,0 @@ -/** - * @file lv_img.h - * - */ - -#ifndef LV_IMG_H -#define LV_IMG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_IMG != 0 - -#include "display/lv_core/lv_obj.h" -#include "display/lv_misc/lv_fs.h" -#include "display/lv_misc/lv_symbol_def.h" -#include "lv_label.h" -#include "display/lv_draw/lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of image*/ -typedef struct -{ - /*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/ - /*New data for this type */ - const void * src; /*Image source: Pointer to an array or a file or a symbol*/ - - lv_coord_t w; /*Width of the image (Handled by the library)*/ - lv_coord_t h; /*Height of the image (Handled by the library)*/ -#if USE_LV_MULTI_LANG - uint16_t lang_txt_id; /*The ID of the image to display. */ -#endif - uint8_t src_type :2; /*See: lv_img_src_t*/ - uint8_t auto_size :1; /*1: automatically set the object size to the image size*/ - uint8_t cf :5; /*Color format from `lv_img_color_format_t`*/ -} lv_img_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create an image objects - * @param par pointer to an object, it will be the parent of the new button - * @param copy pointer to a image object, if not NULL then the new object will be copied from it - * @return pointer to the created image - */ -lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the pixel map to display by the image - * @param img pointer to an image object - * @param data the image data - */ -void lv_img_set_src(lv_obj_t * img, const void * src_img); - -#if USE_LV_MULTI_LANG -/** - * Set an ID which means a the same source but on different languages - * @param img pointer to an image object - * @param src_id ID of the source - */ -void lv_img_set_src_id(lv_obj_t * img, uint32_t txt_id); -#endif - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0. - * Use 'lv_img_set_src()' instead. - * @param img - - * @param fn - - */ -static inline void lv_img_set_file(lv_obj_t * img, const char * fn) -{ - (void) img; - (void) fn; -} - -/** - * Enable the auto size feature. - * If enabled the object size will be same as the picture size. - * @param img pointer to an image - * @param en true: auto size enable, false: auto size disable - */ -void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en); - -/** - * Set the style of an image - * @param img pointer to an image object - * @param style pointer to a style - */ -static inline void lv_img_set_style(lv_obj_t *img, lv_style_t *style) -{ - lv_obj_set_style(img, style); -} - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 - * @param img - - * @param upscale - - */ -static inline void lv_img_set_upscale(lv_obj_t * img, bool upcale) -{ - (void) img; - (void) upcale; -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the source of the image - * @param img pointer to an image object - * @return the image source (symbol, file name or C array) - */ -const void * lv_img_get_src(lv_obj_t * img); - -/** - * Get the name of the file set for an image - * @param img pointer to an image - * @return file name - */ -const char * lv_img_get_file_name(const lv_obj_t * img); - -#if USE_LV_MULTI_LANG -/** - * Get the source ID of the image. (Used by the multi-language feature) - * @param img pointer to an image - * @return ID of the source - */ -uint16_t lv_img_get_src_id(lv_obj_t * img); -#endif - -/** - * Get the auto size enable attribute - * @param img pointer to an image - * @return true: auto size is enabled, false: auto size is disabled - */ -bool lv_img_get_auto_size(const lv_obj_t * img); - -/** - * Get the style of an image object - * @param img pointer to an image object - * @return pointer to the image's style - */ -static inline lv_style_t* lv_img_get_style(const lv_obj_t *img) -{ - return lv_obj_get_style(img); -} - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 - * @param img - - * @return false - */ -static inline bool lv_img_get_upscale(const lv_obj_t * img) -{ - (void)img; - return false; -} - -/********************** - * MACROS - **********************/ - -/*Use this macro to declare an image in a c file*/ -#define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name; - -#endif /*USE_LV_IMG*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_IMG_H*/ diff --git a/include/display/lv_objx/lv_imgbtn.h b/include/display/lv_objx/lv_imgbtn.h deleted file mode 100644 index 295be8f2..00000000 --- a/include/display/lv_objx/lv_imgbtn.h +++ /dev/null @@ -1,248 +0,0 @@ -/** - * @file lv_imgbtn.h - * - */ - -#ifndef LV_IMGBTN_H -#define LV_IMGBTN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_IMGBTN != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTN == 0 -#error "lv_imgbtn: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_btn.h" -#include "display/lv_draw/lv_draw_img.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of image button*/ -typedef struct { - lv_btn_ext_t btn; /*Ext. of ancestor*/ - /*New data for this type */ -#if LV_IMGBTN_TILED == 0 - const void * img_src[LV_BTN_STATE_NUM]; /*Store images to each state*/ -#else - const void * img_src_left[LV_BTN_STATE_NUM]; /*Store left side images to each state*/ - const void * img_src_mid[LV_BTN_STATE_NUM]; /*Store center images to each state*/ - const void * img_src_right[LV_BTN_STATE_NUM]; /*Store right side images to each state*/ -#endif - lv_img_cf_t act_cf; /*Color format of the currently active image*/ -} lv_imgbtn_ext_t; - - -/*Styles*/ -enum { - LV_IMGBTN_STYLE_REL, - LV_IMGBTN_STYLE_PR, - LV_IMGBTN_STYLE_TGL_REL, - LV_IMGBTN_STYLE_TGL_PR, - LV_IMGBTN_STYLE_INA, -}; -typedef uint8_t lv_imgbtn_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a image button objects - * @param par pointer to an object, it will be the parent of the new image button - * @param copy pointer to a image button object, if not NULL then the new object will be copied from it - * @return pointer to the created image button - */ -lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - - -/*===================== - * Setter functions - *====================*/ - -#if LV_IMGBTN_TILED == 0 -/** - * Set images for a state of the image button - * @param imgbtn pointer to an image button object - * @param state for which state set the new image (from `lv_btn_state_t`) ` - * @param src pointer to an image source (a C array or path to a file) - */ -void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src); -#else -/** - * Set images for a state of the image button - * @param imgbtn pointer to an image button object - * @param state for which state set the new image (from `lv_btn_state_t`) ` - * @param src_left pointer to an image source for the left side of the button (a C array or path to a file) - * @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C array or path to a file) - * @param src_right pointer to an image source for the right side of the button (a C array or path to a file) - */ -void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid, const void * src_right); - -#endif - -/** - * Enable the toggled states. On release the button will change from/to toggled state. - * @param imgbtn pointer to an image button object - * @param tgl true: enable toggled states, false: disable - */ -static inline void lv_imgbtn_set_toggle(lv_obj_t * imgbtn, bool tgl) -{ - lv_btn_set_toggle(imgbtn, tgl); -} - -/** - * Set the state of the image button - * @param imgbtn pointer to an image button object - * @param state the new state of the button (from lv_btn_state_t enum) - */ -static inline void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_btn_state_t state) -{ - lv_btn_set_state(imgbtn, state); -} - -/** - * Toggle the state of the image button (ON->OFF, OFF->ON) - * @param imgbtn pointer to a image button object - */ -static inline void lv_imgbtn_toggle(lv_obj_t * imgbtn) -{ - lv_btn_toggle(imgbtn); -} - -/** - * Set a function to call when a button event happens - * @param imgbtn pointer to an image button object - * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) - */ -static inline void lv_imgbtn_set_action(lv_obj_t * imgbtn, lv_btn_action_t type, lv_action_t action) -{ - lv_btn_set_action(imgbtn, type, action); -} - -/** - * Set a style of a image button. - * @param imgbtn pointer to image button object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_imgbtn_set_style(lv_obj_t * imgbtn, lv_imgbtn_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - - -#if LV_IMGBTN_TILED == 0 -/** - * Get the images in a given state - * @param imgbtn pointer to an image button object - * @param state the state where to get the image (from `lv_btn_state_t`) ` - * @return pointer to an image source (a C array or path to a file) - */ -const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state); - -#else - -/** - * Get the left image in a given state - * @param imgbtn pointer to an image button object - * @param state the state where to get the image (from `lv_btn_state_t`) ` - * @return pointer to the left image source (a C array or path to a file) - */ -const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_btn_state_t state); - -/** - * Get the middle image in a given state - * @param imgbtn pointer to an image button object - * @param state the state where to get the image (from `lv_btn_state_t`) ` - * @return pointer to the middle image source (a C array or path to a file) - */ -const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_btn_state_t state); - -/** - * Get the right image in a given state - * @param imgbtn pointer to an image button object - * @param state the state where to get the image (from `lv_btn_state_t`) ` - * @return pointer to the left image source (a C array or path to a file) - */ -const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_btn_state_t state); - -#endif -/** - * Get the current state of the image button - * @param imgbtn pointer to a image button object - * @return the state of the button (from lv_btn_state_t enum) - */ -static inline lv_btn_state_t lv_imgbtn_get_state(const lv_obj_t * imgbtn) -{ - return lv_btn_get_state(imgbtn); -} - -/** - * Get the toggle enable attribute of the image button - * @param imgbtn pointer to a image button object - * @return ture: toggle enabled, false: disabled - */ -static inline bool lv_imgbtn_get_toggle(const lv_obj_t * imgbtn) -{ - return lv_btn_get_toggle(imgbtn); -} - -/** - * Get the release action of a image button - * @param imgbtn pointer to a image button object - * @return pointer to the release action function - */ -static inline lv_action_t lv_imgbtn_get_action(const lv_obj_t * imgbtn, lv_btn_action_t type) -{ - return lv_btn_get_action(imgbtn, type); -} - -/** - * Get style of a image button. - * @param imgbtn pointer to image button object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_imgbtn_get_style(const lv_obj_t * imgbtn, lv_imgbtn_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_IMGBTN*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_IMGBTN_H*/ diff --git a/include/display/lv_objx/lv_kb.h b/include/display/lv_objx/lv_kb.h deleted file mode 100644 index d6ab9795..00000000 --- a/include/display/lv_objx/lv_kb.h +++ /dev/null @@ -1,199 +0,0 @@ -/** - * @file lv_kb.h - * - */ - -#ifndef LV_KB_H -#define LV_KB_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_KB != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTNM == 0 -#error "lv_kb: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " -#endif - -#if USE_LV_TA == 0 -#error "lv_kb: lv_ta is required. Enable it in lv_conf.h (USE_LV_TA 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_btnm.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -enum { - LV_KB_MODE_TEXT, - LV_KB_MODE_NUM, -}; -typedef uint8_t lv_kb_mode_t; - -/*Data of keyboard*/ -typedef struct { - lv_btnm_ext_t btnm; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t *ta; /*Pointer to the assigned text area*/ - lv_kb_mode_t mode; /*Key map type*/ - uint8_t cursor_mng :1; /*1: automatically show/hide cursor when a text area is assigned or left*/ - lv_action_t ok_action; /*Called when the "Ok" button is clicked*/ - lv_action_t hide_action; /*Called when the "Hide" button is clicked*/ -} lv_kb_ext_t; - -enum { - LV_KB_STYLE_BG, - LV_KB_STYLE_BTN_REL, - LV_KB_STYLE_BTN_PR, - LV_KB_STYLE_BTN_TGL_REL, - LV_KB_STYLE_BTN_TGL_PR, - LV_KB_STYLE_BTN_INA, -}; -typedef uint8_t lv_kb_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a keyboard objects - * @param par pointer to an object, it will be the parent of the new keyboard - * @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it - * @return pointer to the created keyboard - */ -lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Assign a Text Area to the Keyboard. The pressed characters will be put there. - * @param kb pointer to a Keyboard object - * @param ta pointer to a Text Area object to write there - */ -void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta); - -/** - * Set a new a mode (text or number map) - * @param kb pointer to a Keyboard object - * @param mode the mode from 'lv_kb_mode_t' - */ -void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode); - -/** - * Automatically hide or show the cursor of the current Text Area - * @param kb pointer to a Keyboard object - * @param en true: show cursor on the current text area, false: hide cursor - */ -void lv_kb_set_cursor_manage(lv_obj_t * kb, bool en); - -/** - * Set call back to call when the "Ok" button is pressed - * @param kb pointer to Keyboard object - * @param action a callback with 'lv_action_t' type - */ -void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action); - -/** - * Set call back to call when the "Hide" button is pressed - * @param kb pointer to Keyboard object - * @param action a callback with 'lv_action_t' type - */ -void lv_kb_set_hide_action(lv_obj_t * kb, lv_action_t action); - -/** - * Set a new map for the keyboard - * @param kb pointer to a Keyboard object - * @param map pointer to a string array to describe the map. - * See 'lv_btnm_set_map()' for more info. - */ -static inline void lv_kb_set_map(lv_obj_t *kb, const char ** map) -{ - lv_btnm_set_map(kb, map); -} - -/** - * Set a style of a keyboard - * @param kb pointer to a keyboard object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_kb_set_style(lv_obj_t *kb, lv_kb_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Assign a Text Area to the Keyboard. The pressed characters will be put there. - * @param kb pointer to a Keyboard object - * @return pointer to the assigned Text Area object - */ -lv_obj_t * lv_kb_get_ta(const lv_obj_t * kb); - -/** - * Set a new a mode (text or number map) - * @param kb pointer to a Keyboard object - * @return the current mode from 'lv_kb_mode_t' - */ -lv_kb_mode_t lv_kb_get_mode(const lv_obj_t * kb); - -/** - * Get the current cursor manage mode. - * @param kb pointer to a Keyboard object - * @return true: show cursor on the current text area, false: hide cursor - */ -bool lv_kb_get_cursor_manage(const lv_obj_t * kb); - -/** - * Get the callback to call when the "Ok" button is pressed - * @param kb pointer to Keyboard object - * @return the ok callback - */ -lv_action_t lv_kb_get_ok_action(const lv_obj_t * kb); - -/** - * Get the callback to call when the "Hide" button is pressed - * @param kb pointer to Keyboard object - * @return the close callback - */ -lv_action_t lv_kb_get_hide_action(const lv_obj_t * kb); - -/** - * Get a style of a keyboard - * @param kb pointer to a keyboard object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_kb_get_style(const lv_obj_t *kb, lv_kb_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_KB*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_KB_H*/ diff --git a/include/display/lv_objx/lv_label.h b/include/display/lv_objx/lv_label.h deleted file mode 100644 index abd176a0..00000000 --- a/include/display/lv_objx/lv_label.h +++ /dev/null @@ -1,295 +0,0 @@ -/** - * @file lv_rect.h - * - */ - -#ifndef LV_LABEL_H -#define LV_LABEL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LABEL != 0 - -#include "display/lv_core/lv_obj.h" -#include "display/lv_misc/lv_font.h" -#include "display/lv_misc/lv_txt.h" -#include "display/lv_misc/lv_symbol_def.h" - -/********************* - * DEFINES - *********************/ -#define LV_LABEL_DOT_NUM 3 -#define LV_LABEL_POS_LAST 0xFFFF - -/********************** - * TYPEDEFS - **********************/ - -/*Long mode behaviors. Used in 'lv_label_ext_t' */ -enum -{ - LV_LABEL_LONG_EXPAND, /*Expand the object size to the text size*/ - LV_LABEL_LONG_BREAK, /*Keep the object width, break the too long lines and expand the object height*/ - LV_LABEL_LONG_SCROLL, /*Expand the object size and scroll the text on the parent (move the label object)*/ - LV_LABEL_LONG_DOT, /*Keep the size and write dots at the end if the text is too long*/ - LV_LABEL_LONG_ROLL, /*Keep the size and roll the text infinitely*/ - LV_LABEL_LONG_CROP, /*Keep the size and crop the text out of it*/ -}; -typedef uint8_t lv_label_long_mode_t; - -/*Label align policy*/ -enum { - LV_LABEL_ALIGN_LEFT, - LV_LABEL_ALIGN_CENTER, - LV_LABEL_ALIGN_RIGHT, -}; -typedef uint8_t lv_label_align_t; - -/*Data of label*/ -typedef struct -{ - /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ - /*New data for this type */ - char * text; /*Text of the label*/ - lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/ -#if LV_TXT_UTF8 == 0 - char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ -#else - char dot_tmp[LV_LABEL_DOT_NUM * 4 + 1]; /*Store the character which are replaced by dots (Handled by the library)*/ -#endif - -#if USE_LV_MULTI_LANG - uint16_t lang_txt_id; /*The ID of the text to display*/ -#endif - uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/ - uint16_t anim_speed; /*Speed of scroll and roll animation in px/sec unit*/ - lv_point_t offset; /*Text draw position offset*/ - uint8_t static_txt :1; /*Flag to indicate the text is static*/ - uint8_t align :2; /*Align type from 'lv_label_align_t'*/ - uint8_t recolor :1; /*Enable in-line letter re-coloring*/ - uint8_t expand :1; /*Ignore real width (used by the library with LV_LABEL_LONG_ROLL)*/ - uint8_t body_draw :1; /*Draw background body*/ -} lv_label_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Create a label objects - * @param par pointer to an object, it will be the parent of the new label - * @param copy pointer to a button object, if not NULL then the new object will be copied from it - * @return pointer to the created button - */ -lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new text for a label. Memory will be allocated to store the text by the label. - * @param label pointer to a label object - * @param text '\0' terminated character string. NULL to refresh with the current text. - */ -void lv_label_set_text(lv_obj_t * label, const char * text); - -/** - * Set a new text for a label from a character array. The array don't has to be '\0' terminated. - * Memory will be allocated to store the array by the label. - * @param label pointer to a label object - * @param array array of characters or NULL to refresh the label - * @param size the size of 'array' in bytes - */ -void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size); - -/** - * Set a static text. It will not be saved by the label so the 'text' variable - * has to be 'alive' while the label exist. - * @param label pointer to a label object - * @param text pointer to a text. NULL to refresh with the current text. - */ -void lv_label_set_static_text(lv_obj_t * label, const char * text); - -/** - *Set a text ID which means a the same text but on different languages - * @param label pointer to a label object - * @param txt_id ID of the text - */ -#if USE_LV_MULTI_LANG -void lv_label_set_text_id(lv_obj_t * label, uint32_t txt_id); -#endif - -/** - * Set the behavior of the label with longer text then the object size - * @param label pointer to a label object - * @param long_mode the new mode from 'lv_label_long_mode' enum. - * In LV_LONG_BREAK/LONG/ROLL the size of the label should be set AFTER this function - */ -void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode); - -/** - * Set the align of the label (left or center) - * @param label pointer to a label object - * @param align 'LV_LABEL_ALIGN_LEFT' or 'LV_LABEL_ALIGN_LEFT' - */ -void lv_label_set_align(lv_obj_t *label, lv_label_align_t align); - -/** - * Enable the recoloring by in-line commands - * @param label pointer to a label object - * @param en true: enable recoloring, false: disable - */ -void lv_label_set_recolor(lv_obj_t * label, bool en); - -/** - * Set the label to draw (or not draw) background specified in its style's body - * @param label pointer to a label object - * @param en true: draw body; false: don't draw body - */ -void lv_label_set_body_draw(lv_obj_t *label, bool en); - -/** - * Set the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes - * @param label pointer to a label object - * @param anim_speed speed of animation in px/sec unit - */ -void lv_label_set_anim_speed(lv_obj_t *label, uint16_t anim_speed); - -/** - * Set the style of an label - * @param label pointer to an label object - * @param style pointer to a style - */ -static inline void lv_label_set_style(lv_obj_t *label, lv_style_t *style) -{ - lv_obj_set_style(label, style); -} -/*===================== - * Getter functions - *====================*/ - -/** - * Get the text of a label - * @param label pointer to a label object - * @return the text of the label - */ -char * lv_label_get_text(const lv_obj_t * label); - -#if USE_LV_MULTI_LANG -/** - * Get the text ID of the label. (Used by the multi-language feature) - * @param label pointer to a label object - * @return ID of the text - */ -uint16_t lv_label_get_text_id(lv_obj_t * label); -#endif - -/** - * Get the long mode of a label - * @param label pointer to a label object - * @return the long mode - */ -lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * label); - -/** - * Get the align attribute - * @param label pointer to a label object - * @return LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER - */ -lv_label_align_t lv_label_get_align(const lv_obj_t * label); - -/** - * Get the recoloring attribute - * @param label pointer to a label object - * @return true: recoloring is enabled, false: disable - */ -bool lv_label_get_recolor(const lv_obj_t * label); - -/** - * Get the body draw attribute - * @param label pointer to a label object - * @return true: draw body; false: don't draw body - */ -bool lv_label_get_body_draw(const lv_obj_t *label); - -/** - * Get the label's animation speed in LV_LABEL_LONG_ROLL and SCROLL modes - * @param label pointer to a label object - * @return speed of animation in px/sec unit - */ -uint16_t lv_label_get_anim_speed(const lv_obj_t *label); - -/** - * Get the relative x and y coordinates of a letter - * @param label pointer to a label object - * @param index index of the letter [0 ... text length]. Expressed in character index, not byte index (different in UTF-8) - * @param pos store the result here (E.g. index = 0 gives 0;0 coordinates) - */ -void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t * pos); - -/** - * Get the index of letter on a relative point of a label - * @param label pointer to label object - * @param pos pointer to point with coordinates on a the label - * @return the index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter) - * Expressed in character index and not byte index (different in UTF-8) - */ -uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos); - -/** - * Get the style of an label object - * @param label pointer to an label object - * @return pointer to the label's style - */ -static inline lv_style_t* lv_label_get_style(const lv_obj_t *label) -{ - return lv_obj_get_style(label); -} - -/*===================== - * Other functions - *====================*/ - -/** - * Insert a text to the label. The label text can not be static. - * @param label pointer to a label object - * @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8) - * 0: before first char. - * LV_LABEL_POS_LAST: after last char. - * @param txt pointer to the text to insert - */ -void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt); - -/** - * Delete characters from a label. The label text can not be static. - * @param label pointer to a label object - * @param pos character index to insert. Expressed in character index and not byte index (Different in UTF-8) - * 0: before first char. - * @param cnt number of characters to cut - */ -void lv_label_cut_text(lv_obj_t * label, uint32_t pos, uint32_t cnt); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LABEL*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LABEL_H*/ diff --git a/include/display/lv_objx/lv_led.h b/include/display/lv_objx/lv_led.h deleted file mode 100644 index f6a18acb..00000000 --- a/include/display/lv_objx/lv_led.h +++ /dev/null @@ -1,116 +0,0 @@ -/** - * @file lv_led.h - * - */ - -#ifndef LV_LED_H -#define LV_LED_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LED != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of led*/ -typedef struct -{ - /*No inherited ext.*/ - /*New data for this type */ - uint8_t bright; /*Current brightness of the LED (0..255)*/ -} lv_led_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a led objects - * @param par pointer to an object, it will be the parent of the new led - * @param copy pointer to a led object, if not NULL then the new object will be copied from it - * @return pointer to the created led - */ -lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Set the brightness of a LED object - * @param led pointer to a LED object - * @param bright 0 (max. dark) ... 255 (max. light) - */ -void lv_led_set_bright(lv_obj_t * led, uint8_t bright); - -/** - * Light on a LED - * @param led pointer to a LED object - */ -void lv_led_on(lv_obj_t * led); - -/** - * Light off a LED - * @param led pointer to a LED object - */ -void lv_led_off(lv_obj_t * led); - -/** - * Toggle the state of a LED - * @param led pointer to a LED object - */ -void lv_led_toggle(lv_obj_t * led); - -/** - * Set the style of a led - * @param led pointer to a led object - * @param style pointer to a style - */ -static inline void lv_led_set_style(lv_obj_t *led, lv_style_t *style) -{ - lv_obj_set_style(led, style); -} - -/** - * Get the brightness of a LEd object - * @param led pointer to LED object - * @return bright 0 (max. dark) ... 255 (max. light) - */ -uint8_t lv_led_get_bright(const lv_obj_t * led); - -/** - * Get the style of an led object - * @param led pointer to an led object - * @return pointer to the led's style - */ -static inline lv_style_t* lv_led_get_style(const lv_obj_t *led) -{ - return lv_obj_get_style(led); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LED*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LED_H*/ diff --git a/include/display/lv_objx/lv_line.h b/include/display/lv_objx/lv_line.h deleted file mode 100644 index e7be8a32..00000000 --- a/include/display/lv_objx/lv_line.h +++ /dev/null @@ -1,158 +0,0 @@ -/** - * @file lv_line.h - * - */ - -#ifndef LV_LINE_H -#define LV_LINE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LINE != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of line*/ -typedef struct -{ - /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ - const lv_point_t * point_array; /*Pointer to an array with the points of the line*/ - uint16_t point_num; /*Number of points in 'point_array' */ - uint8_t auto_size :1; /*1: set obj. width to x max and obj. height to y max */ - uint8_t y_inv :1; /*1: y == 0 will be on the bottom*/ -} lv_line_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Create a line objects - * @param par pointer to an object, it will be the parent of the new line - * @return pointer to the created line - */ -lv_obj_t * lv_line_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set an array of points. The line object will connect these points. - * @param line pointer to a line object - * @param point_a an array of points. Only the address is saved, - * so the array can NOT be a local variable which will be destroyed - * @param point_num number of points in 'point_a' - */ -void lv_line_set_points(lv_obj_t * line, const lv_point_t * point_a, uint16_t point_num); - -/** - * Enable (or disable) the auto-size option. The size of the object will fit to its points. - * (set width to x max and height to y max) - * @param line pointer to a line object - * @param en true: auto size is enabled, false: auto size is disabled - */ -void lv_line_set_auto_size(lv_obj_t * line, bool en); - -/** - * Enable (or disable) the y coordinate inversion. - * If enabled then y will be subtracted from the height of the object, - * therefore the y=0 coordinate will be on the bottom. - * @param line pointer to a line object - * @param en true: enable the y inversion, false:disable the y inversion - */ -void lv_line_set_y_invert(lv_obj_t * line, bool en); - -#define lv_line_set_y_inv lv_line_set_y_invert /*The name was inconsistent. In v.6.0 only `lv_line_set_y_invert`will work */ - -/** - * Set the style of a line - * @param line pointer to a line object - * @param style pointer to a style - */ -static inline void lv_line_set_style(lv_obj_t *line, lv_style_t *style) -{ - lv_obj_set_style(line, style); -} - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 - * @param line - - * @param upscale - - */ -static inline void lv_line_set_upscale(lv_obj_t * line, bool upcale) -{ - (void) line; - (void) upcale; -} -/*===================== - * Getter functions - *====================*/ - -/** - * Get the auto size attribute - * @param line pointer to a line object - * @return true: auto size is enabled, false: disabled - */ -bool lv_line_get_auto_size(const lv_obj_t * line); - -/** - * Get the y inversion attribute - * @param line pointer to a line object - * @return true: y inversion is enabled, false: disabled - */ -bool lv_line_get_y_invert(const lv_obj_t * line); - -/** - * Get the style of an line object - * @param line pointer to an line object - * @return pointer to the line's style - */ -static inline lv_style_t* lv_line_get_style(const lv_obj_t *line) -{ - return lv_obj_get_style(line); -} - -/** - * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in v6.0 - * @param line - - * @return false - */ -static inline bool lv_line_get_upscale(const lv_obj_t * line) -{ - (void) line; - return false; -} - - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LINE*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LINE_H*/ diff --git a/include/display/lv_objx/lv_list.h b/include/display/lv_objx/lv_list.h deleted file mode 100644 index 397059a5..00000000 --- a/include/display/lv_objx/lv_list.h +++ /dev/null @@ -1,336 +0,0 @@ -/** - * @file lv_list.h - * - */ - -#ifndef LV_LIST_H -#define LV_LIST_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LIST != 0 - -/*Testing of dependencies*/ -#if USE_LV_PAGE == 0 -#error "lv_list: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#if USE_LV_BTN == 0 -#error "lv_list: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_list: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - - -#include "display/lv_core/lv_obj.h" -#include "lv_page.h" -#include "lv_btn.h" -#include "lv_label.h" -#include "lv_img.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of list*/ -typedef struct -{ - lv_page_ext_t page; /*Ext. of ancestor*/ - /*New data for this type */ - uint16_t anim_time; /*Scroll animation time*/ - lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of the list element buttons*/ - lv_style_t *style_img; /*Style of the list element images on buttons*/ - uint32_t size; /*the number of items(buttons) in the list*/ - bool single_mode; /* whether single selected mode is enabled */ -#if USE_LV_GROUP - lv_obj_t * last_sel; /* The last selected button. It will be reverted when the list is focused again */ - lv_obj_t * selected_btn; /* The button is currently being selected*/ -#endif -} lv_list_ext_t; - -enum { - LV_LIST_STYLE_BG, - LV_LIST_STYLE_SCRL, - LV_LIST_STYLE_SB, - LV_LIST_STYLE_EDGE_FLASH, - LV_LIST_STYLE_BTN_REL, - LV_LIST_STYLE_BTN_PR, - LV_LIST_STYLE_BTN_TGL_REL, - LV_LIST_STYLE_BTN_TGL_PR, - LV_LIST_STYLE_BTN_INA, -}; -typedef uint8_t lv_list_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a list objects - * @param par pointer to an object, it will be the parent of the new list - * @param copy pointer to a list object, if not NULL then the new object will be copied from it - * @return pointer to the created list - */ -lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Delete all children of the scrl object, without deleting scrl child. - * @param obj pointer to an object - */ -void lv_list_clean(lv_obj_t *obj); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Add a list element to the list - * @param list pointer to list object - * @param img_fn file name of an image before the text (NULL if unused) - * @param txt text of the list element (NULL if unused) - * @param rel_action pointer to release action function (like with lv_btn) - * @return pointer to the new list element which can be customized (a button) - */ -lv_obj_t * lv_list_add(lv_obj_t * list, const void * img_src, const char * txt, lv_action_t rel_action); - -/** - * Remove the index of the button in the list - * @param list pointer to a list object - * @param index pointer to a the button's index in the list, index must be 0 <= index < lv_list_ext_t.size - * @return true: successfully deleted - */ -bool lv_list_remove(const lv_obj_t * list, uint32_t index); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set single button selected mode, only one button will be selected if enabled. - * @param list pointer to the currently pressed list object - * @param mode, enable(true)/disable(false) single selected mode. - */ -void lv_list_set_single_mode(lv_obj_t *list, bool mode); - -#if USE_LV_GROUP - -/** - * Make a button selected. Can be used while navigating in the list with a keypad. - * @param list pointer to a list object - * @param btn pointer to a button to select - */ -void lv_list_set_btn_selected(lv_obj_t * list, lv_obj_t * btn); -#endif - -/** - * Set scroll animation duration on 'list_up()' 'list_down()' 'list_focus()' - * @param list pointer to a list object - * @param anim_time duration of animation [ms] - */ -void lv_list_set_anim_time(lv_obj_t *list, uint16_t anim_time); - -/** - * Set the scroll bar mode of a list - * @param list pointer to a list object - * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum - */ -static inline void lv_list_set_sb_mode(lv_obj_t * list, lv_sb_mode_t mode) -{ - lv_page_set_sb_mode(list, mode); -} - -/** - * Enable the scroll propagation feature. If enabled then the List will move its parent if there is no more space to scroll. - * @param list pointer to a List - * @param en true or false to enable/disable scroll propagation - */ -static inline void lv_list_set_scroll_propagation(lv_obj_t * list, bool en) -{ - lv_page_set_scroll_propagation(list, en); -} - -/** - * Enable the edge flash effect. (Show an arc when the an edge is reached) - * @param list pointer to a List - * @param en true or false to enable/disable end flash - */ -static inline void lv_list_set_edge_flash(lv_obj_t * list, bool en) -{ - lv_page_set_edge_flash(list, en); -} - -/** - * Set a style of a list - * @param list pointer to a list object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_list_set_style(lv_obj_t *list, lv_list_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get single button selected mode. - * @param list pointer to the currently pressed list object. - */ -bool lv_list_get_single_mode(lv_obj_t *list); - -/** - * Get the text of a list element - * @param btn pointer to list element - * @return pointer to the text - */ -const char * lv_list_get_btn_text(const lv_obj_t * btn); -/** - * Get the label object from a list element - * @param btn pointer to a list element (button) - * @return pointer to the label from the list element or NULL if not found - */ -lv_obj_t * lv_list_get_btn_label(const lv_obj_t * btn); - -/** - * Get the image object from a list element - * @param btn pointer to a list element (button) - * @return pointer to the image from the list element or NULL if not found - */ -lv_obj_t * lv_list_get_btn_img(const lv_obj_t * btn); - -/** - * Get the next button from list. (Starts from the bottom button) - * @param list pointer to a list object - * @param prev_btn pointer to button. Search the next after it. - * @return pointer to the next button or NULL when no more buttons - */ -lv_obj_t * lv_list_get_prev_btn(const lv_obj_t * list, lv_obj_t * prev_btn); - -/** - * Get the previous button from list. (Starts from the top button) - * @param list pointer to a list object - * @param prev_btn pointer to button. Search the previous before it. - * @return pointer to the previous button or NULL when no more buttons - */ -lv_obj_t * lv_list_get_next_btn(const lv_obj_t * list, lv_obj_t * prev_btn); - -/** - * Get the index of the button in the list - * @param list pointer to a list object. If NULL, assumes btn is part of a list. - * @param btn pointer to a list element (button) - * @return the index of the button in the list, or -1 of the button not in this list - */ -int32_t lv_list_get_btn_index(const lv_obj_t * list, const lv_obj_t * btn); - -/** - * Get the number of buttons in the list - * @param list pointer to a list object - * @return the number of buttons in the list - */ -uint32_t lv_list_get_size(const lv_obj_t * list); - -#if USE_LV_GROUP -/** - * Get the currently selected button. Can be used while navigating in the list with a keypad. - * @param list pointer to a list object - * @return pointer to the selected button - */ -lv_obj_t * lv_list_get_btn_selected(const lv_obj_t * list); -#endif - - -/** - * Get scroll animation duration - * @param list pointer to a list object - * @return duration of animation [ms] - */ -uint16_t lv_list_get_anim_time(const lv_obj_t *list); - - -/** - * Get the scroll bar mode of a list - * @param list pointer to a list object - * @return scrollbar mode from 'lv_page_sb_mode_t' enum - */ -static inline lv_sb_mode_t lv_list_get_sb_mode(const lv_obj_t * list) -{ - return lv_page_get_sb_mode(list); -} - -/** - * Get the scroll propagation property - * @param list pointer to a List - * @return true or false - */ -static inline bool lv_list_get_scroll_propagation(lv_obj_t * list) -{ - return lv_page_get_scroll_propagation(list); -} - -/** - * Get the scroll propagation property - * @param list pointer to a List - * @return true or false - */ -static inline bool lv_list_get_edge_flash(lv_obj_t * list) -{ - return lv_page_get_edge_flash(list); -} - -/** - * Get a style of a list - * @param list pointer to a list object - * @param type which style should be get - * @return style pointer to a style - * */ -lv_style_t * lv_list_get_style(const lv_obj_t *list, lv_list_style_t type); - -/*===================== - * Other functions - *====================*/ - -/** - * Move the list elements up by one - * @param list pointer a to list object - */ -void lv_list_up(const lv_obj_t * list); -/** - * Move the list elements down by one - * @param list pointer to a list object - */ -void lv_list_down(const lv_obj_t * list); - -/** - * Focus on a list button. It ensures that the button will be visible on the list. - * @param btn pointer to a list button to focus - * @param anim_en true: scroll with animation, false: without animation - */ -void lv_list_focus(const lv_obj_t *btn, bool anim_en); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LIST*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LIST_H*/ diff --git a/include/display/lv_objx/lv_lmeter.h b/include/display/lv_objx/lv_lmeter.h deleted file mode 100644 index dcb42bf4..00000000 --- a/include/display/lv_objx/lv_lmeter.h +++ /dev/null @@ -1,153 +0,0 @@ -/** - * @file lv_lmeter.h - * - */ - -#ifndef LV_LMETER_H -#define LV_LMETER_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_LMETER != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of line meter*/ -typedef struct -{ - /*No inherited ext.*/ /*Ext. of ancestor*/ - /*New data for this type */ - uint16_t scale_angle; /*Angle of the scale in deg. (0..360)*/ - uint8_t line_cnt; /*Count of lines */ - int16_t cur_value; - int16_t min_value; - int16_t max_value; -} lv_lmeter_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a line meter objects - * @param par pointer to an object, it will be the parent of the new line meter - * @param copy pointer to a line meter object, if not NULL then the new object will be copied from it - * @return pointer to the created line meter - */ -lv_obj_t * lv_lmeter_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new value on the line meter - * @param lmeter pointer to a line meter object - * @param value new value - */ -void lv_lmeter_set_value(lv_obj_t *lmeter, int16_t value); - -/** - * Set minimum and the maximum values of a line meter - * @param lmeter pointer to he line meter object - * @param min minimum value - * @param max maximum value - */ -void lv_lmeter_set_range(lv_obj_t *lmeter, int16_t min, int16_t max); - -/** - * Set the scale settings of a line meter - * @param lmeter pointer to a line meter object - * @param angle angle of the scale (0..360) - * @param line_cnt number of lines - */ -void lv_lmeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint8_t line_cnt); - -/** - * Set the styles of a line meter - * @param lmeter pointer to a line meter object - * @param bg set the style of the line meter - */ -static inline void lv_lmeter_set_style(lv_obj_t *lmeter, lv_style_t *bg) -{ - lv_obj_set_style(lmeter, bg); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a line meter - * @param lmeter pointer to a line meter object - * @return the value of the line meter - */ -int16_t lv_lmeter_get_value(const lv_obj_t *lmeter); - -/** - * Get the minimum value of a line meter - * @param lmeter pointer to a line meter object - * @return the minimum value of the line meter - */ -int16_t lv_lmeter_get_min_value(const lv_obj_t * lmeter); - -/** - * Get the maximum value of a line meter - * @param lmeter pointer to a line meter object - * @return the maximum value of the line meter - */ -int16_t lv_lmeter_get_max_value(const lv_obj_t * lmeter); - -/** - * Get the scale number of a line meter - * @param lmeter pointer to a line meter object - * @return number of the scale units - */ -uint8_t lv_lmeter_get_line_count(const lv_obj_t * lmeter); - -/** - * Get the scale angle of a line meter - * @param lmeter pointer to a line meter object - * @return angle of the scale - */ -uint16_t lv_lmeter_get_scale_angle(const lv_obj_t * lmeter); - -/** - * Get the style of a line meter - * @param lmeter pointer to a line meter object - * @return pointer to the line meter's style - */ -static inline lv_style_t * lv_lmeter_get_style(const lv_obj_t * lmeter) -{ - return lv_obj_get_style(lmeter); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_LMETER*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_LMETER_H*/ diff --git a/include/display/lv_objx/lv_mbox.h b/include/display/lv_objx/lv_mbox.h deleted file mode 100644 index 2dc0c6dc..00000000 --- a/include/display/lv_objx/lv_mbox.h +++ /dev/null @@ -1,203 +0,0 @@ -/** - * @file lv_mbox.h - * - */ - -#ifndef LV_MBOX_H -#define LV_MBOX_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_MBOX != 0 - -/*Testing of dependencies*/ -#if USE_LV_CONT == 0 -#error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " -#endif - -#if USE_LV_BTNM == 0 -#error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_mbox: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - - -#include "display/lv_core/lv_obj.h" -#include "lv_cont.h" -#include "lv_btnm.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of message box*/ -typedef struct -{ - lv_cont_ext_t bg; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t *text; /*Text of the message box*/ - lv_obj_t *btnm; /*Button matrix for the buttons*/ - uint16_t anim_time; /*Duration of close animation [ms] (0: no animation)*/ -} lv_mbox_ext_t; - -enum { - LV_MBOX_STYLE_BG, - LV_MBOX_STYLE_BTN_BG, - LV_MBOX_STYLE_BTN_REL, - LV_MBOX_STYLE_BTN_PR, - LV_MBOX_STYLE_BTN_TGL_REL, - LV_MBOX_STYLE_BTN_TGL_PR, - LV_MBOX_STYLE_BTN_INA, -}; -typedef uint8_t lv_mbox_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a message box objects - * @param par pointer to an object, it will be the parent of the new message box - * @param copy pointer to a message box object, if not NULL then the new object will be copied from it - * @return pointer to the created message box - */ -lv_obj_t * lv_mbox_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Add button to the message box - * @param mbox pointer to message box object - * @param btn_map button descriptor (button matrix map). - * E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable) - * @param action a function which will be called when a button is released - */ -void lv_mbox_add_btns(lv_obj_t * mbox, const char **btn_map, lv_btnm_action_t action); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the text of the message box - * @param mbox pointer to a message box - * @param txt a '\0' terminated character string which will be the message box text - */ -void lv_mbox_set_text(lv_obj_t * mbox, const char * txt); - -/** - * Stop the action to call when button is released - * @param mbox pointer to a message box object - * @param pointer to an 'lv_btnm_action_t' action. In the action you need to use `lv_mbox_get_from_btn()` to get the `mbox`. - */ -void lv_mbox_set_action(lv_obj_t * mbox, lv_btnm_action_t action); - -/** - * Set animation duration - * @param mbox pointer to a message box object - * @param anim_time animation length in milliseconds (0: no animation) - */ -void lv_mbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time); - -/** - * Automatically delete the message box after a given time - * @param mbox pointer to a message box object - * @param delay a time (in milliseconds) to wait before delete the message box - */ -void lv_mbox_start_auto_close(lv_obj_t * mbox, uint16_t delay); - -/** - * Stop the auto. closing of message box - * @param mbox pointer to a message box object - */ -void lv_mbox_stop_auto_close(lv_obj_t * mbox); - -/** - * Set a style of a message box - * @param mbox pointer to a message box object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_mbox_set_style(lv_obj_t *mbox, lv_mbox_style_t type, lv_style_t *style); - -/** - * Set whether recoloring is enabled. Must be called after `lv_mbox_add_btns`. - * @param btnm pointer to button matrix object - * @param en whether recoloring is enabled - */ -void lv_mbox_set_recolor(lv_obj_t * mbox, bool en); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the text of the message box - * @param mbox pointer to a message box object - * @return pointer to the text of the message box - */ -const char * lv_mbox_get_text(const lv_obj_t * mbox); - -/** - * Get the message box object from one of its button. - * It is useful in the button release actions where only the button is known - * @param btn pointer to a button of a message box - * @return pointer to the button's message box - */ -lv_obj_t * lv_mbox_get_from_btn(const lv_obj_t * btn); - -/** - * Get the animation duration (close animation time) - * @param mbox pointer to a message box object - * @return animation length in milliseconds (0: no animation) - */ -uint16_t lv_mbox_get_anim_time(const lv_obj_t * mbox); - - -/** - * Get a style of a message box - * @param mbox pointer to a message box object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_mbox_get_style(const lv_obj_t *mbox, lv_mbox_style_t type); - -/** - * Get whether recoloring is enabled - * @param btnm pointer to button matrix object - * @return whether recoloring is enabled - */ -bool lv_mbox_get_recolor(const lv_obj_t * mbox); - -/********************** - * MACROS - **********************/ - - -#endif /*USE_LV_MBOX*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_MBOX_H*/ diff --git a/include/display/lv_objx/lv_objx.mk b/include/display/lv_objx/lv_objx.mk deleted file mode 100644 index d35252bc..00000000 --- a/include/display/lv_objx/lv_objx.mk +++ /dev/null @@ -1,36 +0,0 @@ -CSRCS += lv_arc.c -CSRCS += lv_bar.c -CSRCS += lv_cb.c -CSRCS += lv_ddlist.c -CSRCS += lv_kb.c -CSRCS += lv_line.c -CSRCS += lv_mbox.c -CSRCS += lv_preload.c -CSRCS += lv_roller.c -CSRCS += lv_table.c -CSRCS += lv_tabview.c -CSRCS += lv_tileview.c -CSRCS += lv_btn.c -CSRCS += lv_calendar.c -CSRCS += lv_chart.c -CSRCS += lv_canvas.c -CSRCS += lv_gauge.c -CSRCS += lv_label.c -CSRCS += lv_list.c -CSRCS += lv_slider.c -CSRCS += lv_ta.c -CSRCS += lv_spinbox.c -CSRCS += lv_btnm.c -CSRCS += lv_cont.c -CSRCS += lv_img.c -CSRCS += lv_imgbtn.c -CSRCS += lv_led.c -CSRCS += lv_lmeter.c -CSRCS += lv_page.c -CSRCS += lv_sw.c -CSRCS += lv_win.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_objx -VPATH += :$(LVGL_DIR)/lvgl/lv_objx - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_objx" diff --git a/include/display/lv_objx/lv_objx_templ.h b/include/display/lv_objx/lv_objx_templ.h deleted file mode 100644 index b8473dfb..00000000 --- a/include/display/lv_objx/lv_objx_templ.h +++ /dev/null @@ -1,111 +0,0 @@ -/** - * @file lv_templ.h - * - */ - - -/* TODO Remove these instructions - * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) - * templ -> object short name with lower case(e.g. btn, label etc) - * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) - * - */ - -#ifndef LV_TEMPL_H -#define LV_TEMPL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TEMPL != 0 - -#include "display/lv_core/lv_obj.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of template*/ -typedef struct { - lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ - /*New data for this type */ -} lv_templ_ext_t; - - -/*Styles*/ -enum { - LV_TEMPL_STYLE_X, - LV_TEMPL_STYLE_Y, -}; -typedef uint8_t lv_templ_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a template objects - * @param par pointer to an object, it will be the parent of the new template - * @param copy pointer to a template object, if not NULL then the new object will be copied from it - * @return pointer to the created template - */ -lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a style of a template. - * @param templ pointer to template object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get style of a template. - * @param templ pointer to template object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TEMPL*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TEMPL_H*/ diff --git a/include/display/lv_objx/lv_page.h b/include/display/lv_objx/lv_page.h deleted file mode 100644 index d01de358..00000000 --- a/include/display/lv_objx/lv_page.h +++ /dev/null @@ -1,382 +0,0 @@ -/** - * @file lv_page.h - * - */ - -#ifndef LV_PAGE_H -#define LV_PAGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_PAGE != 0 - -/*Testing of dependencies*/ -#if USE_LV_CONT == 0 -#error "lv_page: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " -#endif - -#include "lv_cont.h" -#include "display/lv_core/lv_indev.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Scrollbar modes: shows when should the scrollbars be visible*/ -enum -{ - LV_SB_MODE_OFF = 0x0, /*Never show scrollbars*/ - LV_SB_MODE_ON = 0x1, /*Always show scrollbars*/ - LV_SB_MODE_DRAG = 0x2, /*Show scrollbars when page is being dragged*/ - LV_SB_MODE_AUTO = 0x3, /*Show scrollbars when the scrollable container is large enough to be scrolled*/ - LV_SB_MODE_HIDE = 0x4, /*Hide the scroll bar temporally*/ - LV_SB_MODE_UNHIDE = 0x5, /*Unhide the previously hidden scrollbar. Recover it's type too*/ -}; -typedef uint8_t lv_sb_mode_t; - -/*Data of page*/ -typedef struct -{ - lv_cont_ext_t bg; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * scrl; /*The scrollable object on the background*/ - lv_action_t rel_action; /*Function to call when the page is released*/ - lv_action_t pr_action; /*Function to call when the page is pressed*/ - struct { - lv_style_t *style; /*Style of scrollbars*/ - lv_area_t hor_area; /*Horizontal scrollbar area relative to the page. (Handled by the library) */ - lv_area_t ver_area; /*Vertical scrollbar area relative to the page (Handled by the library)*/ - uint8_t hor_draw :1; /*1: horizontal scrollbar is visible now (Handled by the library)*/ - uint8_t ver_draw :1; /*1: vertical scrollbar is visible now (Handled by the library)*/ - lv_sb_mode_t mode:3; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/ - } sb; - struct { - uint16_t state; /*Store the current size of the edge flash effect*/ - lv_style_t *style; /*Style of edge flash effect (usually homogeneous circle)*/ - uint8_t enabled :1; /*1: Show a flash animation on the edge*/ - uint8_t top_ip :1; /*Used internally to show that top most position is reached (flash is In Progress)*/ - uint8_t bottom_ip :1; /*Used internally to show that bottom most position is reached (flash is In Progress)*/ - uint8_t right_ip :1; /*Used internally to show that right most position is reached (flash is In Progress)*/ - uint8_t left_ip :1; /*Used internally to show that left most position is reached (flash is In Progress)*/ - }edge_flash; - - uint8_t arrow_scroll :1; /*1: Enable scrolling with LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN*/ - uint8_t scroll_prop :1; /*1: Propagate the scrolling the the parent if the edge is reached*/ - uint8_t scroll_prop_ip :1; /*1: Scroll propagation is in progress (used by the library)*/ -} lv_page_ext_t; - -enum { - LV_PAGE_STYLE_BG, - LV_PAGE_STYLE_SCRL, - LV_PAGE_STYLE_SB, - LV_PAGE_STYLE_EDGE_FLASH, -}; -typedef uint8_t lv_page_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a page objects - * @param par pointer to an object, it will be the parent of the new page - * @param copy pointer to a page object, if not NULL then the new object will be copied from it - * @return pointer to the created page - */ -lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Delete all children of the scrl object, without deleting scrl child. - * @param obj pointer to an object - */ -void lv_page_clean(lv_obj_t *obj); - -/** - * Get the press action of the page - * @param page pointer to a page object - * @return a function to call when the page is pressed - */ -lv_action_t lv_page_get_pr_action(lv_obj_t * page); - -/** - * Get the release action of the page - * @param page pointer to a page object - * @return a function to call when the page is released - */ -lv_action_t lv_page_get_rel_action(lv_obj_t * page); - -/** - * Get the scrollable object of a page - * @param page pointer to a page object - * @return pointer to a container which is the scrollable part of the page - */ -lv_obj_t * lv_page_get_scrl(const lv_obj_t * page); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a release action for the page - * @param page pointer to a page object - * @param rel_action a function to call when the page is released - */ -void lv_page_set_rel_action(lv_obj_t * page, lv_action_t rel_action); - -/** - * Set a press action for the page - * @param page pointer to a page object - * @param pr_action a function to call when the page is pressed - */ -void lv_page_set_pr_action(lv_obj_t * page, lv_action_t pr_action); - -/** - * Set the scroll bar mode on a page - * @param page pointer to a page object - * @param sb_mode the new mode from 'lv_page_sb.mode_t' enum - */ -void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode); - -/** - * Enable/Disable scrolling with arrows if the page is in group (arrows: LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) - * @param page pointer to a page object - * @param en true: enable scrolling with arrows - */ -void lv_page_set_arrow_scroll(lv_obj_t * page, bool en); - -/** - * Enable the scroll propagation feature. If enabled then the page will move its parent if there is no more space to scroll. - * @param page pointer to a Page - * @param en true or false to enable/disable scroll propagation - */ -void lv_page_set_scroll_propagation(lv_obj_t * page, bool en); - -/** - * Enable the edge flash effect. (Show an arc when the an edge is reached) - * @param page pointer to a Page - * @param en true or false to enable/disable end flash - */ -void lv_page_set_edge_flash(lv_obj_t * page, bool en); - -/** - * Set the fit attribute of the scrollable part of a page. - * It means it can set its size automatically to involve all children. - * (Can be set separately horizontally and vertically) - * @param page pointer to a page object - * @param hor_en true: enable horizontal fit - * @param ver_en true: enable vertical fit - */ -static inline void lv_page_set_scrl_fit(lv_obj_t *page, bool hor_en, bool ver_en) -{ - lv_cont_set_fit(lv_page_get_scrl(page), hor_en, ver_en); -} - -/** - * Set width of the scrollable part of a page - * @param page pointer to a page object - * @param w the new width of the scrollable (it ha no effect is horizontal fit is enabled) - */ -static inline void lv_page_set_scrl_width(lv_obj_t *page, lv_coord_t w) -{ - lv_obj_set_width(lv_page_get_scrl(page), w); -} - -/** - * Set height of the scrollable part of a page - * @param page pointer to a page object - * @param h the new height of the scrollable (it ha no effect is vertical fit is enabled) - */ -static inline void lv_page_set_scrl_height(lv_obj_t *page, lv_coord_t h) -{ - lv_obj_set_height(lv_page_get_scrl(page), h); - -} - -/** -* Set the layout of the scrollable part of the page -* @param page pointer to a page object -* @param layout a layout from 'lv_cont_layout_t' -*/ -static inline void lv_page_set_scrl_layout(lv_obj_t * page, lv_layout_t layout) -{ - lv_cont_set_layout(lv_page_get_scrl(page), layout); -} - -/** - * Set a style of a page - * @param page pointer to a page object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_page_set_style(lv_obj_t *page, lv_page_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Set the scroll bar mode on a page - * @param page pointer to a page object - * @return the mode from 'lv_page_sb.mode_t' enum - */ -lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page); - - -/** - * Get the the scrolling with arrows (LV_GROUP_KEY_LEFT/RIGHT/UP/DOWN) is enabled or not - * @param page pointer to a page object - * @return true: scrolling with arrows is enabled - */ -bool lv_page_get_arrow_scroll(const lv_obj_t * page); - -/** - * Get the scroll propagation property - * @param page pointer to a Page - * @return true or false - */ -bool lv_page_get_scroll_propagation(lv_obj_t * page); - -/** - * Get the edge flash effect property. - * @param page pointer to a Page - * return true or false - */ -bool lv_page_get_edge_flash(lv_obj_t * page); - -/** - * Get that width which can be set to the children to still not cause overflow (show scrollbars) - * @param page pointer to a page object - * @return the width which still fits into the page - */ -lv_coord_t lv_page_get_fit_width(lv_obj_t * page); - -/** - * Get that height which can be set to the children to still not cause overflow (show scrollbars) - * @param page pointer to a page object - * @return the height which still fits into the page - */ -lv_coord_t lv_page_get_fit_height(lv_obj_t * page); - -/** - * Get width of the scrollable part of a page - * @param page pointer to a page object - * @return the width of the scrollable - */ -static inline lv_coord_t lv_page_get_scrl_width(const lv_obj_t *page) -{ - return lv_obj_get_width(lv_page_get_scrl(page)); -} - -/** - * Get height of the scrollable part of a page - * @param page pointer to a page object - * @return the height of the scrollable - */ -static inline lv_coord_t lv_page_get_scrl_height(const lv_obj_t *page) -{ - return lv_obj_get_height(lv_page_get_scrl(page)); -} - -/** -* Get the layout of the scrollable part of a page -* @param page pointer to page object -* @return the layout from 'lv_cont_layout_t' -*/ -static inline lv_layout_t lv_page_get_scrl_layout(const lv_obj_t * page) -{ - return lv_cont_get_layout(lv_page_get_scrl(page)); -} - -/** -* Get horizontal fit attribute of the scrollable part of a page -* @param page pointer to a page object -* @return true: horizontal fit is enabled; false: disabled -*/ -static inline bool lv_page_get_scrl_hor_fit(const lv_obj_t * page) -{ - return lv_cont_get_hor_fit(lv_page_get_scrl(page)); -} - -/** -* Get vertical fit attribute of the scrollable part of a page -* @param page pointer to a page object -* @return true: vertical fit is enabled; false: disabled -*/ -static inline bool lv_page_get_scrl_fit_ver(const lv_obj_t * page) -{ - return lv_cont_get_ver_fit(lv_page_get_scrl(page)); -} - -/** - * Get a style of a page - * @param page pointer to page object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_page_get_style(const lv_obj_t *page, lv_page_style_t type); - -/*===================== - * Other functions - *====================*/ - -/** - * Glue the object to the page. After it the page can be moved (dragged) with this object too. - * @param obj pointer to an object on a page - * @param glue true: enable glue, false: disable glue - */ -void lv_page_glue_obj(lv_obj_t * obj, bool glue); - -/** - * Focus on an object. It ensures that the object will be visible on the page. - * @param page pointer to a page object - * @param obj pointer to an object to focus (must be on the page) - * @param anim_time scroll animation time in milliseconds (0: no animation) - */ -void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time); - -/** - * Scroll the page horizontally - * @param page pointer to a page object - * @param dist the distance to scroll (< 0: scroll left; > 0 scroll right) - */ -void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist); - -/** - * Scroll the page vertically - * @param page pointer to a page object - * @param dist the distance to scroll (< 0: scroll down; > 0 scroll up) - */ -void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist); - -/** - * Not intended to use directly by the user but by other object types internally. - * Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set - * @param page - */ -void lv_page_start_edge_flash(lv_obj_t * page); -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_PAGE*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_PAGE_H*/ diff --git a/include/display/lv_objx/lv_preload.h b/include/display/lv_objx/lv_preload.h deleted file mode 100644 index 7e228906..00000000 --- a/include/display/lv_objx/lv_preload.h +++ /dev/null @@ -1,168 +0,0 @@ -/** - * @file lv_preload.h - * - */ - -#ifndef LV_PRELOAD_H -#define LV_PRELOAD_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_PRELOAD != 0 - -/*Testing of dependencies*/ -#if USE_LV_ARC == 0 -#error "lv_preload: lv_arc is required. Enable it in lv_conf.h (USE_LV_ARC 1) " -#endif - -#if USE_LV_ANIMATION == 0 -#error "lv_preload: animations are required. Enable it in lv_conf.h (USE_LV_ANIMATION 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_arc.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -enum { - LV_PRELOAD_TYPE_SPINNING_ARC, - LV_PRELOAD_TYPE_FILLSPIN_ARC, -}; -typedef uint8_t lv_preloader_type_t; - -/*Data of pre loader*/ -typedef struct { - lv_arc_ext_t arc; /*Ext. of ancestor*/ - /*New data for this type */ - uint16_t arc_length; /*Length of the spinning indicator in degree*/ - uint16_t time; /*Time of one round*/ - lv_preloader_type_t anim_type; /*Type of the arc animation*/ -} lv_preload_ext_t; - - -/*Styles*/ -enum { - LV_PRELOAD_STYLE_MAIN, -}; -typedef uint8_t lv_preload_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a pre loader objects - * @param par pointer to an object, it will be the parent of the new pre loader - * @param copy pointer to a pre loader object, if not NULL then the new object will be copied from it - * @return pointer to the created pre loader - */ -lv_obj_t * lv_preload_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Set the length of the spinning arc in degrees - * @param preload pointer to a preload object - * @param deg length of the arc - */ -void lv_preload_set_arc_length(lv_obj_t * preload, uint16_t deg); - -/** - * Set the spin time of the arc - * @param preload pointer to a preload object - * @param time time of one round in milliseconds - */ -void lv_preload_set_spin_time(lv_obj_t * preload, uint16_t time); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a style of a pre loader. - * @param preload pointer to pre loader object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_preload_set_style(lv_obj_t * preload, lv_preload_style_t type, lv_style_t *style); - -/** - * Set the animation type of a preloadeer. - * @param preload pointer to pre loader object - * @param type animation type of the preload - * */ -void lv_preload_set_animation_type(lv_obj_t * preload, lv_preloader_type_t type); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the arc length [degree] of the a pre loader - * @param preload pointer to a pre loader object - */ -uint16_t lv_preload_get_arc_length(const lv_obj_t * preload); - -/** - * Get the spin time of the arc - * @param preload pointer to a pre loader object [milliseconds] - */ -uint16_t lv_preload_get_spin_time(const lv_obj_t * preload); - -/** - * Get style of a pre loader. - * @param preload pointer to pre loader object - * @param type which style should be get - * @return style pointer to the style - * */ -lv_style_t * lv_preload_get_style(const lv_obj_t * preload, lv_preload_style_t type); - -/** - * Get the animation type of a preloadeer. - * @param preload pointer to pre loader object - * @return animation type - * */ -lv_preloader_type_t lv_preload_get_animation_type(lv_obj_t * preload); - -/*===================== - * Other functions - *====================*/ - -/** - * Get style of a pre loader. - * @param preload pointer to pre loader object - * @param type which style should be get - * @return style pointer to the style - * */ -void lv_preload_spinner_animation(void * ptr, int32_t val); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_PRELOAD*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_PRELOAD_H*/ diff --git a/include/display/lv_objx/lv_roller.h b/include/display/lv_objx/lv_roller.h deleted file mode 100644 index 232f5526..00000000 --- a/include/display/lv_objx/lv_roller.h +++ /dev/null @@ -1,224 +0,0 @@ -/** - * @file lv_roller.h - * - */ - -#ifndef LV_ROLLER_H -#define LV_ROLLER_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_ROLLER != 0 - -/*Testing of dependencies*/ -#if USE_LV_DDLIST == 0 -#error "lv_roller: lv_ddlist is required. Enable it in lv_conf.h (USE_LV_DDLIST 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_ddlist.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of roller*/ -typedef struct { - lv_ddlist_ext_t ddlist; /*Ext. of ancestor*/ - /*New data for this type */ -} lv_roller_ext_t; - -enum { - LV_ROLLER_STYLE_BG, - LV_ROLLER_STYLE_SEL, -}; -typedef uint8_t lv_roller_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a roller object - * @param par pointer to an object, it will be the parent of the new roller - * @param copy pointer to a roller object, if not NULL then the new object will be copied from it - * @return pointer to the created roller - */ -lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the align of the roller's options (left, right or center[default]) - * @param roller - pointer to a roller object - * @param align - one of lv_label_align_t values (left, right, center) - */ -void lv_roller_set_align(lv_obj_t * roller, lv_label_align_t align); - -/** - * Set the options on a roller - * @param roller pointer to roller object - * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" - */ -static inline void lv_roller_set_options(lv_obj_t * roller, const char * options) -{ - lv_ddlist_set_options(roller, options); -} - -/** - * Set the selected option - * @param roller pointer to a roller object - * @param sel_opt id of the selected option (0 ... number of option - 1); - * @param anim_en true: set with animation; false set immediately - */ -void lv_roller_set_selected(lv_obj_t *roller, uint16_t sel_opt, bool anim_en); - -/** - * Set a function to call when a new option is chosen - * @param roller pointer to a roller - * @param action pointer to a callback function - */ -static inline void lv_roller_set_action(lv_obj_t * roller, lv_action_t action) -{ - lv_ddlist_set_action(roller, action); -} - -/** - * Set the height to show the given number of rows (options) - * @param roller pointer to a roller object - * @param row_cnt number of desired visible rows - */ -void lv_roller_set_visible_row_count(lv_obj_t *roller, uint8_t row_cnt); - -/** - * Enable or disable the horizontal fit to the content - * @param roller pointer to a roller - * @param en true: enable auto fit; false: disable auto fit - */ -static inline void lv_roller_set_hor_fit(lv_obj_t * roller, bool en) -{ - lv_ddlist_set_hor_fit(roller, en); -} - -/** - * Set the open/close animation time. - * @param roller pointer to a roller object - * @param anim_time: open/close animation time [ms] - */ -static inline void lv_roller_set_anim_time(lv_obj_t *roller, uint16_t anim_time) -{ - lv_ddlist_set_anim_time(roller, anim_time); -} - -/** - * Set a style of a roller - * @param roller pointer to a roller object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_roller_set_style(lv_obj_t *roller, lv_roller_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER - * @param roller pointer to a roller object - * @return LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_RIGHT or LV_LABEL_ALIGN_CENTER - */ -lv_label_align_t lv_roller_get_align(const lv_obj_t * roller); - -/** - * Get the options of a roller - * @param roller pointer to roller object - * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") - */ -static inline const char * lv_roller_get_options(const lv_obj_t *roller) -{ - return lv_ddlist_get_options(roller); -} - -/** - * Get the id of the selected option - * @param roller pointer to a roller object - * @return id of the selected option (0 ... number of option - 1); - */ -static inline uint16_t lv_roller_get_selected(const lv_obj_t *roller) -{ - return lv_ddlist_get_selected(roller); -} - -/** - * Get the current selected option as a string - * @param roller pointer to roller object - * @param buf pointer to an array to store the string - */ -static inline void lv_roller_get_selected_str(const lv_obj_t * roller, char * buf) -{ - lv_ddlist_get_selected_str(roller, buf); -} - -/** - * Get the "option selected" callback function - * @param roller pointer to a roller - * @return pointer to the call back function - */ -static inline lv_action_t lv_roller_get_action(const lv_obj_t * roller) -{ - return lv_ddlist_get_action(roller); -} - -/** - * Get the open/close animation time. - * @param roller pointer to a roller - * @return open/close animation time [ms] - */ -static inline uint16_t lv_roller_get_anim_time(const lv_obj_t * roller) -{ - return lv_ddlist_get_anim_time(roller); -} - -/** - * Get the auto width set attribute - * @param roller pointer to a roller object - * @return true: auto size enabled; false: manual width settings enabled - */ -bool lv_roller_get_hor_fit(const lv_obj_t *roller); - -/** - * Get a style of a roller - * @param roller pointer to a roller object - * @param type which style should be get - * @return style pointer to a style - * */ -lv_style_t * lv_roller_get_style(const lv_obj_t *roller, lv_roller_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_ROLLER*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_ROLLER_H*/ diff --git a/include/display/lv_objx/lv_slider.h b/include/display/lv_objx/lv_slider.h deleted file mode 100644 index 8d0d9d66..00000000 --- a/include/display/lv_objx/lv_slider.h +++ /dev/null @@ -1,202 +0,0 @@ -/** - * @file lv_slider.h - * - */ - -#ifndef LV_SLIDER_H -#define LV_SLIDER_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_SLIDER != 0 - -/*Testing of dependencies*/ -#if USE_LV_BAR == 0 -#error "lv_slider: lv_bar is required. Enable it in lv_conf.h (USE_LV_BAR 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_bar.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of slider*/ -typedef struct -{ - lv_bar_ext_t bar; /*Ext. of ancestor*/ - /*New data for this type */ - lv_action_t action; /*Function to call when a new value is set*/ - lv_style_t *style_knob; /*Style of the knob*/ - int16_t drag_value; /*Store a temporal value during press until release (Handled by the library)*/ - uint8_t knob_in :1; /*1: Draw the knob inside the bar*/ -} lv_slider_ext_t; - -/*Built-in styles of slider*/ -enum -{ - LV_SLIDER_STYLE_BG, - LV_SLIDER_STYLE_INDIC, - LV_SLIDER_STYLE_KNOB, -}; -typedef uint8_t lv_slider_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a slider objects - * @param par pointer to an object, it will be the parent of the new slider - * @param copy pointer to a slider object, if not NULL then the new object will be copied from it - * @return pointer to the created slider - */ -lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new value on the slider - * @param slider pointer to a slider object - * @param value new value - */ -static inline void lv_slider_set_value(lv_obj_t * slider, int16_t value) -{ - lv_bar_set_value(slider, value); -} - -/** - * Set a new value with animation on a slider - * @param slider pointer to a slider object - * @param value new value - * @param anim_time animation time in milliseconds - */ -static inline void lv_slider_set_value_anim(lv_obj_t * slider, int16_t value, uint16_t anim_time) -{ - lv_bar_set_value_anim(slider, value, anim_time); -} - -/** - * Set minimum and the maximum values of a bar - * @param slider pointer to the slider object - * @param min minimum value - * @param max maximum value - */ -static inline void lv_slider_set_range(lv_obj_t *slider, int16_t min, int16_t max) -{ - lv_bar_set_range(slider, min, max); -} - -/** - * Set a function which will be called when a new value is set on the slider - * @param slider pointer to slider object - * @param action a callback function - */ -void lv_slider_set_action(lv_obj_t * slider, lv_action_t action); - -/** - * Set the 'knob in' attribute of a slider - * @param slider pointer to slider object - * @param in true: the knob is drawn always in the slider; - * false: the knob can be out on the edges - */ -void lv_slider_set_knob_in(lv_obj_t * slider, bool in); - -/** - * Set a style of a slider - * @param slider pointer to a slider object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_slider_set_style(lv_obj_t *slider, lv_slider_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a slider - * @param slider pointer to a slider object - * @return the value of the slider - */ -int16_t lv_slider_get_value(const lv_obj_t * slider); - -/** - * Get the minimum value of a slider - * @param slider pointer to a slider object - * @return the minimum value of the slider - */ -static inline int16_t lv_slider_get_min_value(const lv_obj_t * slider) -{ - return lv_bar_get_min_value(slider); -} - -/** - * Get the maximum value of a slider - * @param slider pointer to a slider object - * @return the maximum value of the slider - */ -static inline int16_t lv_slider_get_max_value(const lv_obj_t * slider) -{ - return lv_bar_get_max_value(slider); -} - -/** - * Get the slider action function - * @param slider pointer to slider object - * @return the callback function - */ -lv_action_t lv_slider_get_action(const lv_obj_t * slider); - -/** - * Give the slider is being dragged or not - * @param slider pointer to a slider object - * @return true: drag in progress false: not dragged - */ -bool lv_slider_is_dragged(const lv_obj_t * slider); - -/** - * Get the 'knob in' attribute of a slider - * @param slider pointer to slider object - * @return true: the knob is drawn always in the slider; - * false: the knob can be out on the edges - */ -bool lv_slider_get_knob_in(const lv_obj_t * slider); - - -/** - * Get a style of a slider - * @param slider pointer to a slider object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_slider_get_style(const lv_obj_t *slider, lv_slider_style_t type); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_SLIDER*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_SLIDER_H*/ diff --git a/include/display/lv_objx/lv_spinbox.h b/include/display/lv_objx/lv_spinbox.h deleted file mode 100644 index 6ec1e667..00000000 --- a/include/display/lv_objx/lv_spinbox.h +++ /dev/null @@ -1,201 +0,0 @@ -/** - * @file lv_spinbox.h - * - */ - - -#ifndef LV_SPINBOX_H -#define LV_SPINBOX_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_SPINBOX != 0 - -/*Testing of dependencies*/ -#if USE_LV_TA == 0 -#error "lv_spinbox: lv_ta is required. Enable it in lv_conf.h (USE_LV_TA 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "display/lv_objx/lv_ta.h" - -/********************* - * DEFINES - *********************/ -#define LV_SPINBOX_MAX_DIGIT_COUNT 16 - -/********************** - * TYPEDEFS - **********************/ - -/*callback on value change*/ -typedef void (*lv_spinbox_value_changed_cb_t)(lv_obj_t * spinbox, int32_t new_value); - -/*Data of spinbox*/ -typedef struct { - lv_ta_ext_t ta; /*Ext. of ancestor*/ - /*New data for this type */ - int32_t value; - int32_t range_max; - int32_t range_min; - int32_t step; - uint16_t digit_count:4; - uint16_t dec_point_pos:4; /*if 0, there is no separator and the number is an integer*/ - uint16_t digit_padding_left:4; - lv_spinbox_value_changed_cb_t value_changed_cb; -} lv_spinbox_ext_t; - - -/*Styles*/ -enum { - LV_SPINBOX_STYLE_BG, - LV_SPINBOX_STYLE_SB, - LV_SPINBOX_STYLE_CURSOR, -}; -typedef uint8_t lv_spinbox_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a spinbox objects - * @param par pointer to an object, it will be the parent of the new spinbox - * @param copy pointer to a spinbox object, if not NULL then the new object will be copied from it - * @return pointer to the created spinbox - */ -lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a style of a spinbox. - * @param templ pointer to template object - * @param type which style should be set - * @param style pointer to a style - */ -static inline void lv_spinbox_set_style(lv_obj_t * spinbox, lv_spinbox_style_t type, lv_style_t *style) -{ - lv_ta_set_style(spinbox, type, style); -} - -/** - * Set spinbox value - * @param spinbox pointer to spinbox - * @param i value to be set - */ -void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i); - -/** - * Set spinbox digit format (digit count and decimal format) - * @param spinbox pointer to spinbox - * @param digit_count number of digit excluding the decimal separator and the sign - * @param separator_position number of digit before the decimal point. If 0, decimal point is not shown - */ -void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position); - -/** - * Set spinbox step - * @param spinbox pointer to spinbox - * @param step steps on increment/decrement - */ -void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step); - -/** - * Set spinbox value range - * @param spinbox pointer to spinbox - * @param range_min maximum value, inclusive - * @param range_max minimum value, inclusive - */ -void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max); - -/** - * Set spinbox callback on calue change - * @param spinbox pointer to spinbox - * @param cb Callback function called on value change event - */ -void lv_spinbox_set_value_changed_cb(lv_obj_t * spinbox, lv_spinbox_value_changed_cb_t cb); - -/** - * Set spinbox left padding in digits count (added between sign and first digit) - * @param spinbox pointer to spinbox - * @param cb Callback function called on value change event - */ -void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get style of a spinbox. - * @param templ pointer to template object - * @param type which style should be get - * @return style pointer to the style - */ -static inline lv_style_t * lv_spinbox_get_style(lv_obj_t * spinbox, lv_spinbox_style_t type) -{ - return lv_ta_get_style(spinbox, type); -} - -/** - * Get the spinbox numeral value (user has to convert to float according to its digit format) - * @param spinbox pointer to spinbox - * @return value integer value of the spinbox - */ -int32_t lv_spinbox_get_value(lv_obj_t * spinbox); - -/*===================== - * Other functions - *====================*/ - -/** - * Select next lower digit for edition by dividing the step by 10 - * @param spinbox pointer to spinbox - */ -void lv_spinbox_step_next(lv_obj_t * spinbox); - -/** - * Select next higher digit for edition by multiplying the step by 10 - * @param spinbox pointer to spinbox - */ -void lv_spinbox_step_previous(lv_obj_t * spinbox); - -/** - * Increment spinbox value by one step - * @param spinbox pointer to spinbox - */ -void lv_spinbox_increment(lv_obj_t * spinbox); - -/** - * Decrement spinbox value by one step - * @param spinbox pointer to spinbox - */ -void lv_spinbox_decrement(lv_obj_t * spinbox); - - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_SPINBOX*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_SPINBOX_H*/ diff --git a/include/display/lv_objx/lv_sw.h b/include/display/lv_objx/lv_sw.h deleted file mode 100644 index 7f4513c8..00000000 --- a/include/display/lv_objx/lv_sw.h +++ /dev/null @@ -1,194 +0,0 @@ -/** - * @file lv_sw.h - * - */ - -#ifndef LV_SW_H -#define LV_SW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_SW != 0 - -/*Testing of dependencies*/ -#if USE_LV_SLIDER == 0 -#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1)" -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_slider.h" - -/********************* - * DEFINES - *********************/ -#define LV_SWITCH_SLIDER_ANIM_MAX 1000 - -/********************** - * TYPEDEFS - **********************/ -/*Data of switch*/ -typedef struct -{ - lv_slider_ext_t slider; /*Ext. of ancestor*/ - /*New data for this type */ - lv_style_t *style_knob_off; /*Style of the knob when the switch is OFF*/ - lv_style_t *style_knob_on; /*Style of the knob when the switch is ON (NULL to use the same as OFF)*/ - lv_coord_t start_x; - uint8_t changed :1; /*Indicates the switch state explicitly changed by drag*/ - uint8_t slided :1; -#if USE_LV_ANIMATION - uint16_t anim_time; /*switch animation time */ -#endif -} lv_sw_ext_t; - -enum { - LV_SW_STYLE_BG, - LV_SW_STYLE_INDIC, - LV_SW_STYLE_KNOB_OFF, - LV_SW_STYLE_KNOB_ON, -}; -typedef uint8_t lv_sw_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a switch objects - * @param par pointer to an object, it will be the parent of the new switch - * @param copy pointer to a switch object, if not NULL then the new object will be copied from it - * @return pointer to the created switch - */ -lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Turn ON the switch - * @param sw pointer to a switch object - */ -void lv_sw_on(lv_obj_t *sw); - -/** - * Turn OFF the switch - * @param sw pointer to a switch object - */ -void lv_sw_off(lv_obj_t *sw); - -/** - * Toggle the position of the switch - * @param sw pointer to a switch object - * @return resulting state of the switch. - */ -bool lv_sw_toggle(lv_obj_t *sw); - -/** - * Turn ON the switch with an animation - * @param sw pointer to a switch object - */ -void lv_sw_on_anim(lv_obj_t * sw); - -/** - * Turn OFF the switch with an animation - * @param sw pointer to a switch object - */ -void lv_sw_off_anim(lv_obj_t * sw); - -/** - * Toggle the position of the switch with an animation - * @param sw pointer to a switch object - * @return resulting state of the switch. - */ -bool lv_sw_toggle_anim(lv_obj_t *sw); - -/** - * Set a function which will be called when the switch is toggled by the user - * @param sw pointer to switch object - * @param action a callback function - */ -static inline void lv_sw_set_action(lv_obj_t * sw, lv_action_t action) -{ - lv_slider_set_action(sw, action); -} - -/** - * Set a style of a switch - * @param sw pointer to a switch object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style); - -#if USE_LV_ANIMATION -/** - * Set the animation time of the switch - * @param sw pointer to a switch object - * @param anim_time animation time - * @return style pointer to a style - */ -void lv_sw_set_anim_time(lv_obj_t *sw, uint16_t anim_time); -#endif - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the state of a switch - * @param sw pointer to a switch object - * @return false: OFF; true: ON - */ -static inline bool lv_sw_get_state(const lv_obj_t *sw) -{ - return lv_bar_get_value(sw) < LV_SWITCH_SLIDER_ANIM_MAX / 2 ? false : true; -} - -/** - * Get the switch action function - * @param slider pointer to a switch object - * @return the callback function - */ -static inline lv_action_t lv_sw_get_action(const lv_obj_t * slider) -{ - return lv_slider_get_action(slider); -} - -/** - * Get a style of a switch - * @param sw pointer to a switch object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_sw_get_style(const lv_obj_t *sw, lv_sw_style_t type); - -/** - * Get the animation time of the switch - * @param sw pointer to a switch object - * @return style pointer to a style - */ -uint16_t lv_sw_get_anim_time(const lv_obj_t *sw); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_SW*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_SW_H*/ diff --git a/include/display/lv_objx/lv_ta.h b/include/display/lv_objx/lv_ta.h deleted file mode 100644 index 8e12314a..00000000 --- a/include/display/lv_objx/lv_ta.h +++ /dev/null @@ -1,390 +0,0 @@ -/** - * @file lv_ta.h - * - */ - -#ifndef LV_TA_H -#define LV_TA_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TA != 0 - -/*Testing of dependencies*/ -#if USE_LV_PAGE == 0 -#error "lv_ta: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_ta: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_page.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ -#define LV_TA_CURSOR_LAST (0x7FFF) /*Put the cursor after the last character*/ - -/********************** - * TYPEDEFS - **********************/ - -enum { - LV_CURSOR_NONE, - LV_CURSOR_LINE, - LV_CURSOR_BLOCK, - LV_CURSOR_OUTLINE, - LV_CURSOR_UNDERLINE, - LV_CURSOR_HIDDEN = 0x08, /*Or it to any value to hide the cursor temporally*/ -}; -typedef uint8_t lv_cursor_type_t; - -/*Data of text area*/ -typedef struct -{ - lv_page_ext_t page; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * label; /*Label of the text area*/ - char * pwd_tmp; /*Used to store the original text in password mode*/ - const char * accapted_chars;/*Only these characters will be accepted. NULL: accept all*/ - uint16_t max_length; /*The max. number of characters. 0: no limit*/ - uint8_t pwd_mode :1; /*Replace characters with '*' */ - uint8_t one_line :1; /*One line mode (ignore line breaks)*/ - struct { - lv_style_t *style; /*Style of the cursor (NULL to use label's style)*/ - lv_coord_t valid_x; /*Used when stepping up/down in text area when stepping to a shorter line. (Handled by the library)*/ - uint16_t pos; /*The current cursor position (0: before 1. letter; 1: before 2. letter etc.)*/ - lv_area_t area; /*Cursor area relative to the Text Area*/ - uint16_t txt_byte_pos; /*Byte index of the letter after (on) the cursor*/ - lv_cursor_type_t type:4; /*Shape of the cursor*/ - uint8_t state :1; /*Indicates that the cursor is visible now or not (Handled by the library)*/ - } cursor; -} lv_ta_ext_t; - -enum { - LV_TA_STYLE_BG, - LV_TA_STYLE_SB, - LV_TA_STYLE_EDGE_FLASH, - LV_TA_STYLE_CURSOR, -}; -typedef uint8_t lv_ta_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Create a text area objects - * @param par pointer to an object, it will be the parent of the new text area - * @param copy pointer to a text area object, if not NULL then the new object will be copied from it - * @return pointer to the created text area - */ -lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy); - - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Insert a character to the current cursor position. - * To add a wide char, e.g. 'Á' use `lv_txt_encoded_conv_wc('Á')` - * @param ta pointer to a text area object - * @param c a character (e.g. 'a') - */ -void lv_ta_add_char(lv_obj_t * ta, uint32_t c); - -/** - * Insert a text to the current cursor position - * @param ta pointer to a text area object - * @param txt a '\0' terminated string to insert - */ -void lv_ta_add_text(lv_obj_t * ta, const char * txt); - -/** - * Delete a the left character from the current cursor position - * @param ta pointer to a text area object - */ -void lv_ta_del_char(lv_obj_t * ta); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the text of a text area - * @param ta pointer to a text area - * @param txt pointer to the text - */ -void lv_ta_set_text(lv_obj_t * ta, const char * txt); - -/** - * Set the cursor position - * @param obj pointer to a text area object - * @param pos the new cursor position in character index - * < 0 : index from the end of the text - * LV_TA_CURSOR_LAST: go after the last character - */ -void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos); - -/** - * Set the cursor type. - * @param ta pointer to a text area object - * @param cur_type: element of 'lv_cursor_type_t' - */ -void lv_ta_set_cursor_type(lv_obj_t * ta, lv_cursor_type_t cur_type); - -/** - * Enable/Disable password mode - * @param ta pointer to a text area object - * @param en true: enable, false: disable - */ -void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en); - -/** - * Configure the text area to one line or back to normal - * @param ta pointer to a Text area object - * @param en true: one line, false: normal - */ -void lv_ta_set_one_line(lv_obj_t * ta, bool en); - -/** - * Set the alignment of the text area. - * In one line mode the text can be scrolled only with `LV_LABEL_ALIGN_LEFT`. - * This function should be called if the size of text area changes. - * @param ta pointer to a text are object - * @param align the desired alignment from `lv_label_align_t`. (LV_LABEL_ALIGN_LEFT/CENTER/RIGHT) - */ -void lv_ta_set_text_align(lv_obj_t * ta, lv_label_align_t align); - -/** - * Set a list of characters. Only these characters will be accepted by the text area - * @param ta pointer to Text Area - * @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789" - */ -void lv_ta_set_accepted_chars(lv_obj_t * ta, const char * list); - -/** - * Set max length of a Text Area. - * @param ta pointer to Text Area - * @param num the maximal number of characters can be added (`lv_ta_set_text` ignores it) - */ -void lv_ta_set_max_length(lv_obj_t * ta, uint16_t num); - -/** - * Set an action to call when the Text area is clicked - * @param ta pointer to a Text area - * @param action a function pointer - */ -static inline void lv_ta_set_action(lv_obj_t * ta, lv_action_t action) -{ - lv_page_set_rel_action(ta, action); -} - -/** - * Set the scroll bar mode of a text area - * @param ta pointer to a text area object - * @param sb_mode the new mode from 'lv_page_sb_mode_t' enum - */ -static inline void lv_ta_set_sb_mode(lv_obj_t * ta, lv_sb_mode_t mode) -{ - lv_page_set_sb_mode(ta, mode); -} - -/** - * Enable the scroll propagation feature. If enabled then the Text area will move its parent if there is no more space to scroll. - * @param ta pointer to a Text area - * @param en true or false to enable/disable scroll propagation - */ -static inline void lv_ta_set_scroll_propagation(lv_obj_t * ta, bool en) -{ - lv_page_set_scroll_propagation(ta, en); -} - -/** - * Enable the edge flash effect. (Show an arc when the an edge is reached) - * @param page pointer to a Text Area - * @param en true or false to enable/disable end flash - */ -static inline void lv_ta_set_edge_flash(lv_obj_t * ta, bool en) -{ - lv_page_set_edge_flash(ta, en); -} - -/** - * Set a style of a text area - * @param ta pointer to a text area object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_ta_set_style(lv_obj_t *ta, lv_ta_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the text of a text area. In password mode it gives the real text (not '*'s). - * @param ta pointer to a text area object - * @return pointer to the text - */ -const char * lv_ta_get_text(const lv_obj_t * ta); - -/** - * Get the label of a text area - * @param ta pointer to a text area object - * @return pointer to the label object - */ -lv_obj_t * lv_ta_get_label(const lv_obj_t * ta); - -/** - * Get the current cursor position in character index - * @param ta pointer to a text area object - * @return the cursor position - */ -uint16_t lv_ta_get_cursor_pos(const lv_obj_t * ta); - -/** - * Get the current cursor visibility. - * @param ta pointer to a text area object - * @return true: the cursor is drawn, false: the cursor is hidden - */ -//bool lv_ta_get_cursor_show(const lv_obj_t * ta); - -/** - * Get the current cursor type. - * @param ta pointer to a text area object - * @return element of 'lv_cursor_type_t' - */ -lv_cursor_type_t lv_ta_get_cursor_type(const lv_obj_t * ta); - -/** - * Get the password mode attribute - * @param ta pointer to a text area object - * @return true: password mode is enabled, false: disabled - */ -bool lv_ta_get_pwd_mode(const lv_obj_t * ta); - -/** - * Get the one line configuration attribute - * @param ta pointer to a text area object - * @return true: one line configuration is enabled, false: disabled - */ -bool lv_ta_get_one_line(const lv_obj_t * ta); - -/** - * Get a list of accepted characters. - * @param ta pointer to Text Area - * @return list of accented characters. - */ -const char * lv_ta_get_accepted_chars(lv_obj_t * ta); - -/** - * Set max length of a Text Area. - * @param ta pointer to Text Area - * @return the maximal number of characters to be add - */ -uint16_t lv_ta_get_max_length(lv_obj_t * ta); - -/** - * Set an action to call when the Text area is clicked - * @param ta pointer to a Text area - * @param action a function pointer - */ -static inline lv_action_t lv_ta_get_action(lv_obj_t * ta) -{ - return lv_page_get_rel_action(ta); -} - -/** - * Get the scroll bar mode of a text area - * @param ta pointer to a text area object - * @return scrollbar mode from 'lv_page_sb_mode_t' enum - */ -static inline lv_sb_mode_t lv_ta_get_sb_mode(const lv_obj_t * ta) -{ - return lv_page_get_sb_mode(ta); -} - -/** - * Get the scroll propagation property - * @param ta pointer to a Text area - * @return true or false - */ -static inline bool lv_ta_get_scroll_propagation(lv_obj_t * ta) -{ - return lv_page_get_scroll_propagation(ta); -} - -/** - * Get the scroll propagation property - * @param ta pointer to a Text area - * @return true or false - */ -static inline bool lv_ta_get_edge_flash(lv_obj_t * ta) -{ - return lv_page_get_edge_flash(ta); -} - -/** - * Get a style of a text area - * @param ta pointer to a text area object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_ta_get_style(const lv_obj_t *ta, lv_ta_style_t type); - -/*===================== - * Other functions - *====================*/ - -/** - * Move the cursor one character right - * @param ta pointer to a text area object - */ -void lv_ta_cursor_right(lv_obj_t * ta); - -/** - * Move the cursor one character left - * @param ta pointer to a text area object - */ -void lv_ta_cursor_left(lv_obj_t * ta); - -/** - * Move the cursor one line down - * @param ta pointer to a text area object - */ -void lv_ta_cursor_down(lv_obj_t * ta); - -/** - * Move the cursor one line up - * @param ta pointer to a text area object - */ -void lv_ta_cursor_up(lv_obj_t * ta); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TA_H*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TA_H*/ diff --git a/include/display/lv_objx/lv_table.h b/include/display/lv_objx/lv_table.h deleted file mode 100644 index 79ba22dc..00000000 --- a/include/display/lv_objx/lv_table.h +++ /dev/null @@ -1,261 +0,0 @@ -/** - * @file lv_table.h - * - */ - -#ifndef LV_TABLE_H -#define LV_TABLE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TABLE != 0 - -/*Testing of dependencies*/ -#if USE_LV_LABEL == 0 -#error "lv_table: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_label.h" - -/********************* - * DEFINES - *********************/ -#ifndef LV_TABLE_COL_MAX -#define LV_TABLE_COL_MAX 12 -#endif - -#define LV_TABLE_CELL_STYLE_CNT 4 -/********************** - * TYPEDEFS - **********************/ - -typedef union { - struct { - uint8_t align:2; - uint8_t right_merge:1; - uint8_t type:2; - uint8_t crop:1; - }; - uint8_t format_byte; -}lv_table_cell_format_t; - -/*Data of table*/ -typedef struct { - /*New data for this type */ - uint16_t col_cnt; - uint16_t row_cnt; - char ** cell_data; - lv_style_t * cell_style[LV_TABLE_CELL_STYLE_CNT]; - lv_coord_t col_w[LV_TABLE_COL_MAX]; -} lv_table_ext_t; - - -/*Styles*/ -enum { - LV_TABLE_STYLE_BG, - LV_TABLE_STYLE_CELL1, - LV_TABLE_STYLE_CELL2, - LV_TABLE_STYLE_CELL3, - LV_TABLE_STYLE_CELL4, -}; -typedef uint8_t lv_table_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a table object - * @param par pointer to an object, it will be the parent of the new table - * @param copy pointer to a table object, if not NULL then the new object will be copied from it - * @return pointer to the created table - */ -lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set the value of a cell. - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param txt text to display in the cell. It will be copied and saved so this variable is not required after this function call. - */ -void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const char * txt); - -/** - * Set the number of rows - * @param table table pointer to a Table object - * @param row_cnt number of rows - */ -void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt); - -/** - * Set the number of columns - * @param table table pointer to a Table object - * @param col_cnt number of columns. Must be < LV_TABLE_COL_MAX - */ -void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt); - -/** - * Set the width of a column - * @param table table pointer to a Table object - * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] - * @param w width of the column - */ -void lv_table_set_col_width(lv_obj_t * table, uint16_t col_id, lv_coord_t w); - -/** - * Set the text align in a cell - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param align LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT - */ -void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_label_align_t align); - -/** - * Set the type of a cell. - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param type 1,2,3 or 4. The cell style will be chosen accordingly. - */ -void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_t type); - -/** - * Set the cell crop. (Don't adjust the height of the cell according to its content) - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param crop true: crop the cell content; false: set the cell height to the content. - */ -void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool crop); - -/** - * Merge a cell with the right neighbor. The value of the cell to the right won't be displayed. - * @param table table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @param en true: merge right; false: don't merge right - */ -void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col, bool en); - -/** - * Set a style of a table. - * @param table pointer to table object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_table_set_style(lv_obj_t * table, lv_table_style_t type, lv_style_t * style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a cell. - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return text in the cell - */ -const char * lv_table_get_cell_value(lv_obj_t * table, uint16_t row, uint16_t col); - -/** - * Get the number of rows. - * @param table table pointer to a Table object - * @return number of rows. - */ -uint16_t lv_table_get_row_cnt(lv_obj_t * table); - -/** - * Get the number of columns. - * @param table table pointer to a Table object - * @return number of columns. - */ -uint16_t lv_table_get_col_cnt(lv_obj_t * table); - -/** - * Get the width of a column - * @param table table pointer to a Table object - * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] - * @return width of the column - */ -lv_coord_t lv_table_get_col_width(lv_obj_t * table, uint16_t col_id); - -/** - * Get the text align of a cell - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return LV_LABEL_ALIGN_LEFT (default in case of error) or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT - */ -lv_label_align_t lv_table_get_cell_align(lv_obj_t * table, uint16_t row, uint16_t col); - -/** - * Get the type of a cell - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return 1,2,3 or 4 - */ -lv_label_align_t lv_table_get_cell_type(lv_obj_t * table, uint16_t row, uint16_t col); - - -/** - * Get the crop property of a cell - * @param table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return true: text crop enabled; false: disabled - */ -lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col); - -/** - * Get the cell merge attribute. - * @param table table pointer to a Table object - * @param row id of the row [0 .. row_cnt -1] - * @param col id of the column [0 .. col_cnt -1] - * @return true: merge right; false: don't merge right - */ -bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col); - -/** - * Get style of a table. - * @param table pointer to table object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_table_get_style(const lv_obj_t * table, lv_table_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TABLE*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TABLE_H*/ diff --git a/include/display/lv_objx/lv_tabview.h b/include/display/lv_objx/lv_tabview.h deleted file mode 100644 index 73d8b17c..00000000 --- a/include/display/lv_objx/lv_tabview.h +++ /dev/null @@ -1,252 +0,0 @@ -/** - * @file lv_tabview.h - * - */ - -#ifndef LV_TABVIEW_H -#define LV_TABVIEW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TABVIEW != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTNM == 0 -#error "lv_tabview: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " -#endif - -#if USE_LV_PAGE == 0 -#error "lv_tabview: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "display/lv_objx/lv_win.h" -#include "display/lv_objx/lv_page.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/* parametes: pointer to a tabview object, tab_id - * return: LV_RES_INV: to prevent the loading of the tab; LV_RES_OK: if everything is fine*/ -typedef lv_res_t (*lv_tabview_action_t)(lv_obj_t *, uint16_t); - - -enum { - LV_TABVIEW_BTNS_POS_TOP, - LV_TABVIEW_BTNS_POS_BOTTOM, -}; -typedef uint8_t lv_tabview_btns_pos_t; - -/*Data of tab*/ -typedef struct -{ - /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * btns; - lv_obj_t * indic; - lv_obj_t * content; /*A rectangle to show the current tab*/ - const char ** tab_name_ptr; - lv_point_t point_last; - uint16_t tab_cur; - uint16_t tab_cnt; - uint16_t anim_time; - uint8_t slide_enable :1; /*1: enable horizontal sliding by touch pad*/ - uint8_t draging :1; - uint8_t drag_hor :1; - uint8_t btns_hide :1; - lv_tabview_btns_pos_t btns_pos :1; - lv_tabview_action_t tab_load_action; -} lv_tabview_ext_t; - -enum { - LV_TABVIEW_STYLE_BG, - LV_TABVIEW_STYLE_INDIC, - LV_TABVIEW_STYLE_BTN_BG, - LV_TABVIEW_STYLE_BTN_REL, - LV_TABVIEW_STYLE_BTN_PR, - LV_TABVIEW_STYLE_BTN_TGL_REL, - LV_TABVIEW_STYLE_BTN_TGL_PR, -}; -typedef uint8_t lv_tabview_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - - -/** - * Create a Tab view object - * @param par pointer to an object, it will be the parent of the new tab - * @param copy pointer to a tab object, if not NULL then the new object will be copied from it - * @return pointer to the created tab - */ -lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Delete all children of the scrl object, without deleting scrl child. - * @param obj pointer to an object - */ -void lv_tabview_clean(lv_obj_t *obj); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Add a new tab with the given name - * @param tabview pointer to Tab view object where to ass the new tab - * @param name the text on the tab button - * @return pointer to the created page object (lv_page). You can create your content here - */ -lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name); - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new tab - * @param tabview pointer to Tab view object - * @param id index of a tab to load - * @param anim_en true: set with sliding animation; false: set immediately - */ -void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en); - -/** - * Set an action to call when a tab is loaded (Good to create content only if required) - * lv_tabview_get_act() still gives the current (old) tab (to remove content from here) - * @param tabview pointer to a tabview object - * @param action pointer to a function to call when a tab is loaded - */ -void lv_tabview_set_tab_load_action(lv_obj_t *tabview, lv_tabview_action_t action); - -/** - * Enable horizontal sliding with touch pad - * @param tabview pointer to Tab view object - * @param en true: enable sliding; false: disable sliding - */ -void lv_tabview_set_sliding(lv_obj_t * tabview, bool en); - -/** - * Set the animation time of tab view when a new tab is loaded - * @param tabview pointer to Tab view object - * @param anim_time time of animation in milliseconds - */ -void lv_tabview_set_anim_time(lv_obj_t * tabview, uint16_t anim_time); - -/** - * Set the style of a tab view - * @param tabview pointer to a tan view object - * @param type which style should be set - * @param style pointer to the new style - */ -void lv_tabview_set_style(lv_obj_t *tabview, lv_tabview_style_t type, lv_style_t *style); - -/** - * Set the position of tab select buttons - * @param tabview pointer to a tab view object - * @param btns_pos which button position - */ -void lv_tabview_set_btns_pos(lv_obj_t *tabview, lv_tabview_btns_pos_t btns_pos); - -/** - * Set whether tab buttons are hidden - * @param tabview pointer to a tab view object - * @param en whether tab buttons are hidden - */ -void lv_tabview_set_btns_hidden(lv_obj_t *tabview, bool en); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the index of the currently active tab - * @param tabview pointer to Tab view object - * @return the active tab index - */ -uint16_t lv_tabview_get_tab_act(const lv_obj_t * tabview); - -/** - * Get the number of tabs - * @param tabview pointer to Tab view object - * @return tab count - */ -uint16_t lv_tabview_get_tab_count(const lv_obj_t * tabview); -/** - * Get the page (content area) of a tab - * @param tabview pointer to Tab view object - * @param id index of the tab (>= 0) - * @return pointer to page (lv_page) object - */ -lv_obj_t * lv_tabview_get_tab(const lv_obj_t * tabview, uint16_t id); - -/** - * Get the tab load action - * @param tabview pointer to a tabview object - * @param return the current tab load action - */ -lv_tabview_action_t lv_tabview_get_tab_load_action(const lv_obj_t *tabview); - -/** - * Get horizontal sliding is enabled or not - * @param tabview pointer to Tab view object - * @return true: enable sliding; false: disable sliding - */ -bool lv_tabview_get_sliding(const lv_obj_t * tabview); - -/** - * Get the animation time of tab view when a new tab is loaded - * @param tabview pointer to Tab view object - * @return time of animation in milliseconds - */ -uint16_t lv_tabview_get_anim_time(const lv_obj_t * tabview); - -/** - * Get a style of a tab view - * @param tabview pointer to a ab view object - * @param type which style should be get - * @return style pointer to a style - */ -lv_style_t * lv_tabview_get_style(const lv_obj_t *tabview, lv_tabview_style_t type); - -/** - * Get position of tab select buttons - * @param tabview pointer to a ab view object - */ -lv_tabview_btns_pos_t lv_tabview_get_btns_pos(const lv_obj_t *tabview); - -/** - * Get whether tab buttons are hidden - * @param tabview pointer to a tab view object - * @return whether tab buttons are hidden - */ -bool lv_tabview_get_btns_hidden(const lv_obj_t *tabview); - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TABVIEW*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TABVIEW_H*/ diff --git a/include/display/lv_objx/lv_tileview.h b/include/display/lv_objx/lv_tileview.h deleted file mode 100644 index b869e7ce..00000000 --- a/include/display/lv_objx/lv_tileview.h +++ /dev/null @@ -1,163 +0,0 @@ -/** - * @file lv_tileview.h - * - */ - - -#ifndef LV_TILEVIEW_H -#define LV_TILEVIEW_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_TILEVIEW != 0 - -#include "display/lv_objx/lv_page.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - - - -/* parametes: pointer to a tileview object, x, y (tile coordinates to load) - * return: LV_RES_INV: to prevent the loading of the tab; LV_RES_OK: if everything is fine*/ -typedef lv_res_t (*lv_tileview_action_t)(lv_obj_t *, lv_coord_t, lv_coord_t); - -/*Data of tileview*/ -typedef struct { - lv_page_ext_t page; - /*New data for this type */ - const lv_point_t * valid_pos; - uint16_t anim_time; - lv_tileview_action_t action; - lv_point_t act_id; - uint8_t drag_top_en :1; - uint8_t drag_bottom_en :1; - uint8_t drag_left_en :1; - uint8_t drag_right_en :1; - uint8_t drag_hor :1; - uint8_t drag_ver :1; -} lv_tileview_ext_t; - - -/*Styles*/ -enum { - LV_TILEVIEW_STYLE_BG, -}; -typedef uint8_t lv_tileview_style_t; - - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a tileview objects - * @param par pointer to an object, it will be the parent of the new tileview - * @param copy pointer to a tileview object, if not NULL then the new object will be copied from it - * @return pointer to the created tileview - */ -lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Register an object on the tileview. The register object will able to slide the tileview - * @param element pointer to an object - */ -void lv_tileview_add_element(lv_obj_t * element); - -/*===================== - * Setter functions - *====================*/ - - -/** - * Set the valid position's indices. The scrolling will be possible only to these positions. - * @param tileview pointer to a Tileview object - * @param valid_pos array width the indices. E.g. `lv_point_t p[] = {{0,0}, {1,0}, {1,1}, {LV_COORD_MIN, LV_COORD_MIN}};` - * Must be closed with `{LV_COORD_MIN, LV_COORD_MIN}`. Only the pointer is saved so can't be a local variable. - */ -void lv_tileview_set_valid_positions(lv_obj_t * tileview, const lv_point_t * valid_pos); - -/** - * Set the tile to be shown - * @param tileview pointer to a tileview object - * @param x column id (0, 1, 2...) - * @param y line id (0, 1, 2...) - * @param anim_en true: move with animation - */ -void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, bool anim_en); - -/** - * Enable the edge flash effect. (Show an arc when the an edge is reached) - * @param tileview pointer to a Tileview - * @param en true or false to enable/disable end flash - */ -static inline void lv_tileview_set_edge_flash(lv_obj_t * tileview, bool en) -{ - lv_page_set_edge_flash(tileview, en); -} - -/** - * Set a style of a tileview. - * @param tileview pointer to tileview object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_tileview_set_style(lv_obj_t * tileview, lv_tileview_style_t type, lv_style_t *style); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the scroll propagation property - * @param tileview pointer to a Tileview - * @return true or false - */ -static inline bool lv_tileview_get_edge_flash(lv_obj_t * tileview) -{ - return lv_page_get_edge_flash(tileview); -} - -/** - * Get style of a tileview. - * @param tileview pointer to tileview object - * @param type which style should be get - * @return style pointer to the style - */ -lv_style_t * lv_tileview_get_style(const lv_obj_t * tileview, lv_tileview_style_t type); - -/*===================== - * Other functions - *====================*/ - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TILEVIEW*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TILEVIEW_H*/ diff --git a/include/display/lv_objx/lv_win.h b/include/display/lv_objx/lv_win.h deleted file mode 100644 index 4a64aa81..00000000 --- a/include/display/lv_objx/lv_win.h +++ /dev/null @@ -1,282 +0,0 @@ -/** - * @file lv_win.h - * - */ - -#ifndef LV_WIN_H -#define LV_WIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_WIN != 0 - -/*Testing of dependencies*/ -#if USE_LV_BTN == 0 -#error "lv_win: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " -#endif - -#if USE_LV_LABEL == 0 -#error "lv_win: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " -#endif - -#if USE_LV_IMG == 0 -#error "lv_win: lv_img is required. Enable it in lv_conf.h (USE_LV_IMG 1) " -#endif - - -#if USE_LV_PAGE == 0 -#error "lv_win: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " -#endif - -#include "display/lv_core/lv_obj.h" -#include "lv_cont.h" -#include "lv_btn.h" -#include "lv_label.h" -#include "lv_img.h" -#include "lv_page.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Data of window*/ -typedef struct -{ - /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * page; /*Pointer to a page which holds the content*/ - lv_obj_t * header; /*Pointer to the header container of the window*/ - lv_obj_t * title; /*Pointer to the title label of the window*/ - lv_style_t * style_header; /*Style of the header container*/ - lv_style_t * style_btn_rel; /*Control button releases style*/ - lv_style_t * style_btn_pr; /*Control button pressed style*/ - lv_coord_t btn_size; /*Size of the control buttons (square)*/ -} lv_win_ext_t; - -enum { - LV_WIN_STYLE_BG, - LV_WIN_STYLE_CONTENT_BG, - LV_WIN_STYLE_CONTENT_SCRL, - LV_WIN_STYLE_SB, - LV_WIN_STYLE_HEADER, - LV_WIN_STYLE_BTN_REL, - LV_WIN_STYLE_BTN_PR, -}; -typedef uint8_t lv_win_style_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a window objects - * @param par pointer to an object, it will be the parent of the new window - * @param copy pointer to a window object, if not NULL then the new object will be copied from it - * @return pointer to the created window - */ -lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy); - -/** - * Delete all children of the scrl object, without deleting scrl child. - * @param obj pointer to an object - */ -void lv_win_clean(lv_obj_t *obj); - -/*====================== - * Add/remove functions - *=====================*/ - -/** - * Add control button to the header of the window - * @param win pointer to a window object - * @param img_src an image source ('lv_img_t' variable, path to file or a symbol) - * @param rel_action a function pointer to call when the button is released - * @return pointer to the created button object - */ -lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src, lv_action_t rel_action); - -/*===================== - * Setter functions - *====================*/ - -/** - * A release action which can be assigned to a window control button to close it - * @param btn pointer to the released button - * @return always LV_ACTION_RES_INV because the button is deleted with the window - */ -lv_res_t lv_win_close_action(lv_obj_t * btn); - -/** - * Set the title of a window - * @param win pointer to a window object - * @param title string of the new title - */ -void lv_win_set_title(lv_obj_t * win, const char * title); - -/** - * Set the control button size of a window - * @param win pointer to a window object - * @return control button size - */ -void lv_win_set_btn_size(lv_obj_t * win, lv_coord_t size); - -/** - * Set the layout of the window - * @param win pointer to a window object - * @param layout the layout from 'lv_layout_t' - */ -void lv_win_set_layout(lv_obj_t *win, lv_layout_t layout); - -/** - * Set the scroll bar mode of a window - * @param win pointer to a window object - * @param sb_mode the new scroll bar mode from 'lv_sb_mode_t' - */ -void lv_win_set_sb_mode(lv_obj_t *win, lv_sb_mode_t sb_mode); - -/** - * Set a style of a window - * @param win pointer to a window object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_win_set_style(lv_obj_t *win, lv_win_style_t type, lv_style_t *style); - -/** - * Set drag status of a window. If set to 'true' window can be dragged like on a PC. - * @param win pointer to a window object - * @param en whether dragging is enabled - */ -void lv_win_set_drag(lv_obj_t *win, bool en); - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the title of a window - * @param win pointer to a window object - * @return title string of the window - */ -const char * lv_win_get_title(const lv_obj_t * win); - -/** -* Get the content holder object of window (`lv_page`) to allow additional customization -* @param win pointer to a window object -* @return the Page object where the window's content is -*/ -lv_obj_t * lv_win_get_content(const lv_obj_t * win); - -/** - * Get the control button size of a window - * @param win pointer to a window object - * @return control button size - */ -lv_coord_t lv_win_get_btn_size(const lv_obj_t * win); - -/** - * Get the pointer of a widow from one of its control button. - * It is useful in the action of the control buttons where only button is known. - * @param ctrl_btn pointer to a control button of a window - * @return pointer to the window of 'ctrl_btn' - */ -lv_obj_t * lv_win_get_from_btn(const lv_obj_t * ctrl_btn); - -/** - * Get the layout of a window - * @param win pointer to a window object - * @return the layout of the window (from 'lv_layout_t') - */ -lv_layout_t lv_win_get_layout(lv_obj_t *win); - -/** - * Get the scroll bar mode of a window - * @param win pointer to a window object - * @return the scroll bar mode of the window (from 'lv_sb_mode_t') - */ -lv_sb_mode_t lv_win_get_sb_mode(lv_obj_t *win); - -/** - * Get width of the content area (page scrollable) of the window - * @param win pointer to a window object - * @return the width of the content area - */ -lv_coord_t lv_win_get_width(lv_obj_t * win); - -/** - * Get a style of a window - * @param win pointer to a button object - * @param type which style window be get - * @return style pointer to a style - */ -lv_style_t * lv_win_get_style(const lv_obj_t *win, lv_win_style_t type); - -/** - * Get drag status of a window. If set to 'true' window can be dragged like on a PC. - * @param win pointer to a window object - * @return whether window is draggable - */ -static inline bool lv_win_get_drag(const lv_obj_t *win) -{ - return lv_obj_get_drag(win); -} - -/*===================== - * Other functions - *====================*/ - -/** - * Focus on an object. It ensures that the object will be visible in the window. - * @param win pointer to a window object - * @param obj pointer to an object to focus (must be in the window) - * @param anim_time scroll animation time in milliseconds (0: no animation) - */ -void lv_win_focus(lv_obj_t * win, lv_obj_t * obj, uint16_t anim_time); - -/** - * Scroll the window horizontally - * @param win pointer to a window object - * @param dist the distance to scroll (< 0: scroll right; > 0 scroll left) - */ -static inline void lv_win_scroll_hor(lv_obj_t * win, lv_coord_t dist) -{ - lv_win_ext_t * ext = (lv_win_ext_t *)lv_obj_get_ext_attr(win); - lv_page_scroll_hor(ext->page, dist); -} -/** - * Scroll the window vertically - * @param win pointer to a window object - * @param dist the distance to scroll (< 0: scroll down; > 0 scroll up) - */ -static inline void lv_win_scroll_ver(lv_obj_t * win, lv_coord_t dist) -{ - lv_win_ext_t * ext = (lv_win_ext_t *)lv_obj_get_ext_attr(win); - lv_page_scroll_ver(ext->page, dist); -} - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_WIN*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_WIN_H*/ diff --git a/include/display/lv_themes/lv_theme.h b/include/display/lv_themes/lv_theme.h deleted file mode 100644 index 69aae29f..00000000 --- a/include/display/lv_themes/lv_theme.h +++ /dev/null @@ -1,332 +0,0 @@ -/** - *@file lv_themes.h - * - */ - -#ifndef LV_THEMES_H -#define LV_THEMES_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#include "display/lv_core/lv_style.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -typedef struct { - lv_style_t *bg; - lv_style_t *panel; - -#if USE_LV_CONT != 0 - lv_style_t *cont; -#endif - -#if USE_LV_BTN != 0 - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; -#endif - - -#if USE_LV_IMGBTN != 0 - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } imgbtn; -#endif - -#if USE_LV_LABEL != 0 - struct { - lv_style_t *prim; - lv_style_t *sec; - lv_style_t *hint; - } label; -#endif - -#if USE_LV_IMG != 0 - struct { - lv_style_t *light; - lv_style_t *dark; - } img; -#endif - -#if USE_LV_LINE != 0 - struct { - lv_style_t *decor; - } line; -#endif - -#if USE_LV_LED != 0 - lv_style_t *led; -#endif - -#if USE_LV_BAR != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - } bar; -#endif - -#if USE_LV_SLIDER != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - lv_style_t *knob; - } slider; -#endif - -#if USE_LV_LMETER != 0 - lv_style_t *lmeter; -#endif - -#if USE_LV_GAUGE != 0 - lv_style_t *gauge; -#endif - -#if USE_LV_ARC != 0 - lv_style_t *arc; -#endif - -#if USE_LV_PRELOAD != 0 - lv_style_t *preload; -#endif - -#if USE_LV_SW != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - lv_style_t *knob_off; - lv_style_t *knob_on; - } sw; -#endif - -#if USE_LV_CHART != 0 - lv_style_t *chart; -#endif - -#if USE_LV_CALENDAR != 0 - struct { - lv_style_t *bg; - lv_style_t *header; - lv_style_t *header_pr; - lv_style_t *day_names; - lv_style_t *highlighted_days; - lv_style_t *inactive_days; - lv_style_t *week_box; - lv_style_t *today_box; - } calendar; -#endif - -#if USE_LV_CB != 0 - struct { - lv_style_t *bg; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } box; - } cb; -#endif - -#if USE_LV_BTNM != 0 - struct { - lv_style_t *bg; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } btnm; -#endif - -#if USE_LV_KB != 0 - struct { - lv_style_t *bg; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } kb; -#endif - -#if USE_LV_MBOX != 0 - struct { - lv_style_t *bg; - struct { - lv_style_t *bg; - lv_style_t *rel; - lv_style_t *pr; - } btn; - } mbox; -#endif - -#if USE_LV_PAGE != 0 - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - } page; -#endif - -#if USE_LV_TA != 0 - struct { - lv_style_t *area; - lv_style_t *oneline; - lv_style_t *cursor; - lv_style_t *sb; - } ta; -#endif - -#if USE_LV_SPINBOX != 0 - struct { - lv_style_t *bg; - lv_style_t *cursor; - lv_style_t *sb; - } spinbox; -#endif - -#if USE_LV_LIST - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - struct { - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - lv_style_t *ina; - } btn; - } list; -#endif - -#if USE_LV_DDLIST != 0 - struct { - lv_style_t *bg; - lv_style_t *sel; - lv_style_t *sb; - } ddlist; -#endif - -#if USE_LV_ROLLER != 0 - struct { - lv_style_t *bg; - lv_style_t *sel; - } roller; -#endif - -#if USE_LV_TABVIEW != 0 - struct { - lv_style_t *bg; - lv_style_t *indic; - struct { - lv_style_t *bg; - lv_style_t *rel; - lv_style_t *pr; - lv_style_t *tgl_rel; - lv_style_t *tgl_pr; - } btn; - } tabview; -#endif - -#if USE_LV_TILEVIEW != 0 - struct { - lv_style_t *bg; - lv_style_t *scrl; - lv_style_t *sb; - } tileview; -#endif - -#if USE_LV_TABLE != 0 - struct { - lv_style_t *bg; - lv_style_t *cell; - } table; -#endif - -#if USE_LV_WIN != 0 - struct { - lv_style_t *bg; - lv_style_t *sb; - lv_style_t *header; - struct { - lv_style_t *bg; - lv_style_t *scrl; - } content; - struct { - lv_style_t *rel; - lv_style_t *pr; - } btn; - } win; -#endif -} lv_theme_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Set a theme for the system. - * From now, all the created objects will use styles from this theme by default - * @param th pointer to theme (return value of: 'lv_theme_init_xxx()') - */ -void lv_theme_set_current(lv_theme_t *th); - -/** - * Get the current system theme. - * @return pointer to the current system theme. NULL if not set. - */ -lv_theme_t * lv_theme_get_current(void); - -/********************** - * MACROS - **********************/ - -/********************** - * POST INCLUDE - *********************/ -#include "lv_theme_templ.h" -#include "lv_theme_default.h" -#include "lv_theme_alien.h" -#include "lv_theme_night.h" -#include "lv_theme_zen.h" -#include "lv_theme_mono.h" -#include "lv_theme_nemo.h" -#include "lv_theme_material.h" - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEMES_H*/ diff --git a/include/display/lv_themes/lv_theme_alien.h b/include/display/lv_themes/lv_theme_alien.h deleted file mode 100644 index 1f62315d..00000000 --- a/include/display/lv_themes/lv_theme_alien.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @file lv_theme_alien.h - * - */ - -#ifndef LV_THEME_ALIEN_H -#define LV_THEME_ALIEN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_ALIEN - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the alien theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t *font); -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_alien(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_ALIEN_H*/ diff --git a/include/display/lv_themes/lv_theme_default.h b/include/display/lv_themes/lv_theme_default.h deleted file mode 100644 index 1348f1fc..00000000 --- a/include/display/lv_themes/lv_theme_default.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_default.h - * - */ - -#ifndef LV_THEME_DEFAULT_H -#define LV_THEME_DEFAULT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_DEFAULT - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the default theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_default_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_default(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_TEMPL_H*/ diff --git a/include/display/lv_themes/lv_theme_material.h b/include/display/lv_themes/lv_theme_material.h deleted file mode 100644 index d9da6646..00000000 --- a/include/display/lv_themes/lv_theme_material.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_material.h - * - */ - -#ifndef LV_THEME_MATERIAL_H -#define LV_THEME_MATERIAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_MATERIAL - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the material theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_material_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_material(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_MATERIAL_H*/ diff --git a/include/display/lv_themes/lv_theme_mono.h b/include/display/lv_themes/lv_theme_mono.h deleted file mode 100644 index 63039fa9..00000000 --- a/include/display/lv_themes/lv_theme_mono.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_mono.h - * - */ - -#ifndef LV_THEME_MONO_H -#define LV_THEME_MONO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_MONO - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the mono theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_mono(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_MONO_H*/ diff --git a/include/display/lv_themes/lv_theme_nemo.h b/include/display/lv_themes/lv_theme_nemo.h deleted file mode 100644 index 46d43bdb..00000000 --- a/include/display/lv_themes/lv_theme_nemo.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_nemo.h - * - */ - -#ifndef LV_THEME_NEMO_H -#define LV_THEME_NEMO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_NEMO - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the material theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_nemo(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_NEMO_H*/ diff --git a/include/display/lv_themes/lv_theme_night.h b/include/display/lv_themes/lv_theme_night.h deleted file mode 100644 index 3e5efb8f..00000000 --- a/include/display/lv_themes/lv_theme_night.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_night.h - * - */ - -#ifndef LV_THEME_NIGHT_H -#define LV_THEME_NIGHT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_NIGHT - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the night theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_night_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_night(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_NIGHT_H*/ diff --git a/include/display/lv_themes/lv_theme_templ.h b/include/display/lv_themes/lv_theme_templ.h deleted file mode 100644 index e7176636..00000000 --- a/include/display/lv_themes/lv_theme_templ.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_templ.h - * - */ - -#ifndef LV_THEME_TEMPL_H -#define LV_THEME_TEMPL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_TEMPL - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the templ theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_templ(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_TEMPL_H*/ diff --git a/include/display/lv_themes/lv_theme_zen.h b/include/display/lv_themes/lv_theme_zen.h deleted file mode 100644 index ddd7cb35..00000000 --- a/include/display/lv_themes/lv_theme_zen.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file lv_theme_zen.h - * - */ - -#ifndef LV_THEME_ZEN_H -#define LV_THEME_ZEN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif - -#if USE_LV_THEME_ZEN - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize the zen theme - * @param hue [0..360] hue value from HSV color space to define the theme's base color - * @param font pointer to a font (NULL to use the default) - * @return pointer to the initialized theme - */ -lv_theme_t * lv_theme_zen_init(uint16_t hue, lv_font_t *font); - -/** - * Get a pointer to the theme - * @return pointer to the theme - */ -lv_theme_t * lv_theme_get_zen(void); - -/********************** - * MACROS - **********************/ - -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_THEME_ZEN_H*/ diff --git a/include/display/lv_themes/lv_themes.mk b/include/display/lv_themes/lv_themes.mk deleted file mode 100644 index 0e4a81a5..00000000 --- a/include/display/lv_themes/lv_themes.mk +++ /dev/null @@ -1,14 +0,0 @@ -CSRCS += lv_theme_alien.c -CSRCS += lv_theme.c -CSRCS += lv_theme_default.c -CSRCS += lv_theme_night.c -CSRCS += lv_theme_templ.c -CSRCS += lv_theme_zen.c -CSRCS += lv_theme_material.c -CSRCS += lv_theme_nemo.c -CSRCS += lv_theme_mono.c - -DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_themes -VPATH += :$(LVGL_DIR)/lvgl/lv_themes - -CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_themes" diff --git a/include/display/lv_version.h b/include/display/lv_version.h deleted file mode 100644 index 1e62e1e2..00000000 --- a/include/display/lv_version.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - * @file lv_version.h - * - */ - -#ifndef LV_VERSION_H -#define LV_VERSION_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -/*Current version of LittlevGL*/ -#define LVGL_VERSION_MAJOR 5 -#define LVGL_VERSION_MINOR 3 -#define LVGL_VERSION_PATCH 0 -#define LVGL_VERSION_INFO "" - - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/********************** - * MACROS - **********************/ -/* Gives 1 if the x.y.z version is supported in the current version - * Usage: - * - * - Require v6 - * #if LV_VERSION_CHECK(6,0,0) - * new_func_in_v6(); - * #endif - * - * - * - Require at least v5.3 - * #if LV_VERSION_CHECK(5,3,0) - * new_feature_from_v5_3(); - * #endif - * - * - * - Require v5.3.2 bugfixes - * #if LV_VERSION_CHECK(5,3,2) - * bugfix_in_v5_3_2(); - * #endif - * - * */ -#define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_VERSION_H*/ diff --git a/include/display/lvgl.h b/include/display/lvgl.h deleted file mode 100644 index d2c93b4e..00000000 --- a/include/display/lvgl.h +++ /dev/null @@ -1,88 +0,0 @@ -/** - * @file lvgl.h - * Include all LittleV GL related headers - */ - -#ifndef LVGL_H -#define LVGL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#include "lv_version.h" - -#include "lv_misc/lv_log.h" -#include "lv_misc/lv_task.h" - -#include "lv_hal/lv_hal.h" - -#include "lv_core/lv_obj.h" -#include "lv_core/lv_group.h" -#include "lv_core/lv_lang.h" -#include "lv_core/lv_vdb.h" -#include "lv_core/lv_refr.h" - -#include "lv_themes/lv_theme.h" - -#include "lv_objx/lv_btn.h" -#include "lv_objx/lv_imgbtn.h" -#include "lv_objx/lv_img.h" -#include "lv_objx/lv_label.h" -#include "lv_objx/lv_line.h" -#include "lv_objx/lv_page.h" -#include "lv_objx/lv_cont.h" -#include "lv_objx/lv_list.h" -#include "lv_objx/lv_chart.h" -#include "lv_objx/lv_table.h" -#include "lv_objx/lv_cb.h" -#include "lv_objx/lv_bar.h" -#include "lv_objx/lv_slider.h" -#include "lv_objx/lv_led.h" -#include "lv_objx/lv_btnm.h" -#include "lv_objx/lv_kb.h" -#include "lv_objx/lv_ddlist.h" -#include "lv_objx/lv_roller.h" -#include "lv_objx/lv_ta.h" -#include "lv_objx/lv_canvas.h" -#include "lv_objx/lv_win.h" -#include "lv_objx/lv_tabview.h" -#include "lv_objx/lv_tileview.h" -#include "lv_objx/lv_mbox.h" -#include "lv_objx/lv_gauge.h" -#include "lv_objx/lv_lmeter.h" -#include "lv_objx/lv_sw.h" -#include "lv_objx/lv_kb.h" -#include "lv_objx/lv_arc.h" -#include "lv_objx/lv_preload.h" -#include "lv_objx/lv_calendar.h" -#include "lv_objx/lv_spinbox.h" -#pragma GCC diagnostic pop - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} -#endif - -#endif /*LVGL_H*/ diff --git a/include/liblvgl/core/lv_disp.h b/include/liblvgl/core/lv_disp.h new file mode 100644 index 00000000..cd6efcc2 --- /dev/null +++ b/include/liblvgl/core/lv_disp.h @@ -0,0 +1,264 @@ +/** + * @file lv_disp.h + * + */ + +#ifndef LV_DISP_H +#define LV_DISP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/hal/lv_hal.h" +#include "lv_obj.h" +#include "lv_theme.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef enum { + LV_SCR_LOAD_ANIM_NONE, + LV_SCR_LOAD_ANIM_OVER_LEFT, + LV_SCR_LOAD_ANIM_OVER_RIGHT, + LV_SCR_LOAD_ANIM_OVER_TOP, + LV_SCR_LOAD_ANIM_OVER_BOTTOM, + LV_SCR_LOAD_ANIM_MOVE_LEFT, + LV_SCR_LOAD_ANIM_MOVE_RIGHT, + LV_SCR_LOAD_ANIM_MOVE_TOP, + LV_SCR_LOAD_ANIM_MOVE_BOTTOM, + LV_SCR_LOAD_ANIM_FADE_IN, + LV_SCR_LOAD_ANIM_FADE_ON = LV_SCR_LOAD_ANIM_FADE_IN, /*For backward compatibility*/ + LV_SCR_LOAD_ANIM_FADE_OUT, + LV_SCR_LOAD_ANIM_OUT_LEFT, + LV_SCR_LOAD_ANIM_OUT_RIGHT, + LV_SCR_LOAD_ANIM_OUT_TOP, + LV_SCR_LOAD_ANIM_OUT_BOTTOM, +} lv_scr_load_anim_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Return with a pointer to the active screen + * @param disp pointer to display which active screen should be get. (NULL to use the default + * screen) + * @return pointer to the active screen object (loaded by 'lv_scr_load()') + */ +lv_obj_t * lv_disp_get_scr_act(lv_disp_t * disp); + +/** + * Return with a pointer to the previous screen. Only used during screen transitions. + * @param disp pointer to display which previous screen should be get. (NULL to use the default + * screen) + * @return pointer to the previous screen object or NULL if not used now + */ +lv_obj_t * lv_disp_get_scr_prev(lv_disp_t * disp); + +/** + * Make a screen active + * @param scr pointer to a screen + */ +void lv_disp_load_scr(lv_obj_t * scr); + +/** + * Return with the top layer. (Same on every screen and it is above the normal screen layer) + * @param disp pointer to display which top layer should be get. (NULL to use the default screen) + * @return pointer to the top layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_disp_get_layer_top(lv_disp_t * disp); + +/** + * Return with the sys. layer. (Same on every screen and it is above the normal screen and the top + * layer) + * @param disp pointer to display which sys. layer should be retrieved. (NULL to use the default screen) + * @return pointer to the sys layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_disp_get_layer_sys(lv_disp_t * disp); + +/** + * Set the theme of a display + * @param disp pointer to a display + */ +void lv_disp_set_theme(lv_disp_t * disp, lv_theme_t * th); + +/** + * Get the theme of a display + * @param disp pointer to a display + * @return the display's theme (can be NULL) + */ +lv_theme_t * lv_disp_get_theme(lv_disp_t * disp); + +/** + * Set the background color of a display + * @param disp pointer to a display + * @param color color of the background + */ +void lv_disp_set_bg_color(lv_disp_t * disp, lv_color_t color); + +/** + * Set the background image of a display + * @param disp pointer to a display + * @param img_src path to file or pointer to an `lv_img_dsc_t` variable + */ +void lv_disp_set_bg_image(lv_disp_t * disp, const void * img_src); + +/** + * Set opacity of the background + * @param disp pointer to a display + * @param opa opacity (0..255) + */ +void lv_disp_set_bg_opa(lv_disp_t * disp, lv_opa_t opa); + +/** + * Switch screen with animation + * @param scr pointer to the new screen to load + * @param anim_type type of the animation from `lv_scr_load_anim_t`, e.g. `LV_SCR_LOAD_ANIM_MOVE_LEFT` + * @param time time of the animation + * @param delay delay before the transition + * @param auto_del true: automatically delete the old screen + */ +void lv_scr_load_anim(lv_obj_t * scr, lv_scr_load_anim_t anim_type, uint32_t time, uint32_t delay, bool auto_del); + +/** + * Get elapsed time since last user activity on a display (e.g. click) + * @param disp pointer to a display (NULL to get the overall smallest inactivity) + * @return elapsed ticks (milliseconds) since the last activity + */ +uint32_t lv_disp_get_inactive_time(const lv_disp_t * disp); + +/** + * Manually trigger an activity on a display + * @param disp pointer to a display (NULL to use the default display) + */ +void lv_disp_trig_activity(lv_disp_t * disp); + +/** + * Clean any CPU cache that is related to the display. + * @param disp pointer to a display (NULL to use the default display) + */ +void lv_disp_clean_dcache(lv_disp_t * disp); + +/** + * Temporarily enable and disable the invalidation of the display. + * @param disp pointer to a display (NULL to use the default display) + * @param en true: enable invalidation; false: invalidation + */ +void lv_disp_enable_invalidation(lv_disp_t * disp, bool en); + +/** + * Get display invalidation is enabled. + * @param disp pointer to a display (NULL to use the default display) + * @return return true if invalidation is enabled + */ +bool lv_disp_is_invalidation_enabled(lv_disp_t * disp); + +/** + * Get a pointer to the screen refresher timer to + * modify its parameters with `lv_timer_...` functions. + * @param disp pointer to a display + * @return pointer to the display refresher timer. (NULL on error) + */ +lv_timer_t * _lv_disp_get_refr_timer(lv_disp_t * disp); + +/*------------------------------------------------ + * To improve backward compatibility + * Recommended only if you have one display + *------------------------------------------------*/ + +/** + * Get the active screen of the default display + * @return pointer to the active screen + */ +static inline lv_obj_t * lv_scr_act(void) +{ + return lv_disp_get_scr_act(lv_disp_get_default()); +} + +/** + * Get the top layer of the default display + * @return pointer to the top layer + */ +static inline lv_obj_t * lv_layer_top(void) +{ + return lv_disp_get_layer_top(lv_disp_get_default()); +} + +/** + * Get the active screen of the default display + * @return pointer to the sys layer + */ +static inline lv_obj_t * lv_layer_sys(void) +{ + return lv_disp_get_layer_sys(lv_disp_get_default()); +} + +static inline void lv_scr_load(lv_obj_t * scr) +{ + lv_disp_load_scr(scr); +} + +/********************** + * MACROS + **********************/ + +/*------------------------------------------------ + * To improve backward compatibility + * Recommended only if you have one display + *------------------------------------------------*/ + +#ifndef LV_HOR_RES +/** + * The horizontal resolution of the currently active display. + */ +#define LV_HOR_RES lv_disp_get_hor_res(lv_disp_get_default()) +#endif + +#ifndef LV_VER_RES +/** + * The vertical resolution of the currently active display. + */ +#define LV_VER_RES lv_disp_get_ver_res(lv_disp_get_default()) +#endif + +/** + * Scale the given number of pixels (a distance or size) relative to a 160 DPI display + * considering the DPI of the default display. + * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the + * DPI of the display. + * @param n the number of pixels to scale + * @return `n x current_dpi/160` + */ +static inline lv_coord_t lv_dpx(lv_coord_t n) +{ + return LV_DPX(n); +} + +/** + * Scale the given number of pixels (a distance or size) relative to a 160 DPI display + * considering the DPI of the given display. + * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the + * DPI of the display. + * @param obj a display whose dpi should be considered + * @param n the number of pixels to scale + * @return `n x current_dpi/160` + */ +static inline lv_coord_t lv_disp_dpx(const lv_disp_t * disp, lv_coord_t n) +{ + return _LV_DPX_CALC(lv_disp_get_dpi(disp), n); +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DISP_H*/ diff --git a/include/liblvgl/core/lv_event.h b/include/liblvgl/core/lv_event.h new file mode 100644 index 00000000..d5a9eb6b --- /dev/null +++ b/include/liblvgl/core/lv_event.h @@ -0,0 +1,363 @@ +/** + * @file lv_event.h + * + */ + +#ifndef LV_EVENT_H +#define LV_EVENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_event_dsc_t; + +/** + * Type of event being sent to the object. + */ +typedef enum { + LV_EVENT_ALL = 0, + + /** Input device events*/ + LV_EVENT_PRESSED, /**< The object has been pressed*/ + LV_EVENT_PRESSING, /**< The object is being pressed (called continuously while pressing)*/ + LV_EVENT_PRESS_LOST, /**< The object is still being pressed but slid cursor/finger off of the object */ + LV_EVENT_SHORT_CLICKED, /**< The object was pressed for a short period of time, then released it. Not called if scrolled.*/ + LV_EVENT_LONG_PRESSED, /**< Object has been pressed for at least `long_press_time`. Not called if scrolled.*/ + LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `long_press_time` in every `long_press_repeat_time` ms. Not called if scrolled.*/ + LV_EVENT_CLICKED, /**< Called on release if not scrolled (regardless to long press)*/ + LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/ + LV_EVENT_SCROLL_BEGIN, /**< Scrolling begins. The event parameter is a pointer to the animation of the scroll. Can be modified*/ + LV_EVENT_SCROLL_END, /**< Scrolling ends*/ + LV_EVENT_SCROLL, /**< Scrolling*/ + LV_EVENT_GESTURE, /**< A gesture is detected. Get the gesture with `lv_indev_get_gesture_dir(lv_indev_get_act());` */ + LV_EVENT_KEY, /**< A key is sent to the object. Get the key with `lv_indev_get_key(lv_indev_get_act());`*/ + LV_EVENT_FOCUSED, /**< The object is focused*/ + LV_EVENT_DEFOCUSED, /**< The object is defocused*/ + LV_EVENT_LEAVE, /**< The object is defocused but still selected*/ + LV_EVENT_HIT_TEST, /**< Perform advanced hit-testing*/ + + /** Drawing events*/ + LV_EVENT_COVER_CHECK, /**< Check if the object fully covers an area. The event parameter is `lv_cover_check_info_t *`.*/ + LV_EVENT_REFR_EXT_DRAW_SIZE, /**< Get the required extra draw area around the object (e.g. for shadow). The event parameter is `lv_coord_t *` to store the size.*/ + LV_EVENT_DRAW_MAIN_BEGIN, /**< Starting the main drawing phase*/ + LV_EVENT_DRAW_MAIN, /**< Perform the main drawing*/ + LV_EVENT_DRAW_MAIN_END, /**< Finishing the main drawing phase*/ + LV_EVENT_DRAW_POST_BEGIN, /**< Starting the post draw phase (when all children are drawn)*/ + LV_EVENT_DRAW_POST, /**< Perform the post draw phase (when all children are drawn)*/ + LV_EVENT_DRAW_POST_END, /**< Finishing the post draw phase (when all children are drawn)*/ + LV_EVENT_DRAW_PART_BEGIN, /**< Starting to draw a part. The event parameter is `lv_obj_draw_dsc_t *`. */ + LV_EVENT_DRAW_PART_END, /**< Finishing to draw a part. The event parameter is `lv_obj_draw_dsc_t *`. */ + + /** Special events*/ + LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved)*/ + LV_EVENT_INSERT, /**< A text is inserted to the object. The event data is `char *` being inserted.*/ + LV_EVENT_REFRESH, /**< Notify the object to refresh something on it (for the user)*/ + LV_EVENT_READY, /**< A process has finished*/ + LV_EVENT_CANCEL, /**< A process has been cancelled */ + + /** Other events*/ + LV_EVENT_DELETE, /**< Object is being deleted*/ + LV_EVENT_CHILD_CHANGED, /**< Child was removed, added, or its size, position were changed */ + LV_EVENT_CHILD_CREATED, /**< Child was created, always bubbles up to all parents*/ + LV_EVENT_CHILD_DELETED, /**< Child was deleted, always bubbles up to all parents*/ + LV_EVENT_SCREEN_UNLOAD_START, /**< A screen unload started, fired immediately when scr_load is called*/ + LV_EVENT_SCREEN_LOAD_START, /**< A screen load started, fired when the screen change delay is expired*/ + LV_EVENT_SCREEN_LOADED, /**< A screen was loaded*/ + LV_EVENT_SCREEN_UNLOADED, /**< A screen was unloaded*/ + LV_EVENT_SIZE_CHANGED, /**< Object coordinates/size have changed*/ + LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/ + LV_EVENT_LAYOUT_CHANGED, /**< The children position has changed due to a layout recalculation*/ + LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/ + + _LV_EVENT_LAST, /** Number of default events*/ + + + LV_EVENT_PREPROCESS = 0x80, /** This is a flag that can be set with an event so it's processed + before the class default event processing */ +} lv_event_code_t; + +typedef struct _lv_event_t { + struct _lv_obj_t * target; + struct _lv_obj_t * current_target; + lv_event_code_t code; + void * user_data; + void * param; + struct _lv_event_t * prev; + uint8_t deleted : 1; + uint8_t stop_processing : 1; + uint8_t stop_bubbling : 1; +} lv_event_t; + +/** + * @brief Event callback. + * Events are used to notify the user of some action being taken on the object. + * For details, see ::lv_event_t. + */ +typedef void (*lv_event_cb_t)(lv_event_t * e); + +/** + * Used as the event parameter of ::LV_EVENT_HIT_TEST to check if an `point` can click the object or not. + * `res` should be set like this: + * - If already set to `false` an other event wants that point non clickable. If you want to respect it leave it as `false` or set `true` to overwrite it. + * - If already set `true` and `point` shouldn't be clickable set to `false` + * - If already set to `true` you agree that `point` can click the object leave it as `true` + */ +typedef struct { + const lv_point_t * point; /**< A point relative to screen to check if it can click the object or not*/ + bool res; /**< true: `point` can click the object; false: it cannot*/ +} lv_hit_test_info_t; + +/** + * Used as the event parameter of ::LV_EVENT_COVER_CHECK to check if an area is covered by the object or not. + * In the event use `const lv_area_t * area = lv_event_get_cover_area(e)` to get the area to check + * and `lv_event_set_cover_res(e, res)` to set the result. + */ +typedef struct { + lv_cover_res_t res; + const lv_area_t * area; +} lv_cover_check_info_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Send an event to the object + * @param obj pointer to an object + * @param event_code the type of the event from `lv_event_t` + * @param param arbitrary data depending on the widget type and the event. (Usually `NULL`) + * @return LV_RES_OK: `obj` was not deleted in the event; LV_RES_INV: `obj` was deleted in the event_code + */ +lv_res_t lv_event_send(struct _lv_obj_t * obj, lv_event_code_t event_code, void * param); + +/** + * Used by the widgets internally to call the ancestor widget types's event handler + * @param class_p pointer to the class of the widget (NOT the ancestor class) + * @param e pointer to the event descriptor + * @return LV_RES_OK: the target object was not deleted in the event; LV_RES_INV: it was deleted in the event_code + */ +lv_res_t lv_obj_event_base(const lv_obj_class_t * class_p, lv_event_t * e); + +/** + * Get the object originally targeted by the event. It's the same even if the event is bubbled. + * @param e pointer to the event descriptor + * @return the target of the event_code + */ +struct _lv_obj_t * lv_event_get_target(lv_event_t * e); + +/** + * Get the current target of the event. It's the object which event handler being called. + * If the event is not bubbled it's the same as "normal" target. + * @param e pointer to the event descriptor + * @return pointer to the current target of the event_code + */ +struct _lv_obj_t * lv_event_get_current_target(lv_event_t * e); + +/** + * Get the event code of an event + * @param e pointer to the event descriptor + * @return the event code. (E.g. `LV_EVENT_CLICKED`, `LV_EVENT_FOCUSED`, etc) + */ +lv_event_code_t lv_event_get_code(lv_event_t * e); + +/** + * Get the parameter passed when the event was sent + * @param e pointer to the event descriptor + * @return pointer to the parameter + */ +void * lv_event_get_param(lv_event_t * e); + +/** + * Get the user_data passed when the event was registered on the object + * @param e pointer to the event descriptor + * @return pointer to the user_data + */ +void * lv_event_get_user_data(lv_event_t * e); + +/** + * Stop the event from bubbling. + * This is only valid when called in the middle of an event processing chain. + * @param e pointer to the event descriptor + */ +void lv_event_stop_bubbling(lv_event_t * e); + +/** + * Stop processing this event. + * This is only valid when called in the middle of an event processing chain. + * @param e pointer to the event descriptor + */ +void lv_event_stop_processing(lv_event_t * e); + +/** + * Register a new, custom event ID. + * It can be used the same way as e.g. `LV_EVENT_CLICKED` to send custom events + * @return the new event id + * @example + * uint32_t LV_EVENT_MINE = 0; + * ... + * e = lv_event_register_id(); + * ... + * lv_event_send(obj, LV_EVENT_MINE, &some_data); + */ +uint32_t lv_event_register_id(void); + +/** + * Nested events can be called and one of them might belong to an object that is being deleted. + * Mark this object's `event_temp_data` deleted to know that its `lv_event_send` should return `LV_RES_INV` + * @param obj pointer to an object to mark as deleted + */ +void _lv_event_mark_deleted(struct _lv_obj_t * obj); + + +/** + * Add an event handler function for an object. + * Used by the user to react on event which happens with the object. + * An object can have multiple event handler. They will be called in the same order as they were added. + * @param obj pointer to an object + * @param filter and event code (e.g. `LV_EVENT_CLICKED`) on which the event should be called. `LV_EVENT_ALL` can be sued the receive all the events. + * @param event_cb the new event function + * @param user_data custom data data will be available in `event_cb` + * @return a pointer the event descriptor. Can be used in ::lv_obj_remove_event_dsc + */ +struct _lv_event_dsc_t * lv_obj_add_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter, + void * user_data); + +/** + * Remove an event handler function for an object. + * @param obj pointer to an object + * @param event_cb the event function to remove, or `NULL` to remove the firstly added event callback + * @return true if any event handlers were removed + */ +bool lv_obj_remove_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb); + +/** + * Remove an event handler function with a specific user_data from an object. + * @param obj pointer to an object + * @param event_cb the event function to remove, or `NULL` only `user_data` matters. + * @param event_user_data the user_data specified in ::lv_obj_add_event_cb + * @return true if any event handlers were removed + */ +bool lv_obj_remove_event_cb_with_user_data(struct _lv_obj_t * obj, lv_event_cb_t event_cb, + const void * event_user_data); + +/** + * DEPRECATED because doesn't work if multiple event handlers are added to an object. + * Remove an event handler function for an object. + * @param obj pointer to an object + * @param event_dsc pointer to an event descriptor to remove (returned by ::lv_obj_add_event_cb) + * @return true if any event handlers were removed + */ +bool lv_obj_remove_event_dsc(struct _lv_obj_t * obj, struct _lv_event_dsc_t * event_dsc); + +/** + * The user data of an event object event callback. Always the first match with `event_cb` will be returned. + * @param obj pointer to an object + * @param event_cb the event function + * @return the user_data + */ +void * lv_obj_get_event_user_data(struct _lv_obj_t * obj, lv_event_cb_t event_cb); + +/** + * Get the input device passed as parameter to indev related events. + * @param e pointer to an event + * @return the indev that triggered the event or NULL if called on a not indev related event + */ +lv_indev_t * lv_event_get_indev(lv_event_t * e); + +/** + * Get the part draw descriptor passed as parameter to `LV_EVENT_DRAW_PART_BEGIN/END`. + * @param e pointer to an event + * @return the part draw descriptor to hook the drawing or NULL if called on an unrelated event + */ +lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e); + +/** + * Get the draw context which should be the first parameter of the draw functions. + * Namely: `LV_EVENT_DRAW_MAIN/POST`, `LV_EVENT_DRAW_MAIN/POST_BEGIN`, `LV_EVENT_DRAW_MAIN/POST_END` + * @param e pointer to an event + * @return pointer to a draw context or NULL if called on an unrelated event + */ +lv_draw_ctx_t * lv_event_get_draw_ctx(lv_event_t * e); + +/** + * Get the old area of the object before its size was changed. Can be used in `LV_EVENT_SIZE_CHANGED` + * @param e pointer to an event + * @return the old absolute area of the object or NULL if called on an unrelated event + */ +const lv_area_t * lv_event_get_old_size(lv_event_t * e); + +/** + * Get the key passed as parameter to an event. Can be used in `LV_EVENT_KEY` + * @param e pointer to an event + * @return the triggering key or NULL if called on an unrelated event + */ +uint32_t lv_event_get_key(lv_event_t * e); + +/** + * Get the animation descriptor of a scrolling. Can be used in `LV_EVENT_SCROLL_BEGIN` + * @param e pointer to an event + * @return the animation that will scroll the object. (can be modified as required) + */ +lv_anim_t * lv_event_get_scroll_anim(lv_event_t * e); + +/** + * Set the new extra draw size. Can be used in `LV_EVENT_REFR_EXT_DRAW_SIZE` + * @param e pointer to an event + * @param size The new extra draw size + */ +void lv_event_set_ext_draw_size(lv_event_t * e, lv_coord_t size); + +/** + * Get a pointer to an `lv_point_t` variable in which the self size should be saved (width in `point->x` and height `point->y`). + * Can be used in `LV_EVENT_GET_SELF_SIZE` + * @param e pointer to an event + * @return pointer to `lv_point_t` or NULL if called on an unrelated event + */ +lv_point_t * lv_event_get_self_size_info(lv_event_t * e); + +/** + * Get a pointer to an `lv_hit_test_info_t` variable in which the hit test result should be saved. Can be used in `LV_EVENT_HIT_TEST` + * @param e pointer to an event + * @return pointer to `lv_hit_test_info_t` or NULL if called on an unrelated event + */ +lv_hit_test_info_t * lv_event_get_hit_test_info(lv_event_t * e); + +/** + * Get a pointer to an area which should be examined whether the object fully covers it or not. + * Can be used in `LV_EVENT_HIT_TEST` + * @param e pointer to an event + * @return an area with absolute coordinates to check + */ +const lv_area_t * lv_event_get_cover_area(lv_event_t * e); + +/** + * Set the result of cover checking. Can be used in `LV_EVENT_COVER_CHECK` + * @param e pointer to an event + * @param res an element of ::lv_cover_check_info_t + */ +void lv_event_set_cover_res(lv_event_t * e, lv_cover_res_t res); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_EVENT_H*/ diff --git a/include/liblvgl/core/lv_group.h b/include/liblvgl/core/lv_group.h new file mode 100644 index 00000000..85df325a --- /dev/null +++ b/include/liblvgl/core/lv_group.h @@ -0,0 +1,266 @@ +/** + * @file lv_group.h + * + */ + +#ifndef LV_GROUP_H +#define LV_GROUP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include "liblvgl/misc/lv_ll.h" +#include "liblvgl/misc/lv_types.h" + +/********************* + * DEFINES + *********************/ +/*Predefined keys to control the focused object via lv_group_send(group, c)*/ + +enum { + LV_KEY_UP = 17, /*0x11*/ + LV_KEY_DOWN = 18, /*0x12*/ + LV_KEY_RIGHT = 19, /*0x13*/ + LV_KEY_LEFT = 20, /*0x14*/ + LV_KEY_ESC = 27, /*0x1B*/ + LV_KEY_DEL = 127, /*0x7F*/ + LV_KEY_BACKSPACE = 8, /*0x08*/ + LV_KEY_ENTER = 10, /*0x0A, '\n'*/ + LV_KEY_NEXT = 9, /*0x09, '\t'*/ + LV_KEY_PREV = 11, /*0x0B, '*/ + LV_KEY_HOME = 2, /*0x02, STX*/ + LV_KEY_END = 3, /*0x03, ETX*/ +}; +typedef uint8_t lv_key_t; + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_group_t; + +typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *); +typedef void (*lv_group_edge_cb_t)(struct _lv_group_t *, bool); + +/** + * Groups can be used to logically hold objects so that they can be individually focused. + * They are NOT for laying out objects on a screen (try layouts for that). + */ +typedef struct _lv_group_t { + lv_ll_t obj_ll; /**< Linked list to store the objects in the group*/ + struct _lv_obj_t ** obj_focus; /**< The object in focus*/ + + lv_group_focus_cb_t focus_cb; /**< A function to call when a new object is focused (optional)*/ + lv_group_edge_cb_t edge_cb; /**< A function to call when an edge is reached, no more focus + targets are available in this direction (to allow edge feedback + like a sound or a scroll bounce) */ + +#if LV_USE_USER_DATA + void * user_data; +#endif + + uint8_t frozen : 1; /**< 1: can't focus to new object*/ + uint8_t editing : 1; /**< 1: Edit mode, 0: Navigate mode*/ + uint8_t refocus_policy : 1; /**< 1: Focus prev if focused on deletion. 0: Focus next if focused on + deletion.*/ + uint8_t wrap : 1; /**< 1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end + of list.*/ +} lv_group_t; + + +typedef enum { + LV_GROUP_REFOCUS_POLICY_NEXT = 0, + LV_GROUP_REFOCUS_POLICY_PREV = 1 +} lv_group_refocus_policy_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Init. the group module + * @remarks Internal function, do not call directly. + */ +void _lv_group_init(void); + +/** + * Create a new object group + * @return pointer to the new object group + */ +lv_group_t * lv_group_create(void); + +/** + * Delete a group object + * @param group pointer to a group + */ +void lv_group_del(lv_group_t * group); + +/** + * Set a default group. New object are added to this group if it's enabled in their class with `add_to_def_group = true` + * @param group pointer to a group (can be `NULL`) + */ +void lv_group_set_default(lv_group_t * group); + +/** + * Get the default group + * @return pointer to the default group + */ +lv_group_t * lv_group_get_default(void); + +/** + * Add an object to a group + * @param group pointer to a group + * @param obj pointer to an object to add + */ +void lv_group_add_obj(lv_group_t * group, struct _lv_obj_t * obj); + +/** + * Swap 2 object in a group. The object must be in the same group + * @param obj1 pointer to an object + * @param obj2 pointer to an other object + */ +void lv_group_swap_obj(struct _lv_obj_t * obj1, struct _lv_obj_t * obj2); + +/** + * Remove an object from its group + * @param obj pointer to an object to remove + */ +void lv_group_remove_obj(struct _lv_obj_t * obj); + +/** + * Remove all objects from a group + * @param group pointer to a group + */ +void lv_group_remove_all_objs(lv_group_t * group); + +/** + * Focus on an object (defocus the current) + * @param obj pointer to an object to focus on + */ +void lv_group_focus_obj(struct _lv_obj_t * obj); + +/** + * Focus the next object in a group (defocus the current) + * @param group pointer to a group + */ +void lv_group_focus_next(lv_group_t * group); + +/** + * Focus the previous object in a group (defocus the current) + * @param group pointer to a group + */ +void lv_group_focus_prev(lv_group_t * group); + +/** + * Do not let to change the focus from the current object + * @param group pointer to a group + * @param en true: freeze, false: release freezing (normal mode) + */ +void lv_group_focus_freeze(lv_group_t * group, bool en); + +/** + * Send a control character to the focuses object of a group + * @param group pointer to a group + * @param c a character (use LV_KEY_.. to navigate) + * @return result of focused object in group. + */ +lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c); + +/** + * Set a function for a group which will be called when a new object is focused + * @param group pointer to a group + * @param focus_cb the call back function or NULL if unused + */ +void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb); + +/** + * Set a function for a group which will be called when a focus edge is reached + * @param group pointer to a group + * @param edge_cb the call back function or NULL if unused + */ +void lv_group_set_edge_cb(lv_group_t * group, lv_group_edge_cb_t edge_cb); + + +/** + * Set whether the next or previous item in a group is focused if the currently focused obj is + * deleted. + * @param group pointer to a group + * @param policy new refocus policy enum + */ +void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy); + +/** + * Manually set the current mode (edit or navigate). + * @param group pointer to group + * @param edit true: edit mode; false: navigate mode + */ +void lv_group_set_editing(lv_group_t * group, bool edit); + +/** + * Set whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en true: wrapping enabled; false: wrapping disabled + */ +void lv_group_set_wrap(lv_group_t * group, bool en); + +/** + * Get the focused object or NULL if there isn't one + * @param group pointer to a group + * @return pointer to the focused object + */ +struct _lv_obj_t * lv_group_get_focused(const lv_group_t * group); + +/** + * Get the focus callback function of a group + * @param group pointer to a group + * @return the call back function or NULL if not set + */ +lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group); + +/** + * Get the edge callback function of a group + * @param group pointer to a group + * @return the call back function or NULL if not set + */ +lv_group_edge_cb_t lv_group_get_edge_cb(const lv_group_t * group); + +/** + * Get the current mode (edit or navigate). + * @param group pointer to group + * @return true: edit mode; false: navigate mode + */ +bool lv_group_get_editing(const lv_group_t * group); + +/** + * Get whether focus next/prev will allow wrapping from first->last or last->first object. + * @param group pointer to group + * @param en true: wrapping enabled; false: wrapping disabled + */ +bool lv_group_get_wrap(lv_group_t * group); + +/** + * Get the number of object in the group + * @param group pointer to a group + * @return number of objects in the group + */ +uint32_t lv_group_get_obj_count(lv_group_t * group); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GROUP_H*/ diff --git a/include/liblvgl/core/lv_indev.h b/include/liblvgl/core/lv_indev.h new file mode 100644 index 00000000..4692ef37 --- /dev/null +++ b/include/liblvgl/core/lv_indev.h @@ -0,0 +1,176 @@ +/** + * @file lv_indev.h + * + */ + +#ifndef LV_INDEV_H +#define LV_INDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" +#include "liblvgl/hal/lv_hal_indev.h" +#include "lv_group.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Called periodically to read the input devices + * @param timer pointer to a timer to read + */ +void lv_indev_read_timer_cb(lv_timer_t * timer); + +/** + * Enable or disable one or all input devices (default enabled) + * @param indev pointer to an input device or NULL to enable/disable all of them + * @param en true to enable, false to disable + */ +void lv_indev_enable(lv_indev_t * indev, bool en); + +/** + * Get the currently processed input device. Can be used in action functions too. + * @return pointer to the currently processed input device or NULL if no input device processing + * right now + */ +lv_indev_t * lv_indev_get_act(void); + +/** + * Get the type of an input device + * @param indev pointer to an input device + * @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`) + */ +lv_indev_type_t lv_indev_get_type(const lv_indev_t * indev); + +/** + * Reset one or all input devices + * @param indev pointer to an input device to reset or NULL to reset all of them + * @param obj pointer to an object which triggers the reset. + */ +void lv_indev_reset(lv_indev_t * indev, lv_obj_t * obj); + +/** + * Reset the long press state of an input device + * @param indev pointer to an input device + */ +void lv_indev_reset_long_press(lv_indev_t * indev); + +/** + * Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON) + * @param indev pointer to an input device + * @param cur_obj pointer to an object to be used as cursor + */ +void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj); + +/** + * Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD) + * @param indev pointer to an input device + * @param group point to a group + */ +void lv_indev_set_group(lv_indev_t * indev, lv_group_t * group); + +/** + * Set the an array of points for LV_INDEV_TYPE_BUTTON. + * These points will be assigned to the buttons to press a specific point on the screen + * @param indev pointer to an input device + * @param group point to a group + */ +void lv_indev_set_button_points(lv_indev_t * indev, const lv_point_t points[]); + +/** + * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @param point pointer to a point to store the result + */ +void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point); + +/** +* Get the current gesture direct +* @param indev pointer to an input device +* @return current gesture direct +*/ +lv_dir_t lv_indev_get_gesture_dir(const lv_indev_t * indev); + +/** + * Get the last pressed key of an input device (for LV_INDEV_TYPE_KEYPAD) + * @param indev pointer to an input device + * @return the last pressed key (0 on error) + */ +uint32_t lv_indev_get_key(const lv_indev_t * indev); + +/** + * Check the current scroll direction of an input device (for LV_INDEV_TYPE_POINTER and + * LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @return LV_DIR_NONE: no scrolling now + * LV_DIR_HOR/VER + */ +lv_dir_t lv_indev_get_scroll_dir(const lv_indev_t * indev); + +/** + * Get the currently scrolled object (for LV_INDEV_TYPE_POINTER and + * LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @return pointer to the currently scrolled object or NULL if no scrolling by this indev + */ +lv_obj_t * lv_indev_get_scroll_obj(const lv_indev_t * indev); + +/** + * Get the movement vector of an input device (for LV_INDEV_TYPE_POINTER and + * LV_INDEV_TYPE_BUTTON) + * @param indev pointer to an input device + * @param point pointer to a point to store the types.pointer.vector + */ +void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point); + +/** + * Do nothing until the next release + * @param indev pointer to an input device + */ +void lv_indev_wait_release(lv_indev_t * indev); + +/** + * Gets a pointer to the currently active object in the currently processed input device. + * @return pointer to currently active object or NULL if no active object + */ +lv_obj_t * lv_indev_get_obj_act(void); + +/** + * Get a pointer to the indev read timer to + * modify its parameters with `lv_timer_...` functions. + * @param indev pointer to an input device + * @return pointer to the indev read refresher timer. (NULL on error) + */ +lv_timer_t * lv_indev_get_read_timer(lv_disp_t * indev); + +/** + * Search the most top, clickable object by a point + * @param obj pointer to a start object, typically the screen + * @param point pointer to a point for searching the most top child + * @return pointer to the found object or NULL if there was no suitable object + */ +lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_INDEV_H*/ diff --git a/include/liblvgl/core/lv_indev_scroll.h b/include/liblvgl/core/lv_indev_scroll.h new file mode 100644 index 00000000..76c64d17 --- /dev/null +++ b/include/liblvgl/core/lv_indev_scroll.h @@ -0,0 +1,65 @@ +/** + * @file lv_indev_scroll.h + * + */ + +#ifndef LV_INDEV_SCROLL_H +#define LV_INDEV_SCROLL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Handle scrolling. Called by LVGL during input device processing + * @param proc pointer to an input device's proc field + */ +void _lv_indev_scroll_handler(_lv_indev_proc_t * proc); + +/** + * Handle throwing after scrolling. Called by LVGL during input device processing + * @param proc pointer to an input device's proc field + */ +void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc); + +/** + * Predict where would a scroll throw end + * @param indev pointer to an input device + * @param dir ` LV_DIR_VER` or `LV_DIR_HOR` + * @return the difference compared to the current position when the throw would be finished + */ +lv_coord_t lv_indev_scroll_throw_predict(lv_indev_t * indev, lv_dir_t dir); + +/** + * Get the distance of the nearest snap point + * @param obj the object on which snap points should be found + * @param p save the distance of the found snap point there + */ +void lv_indev_scroll_get_snap_dist(lv_obj_t * obj, lv_point_t * p); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_INDEV_SCROLL_H*/ diff --git a/include/liblvgl/core/lv_obj.h b/include/liblvgl/core/lv_obj.h new file mode 100644 index 00000000..c89e4609 --- /dev/null +++ b/include/liblvgl/core/lv_obj.h @@ -0,0 +1,409 @@ +/** + * @file lv_obj.h + * + */ + +#ifndef LV_OBJ_H +#define LV_OBJ_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../lv_conf_internal.h" + +#include +#include +#include "../misc/lv_style.h" +#include "../misc/lv_types.h" +#include "../misc/lv_area.h" +#include "../misc/lv_color.h" +#include "../misc/lv_assert.h" +#include "../hal/lv_hal.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; + +/** + * Possible states of a widget. + * OR-ed values are possible + */ +enum { + LV_STATE_DEFAULT = 0x0000, + LV_STATE_CHECKED = 0x0001, + LV_STATE_FOCUSED = 0x0002, + LV_STATE_FOCUS_KEY = 0x0004, + LV_STATE_EDITED = 0x0008, + LV_STATE_HOVERED = 0x0010, + LV_STATE_PRESSED = 0x0020, + LV_STATE_SCROLLED = 0x0040, + LV_STATE_DISABLED = 0x0080, + + LV_STATE_USER_1 = 0x1000, + LV_STATE_USER_2 = 0x2000, + LV_STATE_USER_3 = 0x4000, + LV_STATE_USER_4 = 0x8000, + + LV_STATE_ANY = 0xFFFF, /**< Special value can be used in some functions to target all states*/ +}; + +typedef uint16_t lv_state_t; + +/** + * The possible parts of widgets. + * The parts can be considered as the internal building block of the widgets. + * E.g. slider = background + indicator + knob + * Not all parts are used by every widget + */ +enum { + LV_PART_MAIN = 0x000000, /**< A background like rectangle*/ + LV_PART_SCROLLBAR = 0x010000, /**< The scrollbar(s)*/ + LV_PART_INDICATOR = 0x020000, /**< Indicator, e.g. for slider, bar, switch, or the tick box of the checkbox*/ + LV_PART_KNOB = 0x030000, /**< Like handle to grab to adjust the value*/ + LV_PART_SELECTED = 0x040000, /**< Indicate the currently selected option or section*/ + LV_PART_ITEMS = 0x050000, /**< Used if the widget has multiple similar elements (e.g. table cells)*/ + LV_PART_TICKS = 0x060000, /**< Ticks on scale e.g. for a chart or meter*/ + LV_PART_CURSOR = 0x070000, /**< Mark a specific place e.g. for text area's cursor or on a chart*/ + + LV_PART_CUSTOM_FIRST = 0x080000, /**< Extension point for custom widgets*/ + + LV_PART_ANY = 0x0F0000, /**< Special value can be used in some functions to target all parts*/ +}; + +typedef uint32_t lv_part_t; + +/** + * On/Off features controlling the object's behavior. + * OR-ed values are possible + */ +enum { + LV_OBJ_FLAG_HIDDEN = (1L << 0), /**< Make the object hidden. (Like it wasn't there at all)*/ + LV_OBJ_FLAG_CLICKABLE = (1L << 1), /**< Make the object clickable by the input devices*/ + LV_OBJ_FLAG_CLICK_FOCUSABLE = (1L << 2), /**< Add focused state to the object when clicked*/ + LV_OBJ_FLAG_CHECKABLE = (1L << 3), /**< Toggle checked state when the object is clicked*/ + LV_OBJ_FLAG_SCROLLABLE = (1L << 4), /**< Make the object scrollable*/ + LV_OBJ_FLAG_SCROLL_ELASTIC = (1L << 5), /**< Allow scrolling inside but with slower speed*/ + LV_OBJ_FLAG_SCROLL_MOMENTUM = (1L << 6), /**< Make the object scroll further when "thrown"*/ + LV_OBJ_FLAG_SCROLL_ONE = (1L << 7), /**< Allow scrolling only one snappable children*/ + LV_OBJ_FLAG_SCROLL_CHAIN_HOR = (1L << 8), /**< Allow propagating the horizontal scroll to a parent*/ + LV_OBJ_FLAG_SCROLL_CHAIN_VER = (1L << 9), /**< Allow propagating the vertical scroll to a parent*/ + LV_OBJ_FLAG_SCROLL_CHAIN = (LV_OBJ_FLAG_SCROLL_CHAIN_HOR | LV_OBJ_FLAG_SCROLL_CHAIN_VER), + LV_OBJ_FLAG_SCROLL_ON_FOCUS = (1L << 10), /**< Automatically scroll object to make it visible when focused*/ + LV_OBJ_FLAG_SCROLL_WITH_ARROW = (1L << 11), /**< Allow scrolling the focused object with arrow keys*/ + LV_OBJ_FLAG_SNAPPABLE = (1L << 12), /**< If scroll snap is enabled on the parent it can snap to this object*/ + LV_OBJ_FLAG_PRESS_LOCK = (1L << 13), /**< Keep the object pressed even if the press slid from the object*/ + LV_OBJ_FLAG_EVENT_BUBBLE = (1L << 14), /**< Propagate the events to the parent too*/ + LV_OBJ_FLAG_GESTURE_BUBBLE = (1L << 15), /**< Propagate the gestures to the parent*/ + LV_OBJ_FLAG_ADV_HITTEST = (1L << 16), /**< Allow performing more accurate hit (click) test. E.g. consider rounded corners.*/ + LV_OBJ_FLAG_IGNORE_LAYOUT = (1L << 17), /**< Make the object position-able by the layouts*/ + LV_OBJ_FLAG_FLOATING = (1L << 18), /**< Do not scroll the object when the parent scrolls and ignore layout*/ + LV_OBJ_FLAG_OVERFLOW_VISIBLE = (1L << 19), /**< Do not clip the children's content to the parent's boundary*/ + + LV_OBJ_FLAG_LAYOUT_1 = (1L << 23), /**< Custom flag, free to use by layouts*/ + LV_OBJ_FLAG_LAYOUT_2 = (1L << 24), /**< Custom flag, free to use by layouts*/ + + LV_OBJ_FLAG_WIDGET_1 = (1L << 25), /**< Custom flag, free to use by widget*/ + LV_OBJ_FLAG_WIDGET_2 = (1L << 26), /**< Custom flag, free to use by widget*/ + LV_OBJ_FLAG_USER_1 = (1L << 27), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_2 = (1L << 28), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_3 = (1L << 29), /**< Custom flag, free to use by user*/ + LV_OBJ_FLAG_USER_4 = (1L << 30), /**< Custom flag, free to use by user*/ + +}; + + +typedef uint32_t lv_obj_flag_t; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_obj_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_OBJ_DRAW_PART_RECTANGLE, /**< The main rectangle*/ + LV_OBJ_DRAW_PART_BORDER_POST,/**< The border if style_border_post = true*/ + LV_OBJ_DRAW_PART_SCROLLBAR, /**< The scrollbar*/ +} lv_obj_draw_part_type_t; + +#include "lv_obj_tree.h" +#include "lv_obj_pos.h" +#include "lv_obj_scroll.h" +#include "lv_obj_style.h" +#include "lv_obj_draw.h" +#include "lv_obj_class.h" +#include "lv_event.h" +#include "lv_group.h" + +/** + * Make the base object's class publicly available. + */ +extern const lv_obj_class_t lv_obj_class; + +/** + * Special, rarely used attributes. + * They are allocated automatically if any elements is set. + */ +typedef struct { + struct _lv_obj_t ** children; /**< Store the pointer of the children in an array.*/ + uint32_t child_cnt; /**< Number of children*/ + lv_group_t * group_p; + + struct _lv_event_dsc_t * event_dsc; /**< Dynamically allocated event callback and user data array*/ + lv_point_t scroll; /**< The current X/Y scroll offset*/ + + lv_coord_t ext_click_pad; /**< Extra click padding in all direction*/ + lv_coord_t ext_draw_size; /**< EXTend the size in every direction for drawing.*/ + + lv_scrollbar_mode_t scrollbar_mode : 2; /**< How to display scrollbars*/ + lv_scroll_snap_t scroll_snap_x : 2; /**< Where to align the snappable children horizontally*/ + lv_scroll_snap_t scroll_snap_y : 2; /**< Where to align the snappable children vertically*/ + lv_dir_t scroll_dir : 4; /**< The allowed scroll direction(s)*/ + uint8_t event_dsc_cnt : 6; /**< Number of event callbacks stored in `event_dsc` array*/ + uint8_t layer_type : 2; /**< Cache the layer type here. Element of @lv_intermediate_layer_type_t */ +} _lv_obj_spec_attr_t; + +typedef struct _lv_obj_t { + const lv_obj_class_t * class_p; + struct _lv_obj_t * parent; + _lv_obj_spec_attr_t * spec_attr; + _lv_obj_style_t * styles; +#if LV_USE_USER_DATA + void * user_data; +#endif + lv_area_t coords; + lv_obj_flag_t flags; + lv_state_t state; + uint16_t layout_inv : 1; + uint16_t scr_layout_inv : 1; + uint16_t skip_trans : 1; + uint16_t style_cnt : 6; + uint16_t h_layout : 1; + uint16_t w_layout : 1; +} lv_obj_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize LVGL library. + * Should be called before any other LVGL related function. + */ +void lv_init(void); + +#if LV_ENABLE_GC || !LV_MEM_CUSTOM + +/** + * Deinit the 'lv' library + * Currently only implemented when not using custom allocators, or GC is enabled. + */ +void lv_deinit(void); + +#endif + +/** + * Returns whether the 'lv' library is currently initialized + */ +bool lv_is_initialized(void); + +/** + * Create a base object (a rectangle) + * @param parent pointer to a parent object. If NULL then a screen will be created. + * @return pointer to the new object + */ +lv_obj_t * lv_obj_create(lv_obj_t * parent); + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set one or more flags + * @param obj pointer to an object + * @param f R-ed values from `lv_obj_flag_t` to set. + */ +void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f); + +/** + * Clear one or more flags + * @param obj pointer to an object + * @param f OR-ed values from `lv_obj_flag_t` to set. + */ +void lv_obj_clear_flag(lv_obj_t * obj, lv_obj_flag_t f); + + +/** + * Add one or more states to the object. The other state bits will remain unchanged. + * If specified in the styles, transition animation will be started from the previous state to the current. + * @param obj pointer to an object + * @param state the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` + */ +void lv_obj_add_state(lv_obj_t * obj, lv_state_t state); + +/** + * Remove one or more states to the object. The other state bits will remain unchanged. + * If specified in the styles, transition animation will be started from the previous state to the current. + * @param obj pointer to an object + * @param state the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED` + */ +void lv_obj_clear_state(lv_obj_t * obj, lv_state_t state); + +/** + * Set the user_data field of the object + * @param obj pointer to an object + * @param user_data pointer to the new user_data. + */ +#if LV_USE_USER_DATA +static inline void lv_obj_set_user_data(lv_obj_t * obj, void * user_data) +{ + obj->user_data = user_data; +} +#endif + +/*======================= + * Getter functions + *======================*/ + +/** + * Check if a given flag or all the given flags are set on an object. + * @param obj pointer to an object + * @param f the flag(s) to check (OR-ed values can be used) + * @return true: all flags are set; false: not all flags are set + */ +bool lv_obj_has_flag(const lv_obj_t * obj, lv_obj_flag_t f); + +/** + * Check if a given flag or any of the flags are set on an object. + * @param obj pointer to an object + * @param f the flag(s) to check (OR-ed values can be used) + * @return true: at lest one flag flag is set; false: none of the flags are set + */ +bool lv_obj_has_flag_any(const lv_obj_t * obj, lv_obj_flag_t f); + +/** + * Get the state of an object + * @param obj pointer to an object + * @return the state (OR-ed values from `lv_state_t`) + */ +lv_state_t lv_obj_get_state(const lv_obj_t * obj); + +/** + * Check if the object is in a given state or not. + * @param obj pointer to an object + * @param state a state or combination of states to check + * @return true: `obj` is in `state`; false: `obj` is not in `state` + */ +bool lv_obj_has_state(const lv_obj_t * obj, lv_state_t state); + +/** + * Get the group of the object + * @param obj pointer to an object + * @return the pointer to group of the object + */ +void * lv_obj_get_group(const lv_obj_t * obj); + +/** + * Get the user_data field of the object + * @param obj pointer to an object + * @return the pointer to the user_data of the object + */ +#if LV_USE_USER_DATA +static inline void * lv_obj_get_user_data(lv_obj_t * obj) +{ + return obj->user_data; +} +#endif + +/*======================= + * Other functions + *======================*/ + +/** + * Allocate special data for an object if not allocated yet. + * @param obj pointer to an object + */ +void lv_obj_allocate_spec_attr(lv_obj_t * obj); + +/** + * Check the type of obj. + * @param obj pointer to an object + * @param class_p a class to check (e.g. `lv_slider_class`) + * @return true: `class_p` is the `obj` class. + */ +bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p); + +/** + * Check if any object has a given class (type). + * It checks the ancestor classes too. + * @param obj pointer to an object + * @param class_p a class to check (e.g. `lv_slider_class`) + * @return true: `obj` has the given class + */ +bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p); + +/** + * Get the class (type) of the object + * @param obj pointer to an object + * @return the class (type) of the object + */ +const lv_obj_class_t * lv_obj_get_class(const lv_obj_t * obj); + +/** + * Check if any object is still "alive". + * @param obj pointer to an object + * @return true: valid + */ +bool lv_obj_is_valid(const lv_obj_t * obj); + +/** + * Scale the given number of pixels (a distance or size) relative to a 160 DPI display + * considering the DPI of the `obj`'s display. + * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the + * DPI of the display. + * @param obj an object whose display's dpi should be considered + * @param n the number of pixels to scale + * @return `n x current_dpi/160` + */ +static inline lv_coord_t lv_obj_dpx(const lv_obj_t * obj, lv_coord_t n) +{ + return _LV_DPX_CALC(lv_disp_get_dpi(lv_obj_get_disp(obj)), n); +} + +/********************** + * MACROS + **********************/ + +#if LV_USE_ASSERT_OBJ +# define LV_ASSERT_OBJ(obj_p, obj_class) \ + do { \ + LV_ASSERT_MSG(obj_p != NULL, "The object is NULL"); \ + LV_ASSERT_MSG(lv_obj_has_class(obj_p, obj_class) == true, "Incompatible object type."); \ + LV_ASSERT_MSG(lv_obj_is_valid(obj_p) == true, "The object is invalid, deleted or corrupted?"); \ + } while(0) +# else +# define LV_ASSERT_OBJ(obj_p, obj_class) do{}while(0) +#endif + +#if LV_USE_LOG && LV_LOG_TRACE_OBJ_CREATE +# define LV_TRACE_OBJ_CREATE(...) LV_LOG_TRACE(__VA_ARGS__) +#else +# define LV_TRACE_OBJ_CREATE(...) +#endif + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_H*/ diff --git a/include/liblvgl/core/lv_obj_class.h b/include/liblvgl/core/lv_obj_class.h new file mode 100644 index 00000000..01a7248b --- /dev/null +++ b/include/liblvgl/core/lv_obj_class.h @@ -0,0 +1,94 @@ +/** + * @file lv_obj_class.h + * + */ + +#ifndef LV_OBJ_CLASS_H +#define LV_OBJ_CLASS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include + +/********************* + * DEFINES + *********************/ + + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_obj_class_t; +struct _lv_event_t; + +typedef enum { + LV_OBJ_CLASS_EDITABLE_INHERIT, /**< Check the base class. Must have 0 value to let zero initialized class inherit*/ + LV_OBJ_CLASS_EDITABLE_TRUE, + LV_OBJ_CLASS_EDITABLE_FALSE, +} lv_obj_class_editable_t; + +typedef enum { + LV_OBJ_CLASS_GROUP_DEF_INHERIT, /**< Check the base class. Must have 0 value to let zero initialized class inherit*/ + LV_OBJ_CLASS_GROUP_DEF_TRUE, + LV_OBJ_CLASS_GROUP_DEF_FALSE, +} lv_obj_class_group_def_t; + +typedef void (*lv_obj_class_event_cb_t)(struct _lv_obj_class_t * class_p, struct _lv_event_t * e); +/** + * Describe the common methods of every object. + * Similar to a C++ class. + */ +typedef struct _lv_obj_class_t { + const struct _lv_obj_class_t * base_class; + void (*constructor_cb)(const struct _lv_obj_class_t * class_p, struct _lv_obj_t * obj); + void (*destructor_cb)(const struct _lv_obj_class_t * class_p, struct _lv_obj_t * obj); +#if LV_USE_USER_DATA + void * user_data; +#endif + void (*event_cb)(const struct _lv_obj_class_t * class_p, + struct _lv_event_t * e); /**< Widget type specific event function*/ + lv_coord_t width_def; + lv_coord_t height_def; + uint32_t editable : 2; /**< Value from ::lv_obj_class_editable_t*/ + uint32_t group_def : 2; /**< Value from ::lv_obj_class_group_def_t*/ + uint32_t instance_size : 16; +} lv_obj_class_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an object form a class descriptor + * @param class_p pointer to a class + * @param parent pointer to an object where the new object should be created + * @return pointer to the created object + */ +struct _lv_obj_t * lv_obj_class_create_obj(const struct _lv_obj_class_t * class_p, struct _lv_obj_t * parent); + +void lv_obj_class_init_obj(struct _lv_obj_t * obj); + +void _lv_obj_destruct(struct _lv_obj_t * obj); + +bool lv_obj_is_editable(struct _lv_obj_t * obj); + +bool lv_obj_is_group_def(struct _lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_CLASS_H*/ diff --git a/include/liblvgl/core/lv_obj_draw.h b/include/liblvgl/core/lv_obj_draw.h new file mode 100644 index 00000000..a107e556 --- /dev/null +++ b/include/liblvgl/core/lv_obj_draw.h @@ -0,0 +1,172 @@ +/** + * @file lv_obj_draw.h + * + */ + +#ifndef LV_OBJ_DRAW_H +#define LV_OBJ_DRAW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_obj_class_t; + +/** Cover check results.*/ +typedef enum { + LV_COVER_RES_COVER = 0, + LV_COVER_RES_NOT_COVER = 1, + LV_COVER_RES_MASKED = 2, +} lv_cover_res_t; + +typedef enum { + LV_LAYER_TYPE_NONE, + LV_LAYER_TYPE_SIMPLE, + LV_LAYER_TYPE_TRANSFORM, +} lv_layer_type_t; + +typedef struct { + lv_draw_ctx_t * draw_ctx; /**< Draw context*/ + const struct _lv_obj_class_t * class_p; /**< The class that sent the event */ + uint32_t type; /**< The type if part being draw. Element of `lv__draw_part_type_t` */ + lv_area_t * draw_area; /**< The area of the part being drawn*/ + lv_draw_rect_dsc_t * + rect_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for rectangle-like parts*/ + lv_draw_label_dsc_t * + label_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for text-like parts*/ + lv_draw_line_dsc_t * + line_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for line-like parts*/ + lv_draw_img_dsc_t * + img_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for image-like parts*/ + lv_draw_arc_dsc_t * + arc_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for arc-like parts*/ + const lv_point_t * + p1; /**< A point calculated during drawing. E.g. a point of chart or the center of an arc.*/ + const lv_point_t * p2; /**< A point calculated during drawing. E.g. a point of chart.*/ + char * text; /**< A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis.*/ + uint32_t text_length; /**< Size of the text buffer containing null-terminated text string calculated during drawing.*/ + uint32_t part; /**< The current part for which the event is sent*/ + uint32_t id; /**< The index of the part. E.g. a button's index on button matrix or table cell index.*/ + lv_coord_t radius; /**< E.g. the radius of an arc (not the corner radius).*/ + int32_t value; /**< A value calculated during drawing. E.g. Chart's tick line value.*/ + const void * sub_part_ptr; /**< A pointer the identifies something in the part. E.g. chart series. */ +} lv_obj_draw_part_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize a rectangle draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * If an `..._opa` field is set to `LV_OPA_TRANSP` the related properties won't be initialized. + * Should be initialized with `lv_draw_rect_dsc_init(draw_dsc)`. + * @note Only the relevant fields will be set. + * E.g. if `border width == 0` the other border properties won't be evaluated. + */ +void lv_obj_init_draw_rect_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_rect_dsc_t * draw_dsc); + +/** + * Initialize a label draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * If the `opa` field is set to or the property is equal to `LV_OPA_TRANSP` the rest won't be initialized. + * Should be initialized with `lv_draw_label_dsc_init(draw_dsc)`. + */ +void lv_obj_init_draw_label_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_label_dsc_t * draw_dsc); + +/** + * Initialize an image draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * Should be initialized with `lv_draw_image_dsc_init(draw_dsc)`. + */ +void lv_obj_init_draw_img_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_img_dsc_t * draw_dsc); + + +/** + * Initialize a line draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * Should be initialized with `lv_draw_line_dsc_init(draw_dsc)`. + */ +void lv_obj_init_draw_line_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_line_dsc_t * draw_dsc); + +/** + * Initialize an arc draw descriptor from an object's styles in its current state + * @param obj pointer to an object + * @param part part of the object, e.g. `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc + * @param draw_dsc the descriptor to initialize. + * Should be initialized with `lv_draw_arc_dsc_init(draw_dsc)`. + */ +void lv_obj_init_draw_arc_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_arc_dsc_t * draw_dsc); + +/** + * Get the required extra size (around the object's part) to draw shadow, outline, value etc. + * @param obj pointer to an object + * @param part part of the object + * @return the extra size required around the object + */ +lv_coord_t lv_obj_calculate_ext_draw_size(struct _lv_obj_t * obj, uint32_t part); + +/** + * Initialize a draw descriptor used in events. + * @param dsc pointer to a descriptor. Later it should be passed as parameter to an `LV_EVENT_DRAW_PART_BEGIN/END` event. + * @param draw the current draw context. (usually returned by `lv_event_get_draw_ctx(e)`) + */ +void lv_obj_draw_dsc_init(lv_obj_draw_part_dsc_t * dsc, lv_draw_ctx_t * draw_ctx); + +/** + * Check the type obj a part draw descriptor + * @param dsc the descriptor (normally the event parameter) + * @param class_p pointer to class to which `type` is related + * @param type element of `lv__draw_part_type_t` + * @return true if ::dsc is related to ::class_p and ::type + */ +bool lv_obj_draw_part_check_type(lv_obj_draw_part_dsc_t * dsc, const struct _lv_obj_class_t * class_p, uint32_t type); + +/** + * Send a 'LV_EVENT_REFR_EXT_DRAW_SIZE' Call the ancestor's event handler to the object to refresh the value of the extended draw size. + * The result will be saved in `obj`. + * @param obj pointer to an object + */ +void lv_obj_refresh_ext_draw_size(struct _lv_obj_t * obj); + +/** + * Get the extended draw area of an object. + * @param obj pointer to an object + * @return the size extended draw area around the real coordinates + */ +lv_coord_t _lv_obj_get_ext_draw_size(const struct _lv_obj_t * obj); + + +lv_layer_type_t _lv_obj_get_layer_type(const struct _lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_DRAW_H*/ diff --git a/include/liblvgl/core/lv_obj_pos.h b/include/liblvgl/core/lv_obj_pos.h new file mode 100644 index 00000000..fdc64767 --- /dev/null +++ b/include/liblvgl/core/lv_obj_pos.h @@ -0,0 +1,449 @@ +/** + * @file lv_obj_pos.h + * + */ + +#ifndef LV_OBJ_POS_H +#define LV_OBJ_POS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct _lv_obj_t; + +typedef void (*lv_layout_update_cb_t)(struct _lv_obj_t *, void * user_data); +typedef struct { + lv_layout_update_cb_t cb; + void * user_data; +} lv_layout_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Set the position of an object relative to the set alignment. + * @param obj pointer to an object + * @param x new x coordinate + * @param y new y coordinate + * @note With default alignment it's the distance from the top left corner + * @note E.g. LV_ALIGN_CENTER alignment it's the offset from the center of the parent + * @note The position is interpreted on the content area of the parent + * @note The values can be set in pixel or in percentage of parent size with `lv_pct(v)` + */ +void lv_obj_set_pos(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + +/** + * Set the x coordinate of an object + * @param obj pointer to an object + * @param x new x coordinate + * @note With default alignment it's the distance from the top left corner + * @note E.g. LV_ALIGN_CENTER alignment it's the offset from the center of the parent + * @note The position is interpreted on the content area of the parent + * @note The values can be set in pixel or in percentage of parent size with `lv_pct(v)` + */ +void lv_obj_set_x(struct _lv_obj_t * obj, lv_coord_t x); + +/** + * Set the y coordinate of an object + * @param obj pointer to an object + * @param y new y coordinate + * @note With default alignment it's the distance from the top left corner + * @note E.g. LV_ALIGN_CENTER alignment it's the offset from the center of the parent + * @note The position is interpreted on the content area of the parent + * @note The values can be set in pixel or in percentage of parent size with `lv_pct(v)` + */ +void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y); + +/** + * Set the size of an object. + * @param obj pointer to an object + * @param w the new width + * @param h the new height + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * LV_SIZE_PCT(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range + */ +void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h); + +/** + * Recalculate the size of the object + * @param obj pointer to an object + * @return true: the size has been changed + */ +bool lv_obj_refr_size(struct _lv_obj_t * obj); + +/** + * Set the width of an object + * @param obj pointer to an object + * @param w the new width + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * lv_pct(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range + */ +void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w); + +/** + * Set the height of an object + * @param obj pointer to an object + * @param h the new height + * @note possible values are: + * pixel simple set the size accordingly + * LV_SIZE_CONTENT set the size to involve all children in the given direction + * lv_pct(x) to set size in percentage of the parent's content area size (the size without paddings). + * x should be in [0..1000]% range + */ +void lv_obj_set_height(struct _lv_obj_t * obj, lv_coord_t h); + +/** + * Set the width reduced by the left and right padding and the border width. + * @param obj pointer to an object + * @param w the width without paddings in pixels + */ +void lv_obj_set_content_width(struct _lv_obj_t * obj, lv_coord_t w); + +/** + * Set the height reduced by the top and bottom padding and the border width. + * @param obj pointer to an object + * @param h the height without paddings in pixels + */ +void lv_obj_set_content_height(struct _lv_obj_t * obj, lv_coord_t h); + +/** + * Set a layout for an object + * @param obj pointer to an object + * @param layout pointer to a layout descriptor to set + */ +void lv_obj_set_layout(struct _lv_obj_t * obj, uint32_t layout); + +/** + * Test whether the and object is positioned by a layout or not + * @param obj pointer to an object to test + * @return true: positioned by a layout; false: not positioned by a layout + */ +bool lv_obj_is_layout_positioned(const struct _lv_obj_t * obj); + +/** + * Mark the object for layout update. + * @param obj pointer to an object whose children needs to be updated + */ +void lv_obj_mark_layout_as_dirty(struct _lv_obj_t * obj); + +/** + * Update the layout of an object. + * @param obj pointer to an object whose children needs to be updated + */ +void lv_obj_update_layout(const struct _lv_obj_t * obj); + +/** + * Register a new layout + * @param cb the layout update callback + * @param user_data custom data that will be passed to `cb` + * @return the ID of the new layout + */ +uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data); + +/** + * Change the alignment of an object. + * @param obj pointer to an object to align + * @param align type of alignment (see 'lv_align_t' enum) `LV_ALIGN_OUT_...` can't be used. + */ +void lv_obj_set_align(struct _lv_obj_t * obj, lv_align_t align); + +/** + * Change the alignment of an object and set new coordinates. + * Equivalent to: + * lv_obj_set_align(obj, align); + * lv_obj_set_pos(obj, x_ofs, y_ofs); + * @param obj pointer to an object to align + * @param align type of alignment (see 'lv_align_t' enum) `LV_ALIGN_OUT_...` can't be used. + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment + */ +void lv_obj_align(struct _lv_obj_t * obj, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs); + +/** + * Align an object to an other object. + * @param obj pointer to an object to align + * @param base pointer to an other object (if NULL `obj`s parent is used). 'obj' will be aligned to it. + * @param align type of alignment (see 'lv_align_t' enum) + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment + * @note if the position or size of `base` changes `obj` needs to be aligned manually again + */ +void lv_obj_align_to(struct _lv_obj_t * obj, const struct _lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, + lv_coord_t y_ofs); + +/** + * Align an object to the center on its parent. + * @param obj pointer to an object to align + * @note if the parent size changes `obj` needs to be aligned manually again + */ +static inline void lv_obj_center(struct _lv_obj_t * obj) +{ + lv_obj_align(obj, LV_ALIGN_CENTER, 0, 0); +} + + +/** + * Copy the coordinates of an object to an area + * @param obj pointer to an object + * @param coords pointer to an area to store the coordinates + */ +void lv_obj_get_coords(const struct _lv_obj_t * obj, lv_area_t * coords); + +/** + * Get the x coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the left side of its parent plus the parent's left padding + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @note Zero return value means the object is on the left padding of the parent, and not on the left edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_x(const struct _lv_obj_t * obj); + +/** + * Get the x2 coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the right side of its parent plus the parent's right padding + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @note Zero return value means the object is on the right padding of the parent, and not on the right edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_x2(const struct _lv_obj_t * obj); + +/** + * Get the y coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the top side of its parent plus the parent's top padding + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @note Zero return value means the object is on the top padding of the parent, and not on the top edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_y(const struct _lv_obj_t * obj); + +/** + * Get the y2 coordinate of object. + * @param obj pointer to an object + * @return distance of `obj` from the bottom side of its parent plus the parent's bottom padding + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @note Zero return value means the object is on the bottom padding of the parent, and not on the bottom edge. + * @note Scrolling of the parent doesn't change the returned value. + * @note The returned value is always the distance from the parent even if `obj` is positioned by a layout. + */ +lv_coord_t lv_obj_get_y2(const struct _lv_obj_t * obj); + +/** + * Get the actually set x coordinate of object, i.e. the offset form the set alignment + * @param obj pointer to an object + * @return the set x coordinate + */ +lv_coord_t lv_obj_get_x_aligned(const struct _lv_obj_t * obj); + +/** + * Get the actually set y coordinate of object, i.e. the offset form the set alignment + * @param obj pointer to an object + * @return the set y coordinate + */ +lv_coord_t lv_obj_get_y_aligned(const struct _lv_obj_t * obj); + +/** + * Get the width of an object + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @return the width in pixels + */ +lv_coord_t lv_obj_get_width(const struct _lv_obj_t * obj); + +/** + * Get the height of an object + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @return the height in pixels + */ +lv_coord_t lv_obj_get_height(const struct _lv_obj_t * obj); + +/** + * Get the width reduced by the left and right padding and the border width. + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @return the width which still fits into its parent without causing overflow (making the parent scrollable) + */ +lv_coord_t lv_obj_get_content_width(const struct _lv_obj_t * obj); + +/** + * Get the height reduced by the top and bottom padding and the border width. + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @return the height which still fits into the parent without causing overflow (making the parent scrollable) + */ +lv_coord_t lv_obj_get_content_height(const struct _lv_obj_t * obj); + +/** + * Get the area reduced by the paddings and the border width. + * @param obj pointer to an object + * @note The position of the object is recalculated only on the next redraw. To force coordinate recalculation + * call `lv_obj_update_layout(obj)`. + * @param area the area which still fits into the parent without causing overflow (making the parent scrollable) + */ +void lv_obj_get_content_coords(const struct _lv_obj_t * obj, lv_area_t * area); + +/** + * Get the width occupied by the "parts" of the widget. E.g. the width of all columns of a table. + * @param obj pointer to an objects + * @return the width of the virtually drawn content + * @note This size independent from the real size of the widget. + * It just tells how large the internal ("virtual") content is. + */ +lv_coord_t lv_obj_get_self_width(const struct _lv_obj_t * obj); + +/** + * Get the height occupied by the "parts" of the widget. E.g. the height of all rows of a table. + * @param obj pointer to an objects + * @return the width of the virtually drawn content + * @note This size independent from the real size of the widget. + * It just tells how large the internal ("virtual") content is. + */ +lv_coord_t lv_obj_get_self_height(const struct _lv_obj_t * obj); + +/** + * Handle if the size of the internal ("virtual") content of an object has changed. + * @param obj pointer to an object + * @return false: nothing happened; true: refresh happened + */ +bool lv_obj_refresh_self_size(struct _lv_obj_t * obj); + +void lv_obj_refr_pos(struct _lv_obj_t * obj); + +void lv_obj_move_to(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + + +void lv_obj_move_children_by(struct _lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff, bool ignore_floating); + +/** + * Transform a point using the angle and zoom style properties of an object + * @param obj pointer to an object whose style properties should be used + * @param p a point to transform, the result will be written back here too + * @param recursive consider the transformation properties of the parents too + * @param inv do the inverse of the transformation (-angle and 1/zoom) + */ +void lv_obj_transform_point(const struct _lv_obj_t * obj, lv_point_t * p, bool recursive, bool inv); + +/** + * Transform an area using the angle and zoom style properties of an object + * @param obj pointer to an object whose style properties should be used + * @param area an area to transform, the result will be written back here too + * @param recursive consider the transformation properties of the parents too + * @param inv do the inverse of the transformation (-angle and 1/zoom) + */ +void lv_obj_get_transformed_area(const struct _lv_obj_t * obj, lv_area_t * area, bool recursive, bool inv); + +/** + * Mark an area of an object as invalid. + * The area will be truncated to the object's area and marked for redraw. + * @param obj pointer to an object + * @param area the area to redraw + */ +void lv_obj_invalidate_area(const struct _lv_obj_t * obj, const lv_area_t * area); + +/** + * Mark the object as invalid to redrawn its area + * @param obj pointer to an object + */ +void lv_obj_invalidate(const struct _lv_obj_t * obj); + +/** + * Tell whether an area of an object is visible (even partially) now or not + * @param obj pointer to an object + * @param area the are to check. The visible part of the area will be written back here. + * @return true visible; false not visible (hidden, out of parent, on other screen, etc) + */ +bool lv_obj_area_is_visible(const struct _lv_obj_t * obj, lv_area_t * area); + +/** + * Tell whether an object is visible (even partially) now or not + * @param obj pointer to an object + * @return true: visible; false not visible (hidden, out of parent, on other screen, etc) + */ +bool lv_obj_is_visible(const struct _lv_obj_t * obj); + +/** + * Set the size of an extended clickable area + * @param obj pointer to an object + * @param size extended clickable area in all 4 directions [px] + */ +void lv_obj_set_ext_click_area(struct _lv_obj_t * obj, lv_coord_t size); + +/** + * Get the an area where to object can be clicked. + * It's the object's normal area plus the extended click area. + * @param obj pointer to an object + * @param area store the result area here + */ +void lv_obj_get_click_area(const struct _lv_obj_t * obj, lv_area_t * area); + +/** + * Hit-test an object given a particular point in screen space. + * @param obj object to hit-test + * @param point screen-space point (absolute coordinate) + * @return true: if the object is considered under the point + */ +bool lv_obj_hit_test(struct _lv_obj_t * obj, const lv_point_t * point); + +/** + * Clamp a width between min and max width. If the min/max width is in percentage value use the ref_width + * @param width width to clamp + * @param min_width the minimal width + * @param max_width the maximal width + * @param ref_width the reference width used when min/max width is in percentage + * @return the clamped width + */ +lv_coord_t lv_clamp_width(lv_coord_t width, lv_coord_t min_width, lv_coord_t max_width, lv_coord_t ref_width); + +/** + * Clamp a height between min and max height. If the min/max height is in percentage value use the ref_height + * @param height height to clamp + * @param min_height the minimal height + * @param max_height the maximal height + * @param ref_height the reference height used when min/max height is in percentage + * @return the clamped height + */ +lv_coord_t lv_clamp_height(lv_coord_t height, lv_coord_t min_height, lv_coord_t max_height, lv_coord_t ref_height); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_POS_H*/ diff --git a/include/liblvgl/core/lv_obj_scroll.h b/include/liblvgl/core/lv_obj_scroll.h new file mode 100644 index 00000000..3717dec4 --- /dev/null +++ b/include/liblvgl/core/lv_obj_scroll.h @@ -0,0 +1,307 @@ +/** + * @file lv_obj_scroll.h + * + */ + +#ifndef LV_OBJ_SCROLL_H +#define LV_OBJ_SCROLL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_anim.h" +#include "liblvgl/misc/lv_types.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Can't include lv_obj.h because it includes this header file*/ +struct _lv_obj_t; + +/** Scrollbar modes: shows when should the scrollbars be visible*/ +enum { + LV_SCROLLBAR_MODE_OFF, /**< Never show scrollbars*/ + LV_SCROLLBAR_MODE_ON, /**< Always show scrollbars*/ + LV_SCROLLBAR_MODE_ACTIVE, /**< Show scroll bars when object is being scrolled*/ + LV_SCROLLBAR_MODE_AUTO, /**< Show scroll bars when the content is large enough to be scrolled*/ +}; +typedef uint8_t lv_scrollbar_mode_t; + + +/** Scroll span align options. Tells where to align the snappable children when scroll stops.*/ +enum { + LV_SCROLL_SNAP_NONE, /**< Do not align, leave where it is*/ + LV_SCROLL_SNAP_START, /**< Align to the left/top*/ + LV_SCROLL_SNAP_END, /**< Align to the right/bottom*/ + LV_SCROLL_SNAP_CENTER /**< Align to the center*/ +}; +typedef uint8_t lv_scroll_snap_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*===================== + * Setter functions + *====================*/ + +/** + * Set how the scrollbars should behave. + * @param obj pointer to an object + * @param mode LV_SCROLL_MODE_ON/OFF/AUTO/ACTIVE + */ +void lv_obj_set_scrollbar_mode(struct _lv_obj_t * obj, lv_scrollbar_mode_t mode); + +/** + * Set the object in which directions can be scrolled + * @param obj pointer to an object + * @param dir the allow scroll directions. An element or OR-ed values of `lv_dir_t` + */ +void lv_obj_set_scroll_dir(struct _lv_obj_t * obj, lv_dir_t dir); + +/** + * Set where to snap the children when scrolling ends horizontally + * @param obj pointer to an object + * @param align the snap align to set from `lv_scroll_snap_t` + */ +void lv_obj_set_scroll_snap_x(struct _lv_obj_t * obj, lv_scroll_snap_t align); + +/** + * Set where to snap the children when scrolling ends vertically + * @param obj pointer to an object + * @param align the snap align to set from `lv_scroll_snap_t` + */ +void lv_obj_set_scroll_snap_y(struct _lv_obj_t * obj, lv_scroll_snap_t align); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current scroll mode (when to hide the scrollbars) + * @param obj pointer to an object + * @return the current scroll mode from `lv_scrollbar_mode_t` + */ +lv_scrollbar_mode_t lv_obj_get_scrollbar_mode(const struct _lv_obj_t * obj); + +/** + * Get the object in which directions can be scrolled + * @param obj pointer to an object + * @param dir the allow scroll directions. An element or OR-ed values of `lv_dir_t` + */ +lv_dir_t lv_obj_get_scroll_dir(const struct _lv_obj_t * obj); + +/** + * Get where to snap the children when scrolling ends horizontally + * @param obj pointer to an object + * @return the current snap align from `lv_scroll_snap_t` + */ +lv_scroll_snap_t lv_obj_get_scroll_snap_x(const struct _lv_obj_t * obj); + +/** + * Get where to snap the children when scrolling ends vertically + * @param obj pointer to an object + * @return the current snap align from `lv_scroll_snap_t` + */ +lv_scroll_snap_t lv_obj_get_scroll_snap_y(const struct _lv_obj_t * obj); + +/** + * Get current X scroll position. + * @param obj pointer to an object + * @return the current scroll position from the left edge. + * If the object is not scrolled return 0 + * If scrolled return > 0 + * If scrolled in (elastic scroll) return < 0 + */ +lv_coord_t lv_obj_get_scroll_x(const struct _lv_obj_t * obj); + +/** + * Get current Y scroll position. + * @param obj pointer to an object + * @return the current scroll position from the top edge. + * If the object is not scrolled return 0 + * If scrolled return > 0 + * If scrolled inside return < 0 + */ +lv_coord_t lv_obj_get_scroll_y(const struct _lv_obj_t * obj); + +/** + * Return the height of the area above the object. + * That is the number of pixels the object can be scrolled down. + * Normally positive but can be negative when scrolled inside. + * @param obj pointer to an object + * @return the scrollable area above the object in pixels + */ +lv_coord_t lv_obj_get_scroll_top(struct _lv_obj_t * obj); + +/** + * Return the height of the area below the object. + * That is the number of pixels the object can be scrolled down. + * Normally positive but can be negative when scrolled inside. + * @param obj pointer to an object + * @return the scrollable area below the object in pixels + */ +lv_coord_t lv_obj_get_scroll_bottom(struct _lv_obj_t * obj); + +/** + * Return the width of the area on the left the object. + * That is the number of pixels the object can be scrolled down. + * Normally positive but can be negative when scrolled inside. + * @param obj pointer to an object + * @return the scrollable area on the left the object in pixels + */ +lv_coord_t lv_obj_get_scroll_left(struct _lv_obj_t * obj); + +/** + * Return the width of the area on the right the object. + * That is the number of pixels the object can be scrolled down. + * Normally positive but can be negative when scrolled inside. + * @param obj pointer to an object + * @return the scrollable area on the right the object in pixels + */ +lv_coord_t lv_obj_get_scroll_right(struct _lv_obj_t * obj); + +/** + * Get the X and Y coordinates where the scrolling will end for this object if a scrolling animation is in progress. + * If no scrolling animation, give the current `x` or `y` scroll position. + * @param obj pointer to an object + * @param end pointer to store the result + */ +void lv_obj_get_scroll_end(struct _lv_obj_t * obj, lv_point_t * end); + +/*===================== + * Other functions + *====================*/ + +/** + * Scroll by a given amount of pixels + * @param obj pointer to an object to scroll + * @param dx pixels to scroll horizontally + * @param dy pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * @note > 0 value means scroll right/bottom (show the more content on the right/bottom) + * @note e.g. dy = -20 means scroll down 20 px + */ +void lv_obj_scroll_by(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim_en); + +/** + * Scroll by a given amount of pixels. + * `dx` and `dy` will be limited internally to allow scrolling only on the content area. + * @param obj pointer to an object to scroll + * @param dx pixels to scroll horizontally + * @param dy pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + * @note e.g. dy = -20 means scroll down 20 px + */ +void lv_obj_scroll_by_bounded(struct _lv_obj_t * obj, lv_coord_t dx, lv_coord_t dy, lv_anim_enable_t anim_en); + +/** + * Scroll to a given coordinate on an object. + * `x` and `y` will be limited internally to allow scrolling only on the content area. + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param y pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim_en); + +/** + * Scroll to a given X coordinate on an object. + * `x` will be limited internally to allow scrolling only on the content area. + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_x(struct _lv_obj_t * obj, lv_coord_t x, lv_anim_enable_t anim_en); + +/** + * Scroll to a given Y coordinate on an object + * `y` will be limited internally to allow scrolling only on the content area. + * @param obj pointer to an object to scroll + * @param y pixels to scroll vertically + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_y(struct _lv_obj_t * obj, lv_coord_t y, lv_anim_enable_t anim_en); + +/** + * Scroll to an object until it becomes visible on its parent + * @param obj pointer to an object to scroll into view + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_view(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + +/** + * Scroll to an object until it becomes visible on its parent. + * Do the same on the parent's parent, and so on. + * Therefore the object will be scrolled into view even it has nested scrollable parents + * @param obj pointer to an object to scroll into view + * @param anim_en LV_ANIM_ON: scroll with animation; LV_ANIM_OFF: scroll immediately + */ +void lv_obj_scroll_to_view_recursive(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + + +/** + * Low level function to scroll by given x and y coordinates. + * `LV_EVENT_SCROLL` is sent. + * @param obj pointer to an object to scroll + * @param x pixels to scroll horizontally + * @param y pixels to scroll vertically + * @return `LV_RES_INV`: to object was deleted in `LV_EVENT_SCROLL`; + * `LV_RES_OK`: if the object is still valid + */ +lv_res_t _lv_obj_scroll_by_raw(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + +/** + * Tell whether an object is being scrolled or not at this moment + * @param obj pointer to an object + * @return true: `obj` is being scrolled + */ +bool lv_obj_is_scrolling(const struct _lv_obj_t * obj); + +/** + * Check the children of `obj` and scroll `obj` to fulfill the scroll_snap settings + * @param obj an object whose children needs to checked and snapped + * @param anim_en LV_ANIM_ON/OFF + */ +void lv_obj_update_snap(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + +/** + * Get the area of the scrollbars + * @param obj pointer to an object + * @param hor pointer to store the area of the horizontal scrollbar + * @param ver pointer to store the area of the vertical scrollbar + */ +void lv_obj_get_scrollbar_area(struct _lv_obj_t * obj, lv_area_t * hor, lv_area_t * ver); + +/** + * Invalidate the area of the scrollbars + * @param obj pointer to an object + */ +void lv_obj_scrollbar_invalidate(struct _lv_obj_t * obj); + +/** + * Checked if the content is scrolled "in" and adjusts it to a normal position. + * @param obj pointer to an object + * @param anim_en LV_ANIM_ON/OFF + */ +void lv_obj_readjust_scroll(struct _lv_obj_t * obj, lv_anim_enable_t anim_en); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_SCROLL_H*/ diff --git a/include/liblvgl/core/lv_obj_style.h b/include/liblvgl/core/lv_obj_style.h new file mode 100644 index 00000000..18e530a6 --- /dev/null +++ b/include/liblvgl/core/lv_obj_style.h @@ -0,0 +1,248 @@ +/** + * @file lv_obj_style.h + * + */ + +#ifndef LV_OBJ_STYLE_H +#define LV_OBJ_STYLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include +#include "liblvgl/misc/lv_bidi.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Can't include lv_obj.h because it includes this header file*/ +struct _lv_obj_t; + +typedef enum { + _LV_STYLE_STATE_CMP_SAME, /*The style properties in the 2 states are identical*/ + _LV_STYLE_STATE_CMP_DIFF_REDRAW, /*The differences can be shown with a simple redraw*/ + _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD, /*The differences can be shown with a simple redraw*/ + _LV_STYLE_STATE_CMP_DIFF_LAYOUT, /*The differences can be shown with a simple redraw*/ +} _lv_style_state_cmp_t; + +typedef uint32_t lv_style_selector_t; + +typedef struct { + lv_style_t * style; + uint32_t selector : 24; + uint32_t is_local : 1; + uint32_t is_trans : 1; +} _lv_obj_style_t; + +typedef struct { + uint16_t time; + uint16_t delay; + lv_style_selector_t selector; + lv_style_prop_t prop; + lv_anim_path_cb_t path_cb; +#if LV_USE_USER_DATA + void * user_data; +#endif +} _lv_obj_style_transition_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the object related style manager module. + * Called by LVGL in `lv_init()` + */ +void _lv_obj_style_init(void); + +/** + * Add a style to an object. + * @param obj pointer to an object + * @param style pointer to a style to add + * @param selector OR-ed value of parts and state to which the style should be added + * @example lv_obj_add_style(btn, &style_btn, 0); //Default button style + * @example lv_obj_add_style(btn, &btn_red, LV_STATE_PRESSED); //Overwrite only some colors to red when pressed + */ +void lv_obj_add_style(struct _lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector); + +/** + * Add a style to an object. + * @param obj pointer to an object + * @param style pointer to a style to remove. Can be NULL to check only the selector + * @param selector OR-ed values of states and a part to remove only styles with matching selectors. LV_STATE_ANY and LV_PART_ANY can be used + * @example lv_obj_remove_style(obj, &style, LV_PART_ANY | LV_STATE_ANY); //Remove a specific style + * @example lv_obj_remove_style(obj, NULL, LV_PART_MAIN | LV_STATE_ANY); //Remove all styles from the main part + * @example lv_obj_remove_style(obj, NULL, LV_PART_ANY | LV_STATE_ANY); //Remove all styles + */ +void lv_obj_remove_style(struct _lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector); + +/** + * Remove all styles from an object + * @param obj pointer to an object + */ +static inline void lv_obj_remove_style_all(struct _lv_obj_t * obj) +{ + lv_obj_remove_style(obj, NULL, LV_PART_ANY | LV_STATE_ANY); +} + +/** + * Notify all object if a style is modified + * @param style pointer to a style. Only the objects with this style will be notified + * (NULL to notify all objects) + */ +void lv_obj_report_style_change(lv_style_t * style); + +/** + * Notify an object and its children about its style is modified. + * @param obj pointer to an object + * @param part the part whose style was changed. E.g. `LV_PART_ANY`, `LV_PART_MAIN` + * @param prop `LV_STYLE_PROP_ANY` or an `LV_STYLE_...` property. + * It is used to optimize what needs to be refreshed. + * `LV_STYLE_PROP_INV` to perform only a style cache update + */ +void lv_obj_refresh_style(struct _lv_obj_t * obj, lv_part_t part, lv_style_prop_t prop); + +/** + * Enable or disable automatic style refreshing when a new style is added/removed to/from an object + * or any other style change happens. + * @param en true: enable refreshing; false: disable refreshing + */ +void lv_obj_enable_style_refresh(bool en); + +/** + * Get the value of a style property. The current state of the object will be considered. + * Inherited properties will be inherited. + * If a property is not set a default value will be returned. + * @param obj pointer to an object + * @param part a part from which the property should be get + * @param prop the property to get + * @return the value of the property. + * Should be read from the correct field of the `lv_style_value_t` according to the type of the property. + */ +lv_style_value_t lv_obj_get_style_prop(const struct _lv_obj_t * obj, lv_part_t part, lv_style_prop_t prop); + +/** + * Set local style property on an object's part and state. + * @param obj pointer to an object + * @param prop the property + * @param value value of the property. The correct element should be set according to the type of the property + * @param selector OR-ed value of parts and state for which the style should be set + */ +void lv_obj_set_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t value, + lv_style_selector_t selector); + +void lv_obj_set_local_style_prop_meta(struct _lv_obj_t * obj, lv_style_prop_t prop, uint16_t meta, + lv_style_selector_t selector); + +lv_style_res_t lv_obj_get_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t * value, + lv_style_selector_t selector); + +/** + * Remove a local style property from a part of an object with a given state. + * @param obj pointer to an object + * @param prop a style property to remove. + * @param selector OR-ed value of parts and state for which the style should be removed + * @return true the property was found and removed; false: the property was not found + */ +bool lv_obj_remove_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_selector_t selector); + +/** + * Used internally for color filtering + */ +lv_style_value_t _lv_obj_style_apply_color_filter(const struct _lv_obj_t * obj, uint32_t part, lv_style_value_t v); + +/** + * Used internally to create a style transition + * @param obj + * @param part + * @param prev_state + * @param new_state + * @param tr + */ +void _lv_obj_style_create_transition(struct _lv_obj_t * obj, lv_part_t part, lv_state_t prev_state, + lv_state_t new_state, const _lv_obj_style_transition_dsc_t * tr); + +/** + * Used internally to compare the appearance of an object in 2 states + * @param obj + * @param state1 + * @param state2 + * @return + */ +_lv_style_state_cmp_t _lv_obj_style_state_compare(struct _lv_obj_t * obj, lv_state_t state1, lv_state_t state2); + +/** + * Fade in an an object and all its children. + * @param obj the object to fade in + * @param time time of fade + * @param delay delay to start the animation + */ +void lv_obj_fade_in(struct _lv_obj_t * obj, uint32_t time, uint32_t delay); + +/** + * Fade out an an object and all its children. + * @param obj the object to fade out + * @param time time of fade + * @param delay delay to start the animation + */ +void lv_obj_fade_out(struct _lv_obj_t * obj, uint32_t time, uint32_t delay); + +lv_state_t lv_obj_style_get_selector_state(lv_style_selector_t selector); + +lv_part_t lv_obj_style_get_selector_part(lv_style_selector_t selector); + +#include "lv_obj_style_gen.h" + +static inline void lv_obj_set_style_pad_all(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_pad_left(obj, value, selector); + lv_obj_set_style_pad_right(obj, value, selector); + lv_obj_set_style_pad_top(obj, value, selector); + lv_obj_set_style_pad_bottom(obj, value, selector); +} + +static inline void lv_obj_set_style_pad_hor(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_pad_left(obj, value, selector); + lv_obj_set_style_pad_right(obj, value, selector); +} + +static inline void lv_obj_set_style_pad_ver(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_pad_top(obj, value, selector); + lv_obj_set_style_pad_bottom(obj, value, selector); +} + +static inline void lv_obj_set_style_pad_gap(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_pad_row(obj, value, selector); + lv_obj_set_style_pad_column(obj, value, selector); +} + +static inline void lv_obj_set_style_size(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ + lv_obj_set_style_width(obj, value, selector); + lv_obj_set_style_height(obj, value, selector); +} + +lv_text_align_t lv_obj_calculate_style_text_align(const struct _lv_obj_t * obj, lv_part_t part, const char * txt); + + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_STYLE_H*/ diff --git a/include/liblvgl/core/lv_obj_style_gen.h b/include/liblvgl/core/lv_obj_style_gen.h new file mode 100644 index 00000000..576927d9 --- /dev/null +++ b/include/liblvgl/core/lv_obj_style_gen.h @@ -0,0 +1,648 @@ +static inline lv_coord_t lv_obj_get_style_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_min_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_MIN_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_max_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_MAX_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_min_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_MIN_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_max_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_MAX_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_Y); + return (lv_coord_t)v.num; +} + +static inline lv_align_t lv_obj_get_style_align(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ALIGN); + return (lv_align_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_height(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_HEIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_translate_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_translate_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSLATE_Y); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_zoom(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_ZOOM); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_angle(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_ANGLE); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_pivot_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_PIVOT_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_transform_pivot_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSFORM_PIVOT_Y); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_top(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_TOP); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_bottom(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_BOTTOM); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_left(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_LEFT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_right(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_RIGHT); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_row(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_ROW); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_pad_column(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_PAD_COLUMN); + return (lv_coord_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_bg_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_bg_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_BG_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_bg_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_bg_grad_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_bg_grad_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD_COLOR)); + return v.color; +} + +static inline lv_grad_dir_t lv_obj_get_style_bg_grad_dir(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD_DIR); + return (lv_grad_dir_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_bg_main_stop(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_MAIN_STOP); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_bg_grad_stop(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD_STOP); + return (lv_coord_t)v.num; +} + +static inline const lv_grad_dsc_t * lv_obj_get_style_bg_grad(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_GRAD); + return (const lv_grad_dsc_t *)v.ptr; +} + +static inline lv_dither_mode_t lv_obj_get_style_bg_dither_mode(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_DITHER_MODE); + return (lv_dither_mode_t)v.num; +} + +static inline const void * lv_obj_get_style_bg_img_src(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_SRC); + return (const void *)v.ptr; +} + +static inline lv_opa_t lv_obj_get_style_bg_img_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_bg_img_recolor(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_RECOLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_bg_img_recolor_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_RECOLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_bg_img_recolor_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_RECOLOR_OPA); + return (lv_opa_t)v.num; +} + +static inline bool lv_obj_get_style_bg_img_tiled(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_IMG_TILED); + return (bool)v.num; +} + +static inline lv_color_t lv_obj_get_style_border_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_border_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_border_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_border_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_border_side_t lv_obj_get_style_border_side(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_SIDE); + return (lv_border_side_t)v.num; +} + +static inline bool lv_obj_get_style_border_post(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BORDER_POST); + return (bool)v.num; +} + +static inline lv_coord_t lv_obj_get_style_outline_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_outline_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_outline_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_outline_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_outline_pad(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OUTLINE_PAD); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_shadow_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_shadow_ofs_x(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_OFS_X); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_shadow_ofs_y(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_OFS_Y); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_shadow_spread(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_SPREAD); + return (lv_coord_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_shadow_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_shadow_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_shadow_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_SHADOW_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_opa_t lv_obj_get_style_img_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_IMG_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_color_t lv_obj_get_style_img_recolor(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_IMG_RECOLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_img_recolor_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_IMG_RECOLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_img_recolor_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_IMG_RECOLOR_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_line_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_line_dash_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_DASH_WIDTH); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_line_dash_gap(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_DASH_GAP); + return (lv_coord_t)v.num; +} + +static inline bool lv_obj_get_style_line_rounded(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_ROUNDED); + return (bool)v.num; +} + +static inline lv_color_t lv_obj_get_style_line_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_line_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_line_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_OPA); + return (lv_opa_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_arc_width(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_WIDTH); + return (lv_coord_t)v.num; +} + +static inline bool lv_obj_get_style_arc_rounded(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_ROUNDED); + return (bool)v.num; +} + +static inline lv_color_t lv_obj_get_style_arc_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_arc_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_arc_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_OPA); + return (lv_opa_t)v.num; +} + +static inline const void * lv_obj_get_style_arc_img_src(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_IMG_SRC); + return (const void *)v.ptr; +} + +static inline lv_color_t lv_obj_get_style_text_color(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_COLOR); + return v.color; +} + +static inline lv_color_t lv_obj_get_style_text_color_filtered(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = _lv_obj_style_apply_color_filter(obj, part, lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_COLOR)); + return v.color; +} + +static inline lv_opa_t lv_obj_get_style_text_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_OPA); + return (lv_opa_t)v.num; +} + +static inline const lv_font_t * lv_obj_get_style_text_font(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_FONT); + return (const lv_font_t *)v.ptr; +} + +static inline lv_coord_t lv_obj_get_style_text_letter_space(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_LETTER_SPACE); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_text_line_space(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_LINE_SPACE); + return (lv_coord_t)v.num; +} + +static inline lv_text_decor_t lv_obj_get_style_text_decor(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_DECOR); + return (lv_text_decor_t)v.num; +} + +static inline lv_text_align_t lv_obj_get_style_text_align(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TEXT_ALIGN); + return (lv_text_align_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_radius(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_RADIUS); + return (lv_coord_t)v.num; +} + +static inline bool lv_obj_get_style_clip_corner(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CLIP_CORNER); + return (bool)v.num; +} + +static inline lv_opa_t lv_obj_get_style_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_OPA); + return (lv_opa_t)v.num; +} + +static inline const lv_color_filter_dsc_t * lv_obj_get_style_color_filter_dsc(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_COLOR_FILTER_DSC); + return (const lv_color_filter_dsc_t *)v.ptr; +} + +static inline lv_opa_t lv_obj_get_style_color_filter_opa(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_COLOR_FILTER_OPA); + return (lv_opa_t)v.num; +} + +static inline const lv_anim_t * lv_obj_get_style_anim(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ANIM); + return (const lv_anim_t *)v.ptr; +} + +static inline uint32_t lv_obj_get_style_anim_time(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ANIM_TIME); + return (uint32_t)v.num; +} + +static inline uint32_t lv_obj_get_style_anim_speed(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ANIM_SPEED); + return (uint32_t)v.num; +} + +static inline const lv_style_transition_dsc_t * lv_obj_get_style_transition(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_TRANSITION); + return (const lv_style_transition_dsc_t *)v.ptr; +} + +static inline lv_blend_mode_t lv_obj_get_style_blend_mode(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BLEND_MODE); + return (lv_blend_mode_t)v.num; +} + +static inline uint16_t lv_obj_get_style_layout(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LAYOUT); + return (uint16_t)v.num; +} + +static inline lv_base_dir_t lv_obj_get_style_base_dir(const struct _lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BASE_DIR); + return (lv_base_dir_t)v.num; +} + +void lv_obj_set_style_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_min_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_max_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_min_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_max_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_align(struct _lv_obj_t * obj, lv_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_height(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_translate_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_translate_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_zoom(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_angle(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_pivot_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_transform_pivot_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_top(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_bottom(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_left(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_right(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_row(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_pad_column(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_grad_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_grad_dir(struct _lv_obj_t * obj, lv_grad_dir_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_main_stop(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_grad_stop(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_grad(struct _lv_obj_t * obj, const lv_grad_dsc_t * value, lv_style_selector_t selector); +void lv_obj_set_style_bg_dither_mode(struct _lv_obj_t * obj, lv_dither_mode_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_src(struct _lv_obj_t * obj, const void * value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_recolor(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_recolor_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_bg_img_tiled(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_border_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_border_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_border_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_border_side(struct _lv_obj_t * obj, lv_border_side_t value, lv_style_selector_t selector); +void lv_obj_set_style_border_post(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_outline_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_outline_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_outline_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_outline_pad(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_ofs_x(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_ofs_y(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_spread(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_shadow_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_img_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_img_recolor(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_img_recolor_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_dash_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_dash_gap(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_rounded(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_line_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_line_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_arc_width(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_arc_rounded(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_arc_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_arc_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_arc_img_src(struct _lv_obj_t * obj, const void * value, lv_style_selector_t selector); +void lv_obj_set_style_text_color(struct _lv_obj_t * obj, lv_color_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_font(struct _lv_obj_t * obj, const lv_font_t * value, lv_style_selector_t selector); +void lv_obj_set_style_text_letter_space(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_line_space(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_decor(struct _lv_obj_t * obj, lv_text_decor_t value, lv_style_selector_t selector); +void lv_obj_set_style_text_align(struct _lv_obj_t * obj, lv_text_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_radius(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_clip_corner(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); +void lv_obj_set_style_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value, lv_style_selector_t selector); +void lv_obj_set_style_color_filter_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); +void lv_obj_set_style_anim(struct _lv_obj_t * obj, const lv_anim_t * value, lv_style_selector_t selector); +void lv_obj_set_style_anim_time(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector); +void lv_obj_set_style_anim_speed(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector); +void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, lv_style_selector_t selector); +void lv_obj_set_style_blend_mode(struct _lv_obj_t * obj, lv_blend_mode_t value, lv_style_selector_t selector); +void lv_obj_set_style_layout(struct _lv_obj_t * obj, uint16_t value, lv_style_selector_t selector); +void lv_obj_set_style_base_dir(struct _lv_obj_t * obj, lv_base_dir_t value, lv_style_selector_t selector); diff --git a/include/liblvgl/core/lv_obj_tree.h b/include/liblvgl/core/lv_obj_tree.h new file mode 100644 index 00000000..bee9e160 --- /dev/null +++ b/include/liblvgl/core/lv_obj_tree.h @@ -0,0 +1,172 @@ +/** + * @file struct _lv_obj_tree.h + * + */ + +#ifndef LV_OBJ_TREE_H +#define LV_OBJ_TREE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include + +/********************* + * DEFINES + *********************/ + + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_obj_class_t; + +typedef enum { + LV_OBJ_TREE_WALK_NEXT, + LV_OBJ_TREE_WALK_SKIP_CHILDREN, + LV_OBJ_TREE_WALK_END, +} lv_obj_tree_walk_res_t; + +typedef lv_obj_tree_walk_res_t (*lv_obj_tree_walk_cb_t)(struct _lv_obj_t *, void *); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Delete an object and all of its children. + * Also remove the objects from their group and remove all animations (if any). + * Send `LV_EVENT_DELETED` to deleted objects. + * @param obj pointer to an object + */ +void lv_obj_del(struct _lv_obj_t * obj); + +/** + * Delete all children of an object. + * Also remove the objects from their group and remove all animations (if any). + * Send `LV_EVENT_DELETED` to deleted objects. + * @param obj pointer to an object + */ +void lv_obj_clean(struct _lv_obj_t * obj); + +/** + * Delete an object after some delay + * @param obj pointer to an object + * @param delay_ms time to wait before delete in milliseconds + */ +void lv_obj_del_delayed(struct _lv_obj_t * obj, uint32_t delay_ms); + +/** + * A function to be easily used in animation ready callback to delete an object when the animation is ready + * @param a pointer to the animation + */ +void lv_obj_del_anim_ready_cb(lv_anim_t * a); + +/** + * Helper function for asynchronously deleting objects. + * Useful for cases where you can't delete an object directly in an `LV_EVENT_DELETE` handler (i.e. parent). + * @param obj object to delete + * @see lv_async_call + */ +void lv_obj_del_async(struct _lv_obj_t * obj); + +/** + * Move the parent of an object. The relative coordinates will be kept. + * + * @param obj pointer to an object whose parent needs to be changed + * @param parent pointer to the new parent + */ +void lv_obj_set_parent(struct _lv_obj_t * obj, struct _lv_obj_t * parent); + +/** + * Swap the positions of two objects. + * When used in listboxes, it can be used to sort the listbox items. + * @param obj1 pointer to the first object + * @param obj2 pointer to the second object + */ +void lv_obj_swap(struct _lv_obj_t * obj1, struct _lv_obj_t * obj2); + +/** + * moves the object to the given index in its parent. + * When used in listboxes, it can be used to sort the listbox items. + * @param obj pointer to the object to be moved. + * @param index new index in parent. -1 to count from the back + * @note to move to the background: lv_obj_move_to_index(obj, 0) + * @note to move forward (up): lv_obj_move_to_index(obj, lv_obj_get_index(obj) - 1) + */ +void lv_obj_move_to_index(struct _lv_obj_t * obj, int32_t index); + +/** + * Get the screen of an object + * @param obj pointer to an object + * @return pointer to the object's screen + */ +struct _lv_obj_t * lv_obj_get_screen(const struct _lv_obj_t * obj); + +/** + * Get the display of the object + * @param obj pointer to an object + * @return pointer to the object's display + */ +lv_disp_t * lv_obj_get_disp(const struct _lv_obj_t * obj); + +/** + * Get the parent of an object + * @param obj pointer to an object + * @return the parent of the object. (NULL if `obj` was a screen) + */ +struct _lv_obj_t * lv_obj_get_parent(const struct _lv_obj_t * obj); + +/** + * Get the child of an object by the child's index. + * @param obj pointer to an object whose child should be get + * @param id the index of the child. + * 0: the oldest (firstly created) child + * 1: the second oldest + * child count-1: the youngest + * -1: the youngest + * -2: the second youngest + * @return pointer to the child or NULL if the index was invalid + */ +struct _lv_obj_t * lv_obj_get_child(const struct _lv_obj_t * obj, int32_t id); + +/** + * Get the number of children + * @param obj pointer to an object + * @return the number of children + */ +uint32_t lv_obj_get_child_cnt(const struct _lv_obj_t * obj); + +/** + * Get the index of a child. + * @param obj pointer to an object + * @return the child index of the object. + * E.g. 0: the oldest (firstly created child) + */ +uint32_t lv_obj_get_index(const struct _lv_obj_t * obj); + +/** + * Iterate through all children of any object. + * @param start_obj start integrating from this object + * @param cb call this callback on the objects + * @param user_data pointer to any user related data (will be passed to `cb`) + */ +void lv_obj_tree_walk(struct _lv_obj_t * start_obj, lv_obj_tree_walk_cb_t cb, void * user_data); + +/********************** + * MACROS + **********************/ + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OBJ_TREE_H*/ diff --git a/include/liblvgl/core/lv_refr.h b/include/liblvgl/core/lv_refr.h new file mode 100644 index 00000000..72e8d6c3 --- /dev/null +++ b/include/liblvgl/core/lv_refr.h @@ -0,0 +1,115 @@ +/** + * @file lv_refr.h + * + */ + +#ifndef LV_REFR_H +#define LV_REFR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_obj.h" +#include + +/********************* + * DEFINES + *********************/ + +#define LV_REFR_TASK_PRIO LV_TASK_PRIO_MID + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Initialize the screen refresh subsystem + */ +void _lv_refr_init(void); + +/** + * Redraw the invalidated areas now. + * Normally the redrawing is periodically executed in `lv_timer_handler` but a long blocking process + * can prevent the call of `lv_timer_handler`. In this case if the GUI is updated in the process + * (e.g. progress bar) this function can be called when the screen should be updated. + * @param disp pointer to display to refresh. NULL to refresh all displays. + */ +void lv_refr_now(lv_disp_t * disp); + +/** + * Redrawn on object an all its children using the passed draw context + * @param draw pointer to an initialized draw context + * @param obj the start object from the redraw should start + */ +void lv_obj_redraw(lv_draw_ctx_t * draw_ctx, lv_obj_t * obj); + +/** + * Invalidate an area on display to redraw it + * @param area_p pointer to area which should be invalidated (NULL: delete the invalidated areas) + * @param disp pointer to display where the area should be invalidated (NULL can be used if there is + * only one display) + */ +void _lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p); + +/** + * Get the display which is being refreshed + * @return the display being refreshed + */ +lv_disp_t * _lv_refr_get_disp_refreshing(void); + +/** + * Set the display which is being refreshed. + * It shouldn't be used directly by the user. + * It can be used to trick the drawing functions about there is an active display. + * @param the display being refreshed + */ +void _lv_refr_set_disp_refreshing(lv_disp_t * disp); + +#if LV_USE_PERF_MONITOR +/** + * Reset FPS counter + */ +void lv_refr_reset_fps_counter(void); + +/** + * Get the average FPS + * @return the average FPS + */ +uint32_t lv_refr_get_fps_avg(void); +#endif + +/** + * Called periodically to handle the refreshing + * @param timer pointer to the timer itself + */ +void _lv_disp_refr_timer(lv_timer_t * timer); + +/********************** + * STATIC FUNCTIONS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_REFR_H*/ diff --git a/include/liblvgl/core/lv_theme.h b/include/liblvgl/core/lv_theme.h new file mode 100644 index 00000000..80da522c --- /dev/null +++ b/include/liblvgl/core/lv_theme.h @@ -0,0 +1,120 @@ +/** + *@file lv_theme.h + * + */ + +#ifndef LV_THEME_H +#define LV_THEME_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_theme_t; +struct _lv_disp_t; + +typedef void (*lv_theme_apply_cb_t)(struct _lv_theme_t *, lv_obj_t *); + +typedef struct _lv_theme_t { + lv_theme_apply_cb_t apply_cb; + struct _lv_theme_t * parent; /**< Apply the current theme's style on top of this theme.*/ + void * user_data; + struct _lv_disp_t * disp; + lv_color_t color_primary; + lv_color_t color_secondary; + const lv_font_t * font_small; + const lv_font_t * font_normal; + const lv_font_t * font_large; + uint32_t flags; /*Any custom flag used by the theme*/ +} lv_theme_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Get the theme assigned to the display of the object + * @param obj pointer to a theme object + * @return the theme of the object's display (can be NULL) + */ +lv_theme_t * lv_theme_get_from_obj(lv_obj_t * obj); + +/** + * Apply the active theme on an object + * @param obj pointer to an object + */ +void lv_theme_apply(lv_obj_t * obj); + +/** + * Set a base theme for a theme. + * The styles from the base them will be added before the styles of the current theme. + * Arbitrary long chain of themes can be created by setting base themes. + * @param new_theme pointer to theme which base should be set + * @param parent pointer to the base theme + */ +void lv_theme_set_parent(lv_theme_t * new_theme, lv_theme_t * parent); + +/** + * Set an apply callback for a theme. + * The apply callback is used to add styles to different objects + * @param theme pointer to theme which callback should be set + * @param apply_cb pointer to the callback + */ +void lv_theme_set_apply_cb(lv_theme_t * theme, lv_theme_apply_cb_t apply_cb); + +/** + * Get the small font of the theme + * @param obj pointer to an object + * @return pointer to the font + */ +const lv_font_t * lv_theme_get_font_small(lv_obj_t * obj); +/** + * Get the normal font of the theme + * @param obj pointer to an object + * @return pointer to the font + */ +const lv_font_t * lv_theme_get_font_normal(lv_obj_t * obj); + +/** + * Get the subtitle font of the theme + * @param obj pointer to an object + * @return pointer to the font + */ +const lv_font_t * lv_theme_get_font_large(lv_obj_t * obj); + +/** + * Get the primary color of the theme + * @param obj pointer to an object + * @return the color + */ +lv_color_t lv_theme_get_color_primary(lv_obj_t * obj); + +/** + * Get the secondary color of the theme + * @param obj pointer to an object + * @return the color + */ +lv_color_t lv_theme_get_color_secondary(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_THEME_H*/ diff --git a/include/liblvgl/draw/arm2d/lv_gpu_arm2d.h b/include/liblvgl/draw/arm2d/lv_gpu_arm2d.h new file mode 100644 index 00000000..cc669901 --- /dev/null +++ b/include/liblvgl/draw/arm2d/lv_gpu_arm2d.h @@ -0,0 +1,51 @@ +/** + * @file lv_gpu_arm2d.h + * + */ + +#ifndef LV_GPU_ARM2D_H +#define LV_GPU_ARM2D_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/hal/lv_hal_disp.h" +#include "liblvgl/draw/sw/lv_draw_sw.h" + +#if LV_USE_GPU_ARM2D + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef lv_draw_sw_ctx_t lv_draw_arm2d_ctx_t; + +struct _lv_disp_drv_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_arm2d_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_arm2d_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_ARM2D*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_ARM2D_H*/ diff --git a/include/liblvgl/draw/lv_draw.h b/include/liblvgl/draw/lv_draw.h new file mode 100644 index 00000000..c8aed722 --- /dev/null +++ b/include/liblvgl/draw/lv_draw.h @@ -0,0 +1,218 @@ +/** + * @file lv_draw.h + * + */ + +#ifndef LV_DRAW_H +#define LV_DRAW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include "liblvgl/misc/lv_style.h" +#include "liblvgl/misc/lv_txt.h" +#include "lv_img_decoder.h" +#include "lv_img_cache.h" + +#include "lv_draw_rect.h" +#include "lv_draw_label.h" +#include "lv_draw_img.h" +#include "lv_draw_line.h" +#include "lv_draw_triangle.h" +#include "lv_draw_arc.h" +#include "lv_draw_mask.h" +#include "lv_draw_transform.h" +#include "lv_draw_layer.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + void * user_data; +} lv_draw_mask_t; + +typedef struct _lv_draw_layer_ctx_t { + lv_area_t area_full; + lv_area_t area_act; + lv_coord_t max_row_with_alpha; + lv_coord_t max_row_with_no_alpha; + void * buf; + struct { + const lv_area_t * clip_area; + lv_area_t * buf_area; + void * buf; + bool screen_transp; + } original; +} lv_draw_layer_ctx_t; + +typedef struct _lv_draw_ctx_t { + /** + * Pointer to a buffer to draw into + */ + void * buf; + + /** + * The position and size of `buf` (absolute coordinates) + */ + lv_area_t * buf_area; + + /** + * The current clip area with absolute coordinates, always the same or smaller than `buf_area` + */ + const lv_area_t * clip_area; + + + void (*draw_rect)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); + + void (*draw_arc)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, + uint16_t radius, uint16_t start_angle, uint16_t end_angle); + + void (*draw_img_decoded)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc, + const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t color_format); + + lv_res_t (*draw_img)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * draw_dsc, + const lv_area_t * coords, const void * src); + + void (*draw_letter)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p, + uint32_t letter); + + + void (*draw_line)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1, + const lv_point_t * point2); + + + void (*draw_polygon)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, + const lv_point_t * points, uint16_t point_cnt); + + + /** + * Get an area of a transformed image (zoomed and/or rotated) + * @param draw_ctx pointer to a draw context + * @param dest_area get this area of the result image. It assumes that the original image is placed to the 0;0 position. + * @param src_buf the source image + * @param src_w width of the source image in [px] + * @param src_h height of the source image in [px] + * @param src_stride the stride in [px]. + * @param draw_dsc an `lv_draw_img_dsc_t` descriptor containing the transformation parameters + * @param cf the color format of `src_buf` + * @param cbuf place the colors of the pixels on `dest_area` here in RGB format + * @param abuf place the opacity of the pixels on `dest_area` here + */ + void (*draw_transform)(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf, + lv_coord_t src_w, lv_coord_t src_h, lv_coord_t src_stride, + const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf); + + /** + * Replace the buffer with a rect without decoration like radius or borders + */ + void (*draw_bg)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_area_t * coords); + + /** + * Wait until all background operations are finished. (E.g. GPU operations) + */ + void (*wait_for_finish)(struct _lv_draw_ctx_t * draw_ctx); + + /** + * Copy an area from buffer to an other + * @param draw_ctx pointer to a draw context + * @param dest_buf copy the buffer into this buffer + * @param dest_stride the width of the dest_buf in pixels + * @param dest_area the destination area + * @param src_buf copy from this buffer + * @param src_stride the width of src_buf in pixels + * @param src_area the source area. + * + * @note dest_area and src_area must have the same width and height + * but can have different x and y position. + * @note dest_area and src_area must be clipped to the real dimensions of the buffers + */ + void (*buffer_copy)(struct _lv_draw_ctx_t * draw_ctx, void * dest_buf, lv_coord_t dest_stride, + const lv_area_t * dest_area, + void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area); + + /** + * Initialize a new layer context. + * The original buffer and area data are already saved from `draw_ctx` to `layer_ctx` + * @param draw_ctx pointer to the current draw context + * @param layer_area the coordinates of the layer + * @param flags OR-ed flags from @lv_draw_layer_flags_t + * @return pointer to the layer context, or NULL on error + */ + struct _lv_draw_layer_ctx_t * (*layer_init)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + + /** + * Adjust the layer_ctx and/or draw_ctx based on the `layer_ctx->area_act`. + * It's called only if flags has `LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE` + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + * @param flags OR-ed flags from @lv_draw_layer_flags_t + */ + void (*layer_adjust)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + + /** + * Blend a rendered layer to `layer_ctx->area_act` + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + * @param draw_dsc pointer to an image draw descriptor + */ + void (*layer_blend)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + const lv_draw_img_dsc_t * draw_dsc); + + /** + * Destroy a layer context. The original buffer and area data of the `draw_ctx` will be restored + * and the `layer_ctx` itself will be freed automatically. + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + */ + void (*layer_destroy)(struct _lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx); + + /** + * Size of a layer context in bytes. + */ + size_t layer_instance_size; + +#if LV_USE_USER_DATA + void * user_data; +#endif + +} lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_init(void); + + +void lv_draw_wait_for_finish(lv_draw_ctx_t * draw_ctx); + +/********************** + * GLOBAL VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * POST INCLUDES + *********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_H*/ diff --git a/include/liblvgl/draw/lv_draw_arc.h b/include/liblvgl/draw/lv_draw_arc.h new file mode 100644 index 00000000..8633af5f --- /dev/null +++ b/include/liblvgl/draw/lv_draw_arc.h @@ -0,0 +1,83 @@ +/** + * @file lv_draw_arc.h + * + */ + +#ifndef LV_DRAW_ARC_H +#define LV_DRAW_ARC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_style.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_color_t color; + lv_coord_t width; + uint16_t start_angle; + uint16_t end_angle; + const void * img_src; + lv_opa_t opa; + lv_blend_mode_t blend_mode : 2; + uint8_t rounded : 1; +} lv_draw_arc_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_arc_dsc_init(lv_draw_arc_dsc_t * dsc); + +/** + * Draw an arc. (Can draw pie too with great thickness.) + * @param center_x the x coordinate of the center of the arc + * @param center_y the y coordinate of the center of the arc + * @param radius the radius of the arc + * @param mask the arc will be drawn only in this mask + * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) + * @param end_angle the end angle of the arc + * @param clip_area the arc will be drawn only in this area + * @param dsc pointer to an initialized `lv_draw_line_dsc_t` variable + */ +void lv_draw_arc(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, + uint16_t radius, uint16_t start_angle, uint16_t end_angle); + +/** + * Get an area the should be invalidated when the arcs angle changed between start_angle and end_ange + * @param x the x coordinate of the center of the arc + * @param y the y coordinate of the center of the arc + * @param radius the radius of the arc + * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) + * @param end_angle the end angle of the arc + * @param w width of the arc + * @param rounded true: the arc is rounded + * @param area store the area to invalidate here + */ +void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, + lv_coord_t w, bool rounded, lv_area_t * area); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_ARC_H*/ diff --git a/include/liblvgl/draw/lv_draw_img.h b/include/liblvgl/draw/lv_draw_img.h new file mode 100644 index 00000000..dcb71136 --- /dev/null +++ b/include/liblvgl/draw/lv_draw_img.h @@ -0,0 +1,104 @@ +/** + * @file lv_draw_img.h + * + */ + +#ifndef LV_DRAW_IMG_H +#define LV_DRAW_IMG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_img_decoder.h" +#include "lv_img_buf.h" +#include "liblvgl/misc/lv_style.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + + int16_t angle; + uint16_t zoom; + lv_point_t pivot; + + lv_color_t recolor; + lv_opa_t recolor_opa; + + lv_opa_t opa; + lv_blend_mode_t blend_mode : 4; + + int32_t frame_id; + uint8_t antialias : 1; +} lv_draw_img_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_img_dsc_init(lv_draw_img_dsc_t * dsc); +/** + * Draw an image + * @param coords the coordinates of the image + * @param mask the image will be drawn only in this area + * @param src pointer to a lv_color_t array which contains the pixels of the image + * @param dsc pointer to an initialized `lv_draw_img_dsc_t` variable + */ +void lv_draw_img(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc, const lv_area_t * coords, + const void * src); + + +void lv_draw_img_decoded(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc, + const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t color_format); + +/** + * Get the type of an image source + * @param src pointer to an image source: + * - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code) + * - a path to a file (e.g. "S:/folder/image.bin") + * - or a symbol (e.g. LV_SYMBOL_CLOSE) + * @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKNOWN + */ +lv_img_src_t lv_img_src_get_type(const void * src); + +/** + * Get the pixel size of a color format in bits + * @param cf a color format (`LV_IMG_CF_...`) + * @return the pixel size in bits + */ +uint8_t lv_img_cf_get_px_size(lv_img_cf_t cf); + +/** + * Check if a color format is chroma keyed or not + * @param cf a color format (`LV_IMG_CF_...`) + * @return true: chroma keyed; false: not chroma keyed + */ +bool lv_img_cf_is_chroma_keyed(lv_img_cf_t cf); + +/** + * Check if a color format has alpha channel or not + * @param cf a color format (`LV_IMG_CF_...`) + * @return true: has alpha channel; false: doesn't have alpha channel + */ +bool lv_img_cf_has_alpha(lv_img_cf_t cf); + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_IMG_H*/ diff --git a/include/liblvgl/draw/lv_draw_label.h b/include/liblvgl/draw/lv_draw_label.h new file mode 100644 index 00000000..736aa728 --- /dev/null +++ b/include/liblvgl/draw/lv_draw_label.h @@ -0,0 +1,100 @@ +/** + * @file lv_draw_label.h + * + */ + +#ifndef LV_DRAW_LABEL_H +#define LV_DRAW_LABEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_bidi.h" +#include "liblvgl/misc/lv_txt.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_style.h" + +/********************* + * DEFINES + *********************/ +#define LV_DRAW_LABEL_NO_TXT_SEL (0xFFFF) + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + const lv_font_t * font; + uint32_t sel_start; + uint32_t sel_end; + lv_color_t color; + lv_color_t sel_color; + lv_color_t sel_bg_color; + lv_coord_t line_space; + lv_coord_t letter_space; + lv_coord_t ofs_x; + lv_coord_t ofs_y; + lv_opa_t opa; + lv_base_dir_t bidi_dir; + lv_text_align_t align; + lv_text_flag_t flag; + lv_text_decor_t decor : 3; + lv_blend_mode_t blend_mode: 3; +} lv_draw_label_dsc_t; + +/** Store some info to speed up drawing of very large texts + * It takes a lot of time to get the first visible character because + * all the previous characters needs to be checked to calculate the positions. + * This structure stores an earlier (e.g. at -1000 px) coordinate and the index of that line. + * Therefore the calculations can start from here.*/ +typedef struct _lv_draw_label_hint_t { + /** Index of the line at `y` coordinate*/ + int32_t line_start; + + /** Give the `y` coordinate of the first letter at `line start` index. Relative to the label's coordinates*/ + int32_t y; + + /** The 'y1' coordinate of the label when the hint was saved. + * Used to invalidate the hint if the label has moved too much.*/ + int32_t coord_y; +} lv_draw_label_hint_t; + +struct _lv_draw_ctx_t; +/********************** + * GLOBAL PROTOTYPES + **********************/ + +LV_ATTRIBUTE_FAST_MEM void lv_draw_label_dsc_init(lv_draw_label_dsc_t * dsc); + +/** + * Write a text + * @param coords coordinates of the label + * @param mask the label will be drawn only in this area + * @param dsc pointer to draw descriptor + * @param txt `\0` terminated text to write + * @param hint pointer to a `lv_draw_label_hint_t` variable. + * It is managed by the draw to speed up the drawing of very long texts (thousands of lines). + */ +LV_ATTRIBUTE_FAST_MEM void lv_draw_label(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, + const lv_area_t * coords, const char * txt, lv_draw_label_hint_t * hint); + +void lv_draw_letter(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p, + uint32_t letter); + +/*********************** + * GLOBAL VARIABLES + ***********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_LABEL_H*/ diff --git a/include/liblvgl/draw/lv_draw_layer.h b/include/liblvgl/draw/lv_draw_layer.h new file mode 100644 index 00000000..1280d33a --- /dev/null +++ b/include/liblvgl/draw/lv_draw_layer.h @@ -0,0 +1,83 @@ +/** + * @file lv_draw_layer.h + * + */ + +#ifndef LV_DRAW_LAYER_H +#define LV_DRAW_LAYER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct _lv_draw_ctx_t; +struct _lv_draw_layer_ctx_t; + +typedef enum { + LV_DRAW_LAYER_FLAG_NONE, + LV_DRAW_LAYER_FLAG_HAS_ALPHA, + LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE, +} lv_draw_layer_flags_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a new layer context. It is used to start and independent rendering session + * with the current draw_ctx + * @param draw_ctx pointer to the current draw context + * @param layer_area the coordinates of the layer + * @param flags OR-ed flags from @lv_draw_layer_flags_t + * @return pointer to the layer context, or NULL on error + */ +struct _lv_draw_layer_ctx_t * lv_draw_layer_create(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * layer_area, + lv_draw_layer_flags_t flags); + +/** + * Adjust the layer_ctx and/or draw_ctx based on the `layer_ctx->area_act`. + * It's called only if flags has `LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE` + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + * @param flags OR-ed flags from @lv_draw_layer_flags_t + */ +void lv_draw_layer_adjust(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + +/** + * Blend a rendered layer to `layer_ctx->area_act` + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + * @param draw_dsc pointer to an image draw descriptor + */ +void lv_draw_layer_blend(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_img_dsc_t * draw_dsc); + +/** + * Destroy a layer context. + * @param draw_ctx pointer to the current draw context + * @param layer_ctx pointer to a layer context + */ +void lv_draw_layer_destroy(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_LAYER_H*/ diff --git a/include/liblvgl/draw/lv_draw_line.h b/include/liblvgl/draw/lv_draw_line.h new file mode 100644 index 00000000..79ca0dcf --- /dev/null +++ b/include/liblvgl/draw/lv_draw_line.h @@ -0,0 +1,67 @@ +/** + * @file lv_draw_line.h + * + */ + +#ifndef LV_DRAW_LINE_H +#define LV_DRAW_LINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_style.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_color_t color; + lv_coord_t width; + lv_coord_t dash_width; + lv_coord_t dash_gap; + lv_opa_t opa; + lv_blend_mode_t blend_mode : 2; + uint8_t round_start : 1; + uint8_t round_end : 1; + uint8_t raw_end : 1; /*Do not bother with perpendicular line ending if it's not visible for any reason*/ +} lv_draw_line_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +LV_ATTRIBUTE_FAST_MEM void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc); + +/** + * Draw a line + * @param point1 first point of the line + * @param point2 second point of the line + * @param clip the line will be drawn only in this area + * @param dsc pointer to an initialized `lv_draw_line_dsc_t` variable + */ +void lv_draw_line(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1, + const lv_point_t * point2); + + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_LINE_H*/ diff --git a/include/liblvgl/draw/lv_draw_mask.h b/include/liblvgl/draw/lv_draw_mask.h new file mode 100644 index 00000000..f3c49e5d --- /dev/null +++ b/include/liblvgl/draw/lv_draw_mask.h @@ -0,0 +1,394 @@ +/** + * @file lv_draw_mask.h + * + */ + +#ifndef LV_DRAW_MASK_H +#define LV_DRAW_MASK_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/********************* + * INCLUDES + *********************/ +#include +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_math.h" + +/********************* + * DEFINES + *********************/ +#define LV_MASK_ID_INV (-1) +#if LV_DRAW_COMPLEX +# define _LV_MASK_MAX_NUM 16 +#else +# define _LV_MASK_MAX_NUM 1 +#endif + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_DRAW_MASK_RES_TRANSP, + LV_DRAW_MASK_RES_FULL_COVER, + LV_DRAW_MASK_RES_CHANGED, + LV_DRAW_MASK_RES_UNKNOWN +}; + +typedef uint8_t lv_draw_mask_res_t; + +typedef struct { + void * param; + void * custom_id; +} _lv_draw_mask_saved_t; + +typedef _lv_draw_mask_saved_t _lv_draw_mask_saved_arr_t[_LV_MASK_MAX_NUM]; + + + +#if LV_DRAW_COMPLEX == 0 +static inline uint8_t lv_draw_mask_get_cnt(void) +{ + return 0; +} + +static inline bool lv_draw_mask_is_any(const lv_area_t * a) +{ + LV_UNUSED(a); + return false; +} + +#endif + +#if LV_DRAW_COMPLEX + +enum { + LV_DRAW_MASK_TYPE_LINE, + LV_DRAW_MASK_TYPE_ANGLE, + LV_DRAW_MASK_TYPE_RADIUS, + LV_DRAW_MASK_TYPE_FADE, + LV_DRAW_MASK_TYPE_MAP, + LV_DRAW_MASK_TYPE_POLYGON, +}; + +typedef uint8_t lv_draw_mask_type_t; + +enum { + LV_DRAW_MASK_LINE_SIDE_LEFT = 0, + LV_DRAW_MASK_LINE_SIDE_RIGHT, + LV_DRAW_MASK_LINE_SIDE_TOP, + LV_DRAW_MASK_LINE_SIDE_BOTTOM, +}; + +/** + * A common callback type for every mask type. + * Used internally by the library. + */ +typedef lv_draw_mask_res_t (*lv_draw_mask_xcb_t)(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, + lv_coord_t len, + void * p); + +typedef uint8_t lv_draw_mask_line_side_t; + +typedef struct { + lv_draw_mask_xcb_t cb; + lv_draw_mask_type_t type; +} _lv_draw_mask_common_dsc_t; + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + /*First point*/ + lv_point_t p1; + + /*Second point*/ + lv_point_t p2; + + /*Which side to keep?*/ + lv_draw_mask_line_side_t side : 2; + } cfg; + + /*A point of the line*/ + lv_point_t origo; + + /*X / (1024*Y) steepness (X is 0..1023 range). What is the change of X in 1024 Y?*/ + int32_t xy_steep; + + /*Y / (1024*X) steepness (Y is 0..1023 range). What is the change of Y in 1024 X?*/ + int32_t yx_steep; + + /*Helper which stores yx_steep for flat lines and xy_steep for steep (non flat) lines*/ + int32_t steep; + + /*Steepness in 1 px in 0..255 range. Used only by flat lines.*/ + int32_t spx; + + /*1: It's a flat line? (Near to horizontal)*/ + uint8_t flat : 1; + + /*Invert the mask. The default is: Keep the left part. + *It is used to select left/right/top/bottom*/ + uint8_t inv: 1; +} lv_draw_mask_line_param_t; + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_point_t vertex_p; + lv_coord_t start_angle; + lv_coord_t end_angle; + } cfg; + + lv_draw_mask_line_param_t start_line; + lv_draw_mask_line_param_t end_line; + uint16_t delta_deg; +} lv_draw_mask_angle_param_t; + +typedef struct { + uint8_t * buf; + lv_opa_t * cir_opa; /*Opacity of values on the circumference of an 1/4 circle*/ + uint16_t * x_start_on_y; /*The x coordinate of the circle for each y value*/ + uint16_t * opa_start_on_y; /*The index of `cir_opa` for each y value*/ + int32_t life; /*How many times the entry way used*/ + uint32_t used_cnt; /*Like a semaphore to count the referencing masks*/ + lv_coord_t radius; /*The radius of the entry*/ +} _lv_draw_mask_radius_circle_dsc_t; + +typedef _lv_draw_mask_radius_circle_dsc_t _lv_draw_mask_radius_circle_dsc_arr_t[LV_CIRCLE_CACHE_SIZE]; + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_area_t rect; + lv_coord_t radius; + /*Invert the mask. 0: Keep the pixels inside.*/ + uint8_t outer: 1; + } cfg; + + _lv_draw_mask_radius_circle_dsc_t * circle; +} lv_draw_mask_radius_param_t; + + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_area_t coords; + lv_coord_t y_top; + lv_coord_t y_bottom; + lv_opa_t opa_top; + lv_opa_t opa_bottom; + } cfg; + +} lv_draw_mask_fade_param_t; + + +typedef struct _lv_draw_mask_map_param_t { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_area_t coords; + const lv_opa_t * map; + } cfg; +} lv_draw_mask_map_param_t; + +typedef struct { + /*The first element must be the common descriptor*/ + _lv_draw_mask_common_dsc_t dsc; + + struct { + lv_point_t * points; + uint16_t point_cnt; + } cfg; +} lv_draw_mask_polygon_param_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Add a draw mask. Everything drawn after it (until removing the mask) will be affected by the mask. + * @param param an initialized mask parameter. Only the pointer is saved. + * @param custom_id a custom pointer to identify the mask. Used in `lv_draw_mask_remove_custom`. + * @return the an integer, the ID of the mask. Can be used in `lv_draw_mask_remove_id`. + */ +int16_t lv_draw_mask_add(void * param, void * custom_id); + +//! @cond Doxygen_Suppress + +/** + * Apply the added buffers on a line. Used internally by the library's drawing routines. + * @param mask_buf store the result mask here. Has to be `len` byte long. Should be initialized with `0xFF`. + * @param abs_x absolute X coordinate where the line to calculate start + * @param abs_y absolute Y coordinate where the line to calculate start + * @param len length of the line to calculate (in pixel count) + * @return One of these values: + * - `LV_DRAW_MASK_RES_FULL_TRANSP`: the whole line is transparent. `mask_buf` is not set to zero + * - `LV_DRAW_MASK_RES_FULL_COVER`: the whole line is fully visible. `mask_buf` is unchanged + * - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line + */ +LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, + lv_coord_t len); + +/** + * Apply the specified buffers on a line. Used internally by the library's drawing routines. + * @param mask_buf store the result mask here. Has to be `len` byte long. Should be initialized with `0xFF`. + * @param abs_x absolute X coordinate where the line to calculate start + * @param abs_y absolute Y coordinate where the line to calculate start + * @param len length of the line to calculate (in pixel count) + * @param ids ID array of added buffers + * @param ids_count number of ID array + * @return One of these values: + * - `LV_DRAW_MASK_RES_FULL_TRANSP`: the whole line is transparent. `mask_buf` is not set to zero + * - `LV_DRAW_MASK_RES_FULL_COVER`: the whole line is fully visible. `mask_buf` is unchanged + * - `LV_DRAW_MASK_RES_CHANGED`: `mask_buf` has changed, it shows the desired opacity of each pixel in the given line + */ +LV_ATTRIBUTE_FAST_MEM lv_draw_mask_res_t lv_draw_mask_apply_ids(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, + lv_coord_t len, const int16_t * ids, int16_t ids_count); + +//! @endcond + +/** + * Remove a mask with a given ID + * @param id the ID of the mask. Returned by `lv_draw_mask_add` + * @return the parameter of the removed mask. + * If more masks have `custom_id` ID then the last mask's parameter will be returned + */ +void * lv_draw_mask_remove_id(int16_t id); + +/** + * Remove all mask with a given custom ID + * @param custom_id a pointer used in `lv_draw_mask_add` + * @return return the parameter of the removed mask. + * If more masks have `custom_id` ID then the last mask's parameter will be returned + */ +void * lv_draw_mask_remove_custom(void * custom_id); + +/** + * Free the data from the parameter. + * It's called inside `lv_draw_mask_remove_id` and `lv_draw_mask_remove_custom` + * Needs to be called only in special cases when the mask is not added by `lv_draw_mask_add` + * and not removed by `lv_draw_mask_remove_id` or `lv_draw_mask_remove_custom` + * @param p pointer to a mask parameter + */ +void lv_draw_mask_free_param(void * p); + +/** + * Called by LVGL the rendering of a screen is ready to clean up + * the temporal (cache) data of the masks + */ +void _lv_draw_mask_cleanup(void); + +//! @cond Doxygen_Suppress + +/** + * Count the currently added masks + * @return number of active masks + */ +LV_ATTRIBUTE_FAST_MEM uint8_t lv_draw_mask_get_cnt(void); + + +/** + * Check if there is any added draw mask + * @param a an area to test for affecting masks. + * @return true: there is t least 1 draw mask; false: there are no draw masks + */ +bool lv_draw_mask_is_any(const lv_area_t * a); + +//! @endcond + +/** + *Initialize a line mask from two points. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param p1x X coordinate of the first point of the line + * @param p1y Y coordinate of the first point of the line + * @param p2x X coordinate of the second point of the line + * @param p2y y coordinate of the second point of the line + * @param side and element of `lv_draw_mask_line_side_t` to describe which side to keep. + * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept + * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept + */ +void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, + lv_coord_t p2y, lv_draw_mask_line_side_t side); + +/** + *Initialize a line mask from a point and an angle. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param px X coordinate of a point of the line + * @param py X coordinate of a point of the line + * @param angle right 0 deg, bottom: 90 + * @param side and element of `lv_draw_mask_line_side_t` to describe which side to keep. + * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept + * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept + */ +void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t py, int16_t angle, + lv_draw_mask_line_side_t side); + +/** + * Initialize an angle mask. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param vertex_x X coordinate of the angle vertex (absolute coordinates) + * @param vertex_y Y coordinate of the angle vertex (absolute coordinates) + * @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom + * @param end_angle end angle + */ +void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y, + lv_coord_t start_angle, lv_coord_t end_angle); + +/** + * Initialize a fade mask. + * @param param pointer to an `lv_draw_mask_radius_param_t` to initialize + * @param rect coordinates of the rectangle to affect (absolute coordinates) + * @param radius radius of the rectangle + * @param inv true: keep the pixels inside the rectangle; keep the pixels outside of the rectangle + */ +void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t * param, const lv_area_t * rect, lv_coord_t radius, bool inv); + +/** + * Initialize a fade mask. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param coords coordinates of the area to affect (absolute coordinates) + * @param opa_top opacity on the top + * @param y_top at which coordinate start to change to opacity to `opa_bottom` + * @param opa_bottom opacity at the bottom + * @param y_bottom at which coordinate reach `opa_bottom`. + */ +void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, const lv_area_t * coords, lv_opa_t opa_top, + lv_coord_t y_top, + lv_opa_t opa_bottom, lv_coord_t y_bottom); + +/** + * Initialize a map mask. + * @param param pointer to a `lv_draw_mask_param_t` to initialize + * @param coords coordinates of the map (absolute coordinates) + * @param map array of bytes with the mask values + */ +void lv_draw_mask_map_init(lv_draw_mask_map_param_t * param, const lv_area_t * coords, const lv_opa_t * map); + +void lv_draw_mask_polygon_init(lv_draw_mask_polygon_param_t * param, const lv_point_t * points, uint16_t point_cnt); + +#endif /*LV_DRAW_COMPLEX*/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_MASK_H*/ diff --git a/include/liblvgl/draw/lv_draw_rect.h b/include/liblvgl/draw/lv_draw_rect.h new file mode 100644 index 00000000..e259446e --- /dev/null +++ b/include/liblvgl/draw/lv_draw_rect.h @@ -0,0 +1,96 @@ +/** + * @file lv_draw_rect.h + * + */ + +#ifndef LV_DRAW_RECT_H +#define LV_DRAW_RECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_style.h" +#include "sw/lv_draw_sw_gradient.h" + +/********************* + * DEFINES + *********************/ +#define LV_RADIUS_CIRCLE 0x7FFF /**< A very big radius to always draw as circle*/ +LV_EXPORT_CONST_INT(LV_RADIUS_CIRCLE); + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_coord_t radius; + lv_blend_mode_t blend_mode; + + /*Background*/ + lv_opa_t bg_opa; + lv_color_t bg_color; /**< First element of a gradient is a color, so it maps well here*/ + lv_grad_dsc_t bg_grad; + + /*Background img*/ + const void * bg_img_src; + const void * bg_img_symbol_font; + lv_color_t bg_img_recolor; + lv_opa_t bg_img_opa; + lv_opa_t bg_img_recolor_opa; + uint8_t bg_img_tiled; + + /*Border*/ + lv_color_t border_color; + lv_coord_t border_width; + lv_opa_t border_opa; + uint8_t border_post : 1; /*There is a border it will be drawn later.*/ + lv_border_side_t border_side : 5; + + /*Outline*/ + lv_color_t outline_color; + lv_coord_t outline_width; + lv_coord_t outline_pad; + lv_opa_t outline_opa; + + /*Shadow*/ + lv_color_t shadow_color; + lv_coord_t shadow_width; + lv_coord_t shadow_ofs_x; + lv_coord_t shadow_ofs_y; + lv_coord_t shadow_spread; + lv_opa_t shadow_opa; +} lv_draw_rect_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +LV_ATTRIBUTE_FAST_MEM void lv_draw_rect_dsc_init(lv_draw_rect_dsc_t * dsc); + + +/** + * Draw a rectangle + * @param coords the coordinates of the rectangle + * @param clip the rectangle will be drawn only in this area + * @param dsc pointer to an initialized `lv_draw_rect_dsc_t` variable + */ +void lv_draw_rect(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_RECT_H*/ diff --git a/include/liblvgl/draw/lv_draw_transform.h b/include/liblvgl/draw/lv_draw_transform.h new file mode 100644 index 00000000..6e6236ca --- /dev/null +++ b/include/liblvgl/draw/lv_draw_transform.h @@ -0,0 +1,44 @@ +/** + * @file lv_draw_transform.h + * + */ + +#ifndef LV_DRAW_TRANSFORM_H +#define LV_DRAW_TRANSFORM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_transform(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf, + lv_coord_t src_w, lv_coord_t src_h, + lv_coord_t src_stride, const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_TRANSFORM_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_triangle.h b/include/liblvgl/draw/lv_draw_triangle.h similarity index 57% rename from EZ-Template-Example-Project/include/display/lv_draw/lv_draw_triangle.h rename to include/liblvgl/draw/lv_draw_triangle.h index c3c6208d..e8d85750 100644 --- a/EZ-Template-Example-Project/include/display/lv_draw/lv_draw_triangle.h +++ b/include/liblvgl/draw/lv_draw_triangle.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "lv_draw.h" +#include "lv_draw_rect.h" /********************* * DEFINES @@ -26,26 +26,17 @@ extern "C" { /********************** * GLOBAL PROTOTYPES **********************/ -/*Experimental use for 3D modeling*/ -#define USE_LV_TRIANGLE 1 -#if USE_LV_TRIANGLE != 0 -/** - * - * @param points pointer to an array with 3 points - * @param mask the triangle will be drawn only in this mask - * @param color color of the triangle - */ -void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color); -#endif +void lv_draw_polygon(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t points[], + uint16_t point_cnt); +void lv_draw_triangle(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t points[]); /********************** * MACROS **********************/ - #ifdef __cplusplus -} /* extern "C" */ +} /*extern "C"*/ #endif #endif /*LV_DRAW_TRIANGLE_H*/ diff --git a/include/liblvgl/draw/lv_img_buf.h b/include/liblvgl/draw/lv_img_buf.h new file mode 100644 index 00000000..8998839b --- /dev/null +++ b/include/liblvgl/draw/lv_img_buf.h @@ -0,0 +1,249 @@ +/** + * @file lv_img_buf.h + * + */ + +#ifndef LV_IMG_BUF_H +#define LV_IMG_BUF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ +/*If image pixels contains alpha we need to know how much byte is a pixel*/ +#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8 +#define LV_IMG_PX_SIZE_ALPHA_BYTE 2 +#elif LV_COLOR_DEPTH == 16 +#define LV_IMG_PX_SIZE_ALPHA_BYTE 3 +#elif LV_COLOR_DEPTH == 32 +#define LV_IMG_PX_SIZE_ALPHA_BYTE 4 +#endif + +#define LV_IMG_BUF_SIZE_TRUE_COLOR(w, h) ((LV_COLOR_SIZE / 8) * w * h) +#define LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h) ((LV_COLOR_SIZE / 8) * w * h) +#define LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h) (LV_IMG_PX_SIZE_ALPHA_BYTE * w * h) + +/*+ 1: to be sure no fractional row*/ +#define LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) ((((w / 8) + 1) * h)) +#define LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h) ((((w / 4) + 1) * h)) +#define LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h) ((((w / 2) + 1) * h)) +#define LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h) ((w * h)) + +/*4 * X: for palette*/ +#define LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2) +#define LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h) + 4 * 4) +#define LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h) + 4 * 16) +#define LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h) + 4 * 256) + +#define _LV_ZOOM_INV_UPSCALE 5 + +/********************** + * TYPEDEFS + **********************/ + +/*Image color format*/ +enum { + LV_IMG_CF_UNKNOWN = 0, + + LV_IMG_CF_RAW, /**< Contains the file as it is. Needs custom decoder function*/ + LV_IMG_CF_RAW_ALPHA, /**< Contains the file as it is. The image has alpha. Needs custom decoder + function*/ + LV_IMG_CF_RAW_CHROMA_KEYED, /**< Contains the file as it is. The image is chroma keyed. Needs + custom decoder function*/ + + LV_IMG_CF_TRUE_COLOR, /**< Color format and depth should match with LV_COLOR settings*/ + LV_IMG_CF_TRUE_COLOR_ALPHA, /**< Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/ + LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /**< Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels + will be transparent*/ + + LV_IMG_CF_INDEXED_1BIT, /**< Can have 2 different colors in a palette (can't be chroma keyed)*/ + LV_IMG_CF_INDEXED_2BIT, /**< Can have 4 different colors in a palette (can't be chroma keyed)*/ + LV_IMG_CF_INDEXED_4BIT, /**< Can have 16 different colors in a palette (can't be chroma keyed)*/ + LV_IMG_CF_INDEXED_8BIT, /**< Can have 256 different colors in a palette (can't be chroma keyed)*/ + + LV_IMG_CF_ALPHA_1BIT, /**< Can have one color and it can be drawn or not*/ + LV_IMG_CF_ALPHA_2BIT, /**< Can have one color but 4 different alpha value*/ + LV_IMG_CF_ALPHA_4BIT, /**< Can have one color but 16 different alpha value*/ + LV_IMG_CF_ALPHA_8BIT, /**< Can have one color but 256 different alpha value*/ + + LV_IMG_CF_RGB888, + LV_IMG_CF_RGBA8888, + LV_IMG_CF_RGBX8888, + LV_IMG_CF_RGB565, + LV_IMG_CF_RGBA5658, + LV_IMG_CF_RGB565A8, + + LV_IMG_CF_RESERVED_15, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_16, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_17, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_18, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_19, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_20, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_21, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_22, /**< Reserved for further use.*/ + LV_IMG_CF_RESERVED_23, /**< Reserved for further use.*/ + + LV_IMG_CF_USER_ENCODED_0, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_1, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_2, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_3, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_4, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_5, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_6, /**< User holder encoding format.*/ + LV_IMG_CF_USER_ENCODED_7, /**< User holder encoding format.*/ +}; +typedef uint8_t lv_img_cf_t; + + +/** + * The first 8 bit is very important to distinguish the different source types. + * For more info see `lv_img_get_src_type()` in lv_img.c + * On big endian systems the order is reversed so cf and always_zero must be at + * the end of the struct. + */ +#if LV_BIG_ENDIAN_SYSTEM +typedef struct { + + uint32_t h : 11; /*Height of the image map*/ + uint32_t w : 11; /*Width of the image map*/ + uint32_t reserved : 2; /*Reserved to be used later*/ + uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a + non-printable character*/ + uint32_t cf : 5; /*Color format: See `lv_img_color_format_t`*/ + +} lv_img_header_t; +#else +typedef struct { + + uint32_t cf : 5; /*Color format: See `lv_img_color_format_t`*/ + uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a + non-printable character*/ + + uint32_t reserved : 2; /*Reserved to be used later*/ + + uint32_t w : 11; /*Width of the image map*/ + uint32_t h : 11; /*Height of the image map*/ +} lv_img_header_t; +#endif + +/** Image header it is compatible with + * the result from image converter utility*/ +typedef struct { + lv_img_header_t header; /**< A header describing the basics of the image*/ + uint32_t data_size; /**< Size of the image in bytes*/ + const uint8_t * data; /**< Pointer to the data of the image*/ +} lv_img_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Allocate an image buffer in RAM + * @param w width of image + * @param h height of image + * @param cf a color format (`LV_IMG_CF_...`) + * @return an allocated image, or NULL on failure + */ +lv_img_dsc_t * lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); + +/** + * Get the color of an image's pixel + * @param dsc an image descriptor + * @param x x coordinate of the point to get + * @param y x coordinate of the point to get + * @param color the color of the image. In case of `LV_IMG_CF_ALPHA_1/2/4/8` this color is used. + * Not used in other cases. + * @param safe true: check out of bounds + * @return color of the point + */ +lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t color); + +/** + * Get the alpha value of an image's pixel + * @param dsc pointer to an image descriptor + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param safe true: check out of bounds + * @return alpha value of the point + */ +lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y); + +/** + * Set the color of a pixel of an image. The alpha channel won't be affected. + * @param dsc pointer to an image descriptor + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param c color of the point + * @param safe true: check out of bounds + */ +void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t c); + +/** + * Set the alpha value of a pixel of an image. The color won't be affected + * @param dsc pointer to an image descriptor + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param opa the desired opacity + * @param safe true: check out of bounds + */ +void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_opa_t opa); + +/** + * Set the palette color of an indexed image. Valid only for `LV_IMG_CF_INDEXED1/2/4/8` + * @param dsc pointer to an image descriptor + * @param id the palette color to set: + * - for `LV_IMG_CF_INDEXED1`: 0..1 + * - for `LV_IMG_CF_INDEXED2`: 0..3 + * - for `LV_IMG_CF_INDEXED4`: 0..15 + * - for `LV_IMG_CF_INDEXED8`: 0..255 + * @param c the color to set + */ +void lv_img_buf_set_palette(lv_img_dsc_t * dsc, uint8_t id, lv_color_t c); + +/** + * Free an allocated image buffer + * @param dsc image buffer to free + */ +void lv_img_buf_free(lv_img_dsc_t * dsc); + +/** + * Get the memory consumption of a raw bitmap, given color format and dimensions. + * @param w width + * @param h height + * @param cf color format + * @return size in bytes + */ +uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); + +/** + * Get the area of a rectangle if its rotated and scaled + * @param res store the coordinates here + * @param w width of the rectangle to transform + * @param h height of the rectangle to transform + * @param angle angle of rotation + * @param zoom zoom, (256 no zoom) + * @param pivot x,y pivot coordinates of rotation + */ +void _lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, + const lv_point_t * pivot); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMG_BUF_H*/ diff --git a/include/liblvgl/draw/lv_img_cache.h b/include/liblvgl/draw/lv_img_cache.h new file mode 100644 index 00000000..dc0c5d98 --- /dev/null +++ b/include/liblvgl/draw/lv_img_cache.h @@ -0,0 +1,78 @@ +/** + * @file lv_img_cache.h + * + */ + +#ifndef LV_IMG_CACHE_H +#define LV_IMG_CACHE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_img_decoder.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * When loading images from the network it can take a long time to download and decode the image. + * + * To avoid repeating this heavy load images can be cached. + */ +typedef struct { + lv_img_decoder_dsc_t dec_dsc; /**< Image information*/ + + /** Count the cache entries's life. Add `time_to_open` to `life` when the entry is used. + * Decrement all lifes by one every in every ::lv_img_cache_open. + * If life == 0 the entry can be reused*/ + int32_t life; +} _lv_img_cache_entry_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Open an image using the image decoder interface and cache it. + * The image will be left open meaning if the image decoder open callback allocated memory then it will remain. + * The image is closed if a new image is opened and the new image takes its place in the cache. + * @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable + * @param color The color of the image with `LV_IMG_CF_ALPHA_...` + * @param frame_id the index of the frame. Used only with animated images, set 0 for normal images + * @return pointer to the cache entry or NULL if can open the image + */ +_lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color, int32_t frame_id); + +/** + * Set the number of images to be cached. + * More cached images mean more opened image at same time which might mean more memory usage. + * E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache. + * @param new_entry_cnt number of image to cache + */ +void lv_img_cache_set_size(uint16_t new_slot_num); + +/** + * Invalidate an image source in the cache. + * Useful if the image source is updated therefore it needs to be cached again. + * @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable. + */ +void lv_img_cache_invalidate_src(const void * src); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMG_CACHE_H*/ diff --git a/include/liblvgl/draw/lv_img_decoder.h b/include/liblvgl/draw/lv_img_decoder.h new file mode 100644 index 00000000..c0c5860e --- /dev/null +++ b/include/liblvgl/draw/lv_img_decoder.h @@ -0,0 +1,274 @@ +/** + * @file lv_img_decoder.h + * + */ + +#ifndef LV_IMG_DECODER_H +#define LV_IMG_DECODER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include "lv_img_buf.h" +#include "liblvgl/misc/lv_fs.h" +#include "liblvgl/misc/lv_types.h" +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Source of image.*/ +enum { + LV_IMG_SRC_VARIABLE, /** Binary/C variable*/ + LV_IMG_SRC_FILE, /** File in filesystem*/ + LV_IMG_SRC_SYMBOL, /** Symbol (@ref lv_symbol_def.h)*/ + LV_IMG_SRC_UNKNOWN, /** Unknown source*/ +}; + +typedef uint8_t lv_img_src_t; + +/*Decoder function definitions*/ +struct _lv_img_decoder_dsc_t; +struct _lv_img_decoder_t; + +/** + * Get info from an image and store in the `header` + * @param src the image source. Can be a pointer to a C array or a file name (Use + * `lv_img_src_get_type` to determine the type) + * @param header store the info here + * @return LV_RES_OK: info written correctly; LV_RES_INV: failed + */ +typedef lv_res_t (*lv_img_decoder_info_f_t)(struct _lv_img_decoder_t * decoder, const void * src, + lv_img_header_t * header); + +/** + * Open an image for decoding. Prepare it as it is required to read it later + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor. `src`, `color` are already initialized in it. + */ +typedef lv_res_t (*lv_img_decoder_open_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc); + +/** + * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`. + * Required only if the "open" function can't return with the whole decoded pixel array. + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor + * @param x start x coordinate + * @param y start y coordinate + * @param len number of pixels to decode + * @param buf a buffer to store the decoded pixels + * @return LV_RES_OK: ok; LV_RES_INV: failed + */ +typedef lv_res_t (*lv_img_decoder_read_line_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc, + lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf); + +/** + * Close the pending decoding. Free resources etc. + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor + */ +typedef void (*lv_img_decoder_close_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc); + + +typedef struct _lv_img_decoder_t { + lv_img_decoder_info_f_t info_cb; + lv_img_decoder_open_f_t open_cb; + lv_img_decoder_read_line_f_t read_line_cb; + lv_img_decoder_close_f_t close_cb; + +#if LV_USE_USER_DATA + void * user_data; +#endif +} lv_img_decoder_t; + + +/**Describe an image decoding session. Stores data about the decoding*/ +typedef struct _lv_img_decoder_dsc_t { + /**The decoder which was able to open the image source*/ + lv_img_decoder_t * decoder; + + /**The image source. A file path like "S:my_img.png" or pointer to an `lv_img_dsc_t` variable*/ + const void * src; + + /**Color to draw the image. USed when the image has alpha channel only*/ + lv_color_t color; + + /**Frame of the image, using with animated images*/ + int32_t frame_id; + + /**Type of the source: file or variable. Can be set in `open` function if required*/ + lv_img_src_t src_type; + + /**Info about the opened image: color format, size, etc. MUST be set in `open` function*/ + lv_img_header_t header; + + /** Pointer to a buffer where the image's data (pixels) are stored in a decoded, plain format. + * MUST be set in `open` function*/ + const uint8_t * img_data; + + /** How much time did it take to open the image. [ms] + * If not set `lv_img_cache` will measure and set the time to open*/ + uint32_t time_to_open; + + /**A text to display instead of the image when the image can't be opened. + * Can be set in `open` function or set NULL.*/ + const char * error_msg; + + /**Store any custom data here is required*/ + void * user_data; +} lv_img_decoder_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the image decoder module + */ +void _lv_img_decoder_init(void); + +/** + * Get information about an image. + * Try the created image decoder one by one. Once one is able to get info that info will be used. + * @param src the image source. Can be + * 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via `lv_fs_drv_register()`) + * 2) Variable: Pointer to an `lv_img_dsc_t` variable + * 3) Symbol: E.g. `LV_SYMBOL_OK` + * @param header the image info will be stored here + * @return LV_RES_OK: success; LV_RES_INV: wasn't able to get info about the image + */ +lv_res_t lv_img_decoder_get_info(const void * src, lv_img_header_t * header); + +/** + * Open an image. + * Try the created image decoders one by one. Once one is able to open the image that decoder is saved in `dsc` + * @param dsc describes a decoding session. Simply a pointer to an `lv_img_decoder_dsc_t` variable. + * @param src the image source. Can be + * 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via `lv_fs_drv_register())`) + * 2) Variable: Pointer to an `lv_img_dsc_t` variable + * 3) Symbol: E.g. `LV_SYMBOL_OK` + * @param color The color of the image with `LV_IMG_CF_ALPHA_...` + * @param frame_id the index of the frame. Used only with animated images, set 0 for normal images + * @return LV_RES_OK: opened the image. `dsc->img_data` and `dsc->header` are set. + * LV_RES_INV: none of the registered image decoders were able to open the image. + */ +lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_color_t color, int32_t frame_id); + +/** + * Read a line from an opened image + * @param dsc pointer to `lv_img_decoder_dsc_t` used in `lv_img_decoder_open` + * @param x start X coordinate (from left) + * @param y start Y coordinate (from top) + * @param len number of pixels to read + * @param buf store the data here + * @return LV_RES_OK: success; LV_RES_INV: an error occurred + */ +lv_res_t lv_img_decoder_read_line(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_coord_t len, + uint8_t * buf); + +/** + * Close a decoding session + * @param dsc pointer to `lv_img_decoder_dsc_t` used in `lv_img_decoder_open` + */ +void lv_img_decoder_close(lv_img_decoder_dsc_t * dsc); + +/** + * Create a new image decoder + * @return pointer to the new image decoder + */ +lv_img_decoder_t * lv_img_decoder_create(void); + +/** + * Delete an image decoder + * @param decoder pointer to an image decoder + */ +void lv_img_decoder_delete(lv_img_decoder_t * decoder); + +/** + * Set a callback to get information about the image + * @param decoder pointer to an image decoder + * @param info_cb a function to collect info about an image (fill an `lv_img_header_t` struct) + */ +void lv_img_decoder_set_info_cb(lv_img_decoder_t * decoder, lv_img_decoder_info_f_t info_cb); + +/** + * Set a callback to open an image + * @param decoder pointer to an image decoder + * @param open_cb a function to open an image + */ +void lv_img_decoder_set_open_cb(lv_img_decoder_t * decoder, lv_img_decoder_open_f_t open_cb); + +/** + * Set a callback to a decoded line of an image + * @param decoder pointer to an image decoder + * @param read_line_cb a function to read a line of an image + */ +void lv_img_decoder_set_read_line_cb(lv_img_decoder_t * decoder, lv_img_decoder_read_line_f_t read_line_cb); + +/** + * Set a callback to close a decoding session. E.g. close files and free other resources. + * @param decoder pointer to an image decoder + * @param close_cb a function to close a decoding session + */ +void lv_img_decoder_set_close_cb(lv_img_decoder_t * decoder, lv_img_decoder_close_f_t close_cb); + +/** + * Get info about a built-in image + * @param decoder the decoder where this function belongs + * @param src the image source: pointer to an `lv_img_dsc_t` variable, a file path or a symbol + * @param header store the image data here + * @return LV_RES_OK: the info is successfully stored in `header`; LV_RES_INV: unknown format or other error. + */ +lv_res_t lv_img_decoder_built_in_info(lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header); + +/** + * Open a built in image + * @param decoder the decoder where this function belongs + * @param dsc pointer to decoder descriptor. `src`, `style` are already initialized in it. + * @return LV_RES_OK: the info is successfully stored in `header`; LV_RES_INV: unknown format or other error. + */ +lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc); + +/** + * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`. + * Required only if the "open" function can't return with the whole decoded pixel array. + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor + * @param x start x coordinate + * @param y start y coordinate + * @param len number of pixels to decode + * @param buf a buffer to store the decoded pixels + * @return LV_RES_OK: ok; LV_RES_INV: failed + */ +lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x, + lv_coord_t y, lv_coord_t len, uint8_t * buf); + +/** + * Close the pending decoding. Free resources etc. + * @param decoder pointer to the decoder the function associated with + * @param dsc pointer to decoder descriptor + */ +void lv_img_decoder_built_in_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMG_DECODER_H*/ diff --git a/include/liblvgl/draw/nxp/lv_gpu_nxp.h b/include/liblvgl/draw/nxp/lv_gpu_nxp.h new file mode 100644 index 00000000..853da566 --- /dev/null +++ b/include/liblvgl/draw/nxp/lv_gpu_nxp.h @@ -0,0 +1,71 @@ +/** + * @file lv_gpu_nxp.h + * + */ + +/** + * MIT License + * + * Copyright 2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_GPU_NXP_H +#define LV_GPU_NXP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_GPU_NXP_PXP || LV_USE_GPU_NXP_VG_LITE +#include "../sw/lv_draw_sw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef lv_draw_sw_ctx_t lv_draw_nxp_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_nxp_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_nxp_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_GPU_NXP_PXP || LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_NXP_H*/ diff --git a/include/liblvgl/draw/nxp/pxp/lv_draw_pxp_blend.h b/include/liblvgl/draw/nxp/pxp/lv_draw_pxp_blend.h new file mode 100644 index 00000000..acce8713 --- /dev/null +++ b/include/liblvgl/draw/nxp/pxp/lv_draw_pxp_blend.h @@ -0,0 +1,143 @@ +/** + * @file lv_draw_pxp_blend.h + * + */ + +/** + * MIT License + * + * Copyright 2020-2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_DRAW_PXP_BLEND_H +#define LV_DRAW_PXP_BLEND_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_PXP +#include "lv_gpu_nxp_pxp.h" +#include "../../sw/lv_draw_sw.h" + +/********************* + * DEFINES + *********************/ + +#ifndef LV_GPU_NXP_PXP_BLIT_SIZE_LIMIT +/** Minimum area (in pixels) for image copy with 100% opacity to be handled by PXP*/ +#define LV_GPU_NXP_PXP_BLIT_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_PXP_BLIT_OPA_SIZE_LIMIT +/** Minimum area (in pixels) for image copy with transparency to be handled by PXP*/ +#define LV_GPU_NXP_PXP_BLIT_OPA_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_PXP_BUFF_SYNC_BLIT_SIZE_LIMIT +/** Minimum invalidated area (in pixels) to be synchronized by PXP during buffer sync */ +#define LV_GPU_NXP_PXP_BUFF_SYNC_BLIT_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_PXP_FILL_SIZE_LIMIT +/** Minimum area (in pixels) to be filled by PXP with 100% opacity*/ +#define LV_GPU_NXP_PXP_FILL_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_PXP_FILL_OPA_SIZE_LIMIT +/** Minimum area (in pixels) to be filled by PXP with transparency*/ +#define LV_GPU_NXP_PXP_FILL_OPA_SIZE_LIMIT 5000 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Fill area, with optional opacity. + * + * @param[in/out] dest_buf destination buffer + * @param[in] dest_stride width (stride) of destination buffer in pixels + * @param[in] fill_area area to fill + * @param[in] color color + * @param[in] opa transparency of the color + * @retval LV_RES_OK Fill completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_pxp_fill(lv_color_t * dest_buf, lv_coord_t dest_stride, const lv_area_t * fill_area, + lv_color_t color, lv_opa_t opa); + +/** + * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with effects. + * By default, image is copied directly, with optional opacity. This function can also + * rotate the display output buffer to a specified angle (90x step). + * + * @param[in/out] dest_buf destination buffer + * @param[in] dest_area destination area + * @param[in] dest_stride width (stride) of destination buffer in pixels + * @param[in] src_buf source buffer + * @param[in] src_area source area with absolute coordinates to draw on destination buffer + * @param[in] opa opacity of the result + * @param[in] angle display rotation angle (90x) + * @retval LV_RES_OK Fill completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_pxp_blit(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride, + const lv_color_t * src_buf, const lv_area_t * src_area, lv_opa_t opa, lv_disp_rot_t angle); + +/** + * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with transformation. + * + * + * @param[in/out] dest_buf destination buffer + * @param[in] dest_area destination area + * @param[in] dest_stride width (stride) of destination buffer in pixels + * @param[in] src_buf source buffer + * @param[in] src_area source area with absolute coordinates to draw on destination buffer + * @param[in] dsc image descriptor + * @param[in] cf color format + * @retval LV_RES_OK Fill completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_pxp_blit_transform(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride, + const lv_color_t * src_buf, const lv_area_t * src_area, const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_PXP*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_PXP_BLEND_H*/ diff --git a/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp.h b/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp.h new file mode 100644 index 00000000..aeb9d6c0 --- /dev/null +++ b/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp.h @@ -0,0 +1,153 @@ +/** + * @file lv_gpu_nxp_pxp.h + * + */ + +/** + * MIT License + * + * Copyright 2020-2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_GPU_NXP_PXP_H +#define LV_GPU_NXP_PXP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_PXP +#include "fsl_cache.h" +#include "fsl_pxp.h" + +#include "../../../misc/lv_log.h" + +/********************* + * DEFINES + *********************/ + +/** PXP module instance to use*/ +#define LV_GPU_NXP_PXP_ID PXP + +/** PXP interrupt line ID*/ +#define LV_GPU_NXP_PXP_IRQ_ID PXP_IRQn + +#ifndef LV_GPU_NXP_PXP_LOG_ERRORS +/** Enable logging of PXP errors (\see LV_LOG_ERROR)*/ +#define LV_GPU_NXP_PXP_LOG_ERRORS 1 +#endif + +#ifndef LV_GPU_NXP_PXP_LOG_TRACES +/** Enable logging of PXP errors (\see LV_LOG_ERROR)*/ +#define LV_GPU_NXP_PXP_LOG_TRACES 0 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/** + * NXP PXP device configuration - call-backs used for + * interrupt init/wait/deinit. + */ +typedef struct { + /** Callback for PXP interrupt initialization*/ + lv_res_t (*pxp_interrupt_init)(void); + + /** Callback for PXP interrupt de-initialization*/ + void (*pxp_interrupt_deinit)(void); + + /** Callback that should start PXP and wait for operation complete*/ + void (*pxp_run)(void); +} lv_nxp_pxp_cfg_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Reset and initialize PXP device. This function should be called as a part + * of display init sequence. + * + * @retval LV_RES_OK PXP init completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_pxp_init(void); + +/** + * Disable PXP device. Should be called during display deinit sequence. + */ +void lv_gpu_nxp_pxp_deinit(void); + +/** + * Start PXP job and wait for completion. + */ +void lv_gpu_nxp_pxp_run(void); + +/********************** + * MACROS + **********************/ + +#define PXP_COND_STOP(cond, txt) \ + do { \ + if (cond) { \ + LV_LOG_ERROR("%s. STOP!", txt); \ + for ( ; ; ); \ + } \ + } while(0) + +#if LV_GPU_NXP_PXP_LOG_ERRORS +#define PXP_RETURN_INV(fmt, ...) \ + do { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + return LV_RES_INV; \ + } while (0) +#else +#define PXP_RETURN_INV(fmt, ...) \ + do { \ + return LV_RES_INV; \ + }while(0) +#endif /*LV_GPU_NXP_PXP_LOG_ERRORS*/ + +#if LV_GPU_NXP_PXP_LOG_TRACES +#define PXP_LOG_TRACE(fmt, ...) \ + do { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + } while (0) +#else +#define PXP_LOG_TRACE(fmt, ...) \ + do { \ + } while (0) +#endif /*LV_GPU_NXP_PXP_LOG_TRACES*/ + +#endif /*LV_USE_GPU_NXP_PXP*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_NXP_PXP_H*/ diff --git a/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.h b/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.h new file mode 100644 index 00000000..d9074472 --- /dev/null +++ b/include/liblvgl/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.h @@ -0,0 +1,78 @@ +/** + * @file lv_gpu_nxp_pxp_osa.h + * + */ + +/** + * MIT License + * + * Copyright 2020, 2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_GPU_NXP_PXP_OSA_H +#define LV_GPU_NXP_PXP_OSA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT +#include "lv_gpu_nxp_pxp.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * PXP device interrupt handler. Used to check PXP task completion status. + */ +void PXP_IRQHandler(void); + +/** + * Helper function to get the PXP default configuration. + */ +lv_nxp_pxp_cfg_t * lv_gpu_nxp_pxp_get_cfg(void); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_NXP_PXP_OSA_H*/ diff --git a/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_arc.h b/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_arc.h new file mode 100644 index 00000000..e2da4190 --- /dev/null +++ b/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_arc.h @@ -0,0 +1,79 @@ +/** + * @file lv_draw_vglite_arc.h + * + */ + +/** + * MIT License + * + * Copyright 2021, 2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_DRAW_VGLITE_ARC_H +#define LV_DRAW_VGLITE_ARC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_VG_LITE +#include "lv_gpu_nxp_vglite.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*** + * Draw arc shape with effects + * @param draw_ctx drawing context + * @param dsc the arc description structure (width, rounded ending, opacity) + * @param center the coordinates of the arc center + * @param radius the radius of external arc + * @param start_angle the starting angle in degrees + * @param end_angle the ending angle in degrees + */ +lv_res_t lv_gpu_nxp_vglite_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, + int32_t radius, int32_t start_angle, int32_t end_angle); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_VGLITE_ARC_H*/ diff --git a/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_blend.h b/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_blend.h new file mode 100644 index 00000000..1726dcd9 --- /dev/null +++ b/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_blend.h @@ -0,0 +1,149 @@ +/** + * @file lv_draw_vglite_blend.h + * + */ + +/** + * MIT License + * + * Copyright 2020-2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_DRAW_VGLITE_BLEND_H +#define LV_DRAW_VGLITE_BLEND_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_VG_LITE +#include "lv_gpu_nxp_vglite.h" + +/********************* + * DEFINES + *********************/ + +#ifndef LV_GPU_NXP_VG_LITE_FILL_SIZE_LIMIT +/** Minimum area (in pixels) to be filled by VG-Lite with 100% opacity*/ +#define LV_GPU_NXP_VG_LITE_FILL_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_FILL_OPA_SIZE_LIMIT +/** Minimum area (in pixels) to be filled by VG-Lite with transparency*/ +#define LV_GPU_NXP_VG_LITE_FILL_OPA_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_BLIT_SIZE_LIMIT +/** Minimum area (in pixels) for image copy with 100% opacity to be handled by VG-Lite*/ +#define LV_GPU_NXP_VG_LITE_BLIT_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_BUFF_SYNC_BLIT_SIZE_LIMIT +/** Minimum invalidated area (in pixels) to be synchronized by VG-Lite during buffer sync */ +#define LV_GPU_NXP_VG_LITE_BUFF_SYNC_BLIT_SIZE_LIMIT 5000 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_BLIT_OPA_SIZE_LIMIT +/** Minimum area (in pixels) for image copy with transparency to be handled by VG-Lite*/ +#define LV_GPU_NXP_VG_LITE_BLIT_OPA_SIZE_LIMIT 5000 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/** + * BLock Image Transfer descriptor structure + */ +typedef struct { + + const lv_color_t * src; /**< Source buffer pointer (must be aligned on 32 bytes)*/ + lv_area_t src_area; /**< Area to be copied from source*/ + lv_coord_t src_width; /**< Source buffer width*/ + lv_coord_t src_height; /**< Source buffer height*/ + int32_t src_stride; /**< Source buffer stride in bytes (must be aligned on 16 px)*/ + + const lv_color_t * dst; /**< Destination buffer pointer (must be aligned on 32 bytes)*/ + lv_area_t dst_area; /**< Target area in destination buffer (must be the same as src_area)*/ + lv_coord_t dst_width; /**< Destination buffer width*/ + lv_coord_t dst_height; /**< Destination buffer height*/ + int32_t dst_stride; /**< Destination buffer stride in bytes (must be aligned on 16 px)*/ + + lv_opa_t opa; /**< Opacity - alpha mix (0 = source not copied, 255 = 100% opaque)*/ + uint32_t angle; /**< Rotation angle (1/10 of degree)*/ + uint32_t zoom; /**< 256 = no zoom (1:1 scale ratio)*/ + lv_point_t pivot; /**< The coordinates of rotation pivot in source image buffer*/ +} lv_gpu_nxp_vglite_blit_info_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Fill area, with optional opacity. + * + * @param[in/out] dest_buf Destination buffer pointer (must be aligned on 32 bytes) + * @param[in] dest_width Destination buffer width in pixels (must be aligned on 16 px) + * @param[in] dest_height Destination buffer height in pixels + * @param[in] fill_area Area to be filled + * @param[in] color Fill color + * @param[in] opa Opacity (255 = full, 128 = 50% background/50% color, 0 = no fill) + * @retval LV_RES_OK Fill completed + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_vglite_fill(lv_color_t * dest_buf, lv_coord_t dest_width, lv_coord_t dest_height, + const lv_area_t * fill_area, lv_color_t color, lv_opa_t opa); + +/** + * BLock Image Transfer. + * + * @param[in] blit Description of the transfer + * @retval LV_RES_OK Transfer complete + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_vglite_blit(lv_gpu_nxp_vglite_blit_info_t * blit); + +/** + * BLock Image Transfer with transformation. + * + * @param[in] blit Description of the transfer + * @retval LV_RES_OK Transfer complete + * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS) + */ +lv_res_t lv_gpu_nxp_vglite_blit_transform(lv_gpu_nxp_vglite_blit_info_t * blit); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_VGLITE_BLEND_H*/ diff --git a/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_rect.h b/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_rect.h new file mode 100644 index 00000000..8a641707 --- /dev/null +++ b/include/liblvgl/draw/nxp/vglite/lv_draw_vglite_rect.h @@ -0,0 +1,77 @@ +/** + * @file lv_draw_vglite_rect.h + * + */ + +/** + * MIT License + * + * Copyright 2021, 2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_DRAW_VGLITE_RECT_H +#define LV_DRAW_VGLITE_RECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_VG_LITE +#include "lv_gpu_nxp_vglite.h" +#include "../../lv_draw_rect.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Draw rectangle shape with effects (rounded corners, gradient) + * + * @param draw_ctx drawing context + * @param dsc description of the rectangle + * @param coords the area where rectangle is clipped + */ +lv_res_t lv_gpu_nxp_vglite_draw_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_VGLITE_RECT_H*/ diff --git a/include/liblvgl/draw/nxp/vglite/lv_gpu_nxp_vglite.h b/include/liblvgl/draw/nxp/vglite/lv_gpu_nxp_vglite.h new file mode 100644 index 00000000..87544925 --- /dev/null +++ b/include/liblvgl/draw/nxp/vglite/lv_gpu_nxp_vglite.h @@ -0,0 +1,185 @@ +/** + * @file lv_gpu_nxp_vglite.h + * + */ + +/** + * MIT License + * + * Copyright 2020-2022 NXP + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next paragraph) + * shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef LV_GPU_NXP_VGLITE_H +#define LV_GPU_NXP_VGLITE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_NXP_VG_LITE +#include "vg_lite.h" +#include "../../sw/lv_draw_sw.h" +#include "../../../misc/lv_log.h" +#include "fsl_debug_console.h" + +/********************* + * DEFINES + *********************/ + +/** Use this symbol as limit to disable feature (value has to be larger than supported resolution) */ +#define LV_GPU_NXP_VG_LITE_FEATURE_DISABLED (1920*1080+1) + +/** Stride in px required by VG-Lite HW. Don't change this. */ +#define LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX 16U + +#ifndef LV_GPU_NXP_VG_LITE_LOG_ERRORS +/** Enable logging of VG-Lite errors (\see LV_LOG_ERROR)*/ +#define LV_GPU_NXP_VG_LITE_LOG_ERRORS 1 +#endif + +#ifndef LV_GPU_NXP_VG_LITE_LOG_TRACES +/** Enable logging of VG-Lite errors (\see LV_LOG_ERROR)*/ +#define LV_GPU_NXP_VG_LITE_LOG_TRACES 0 +#endif + +/* Draw rectangles around BLIT tiles */ +#define BLIT_DBG_AREAS 0 + +/* Print detailed info to SDK console (NOT to LVGL log system) */ +#define BLIT_DBG_VERBOSE 0 + +/* Verbose debug print */ +#if BLIT_DBG_VERBOSE +#define PRINT_BLT PRINTF +#else +#define PRINT_BLT(...) +#endif + +/* The optimal Bezier control point offset for radial unit + * see: https://spencermortensen.com/articles/bezier-circle/ + **/ +#define BEZIER_OPTIM_CIRCLE 0.551915024494f + +/* Draw lines for control points of Bezier curves */ +#define BEZIER_DBG_CONTROL_POINTS 0 + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Fills vg_lite_buffer_t structure according given parameters. + * + * @param[in/out] vgbuf Buffer structure to be filled + * @param[in] width Width of buffer in pixels + * @param[in] height Height of buffer in pixels + * @param[in] stride Stride of the buffer in bytes + * @param[in] ptr Pointer to the buffer (must be aligned according VG-Lite requirements) + * @param[in] source Boolean to check if this is a source buffer + */ +lv_res_t lv_vglite_init_buf(vg_lite_buffer_t * vgbuf, uint32_t width, uint32_t height, uint32_t stride, + const lv_color_t * ptr, bool source); + +#if BLIT_DBG_AREAS +/** + * Draw a simple rectangle, 1 px line width. + * + * @param dest_buf Destination buffer + * @param dest_width Destination buffer width (must be aligned on 16px) + * @param dest_height Destination buffer height + * @param fill_area Rectangle coordinates + * @param color Rectangle color + */ +void lv_vglite_dbg_draw_rectangle(lv_color_t * dest_buf, lv_coord_t dest_width, lv_coord_t dest_height, + lv_area_t * fill_area, lv_color_t color); +#endif + +/** + * Clean & invalidate cache. + */ +void lv_vglite_invalidate_cache(void); + +/********************** + * MACROS + **********************/ + +#define VG_LITE_COND_STOP(cond, txt) \ + do { \ + if (cond) { \ + LV_LOG_ERROR("%s. STOP!", txt); \ + for ( ; ; ); \ + } \ + } while(0) + +#if LV_GPU_NXP_VG_LITE_LOG_ERRORS +#define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \ + do { \ + if(err != VG_LITE_SUCCESS) { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + return LV_RES_INV; \ + } \ + } while (0) +#else +#define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \ + do { \ + if(err != VG_LITE_SUCCESS) { \ + return LV_RES_INV; \ + } \ + }while(0) +#endif /*LV_GPU_NXP_VG_LITE_LOG_ERRORS*/ + +#if LV_GPU_NXP_VG_LITE_LOG_TRACES +#define VG_LITE_LOG_TRACE(fmt, ...) \ + do { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + } while (0) + +#define VG_LITE_RETURN_INV(fmt, ...) \ + do { \ + LV_LOG_ERROR(fmt, ##__VA_ARGS__); \ + return LV_RES_INV; \ + } while (0) +#else +#define VG_LITE_LOG_TRACE(fmt, ...) \ + do { \ + } while (0) +#define VG_LITE_RETURN_INV(fmt, ...) \ + do { \ + return LV_RES_INV; \ + }while(0) +#endif /*LV_GPU_NXP_VG_LITE_LOG_TRACES*/ + +#endif /*LV_USE_GPU_NXP_VG_LITE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_NXP_VGLITE_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl.h b/include/liblvgl/draw/sdl/lv_draw_sdl.h new file mode 100644 index 00000000..7708d5b7 --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl.h @@ -0,0 +1,96 @@ +/** + * @file lv_draw_sdl.h + * + */ + +#ifndef LV_DRAW_SDL_H +#define LV_DRAW_SDL_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "../lv_draw.h" +#include "../../core/lv_disp.h" + +/********************* + * DEFINES + *********************/ + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +#define LV_DRAW_SDL_TEXTURE_FORMAT SDL_PIXELFORMAT_ARGB8888 +#else +#define LV_DRAW_SDL_TEXTURE_FORMAT SDL_PIXELFORMAT_RGBA8888 +#endif + +/********************** + * TYPEDEFS + **********************/ + +struct lv_draw_sdl_context_internals_t; + +typedef struct { + /** + * Render for display driver + */ + SDL_Renderer * renderer; + void * user_data; +} lv_draw_sdl_drv_param_t; + +typedef struct { + lv_draw_ctx_t base_draw; + SDL_Renderer * renderer; + struct lv_draw_sdl_context_internals_t * internals; +} lv_draw_sdl_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_sdl_init_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); + +/** + * @brief Free caches + * + */ +void lv_draw_sdl_deinit_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); + +SDL_Texture * lv_draw_sdl_create_screen_texture(SDL_Renderer * renderer, lv_coord_t hor, lv_coord_t ver); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_composite.h b/include/liblvgl/draw/sdl/lv_draw_sdl_composite.h new file mode 100644 index 00000000..3a598d76 --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_composite.h @@ -0,0 +1,73 @@ +/** + * @file lv_draw_sdl_composite.h + * + */ + +#ifndef LV_DRAW_SDL_COMPOSITE_H +#define LV_DRAW_SDL_COMPOSITE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "lv_draw_sdl.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_color.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef enum lv_draw_sdl_composite_texture_id_t { + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM0, + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1, + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0, + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET1, + LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TRANSFORM0, +} lv_draw_sdl_composite_texture_id_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Begin drawing with mask. Render target will be switched to a temporary texture, + * and drawing coordinates may get clipped or translated + * @param coords_in Original coordinates + * @param clip_in Original clip area + * @param extension Useful for shadows or outlines, can be NULL + * @param coords_out Translated coords + * @param clip_out Translated clip area + * @param apply_area Area of actual composited texture will be drawn + * @return true if there are any mask needs to be drawn, false otherwise + */ +bool lv_draw_sdl_composite_begin(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords_in, const lv_area_t * clip_in, + const lv_area_t * extension, lv_blend_mode_t blend_mode, lv_area_t * coords_out, + lv_area_t * clip_out, lv_area_t * apply_area); + +void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_area, lv_blend_mode_t blend_mode); + +SDL_Texture * lv_draw_sdl_composite_texture_obtain(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_composite_texture_id_t id, + lv_coord_t w, lv_coord_t h); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_COMPOSITE_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_img.h b/include/liblvgl/draw/sdl/lv_draw_sdl_img.h new file mode 100644 index 00000000..d6e3758c --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_img.h @@ -0,0 +1,72 @@ +/** + * @file lv_draw_sdl_img.h + * + */ + +#ifndef LV_DRAW_SDL_IMG_H +#define LV_DRAW_SDL_IMG_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "../lv_draw.h" + +#include "lv_draw_sdl_texture_cache.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct lv_draw_sdl_img_header_t { + lv_img_header_t base; + SDL_Rect rect; +} lv_draw_sdl_img_header_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ +bool lv_draw_sdl_img_load_texture(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_cache_key_head_img_t * key, size_t key_size, + const void * src, int32_t frame_id, SDL_Texture ** texture, + lv_draw_sdl_img_header_t ** header); +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_IMG_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_layer.h b/include/liblvgl/draw/sdl/lv_draw_sdl_layer.h new file mode 100644 index 00000000..b60303c4 --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_layer.h @@ -0,0 +1,55 @@ +/** + * @file lv_draw_sdl_refr.h + * + */ + +#ifndef LV_TEMPL_H +#define LV_TEMPL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_sdl.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct _lv_draw_sdl_layer_ctx_t { + lv_draw_layer_ctx_t base; + + SDL_Texture * orig_target; + SDL_Texture * target; + SDL_Rect target_rect; + lv_draw_layer_flags_t flags; +} lv_draw_sdl_layer_ctx_t; +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_draw_layer_ctx_t * lv_draw_sdl_layer_init(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + +void lv_draw_sdl_layer_blend(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * transform_ctx, + const lv_draw_img_dsc_t * draw_dsc); + +void lv_draw_sdl_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx); + +void lv_draw_sdl_transform_areas_offset(lv_draw_sdl_ctx_t * ctx, bool has_composite, lv_area_t * apply_area, + lv_area_t * coords, lv_area_t * clip); +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TEMPL_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_mask.h b/include/liblvgl/draw/sdl/lv_draw_sdl_mask.h new file mode 100644 index 00000000..aa4dd2b8 --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_mask.h @@ -0,0 +1,51 @@ +/** + * @file lv_draw_sdl_mask.h + * + */ + +#ifndef LV_DRAW_SDL_MASK_H +#define LV_DRAW_SDL_MASK_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "lv_draw_sdl.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_color.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_opa_t * lv_draw_sdl_mask_dump_opa(const lv_area_t * coords, const int16_t * ids, int16_t ids_count); + +SDL_Texture * lv_draw_sdl_mask_dump_texture(SDL_Renderer * renderer, const lv_area_t * coords, const int16_t * ids, + int16_t ids_count); + + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_MASK_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_priv.h b/include/liblvgl/draw/sdl/lv_draw_sdl_priv.h new file mode 100644 index 00000000..736fe89f --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_priv.h @@ -0,0 +1,72 @@ +/** + * @file lv_draw_sdl_priv.h + * + */ + +#ifndef LV_DRAW_SDL_PRIV_H +#define LV_DRAW_SDL_PRIV_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "../lv_draw.h" +#include "../../misc/lv_lru.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct lv_draw_sdl_context_internals_t { + lv_lru_t * texture_cache; + SDL_Texture * mask; + SDL_Texture * composition; + SDL_Texture * target_backup; + uint8_t transform_count; +} lv_draw_sdl_context_internals_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_PRIV_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_rect.h b/include/liblvgl/draw/sdl/lv_draw_sdl_rect.h new file mode 100644 index 00000000..fc968945 --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_rect.h @@ -0,0 +1,75 @@ +/** + * @file lv_draw_sdl_rect.h + * + */ + +#ifndef LV_DRAW_SDL_RECT_H +#define LV_DRAW_SDL_RECT_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH + +#include "../lv_draw.h" + +#include "lv_draw_sdl_texture_cache.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct lv_draw_sdl_rect_header_t { + lv_img_header_t base; + SDL_Rect rect; +} lv_draw_sdl_rect_header_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ + +SDL_Texture * lv_draw_sdl_rect_bg_frag_obtain(lv_draw_sdl_ctx_t * ctx, lv_coord_t radius); + +void lv_draw_sdl_rect_bg_frag_draw_corners(lv_draw_sdl_ctx_t * ctx, SDL_Texture * frag, lv_coord_t frag_size, + const lv_area_t * coords, const lv_area_t * clip, bool full); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_RECT_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_stack_blur.h b/include/liblvgl/draw/sdl/lv_draw_sdl_stack_blur.h new file mode 100644 index 00000000..3d854e3a --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_stack_blur.h @@ -0,0 +1,46 @@ +/** + * @file lv_draw_sdl_stack_blur.h + * + */ +#ifndef LV_DRAW_SDL_STACK_BLUR_H +#define LV_DRAW_SDL_STACK_BLUR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include "../../misc/lv_color.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_stack_blur_grayscale(lv_opa_t * buf, uint16_t w, uint16_t h, uint16_t r); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_STACK_BLUR_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_texture_cache.h b/include/liblvgl/draw/sdl/lv_draw_sdl_texture_cache.h new file mode 100644 index 00000000..0b54246f --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_texture_cache.h @@ -0,0 +1,102 @@ +/** + * @file lv_draw_sdl_texture_cache.h + * + */ + +#ifndef LV_DRAW_SDL_TEXTURE_CACHE_H +#define LV_DRAW_SDL_TEXTURE_CACHE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_GPU_SDL + +#include LV_GPU_SDL_INCLUDE_PATH +#include "lv_draw_sdl.h" +#include "lv_draw_sdl_priv.h" +#include "../../draw/lv_img_decoder.h" +#include "../../misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +#define LV_DRAW_SDL_DEC_DSC_TEXTURE_HEAD "@LVSDLTex" + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + char head[8]; + SDL_Texture * texture; + SDL_Rect rect; + bool texture_managed; + bool texture_referenced; +} lv_draw_sdl_dec_dsc_userdata_t; + +typedef enum { + LV_GPU_CACHE_KEY_MAGIC_ARC = 0x01, + LV_GPU_CACHE_KEY_MAGIC_IMG = 0x11, + LV_GPU_CACHE_KEY_MAGIC_IMG_ROUNDED_CORNERS = 0x12, + LV_GPU_CACHE_KEY_MAGIC_LINE = 0x21, + LV_GPU_CACHE_KEY_MAGIC_RECT_BG = 0x31, + LV_GPU_CACHE_KEY_MAGIC_RECT_SHADOW = 0x32, + LV_GPU_CACHE_KEY_MAGIC_RECT_BORDER = 0x33, + LV_GPU_CACHE_KEY_MAGIC_FONT_GLYPH = 0x41, + LV_GPU_CACHE_KEY_MAGIC_MASK = 0x51, +} lv_sdl_cache_key_magic_t; + +typedef enum { + LV_DRAW_SDL_CACHE_FLAG_NONE = 0, + LV_DRAW_SDL_CACHE_FLAG_MANAGED = 1, +} lv_draw_sdl_cache_flag_t; + +typedef struct { + lv_sdl_cache_key_magic_t magic; + lv_img_src_t type; + int32_t frame_id; +} lv_draw_sdl_cache_key_head_img_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_sdl_texture_cache_init(lv_draw_sdl_ctx_t * ctx); + +void lv_draw_sdl_texture_cache_deinit(lv_draw_sdl_ctx_t * ctx); + +/** + * Find cached texture by key. The texture can be destroyed during usage. + */ +SDL_Texture * lv_draw_sdl_texture_cache_get(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, bool * found); + +SDL_Texture * lv_draw_sdl_texture_cache_get_with_userdata(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, + bool * found, void ** userdata); + +void lv_draw_sdl_texture_cache_put(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, SDL_Texture * texture); + +void lv_draw_sdl_texture_cache_put_advanced(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, + SDL_Texture * texture, void * userdata, void userdata_free(void *), + lv_draw_sdl_cache_flag_t flags); + +lv_draw_sdl_cache_key_head_img_t * lv_draw_sdl_texture_img_key_create(const void * src, int32_t frame_id, + size_t * size); + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_GPU_SDL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_TEXTURE_CACHE_H*/ diff --git a/include/liblvgl/draw/sdl/lv_draw_sdl_utils.h b/include/liblvgl/draw/sdl/lv_draw_sdl_utils.h new file mode 100644 index 00000000..943bda3b --- /dev/null +++ b/include/liblvgl/draw/sdl/lv_draw_sdl_utils.h @@ -0,0 +1,65 @@ +/** + * @file lv_draw_sdl_utils.h + * + */ +#ifndef LV_DRAW_SDL_UTILS_H +#define LV_DRAW_SDL_UTILS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_GPU_SDL + +#include "lv_draw_sdl.h" +#include "../../misc/lv_color.h" +#include "../../misc/lv_area.h" + +#include LV_GPU_SDL_INCLUDE_PATH + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void _lv_draw_sdl_utils_init(); + +void _lv_draw_sdl_utils_deinit(); + +void lv_area_to_sdl_rect(const lv_area_t * in, SDL_Rect * out); + +void lv_color_to_sdl_color(const lv_color_t * in, SDL_Color * out); + +void lv_area_zoom_to_sdl_rect(const lv_area_t * in, SDL_Rect * out, uint16_t zoom, const lv_point_t * pivot); + +SDL_Palette * lv_sdl_alloc_palette_for_bpp(const uint8_t * mapping, uint8_t bpp); + +SDL_Surface * lv_sdl_create_opa_surface(lv_opa_t * opa, lv_coord_t width, lv_coord_t height, lv_coord_t stride); + +SDL_Texture * lv_sdl_create_opa_texture(SDL_Renderer * renderer, lv_opa_t * pixels, lv_coord_t width, + lv_coord_t height, lv_coord_t stride); + +void lv_sdl_to_8bpp(uint8_t * dest, const uint8_t * src, int width, int height, int stride, uint8_t bpp); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SDL*/ +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SDL_UTILS_H*/ diff --git a/include/liblvgl/draw/stm32_dma2d/lv_gpu_stm32_dma2d.h b/include/liblvgl/draw/stm32_dma2d/lv_gpu_stm32_dma2d.h new file mode 100644 index 00000000..f2bcdbea --- /dev/null +++ b/include/liblvgl/draw/stm32_dma2d/lv_gpu_stm32_dma2d.h @@ -0,0 +1,70 @@ +/** + * @file lv_gpu_stm32_dma2d.h + * + */ + +#ifndef LV_GPU_STM32_DMA2D_H +#define LV_GPU_STM32_DMA2D_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/hal/lv_hal_disp.h" +#include "liblvgl/draw/sw/lv_draw_sw.h" + +#if LV_USE_GPU_STM32_DMA2D + +/********************* + * DEFINES + *********************/ + +#define LV_DMA2D_ARGB8888 0 +#define LV_DMA2D_RGB888 1 +#define LV_DMA2D_RGB565 2 +#define LV_DMA2D_ARGB1555 3 +#define LV_DMA2D_ARGB4444 4 + +/********************** + * TYPEDEFS + **********************/ +typedef lv_draw_sw_ctx_t lv_draw_stm32_dma2d_ctx_t; + +struct _lv_disp_drv_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Turn on the peripheral and set output color mode, this only needs to be done once + */ +void lv_draw_stm32_dma2d_init(void); + +void lv_draw_stm32_dma2d_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_stm32_dma2d_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_stm32_dma2d_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); + +void lv_draw_stm32_dma2d_buffer_copy(lv_draw_ctx_t * draw_ctx, + void * dest_buf, lv_coord_t dest_stride, const lv_area_t * dest_area, + void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area); + +void lv_gpu_stm32_dma2d_wait_cb(lv_draw_ctx_t * draw_ctx); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_STM32_DMA2D*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_STM32_DMA2D_H*/ diff --git a/include/liblvgl/draw/sw/lv_draw_sw.h b/include/liblvgl/draw/sw/lv_draw_sw.h new file mode 100644 index 00000000..4496612d --- /dev/null +++ b/include/liblvgl/draw/sw/lv_draw_sw.h @@ -0,0 +1,104 @@ +/** + * @file lv_draw_sw.h + * + */ + +#ifndef LV_DRAW_SW_H +#define LV_DRAW_SW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_sw_blend.h" +#include "liblvgl/draw/lv_draw.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/hal/lv_hal_disp.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_disp_drv_t; + +typedef struct { + lv_draw_ctx_t base_draw; + + /** Fill an area of the destination buffer with a color*/ + void (*blend)(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); +} lv_draw_sw_ctx_t; + +typedef struct { + lv_draw_layer_ctx_t base_draw; + + uint32_t buf_size_bytes: 31; + uint32_t has_alpha : 1; +} lv_draw_sw_layer_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_draw_sw_init_ctx(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); +void lv_draw_sw_deinit_ctx(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_sw_wait_for_finish(lv_draw_ctx_t * draw_ctx); + +void lv_draw_sw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center, uint16_t radius, + uint16_t start_angle, uint16_t end_angle); + +void lv_draw_sw_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); + +void lv_draw_sw_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords); +void lv_draw_sw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p, + uint32_t letter); + +LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_img_decoded(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * draw_dsc, + const lv_area_t * coords, const uint8_t * src_buf, lv_img_cf_t cf); + +LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_line(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, + const lv_point_t * point1, const lv_point_t * point2); + +void lv_draw_sw_polygon(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, + const lv_point_t * points, uint16_t point_cnt); + +void lv_draw_sw_buffer_copy(lv_draw_ctx_t * draw_ctx, + void * dest_buf, lv_coord_t dest_stride, const lv_area_t * dest_area, + void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area); + +void lv_draw_sw_transform(lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf, + lv_coord_t src_w, lv_coord_t src_h, lv_coord_t src_stride, + const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf); + +struct _lv_draw_layer_ctx_t * lv_draw_sw_layer_create(struct _lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + +void lv_draw_sw_layer_adjust(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + lv_draw_layer_flags_t flags); + +void lv_draw_sw_layer_blend(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, + const lv_draw_img_dsc_t * draw_dsc); + +void lv_draw_sw_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx); + +/*********************** + * GLOBAL VARIABLES + ***********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SW_H*/ diff --git a/include/liblvgl/draw/sw/lv_draw_sw_blend.h b/include/liblvgl/draw/sw/lv_draw_sw_blend.h new file mode 100644 index 00000000..6fa859c9 --- /dev/null +++ b/include/liblvgl/draw/sw/lv_draw_sw_blend.h @@ -0,0 +1,69 @@ +/** + * @file lv_draw_sw_blend.h + * + */ + +#ifndef LV_DRAW_SW_BLEND_H +#define LV_DRAW_SW_BLEND_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_style.h" +#include "liblvgl/draw/lv_draw_mask.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + const lv_area_t * blend_area; /**< The area with absolute coordinates to draw on `draw_ctx->buf` + * will be clipped to `draw_ctx->clip_area` */ + const lv_color_t * src_buf; /**< Pointer to an image to blend. If set `fill_color` is ignored */ + lv_color_t color; /**< Fill color*/ + lv_opa_t * mask_buf; /**< NULL if ignored, or an alpha mask to apply on `blend_area`*/ + lv_draw_mask_res_t mask_res; /**< The result of the previous mask operation */ + const lv_area_t * mask_area; /**< The area of `mask_buf` with absolute coordinates*/ + lv_opa_t opa; /**< The overall opacity*/ + lv_blend_mode_t blend_mode; /**< E.g. LV_BLEND_MODE_ADDITIVE*/ +} lv_draw_sw_blend_dsc_t; + +struct _lv_draw_ctx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Call the blend function of the `draw_ctx`. + * @param draw_ctx pointer to a draw context + * @param dsc pointer to an initialized blend descriptor + */ +void lv_draw_sw_blend(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); + +/** + * The basic blend function used with software rendering. + * @param draw_ctx pointer to a draw context + * @param dsc pointer to an initialized blend descriptor + */ +LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_blend_basic(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SW_BLEND_H*/ diff --git a/include/liblvgl/draw/sw/lv_draw_sw_dither.h b/include/liblvgl/draw/sw/lv_draw_sw_dither.h new file mode 100644 index 00000000..9785e187 --- /dev/null +++ b/include/liblvgl/draw/sw/lv_draw_sw_dither.h @@ -0,0 +1,70 @@ +/** + * @file lv_draw_sw_dither.h + * + */ + +#ifndef LV_DRAW_SW_DITHER_H +#define LV_DRAW_SW_DITHER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj_pos.h" + + +/********************* + * DEFINES + *********************/ +#if LV_COLOR_DEPTH < 32 && LV_DITHER_GRADIENT == 1 +#define _DITHER_GRADIENT 1 +#else +#define _DITHER_GRADIENT 0 +#endif + +/********************** + * TYPEDEFS + **********************/ +#if _DITHER_GRADIENT +/*A signed error color component*/ +typedef struct { + int8_t r, g, b; +} lv_scolor24_t; + +struct _lv_gradient_cache_t; +typedef void (*lv_dither_func_t)(struct _lv_gradient_cache_t * grad, lv_coord_t x, lv_coord_t y, lv_coord_t w); + +#endif + + +/********************** + * PROTOTYPES + **********************/ +#if LV_DRAW_COMPLEX +#if _DITHER_GRADIENT +LV_ATTRIBUTE_FAST_MEM void lv_dither_none(struct _lv_gradient_cache_t * grad, lv_coord_t x, lv_coord_t y, lv_coord_t w); + +LV_ATTRIBUTE_FAST_MEM void lv_dither_ordered_hor(struct _lv_gradient_cache_t * grad, const lv_coord_t xs, + const lv_coord_t y, const lv_coord_t w); +LV_ATTRIBUTE_FAST_MEM void lv_dither_ordered_ver(struct _lv_gradient_cache_t * grad, const lv_coord_t xs, + const lv_coord_t y, const lv_coord_t w); + +#if LV_DITHER_ERROR_DIFFUSION == 1 +LV_ATTRIBUTE_FAST_MEM void lv_dither_err_diff_hor(struct _lv_gradient_cache_t * grad, const lv_coord_t xs, + const lv_coord_t y, const lv_coord_t w); +LV_ATTRIBUTE_FAST_MEM void lv_dither_err_diff_ver(struct _lv_gradient_cache_t * grad, const lv_coord_t xs, + const lv_coord_t y, const lv_coord_t w); +#endif /* LV_DITHER_ERROR_DIFFUSION */ + +#endif /* _DITHER_GRADIENT */ +#endif + + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/liblvgl/draw/sw/lv_draw_sw_gradient.h b/include/liblvgl/draw/sw/lv_draw_sw_gradient.h new file mode 100644 index 00000000..0860d50d --- /dev/null +++ b/include/liblvgl/draw/sw/lv_draw_sw_gradient.h @@ -0,0 +1,97 @@ +/** + * @file lv_draw_sw_gradient.h + * + */ + +#ifndef LV_DRAW_SW_GRADIENT_H +#define LV_DRAW_SW_GRADIENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_style.h" +#include "lv_draw_sw_dither.h" + +/********************* + * DEFINES + *********************/ +#if LV_GRADIENT_MAX_STOPS < 2 +#error LVGL needs at least 2 stops for gradients. Please increase the LV_GRADIENT_MAX_STOPS +#endif + + +/********************** + * TYPEDEFS + **********************/ +#if _DITHER_GRADIENT +typedef lv_color32_t lv_grad_color_t; +#else +typedef lv_color_t lv_grad_color_t; +#endif + +/** To avoid recomputing gradient for each draw operation, + * it's possible to cache the computation in this structure instance. + * Whenever possible, this structure is reused instead of recomputing the gradient map */ +typedef struct _lv_gradient_cache_t { + uint32_t key; /**< A discriminating key that's built from the drawing operation. + * If the key does not match, the cache item is not used */ + uint32_t life : 30; /**< A life counter that's incremented on usage. Higher counter is + * less likely to be evicted from the cache */ + uint32_t filled : 1; /**< Used to skip dithering in it if already done */ + uint32_t not_cached: 1; /**< The cache was too small so this item is not managed by the cache*/ + lv_color_t * map; /**< The computed gradient low bitdepth color map, points into the + * cache's buffer, no free needed */ + lv_coord_t alloc_size; /**< The map allocated size in colors */ + lv_coord_t size; /**< The computed gradient color map size, in colors */ +#if _DITHER_GRADIENT + lv_color32_t * hmap; /**< If dithering, we need to store the current, high bitdepth gradient + * map too, points to the cache's buffer, no free needed */ +#if LV_DITHER_ERROR_DIFFUSION == 1 + lv_scolor24_t * error_acc; /**< Error diffusion dithering algorithm requires storing the last error + * drawn, points to the cache's buffer, no free needed */ + lv_coord_t w; /**< The error array width in pixels */ +#endif +#endif +} lv_grad_t; + + +/********************** + * PROTOTYPES + **********************/ +/** Compute the color in the given gradient and fraction + * Gradient are specified in a virtual [0-255] range, so this function scales the virtual range to the given range + * @param dsc The gradient descriptor to use + * @param range The range to use in computation. + * @param frac The current part used in the range. frac is in [0; range] + */ +LV_ATTRIBUTE_FAST_MEM lv_grad_color_t lv_gradient_calculate(const lv_grad_dsc_t * dsc, lv_coord_t range, + lv_coord_t frac); + +/** + * Set the gradient cache size + * @param max_bytes Max cahce size + */ +void lv_gradient_set_cache_size(size_t max_bytes); + +/** Free the gradient cache */ +void lv_gradient_free_cache(void); + +/** Get a gradient cache from the given parameters */ +lv_grad_t * lv_gradient_get(const lv_grad_dsc_t * gradient, lv_coord_t w, lv_coord_t h); + +/** + * Clean up the gradient item after it was get with `lv_grad_get_from_cache`. + * @param grad pointer to a gradient + */ +void lv_gradient_cleanup(lv_grad_t * grad); + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_GRADIENT_H*/ diff --git a/include/liblvgl/draw/swm341_dma2d/lv_gpu_swm341_dma2d.h b/include/liblvgl/draw/swm341_dma2d/lv_gpu_swm341_dma2d.h new file mode 100644 index 00000000..baec7fea --- /dev/null +++ b/include/liblvgl/draw/swm341_dma2d/lv_gpu_swm341_dma2d.h @@ -0,0 +1,64 @@ +/** + * @file lv_gpu_swm341_dma2d.h + * + */ + +#ifndef LV_GPU_SWM341_DMA2D_H +#define LV_GPU_SWM341_DMA2D_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/hal/lv_hal_disp.h" +#include "liblvgl/draw/sw/lv_draw_sw.h" + +#if LV_USE_GPU_SWM341_DMA2D + +/********************* + * DEFINES + *********************/ + +#define LV_SWM341_DMA2D_ARGB8888 0 +#define LV_SWM341_DMA2D_RGB888 1 +#define LV_SWM341_DMA2D_RGB565 2 + +/********************** + * TYPEDEFS + **********************/ +typedef lv_draw_sw_ctx_t lv_draw_swm341_dma2d_ctx_t; + +struct _lv_disp_drv_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Turn on the peripheral and set output color mode, this only needs to be done once + */ +void lv_draw_swm341_dma2d_init(void); + +void lv_draw_swm341_dma2d_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_swm341_dma2d_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx); + +void lv_draw_swm341_dma2d_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc); + +void lv_gpu_swm341_dma2d_wait_cb(lv_draw_ctx_t * draw_ctx); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GPU_SWM341_DMA2D*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GPU_SWM341_DMA2D_H*/ diff --git a/include/liblvgl/extra/layouts/flex/lv_flex.h b/include/liblvgl/extra/layouts/flex/lv_flex.h new file mode 100644 index 00000000..d9619610 --- /dev/null +++ b/include/liblvgl/extra/layouts/flex/lv_flex.h @@ -0,0 +1,152 @@ +/** + * @file lv_flex.h + * + */ + +#ifndef LV_FLEX_H +#define LV_FLEX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_FLEX + +/********************* + * DEFINES + *********************/ + +#define LV_OBJ_FLAG_FLEX_IN_NEW_TRACK LV_OBJ_FLAG_LAYOUT_1 +LV_EXPORT_CONST_INT(LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); + +#define _LV_FLEX_COLUMN (1 << 0) +#define _LV_FLEX_WRAP (1 << 2) +#define _LV_FLEX_REVERSE (1 << 3) + +/********************** + * TYPEDEFS + **********************/ + +/*Can't include lv_obj.h because it includes this header file*/ +struct _lv_obj_t; + +typedef enum { + LV_FLEX_ALIGN_START, + LV_FLEX_ALIGN_END, + LV_FLEX_ALIGN_CENTER, + LV_FLEX_ALIGN_SPACE_EVENLY, + LV_FLEX_ALIGN_SPACE_AROUND, + LV_FLEX_ALIGN_SPACE_BETWEEN, +} lv_flex_align_t; + +typedef enum { + LV_FLEX_FLOW_ROW = 0x00, + LV_FLEX_FLOW_COLUMN = _LV_FLEX_COLUMN, + LV_FLEX_FLOW_ROW_WRAP = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP, + LV_FLEX_FLOW_ROW_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_REVERSE, + LV_FLEX_FLOW_ROW_WRAP_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, + LV_FLEX_FLOW_COLUMN_WRAP = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP, + LV_FLEX_FLOW_COLUMN_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_REVERSE, + LV_FLEX_FLOW_COLUMN_WRAP_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, +} lv_flex_flow_t; + +/********************** + * GLOBAL VARIABLES + **********************/ +extern uint16_t LV_LAYOUT_FLEX; +extern lv_style_prop_t LV_STYLE_FLEX_FLOW; +extern lv_style_prop_t LV_STYLE_FLEX_MAIN_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_CROSS_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_TRACK_PLACE; +extern lv_style_prop_t LV_STYLE_FLEX_GROW; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize a flex layout the default values + * @param flex pointer to a flex layout descriptor + */ +void lv_flex_init(void); + +/** + * Set hot the item should flow + * @param flex pointer to a flex layout descriptor + * @param flow an element of `lv_flex_flow_t`. + */ +void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow); + +/** + * Set how to place (where to align) the items and tracks + * @param flex pointer: to a flex layout descriptor + * @param main_place where to place the items on main axis (in their track). Any value of `lv_flex_align_t`. + * @param cross_place where to place the item in their track on the cross axis. `LV_FLEX_ALIGN_START/END/CENTER` + * @param track_place where to place the tracks in the cross direction. Any value of `lv_flex_align_t`. + */ +void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place, + lv_flex_align_t track_cross_place); + +/** + * Sets the width or height (on main axis) to grow the object in order fill the free space + * @param obj pointer to an object. The parent must have flex layout else nothing will happen. + * @param grow a value to set how much free space to take proportionally to other growing items. + */ +void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow); + +void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value); +void lv_style_set_flex_main_place(lv_style_t * style, lv_flex_align_t value); +void lv_style_set_flex_cross_place(lv_style_t * style, lv_flex_align_t value); +void lv_style_set_flex_track_place(lv_style_t * style, lv_flex_align_t value); +void lv_style_set_flex_grow(lv_style_t * style, uint8_t value); +void lv_obj_set_style_flex_flow(lv_obj_t * obj, lv_flex_flow_t value, lv_style_selector_t selector); +void lv_obj_set_style_flex_main_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_flex_cross_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_flex_track_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_flex_grow(lv_obj_t * obj, uint8_t value, lv_style_selector_t selector); + +static inline lv_flex_flow_t lv_obj_get_style_flex_flow(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_FLOW); + return (lv_flex_flow_t)v.num; +} + +static inline lv_flex_align_t lv_obj_get_style_flex_main_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_MAIN_PLACE); + return (lv_flex_align_t)v.num; +} + +static inline lv_flex_align_t lv_obj_get_style_flex_cross_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_CROSS_PLACE); + return (lv_flex_align_t)v.num; +} + +static inline lv_flex_align_t lv_obj_get_style_flex_track_place(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_TRACK_PLACE); + return (lv_flex_align_t)v.num; +} + +static inline uint8_t lv_obj_get_style_flex_grow(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_GROW); + return (uint8_t)v.num; +} + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_FLEX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FLEX_H*/ diff --git a/include/liblvgl/extra/layouts/grid/lv_grid.h b/include/liblvgl/extra/layouts/grid/lv_grid.h new file mode 100644 index 00000000..8e57fd9c --- /dev/null +++ b/include/liblvgl/extra/layouts/grid/lv_grid.h @@ -0,0 +1,194 @@ +/** + * @file lv_grid.h + * + */ + +#ifndef LV_GRID_H +#define LV_GRID_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_GRID + +/********************* + * DEFINES + *********************/ +/** + * Can be used track size to make the track fill the free space. + * @param x how much space to take proportionally to other FR tracks + * @return a special track size + */ +#define LV_GRID_FR(x) (LV_COORD_MAX - 100 + x) + +#define LV_GRID_CONTENT (LV_COORD_MAX - 101) +LV_EXPORT_CONST_INT(LV_GRID_CONTENT); + +#define LV_GRID_TEMPLATE_LAST (LV_COORD_MAX) +LV_EXPORT_CONST_INT(LV_GRID_TEMPLATE_LAST); + +/********************** + * TYPEDEFS + **********************/ + +/*Can't include lv_obj.h because it includes this header file*/ +struct _lv_obj_t; + +typedef enum { + LV_GRID_ALIGN_START, + LV_GRID_ALIGN_CENTER, + LV_GRID_ALIGN_END, + LV_GRID_ALIGN_STRETCH, + LV_GRID_ALIGN_SPACE_EVENLY, + LV_GRID_ALIGN_SPACE_AROUND, + LV_GRID_ALIGN_SPACE_BETWEEN, +} lv_grid_align_t; + +/********************** + * GLOBAL VARIABLES + **********************/ + +extern uint16_t LV_LAYOUT_GRID; +extern lv_style_prop_t LV_STYLE_GRID_COLUMN_DSC_ARRAY; +extern lv_style_prop_t LV_STYLE_GRID_COLUMN_ALIGN; +extern lv_style_prop_t LV_STYLE_GRID_ROW_DSC_ARRAY; +extern lv_style_prop_t LV_STYLE_GRID_ROW_ALIGN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_COLUMN_POS; +extern lv_style_prop_t LV_STYLE_GRID_CELL_COLUMN_SPAN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_X_ALIGN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_POS; +extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_SPAN; +extern lv_style_prop_t LV_STYLE_GRID_CELL_Y_ALIGN; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void lv_grid_init(void); + +void lv_obj_set_grid_dsc_array(lv_obj_t * obj, const lv_coord_t col_dsc[], const lv_coord_t row_dsc[]); + +void lv_obj_set_grid_align(lv_obj_t * obj, lv_grid_align_t column_align, lv_grid_align_t row_align); + +/** + * Set the cell of an object. The object's parent needs to have grid layout, else nothing will happen + * @param obj pointer to an object + * @param column_align the vertical alignment in the cell. `LV_GRID_START/END/CENTER/STRETCH` + * @param col_pos column ID + * @param col_span number of columns to take (>= 1) + * @param row_align the horizontal alignment in the cell. `LV_GRID_START/END/CENTER/STRETCH` + * @param row_pos row ID + * @param row_span number of rows to take (>= 1) + */ +void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_align_t column_align, uint8_t col_pos, uint8_t col_span, + lv_grid_align_t row_align, uint8_t row_pos, uint8_t row_span); + +/** + * Just a wrapper to `LV_GRID_FR` for bindings. + */ +static inline lv_coord_t lv_grid_fr(uint8_t x) +{ + return LV_GRID_FR(x); +} + +void lv_style_set_grid_row_dsc_array(lv_style_t * style, const lv_coord_t value[]); +void lv_style_set_grid_column_dsc_array(lv_style_t * style, const lv_coord_t value[]); +void lv_style_set_grid_row_align(lv_style_t * style, lv_grid_align_t value); +void lv_style_set_grid_column_align(lv_style_t * style, lv_grid_align_t value); +void lv_style_set_grid_cell_column_pos(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_column_span(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_row_pos(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_row_span(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_x_align(lv_style_t * style, lv_coord_t value); +void lv_style_set_grid_cell_y_align(lv_style_t * style, lv_coord_t value); + +void lv_obj_set_style_grid_row_dsc_array(lv_obj_t * obj, const lv_coord_t value[], lv_style_selector_t selector); +void lv_obj_set_style_grid_column_dsc_array(lv_obj_t * obj, const lv_coord_t value[], lv_style_selector_t selector); +void lv_obj_set_style_grid_row_align(lv_obj_t * obj, lv_grid_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_column_align(lv_obj_t * obj, lv_grid_align_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_column_pos(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_column_span(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_row_pos(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_row_span(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_x_align(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); +void lv_obj_set_style_grid_cell_y_align(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); + +static inline const lv_coord_t * lv_obj_get_style_grid_row_dsc_array(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_DSC_ARRAY); + return (const lv_coord_t *)v.ptr; +} + +static inline const lv_coord_t * lv_obj_get_style_grid_column_dsc_array(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COLUMN_DSC_ARRAY); + return (const lv_coord_t *)v.ptr; +} + +static inline lv_grid_align_t lv_obj_get_style_grid_row_align(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_ALIGN); + return (lv_grid_align_t)v.num; +} + +static inline lv_grid_align_t lv_obj_get_style_grid_column_align(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COLUMN_ALIGN); + return (lv_grid_align_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_column_pos(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COLUMN_POS); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_column_span(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COLUMN_SPAN); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_row_pos(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_POS); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_row_span(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_SPAN); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_x_align(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_X_ALIGN); + return (lv_coord_t)v.num; +} + +static inline lv_coord_t lv_obj_get_style_grid_cell_y_align(const lv_obj_t * obj, uint32_t part) +{ + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_Y_ALIGN); + return (lv_coord_t)v.num; +} + +/********************** + * GLOBAL VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_GRID*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GRID_H*/ diff --git a/include/liblvgl/extra/layouts/lv_layouts.h b/include/liblvgl/extra/layouts/lv_layouts.h new file mode 100644 index 00000000..9c1e958d --- /dev/null +++ b/include/liblvgl/extra/layouts/lv_layouts.h @@ -0,0 +1,44 @@ +/** + * @file lv_layouts.h + * + */ + +#ifndef LV_LAYOUTS_H +#define LV_LAYOUTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "flex/lv_flex.h" +#include "grid/lv_grid.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ +#if LV_USE_LOG && LV_LOG_TRACE_LAYOUT +# define LV_TRACE_LAYOUT(...) LV_LOG_TRACE(__VA_ARGS__) +#else +# define LV_TRACE_LAYOUT(...) +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LAYOUTS_H*/ diff --git a/include/liblvgl/extra/libs/bmp/lv_bmp.h b/include/liblvgl/extra/libs/bmp/lv_bmp.h new file mode 100644 index 00000000..3d9e9484 --- /dev/null +++ b/include/liblvgl/extra/libs/bmp/lv_bmp.h @@ -0,0 +1,42 @@ +/** + * @file lv_bmp.h + * + */ + +#ifndef LV_BMP_H +#define LV_BMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_BMP + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void lv_bmp_init(void); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_BMP*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_BMP_H*/ diff --git a/include/liblvgl/extra/libs/ffmpeg/lv_ffmpeg.h b/include/liblvgl/extra/libs/ffmpeg/lv_ffmpeg.h new file mode 100644 index 00000000..f3a365c3 --- /dev/null +++ b/include/liblvgl/extra/libs/ffmpeg/lv_ffmpeg.h @@ -0,0 +1,104 @@ +/** + * @file lv_ffmpeg.h + * + */ +#ifndef LV_FFMPEG_H +#define LV_FFMPEG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" +#if LV_USE_FFMPEG != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct ffmpeg_context_s; + +extern const lv_obj_class_t lv_ffmpeg_player_class; + +typedef struct { + lv_img_t img; + lv_timer_t * timer; + lv_img_dsc_t imgdsc; + bool auto_restart; + struct ffmpeg_context_s * ffmpeg_ctx; +} lv_ffmpeg_player_t; + +typedef enum { + LV_FFMPEG_PLAYER_CMD_START, + LV_FFMPEG_PLAYER_CMD_STOP, + LV_FFMPEG_PLAYER_CMD_PAUSE, + LV_FFMPEG_PLAYER_CMD_RESUME, + _LV_FFMPEG_PLAYER_CMD_LAST +} lv_ffmpeg_player_cmd_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Register FFMPEG image decoder + */ +void lv_ffmpeg_init(void); + +/** + * Get the number of frames contained in the file + * @param path image or video file name + * @return Number of frames, less than 0 means failed + */ +int lv_ffmpeg_get_frame_num(const char * path); + +/** + * Create ffmpeg_player object + * @param parent pointer to an object, it will be the parent of the new player + * @return pointer to the created ffmpeg_player + */ +lv_obj_t * lv_ffmpeg_player_create(lv_obj_t * parent); + +/** + * Set the path of the file to be played + * @param obj pointer to a ffmpeg_player object + * @param path video file path + * @return LV_RES_OK: no error; LV_RES_INV: can't get the info. + */ +lv_res_t lv_ffmpeg_player_set_src(lv_obj_t * obj, const char * path); + +/** + * Set command control video player + * @param obj pointer to a ffmpeg_player object + * @param cmd control commands + */ +void lv_ffmpeg_player_set_cmd(lv_obj_t * obj, lv_ffmpeg_player_cmd_t cmd); + +/** + * Set the video to automatically replay + * @param obj pointer to a ffmpeg_player object + * @param en true: enable the auto restart + */ +void lv_ffmpeg_player_set_auto_restart(lv_obj_t * obj, bool en); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_FFMPEG*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FFMPEG_H*/ diff --git a/include/liblvgl/extra/libs/freetype/lv_freetype.h b/include/liblvgl/extra/libs/freetype/lv_freetype.h new file mode 100644 index 00000000..e576c2e1 --- /dev/null +++ b/include/liblvgl/extra/libs/freetype/lv_freetype.h @@ -0,0 +1,83 @@ +/** + * @file lv_freetype.h + * + */ +#ifndef LV_FREETYPE_H +#define LV_FREETYPE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" +#if LV_USE_FREETYPE + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef enum { + FT_FONT_STYLE_NORMAL = 0, + FT_FONT_STYLE_ITALIC = 1 << 0, + FT_FONT_STYLE_BOLD = 1 << 1 +} LV_FT_FONT_STYLE; + +typedef struct { + const char * name; /* The name of the font file */ + const void * mem; /* The pointer of the font file */ + size_t mem_size; /* The size of the memory */ + lv_font_t * font; /* point to lvgl font */ + uint16_t weight; /* font size */ + uint16_t style; /* font style */ +} lv_ft_info_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * init freetype library + * @param max_faces Maximum number of opened FT_Face objects managed by this cache instance. Use 0 for defaults. + * @param max_sizes Maximum number of opened FT_Size objects managed by this cache instance. Use 0 for defaults. + * @param max_bytes Maximum number of bytes to use for cached data nodes. Use 0 for defaults. + * Note that this value does not account for managed FT_Face and FT_Size objects. + * @return true on success, otherwise false. + */ +bool lv_freetype_init(uint16_t max_faces, uint16_t max_sizes, uint32_t max_bytes); + +/** + * Destroy freetype library + */ +void lv_freetype_destroy(void); + +/** + * Creates a font with info parameter specified. + * @param info See lv_ft_info_t for details. + * when success, lv_ft_info_t->font point to the font you created. + * @return true on success, otherwise false. + */ +bool lv_ft_font_init(lv_ft_info_t * info); + +/** + * Destroy a font that has been created. + * @param font pointer to font. + */ +void lv_ft_font_destroy(lv_font_t * font); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_FREETYPE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* LV_FREETYPE_H */ diff --git a/include/liblvgl/extra/libs/fsdrv/lv_fsdrv.h b/include/liblvgl/extra/libs/fsdrv/lv_fsdrv.h new file mode 100644 index 00000000..2b0adfd0 --- /dev/null +++ b/include/liblvgl/extra/libs/fsdrv/lv_fsdrv.h @@ -0,0 +1,55 @@ +/** + * @file lv_fsdrv.h + * + */ + +#ifndef LV_FSDRV_H +#define LV_FSDRV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +#if LV_USE_FS_FATFS != '\0' +void lv_fs_fatfs_init(void); +#endif + +#if LV_USE_FS_STDIO != '\0' +void lv_fs_stdio_init(void); +#endif + +#if LV_USE_FS_POSIX != '\0' +void lv_fs_posix_init(void); +#endif + +#if LV_USE_FS_WIN32 != '\0' +void lv_fs_win32_init(void); +#endif + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_FSDRV_H*/ + diff --git a/include/liblvgl/extra/libs/gif/gifdec.h b/include/liblvgl/extra/libs/gif/gifdec.h new file mode 100644 index 00000000..eaa4cadd --- /dev/null +++ b/include/liblvgl/extra/libs/gif/gifdec.h @@ -0,0 +1,60 @@ +#ifndef GIFDEC_H +#define GIFDEC_H + +#include +#include "liblvgl/misc/lv_fs.h" + +#if LV_USE_GIF + +typedef struct gd_Palette { + int size; + uint8_t colors[0x100 * 3]; +} gd_Palette; + +typedef struct gd_GCE { + uint16_t delay; + uint8_t tindex; + uint8_t disposal; + int input; + int transparency; +} gd_GCE; + + + +typedef struct gd_GIF { + lv_fs_file_t fd; + const char * data; + uint8_t is_file; + uint32_t f_rw_p; + int32_t anim_start; + uint16_t width, height; + uint16_t depth; + uint16_t loop_count; + gd_GCE gce; + gd_Palette *palette; + gd_Palette lct, gct; + void (*plain_text)( + struct gd_GIF *gif, uint16_t tx, uint16_t ty, + uint16_t tw, uint16_t th, uint8_t cw, uint8_t ch, + uint8_t fg, uint8_t bg + ); + void (*comment)(struct gd_GIF *gif); + void (*application)(struct gd_GIF *gif, char id[8], char auth[3]); + uint16_t fx, fy, fw, fh; + uint8_t bgindex; + uint8_t *canvas, *frame; +} gd_GIF; + +gd_GIF * gd_open_gif_file(const char *fname); + +gd_GIF * gd_open_gif_data(const void *data); + +void gd_render_frame(gd_GIF *gif, uint8_t *buffer); + +int gd_get_frame(gd_GIF *gif); +void gd_rewind(gd_GIF *gif); +void gd_close_gif(gd_GIF *gif); + +#endif /*LV_USE_GIF*/ + +#endif /* GIFDEC_H */ diff --git a/include/liblvgl/extra/libs/gif/lv_gif.h b/include/liblvgl/extra/libs/gif/lv_gif.h new file mode 100644 index 00000000..b40b690a --- /dev/null +++ b/include/liblvgl/extra/libs/gif/lv_gif.h @@ -0,0 +1,58 @@ +/** + * @file lv_gif.h + * + */ + +#ifndef LV_GIF_H +#define LV_GIF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lvgl.h" +#if LV_USE_GIF + +#include "gifdec.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_img_t img; + gd_GIF * gif; + lv_timer_t * timer; + lv_img_dsc_t imgdsc; + uint32_t last_call; +} lv_gif_t; + +extern const lv_obj_class_t lv_gif_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_gif_create(lv_obj_t * parent); +void lv_gif_set_src(lv_obj_t * obj, const void * src); +void lv_gif_restart(lv_obj_t * gif); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_GIF*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_GIF_H*/ diff --git a/include/liblvgl/extra/libs/lv_libs.h b/include/liblvgl/extra/libs/lv_libs.h new file mode 100644 index 00000000..6782b1d0 --- /dev/null +++ b/include/liblvgl/extra/libs/lv_libs.h @@ -0,0 +1,46 @@ +/** + * @file lv_libs.h + * + */ + +#ifndef LV_LIBS_H +#define LV_LIBS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "bmp/lv_bmp.h" +#include "fsdrv/lv_fsdrv.h" +#include "png/lv_png.h" +#include "gif/lv_gif.h" +#include "qrcode/lv_qrcode.h" +#include "sjpg/lv_sjpg.h" +#include "freetype/lv_freetype.h" +#include "rlottie/lv_rlottie.h" +#include "ffmpeg/lv_ffmpeg.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LIBS_H*/ diff --git a/include/liblvgl/extra/libs/png/lodepng.h b/include/liblvgl/extra/libs/png/lodepng.h new file mode 100644 index 00000000..4068d4b1 --- /dev/null +++ b/include/liblvgl/extra/libs/png/lodepng.h @@ -0,0 +1,1981 @@ +/* +LodePNG version 20201017 + +Copyright (c) 2005-2020 Lode Vandevenne + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ + +#ifndef LODEPNG_H +#define LODEPNG_H + +#include /*for size_t*/ + +#include "liblvgl/lvgl.h" +#if LV_USE_PNG +extern const char* LODEPNG_VERSION_STRING; + +/* +The following #defines are used to create code sections. They can be disabled +to disable code sections, which can give faster compile time and smaller binary. +The "NO_COMPILE" defines are designed to be used to pass as defines to the +compiler command to disable them without modifying this header, e.g. +-DLODEPNG_NO_COMPILE_ZLIB for gcc. +In addition to those below, you can also define LODEPNG_NO_COMPILE_CRC to +allow implementing a custom lodepng_crc32. +*/ +/*deflate & zlib. If disabled, you must specify alternative zlib functions in +the custom_zlib field of the compress and decompress settings*/ +#ifndef LODEPNG_NO_COMPILE_ZLIB +#define LODEPNG_COMPILE_ZLIB +#endif + +/*png encoder and png decoder*/ +#ifndef LODEPNG_NO_COMPILE_PNG +#define LODEPNG_COMPILE_PNG +#endif + +/*deflate&zlib decoder and png decoder*/ +#ifndef LODEPNG_NO_COMPILE_DECODER +#define LODEPNG_COMPILE_DECODER +#endif + +/*deflate&zlib encoder and png encoder*/ +#ifndef LODEPNG_NO_COMPILE_ENCODER +#define LODEPNG_COMPILE_ENCODER +#endif + +/*the optional built in harddisk file loading and saving functions*/ +#ifndef LODEPNG_NO_COMPILE_DISK +#define LODEPNG_COMPILE_DISK +#endif + +/*support for chunks other than IHDR, IDAT, PLTE, tRNS, IEND: ancillary and unknown chunks*/ +#ifndef LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS +#define LODEPNG_COMPILE_ANCILLARY_CHUNKS +#endif + +/*ability to convert error numerical codes to English text string*/ +#ifndef LODEPNG_NO_COMPILE_ERROR_TEXT +#define LODEPNG_COMPILE_ERROR_TEXT +#endif + +/*Compile the default allocators (C's free, malloc and realloc). If you disable this, +you can define the functions lodepng_free, lodepng_malloc and lodepng_realloc in your +source files with custom allocators.*/ +#ifndef LODEPNG_NO_COMPILE_ALLOCATORS +#define LODEPNG_COMPILE_ALLOCATORS +#endif + +/*compile the C++ version (you can disable the C++ wrapper here even when compiling for C++)*/ +#ifdef __cplusplus +#ifndef LODEPNG_NO_COMPILE_CPP +#define LODEPNG_COMPILE_CPP +#endif +#endif + +#ifdef LODEPNG_COMPILE_CPP +#include +#include +#endif /*LODEPNG_COMPILE_CPP*/ + +#ifdef LODEPNG_COMPILE_PNG +/*The PNG color types (also used for raw image).*/ +typedef enum LodePNGColorType { + LCT_GREY = 0, /*grayscale: 1,2,4,8,16 bit*/ + LCT_RGB = 2, /*RGB: 8,16 bit*/ + LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/ + LCT_GREY_ALPHA = 4, /*grayscale with alpha: 8,16 bit*/ + LCT_RGBA = 6, /*RGB with alpha: 8,16 bit*/ + /*LCT_MAX_OCTET_VALUE lets the compiler allow this enum to represent any invalid + byte value from 0 to 255 that could be present in an invalid PNG file header. Do + not use, compare with or set the name LCT_MAX_OCTET_VALUE, instead either use + the valid color type names above, or numeric values like 1 or 7 when checking for + particular disallowed color type byte values, or cast to integer to print it.*/ + LCT_MAX_OCTET_VALUE = 255 +} LodePNGColorType; + +#ifdef LODEPNG_COMPILE_DECODER +/* +Converts PNG data in memory to raw pixel data. +out: Output parameter. Pointer to buffer that will contain the raw pixel data. + After decoding, its size is w * h * (bytes per pixel) bytes larger than + initially. Bytes per pixel depends on colortype and bitdepth. + Must be freed after usage with free(*out). + Note: for 16-bit per channel colors, uses big endian format like PNG does. +w: Output parameter. Pointer to width of pixel data. +h: Output parameter. Pointer to height of pixel data. +in: Memory buffer with the PNG file. +insize: size of the in buffer. +colortype: the desired color type for the raw output image. See explanation on PNG color types. +bitdepth: the desired bit depth for the raw output image. See explanation on PNG color types. +Return value: LodePNG error code (0 means no error). +*/ +unsigned lodepng_decode_memory(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_decode_memory, but always decodes to 32-bit RGBA raw image*/ +unsigned lodepng_decode32(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize); + +/*Same as lodepng_decode_memory, but always decodes to 24-bit RGB raw image*/ +unsigned lodepng_decode24(unsigned char** out, unsigned* w, unsigned* h, + const unsigned char* in, size_t insize); + +#ifdef LODEPNG_COMPILE_DISK +/* +Load PNG from disk, from file with given name. +Same as the other decode functions, but instead takes a filename as input. +*/ +unsigned lodepng_decode_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_decode_file, but always decodes to 32-bit RGBA raw image.*/ +unsigned lodepng_decode32_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename); + +/*Same as lodepng_decode_file, but always decodes to 24-bit RGB raw image.*/ +unsigned lodepng_decode24_file(unsigned char** out, unsigned* w, unsigned* h, + const char* filename); +#endif /*LODEPNG_COMPILE_DISK*/ +#endif /*LODEPNG_COMPILE_DECODER*/ + + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Converts raw pixel data into a PNG image in memory. The colortype and bitdepth + of the output PNG image cannot be chosen, they are automatically determined + by the colortype, bitdepth and content of the input pixel data. + Note: for 16-bit per channel colors, needs big endian format like PNG does. +out: Output parameter. Pointer to buffer that will contain the PNG image data. + Must be freed after usage with free(*out). +outsize: Output parameter. Pointer to the size in bytes of the out buffer. +image: The raw pixel data to encode. The size of this buffer should be + w * h * (bytes per pixel), bytes per pixel depends on colortype and bitdepth. +w: width of the raw pixel data in pixels. +h: height of the raw pixel data in pixels. +colortype: the color type of the raw input image. See explanation on PNG color types. +bitdepth: the bit depth of the raw input image. See explanation on PNG color types. +Return value: LodePNG error code (0 means no error). +*/ +unsigned lodepng_encode_memory(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_encode_memory, but always encodes from 32-bit RGBA raw image.*/ +unsigned lodepng_encode32(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h); + +/*Same as lodepng_encode_memory, but always encodes from 24-bit RGB raw image.*/ +unsigned lodepng_encode24(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h); + +#ifdef LODEPNG_COMPILE_DISK +/* +Converts raw pixel data into a PNG file on disk. +Same as the other encode functions, but instead takes a filename as output. +NOTE: This overwrites existing files without warning! +*/ +unsigned lodepng_encode_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h, + LodePNGColorType colortype, unsigned bitdepth); + +/*Same as lodepng_encode_file, but always encodes from 32-bit RGBA raw image.*/ +unsigned lodepng_encode32_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h); + +/*Same as lodepng_encode_file, but always encodes from 24-bit RGB raw image.*/ +unsigned lodepng_encode24_file(const char* filename, + const unsigned char* image, unsigned w, unsigned h); +#endif /*LODEPNG_COMPILE_DISK*/ +#endif /*LODEPNG_COMPILE_ENCODER*/ + + +#ifdef LODEPNG_COMPILE_CPP +namespace lodepng { +#ifdef LODEPNG_COMPILE_DECODER +/*Same as lodepng_decode_memory, but decodes to an std::vector. The colortype +is the format to output the pixels to. Default is RGBA 8-bit per channel.*/ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const unsigned char* in, size_t insize, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::vector& in, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#ifdef LODEPNG_COMPILE_DISK +/* +Converts PNG file from disk to raw pixel data in memory. +Same as the other decode functions, but instead takes a filename as input. +*/ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + const std::string& filename, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_DECODER */ + +#ifdef LODEPNG_COMPILE_ENCODER +/*Same as lodepng_encode_memory, but encodes to an std::vector. colortype +is that of the raw input data. The output PNG color type will be auto chosen.*/ +unsigned encode(std::vector& out, + const unsigned char* in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#ifdef LODEPNG_COMPILE_DISK +/* +Converts 32-bit RGBA raw pixel data into a PNG file on disk. +Same as the other encode functions, but instead takes a filename as output. +NOTE: This overwrites existing files without warning! +*/ +unsigned encode(const std::string& filename, + const unsigned char* in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +unsigned encode(const std::string& filename, + const std::vector& in, unsigned w, unsigned h, + LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_ENCODER */ +} /* namespace lodepng */ +#endif /*LODEPNG_COMPILE_CPP*/ +#endif /*LODEPNG_COMPILE_PNG*/ + +#ifdef LODEPNG_COMPILE_ERROR_TEXT +/*Returns an English description of the numerical error code.*/ +const char* lodepng_error_text(unsigned code); +#endif /*LODEPNG_COMPILE_ERROR_TEXT*/ + +#ifdef LODEPNG_COMPILE_DECODER +/*Settings for zlib decompression*/ +typedef struct LodePNGDecompressSettings LodePNGDecompressSettings; +struct LodePNGDecompressSettings { + /* Check LodePNGDecoderSettings for more ignorable errors such as ignore_crc */ + unsigned ignore_adler32; /*if 1, continue and don't give an error message if the Adler32 checksum is corrupted*/ + unsigned ignore_nlen; /*ignore complement of len checksum in uncompressed blocks*/ + + /*Maximum decompressed size, beyond this the decoder may (and is encouraged to) stop decoding, + return an error, output a data size > max_output_size and all the data up to that point. This is + not hard limit nor a guarantee, but can prevent excessive memory usage. This setting is + ignored by the PNG decoder, but is used by the deflate/zlib decoder and can be used by custom ones. + Set to 0 to impose no limit (the default).*/ + size_t max_output_size; + + /*use custom zlib decoder instead of built in one (default: null). + Should return 0 if success, any non-0 if error (numeric value not exposed).*/ + unsigned (*custom_zlib)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGDecompressSettings*); + /*use custom deflate decoder instead of built in one (default: null) + if custom_zlib is not null, custom_inflate is ignored (the zlib format uses deflate). + Should return 0 if success, any non-0 if error (numeric value not exposed).*/ + unsigned (*custom_inflate)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGDecompressSettings*); + + const void* custom_context; /*optional custom settings for custom functions*/ +}; + +extern const LodePNGDecompressSettings lodepng_default_decompress_settings; +void lodepng_decompress_settings_init(LodePNGDecompressSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Settings for zlib compression. Tweaking these settings tweaks the balance +between speed and compression ratio. +*/ +typedef struct LodePNGCompressSettings LodePNGCompressSettings; +struct LodePNGCompressSettings /*deflate = compress*/ { + /*LZ77 related settings*/ + unsigned btype; /*the block type for LZ (0, 1, 2 or 3, see zlib standard). Should be 2 for proper compression.*/ + unsigned use_lz77; /*whether or not to use LZ77. Should be 1 for proper compression.*/ + unsigned windowsize; /*must be a power of two <= 32768. higher compresses more but is slower. Default value: 2048.*/ + unsigned minmatch; /*minimum lz77 length. 3 is normally best, 6 can be better for some PNGs. Default: 0*/ + unsigned nicematch; /*stop searching if >= this length found. Set to 258 for best compression. Default: 128*/ + unsigned lazymatching; /*use lazy matching: better compression but a bit slower. Default: true*/ + + /*use custom zlib encoder instead of built in one (default: null)*/ + unsigned (*custom_zlib)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGCompressSettings*); + /*use custom deflate encoder instead of built in one (default: null) + if custom_zlib is used, custom_deflate is ignored since only the built in + zlib function will call custom_deflate*/ + unsigned (*custom_deflate)(unsigned char**, size_t*, + const unsigned char*, size_t, + const LodePNGCompressSettings*); + + const void* custom_context; /*optional custom settings for custom functions*/ +}; + +extern const LodePNGCompressSettings lodepng_default_compress_settings; +void lodepng_compress_settings_init(LodePNGCompressSettings* settings); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#ifdef LODEPNG_COMPILE_PNG +/* +Color mode of an image. Contains all information required to decode the pixel +bits to RGBA colors. This information is the same as used in the PNG file +format, and is used both for PNG and raw image data in LodePNG. +*/ +typedef struct LodePNGColorMode { + /*header (IHDR)*/ + LodePNGColorType colortype; /*color type, see PNG standard or documentation further in this header file*/ + unsigned bitdepth; /*bits per sample, see PNG standard or documentation further in this header file*/ + + /* + palette (PLTE and tRNS) + + Dynamically allocated with the colors of the palette, including alpha. + This field may not be allocated directly, use lodepng_color_mode_init first, + then lodepng_palette_add per color to correctly initialize it (to ensure size + of exactly 1024 bytes). + + The alpha channels must be set as well, set them to 255 for opaque images. + + When decoding, by default you can ignore this palette, since LodePNG already + fills the palette colors in the pixels of the raw RGBA output. + + The palette is only supported for color type 3. + */ + unsigned char* palette; /*palette in RGBARGBA... order. Must be either 0, or when allocated must have 1024 bytes*/ + size_t palettesize; /*palette size in number of colors (amount of used bytes is 4 * palettesize)*/ + + /* + transparent color key (tRNS) + + This color uses the same bit depth as the bitdepth value in this struct, which can be 1-bit to 16-bit. + For grayscale PNGs, r, g and b will all 3 be set to the same. + + When decoding, by default you can ignore this information, since LodePNG sets + pixels with this key to transparent already in the raw RGBA output. + + The color key is only supported for color types 0 and 2. + */ + unsigned key_defined; /*is a transparent color key given? 0 = false, 1 = true*/ + unsigned key_r; /*red/grayscale component of color key*/ + unsigned key_g; /*green component of color key*/ + unsigned key_b; /*blue component of color key*/ +} LodePNGColorMode; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_color_mode_init(LodePNGColorMode* info); +void lodepng_color_mode_cleanup(LodePNGColorMode* info); +/*return value is error code (0 means no error)*/ +unsigned lodepng_color_mode_copy(LodePNGColorMode* dest, const LodePNGColorMode* source); +/* Makes a temporary LodePNGColorMode that does not need cleanup (no palette) */ +LodePNGColorMode lodepng_color_mode_make(LodePNGColorType colortype, unsigned bitdepth); + +void lodepng_palette_clear(LodePNGColorMode* info); +/*add 1 color to the palette*/ +unsigned lodepng_palette_add(LodePNGColorMode* info, + unsigned char r, unsigned char g, unsigned char b, unsigned char a); + +/*get the total amount of bits per pixel, based on colortype and bitdepth in the struct*/ +unsigned lodepng_get_bpp(const LodePNGColorMode* info); +/*get the amount of color channels used, based on colortype in the struct. +If a palette is used, it counts as 1 channel.*/ +unsigned lodepng_get_channels(const LodePNGColorMode* info); +/*is it a grayscale type? (only colortype 0 or 4)*/ +unsigned lodepng_is_greyscale_type(const LodePNGColorMode* info); +/*has it got an alpha channel? (only colortype 2 or 6)*/ +unsigned lodepng_is_alpha_type(const LodePNGColorMode* info); +/*has it got a palette? (only colortype 3)*/ +unsigned lodepng_is_palette_type(const LodePNGColorMode* info); +/*only returns true if there is a palette and there is a value in the palette with alpha < 255. +Loops through the palette to check this.*/ +unsigned lodepng_has_palette_alpha(const LodePNGColorMode* info); +/* +Check if the given color info indicates the possibility of having non-opaque pixels in the PNG image. +Returns true if the image can have translucent or invisible pixels (it still be opaque if it doesn't use such pixels). +Returns false if the image can only have opaque pixels. +In detail, it returns true only if it's a color type with alpha, or has a palette with non-opaque values, +or if "key_defined" is true. +*/ +unsigned lodepng_can_have_alpha(const LodePNGColorMode* info); +/*Returns the byte size of a raw image buffer with given width, height and color mode*/ +size_t lodepng_get_raw_size(unsigned w, unsigned h, const LodePNGColorMode* color); + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +/*The information of a Time chunk in PNG.*/ +typedef struct LodePNGTime { + unsigned year; /*2 bytes used (0-65535)*/ + unsigned month; /*1-12*/ + unsigned day; /*1-31*/ + unsigned hour; /*0-23*/ + unsigned minute; /*0-59*/ + unsigned second; /*0-60 (to allow for leap seconds)*/ +} LodePNGTime; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +/*Information about the PNG image, except pixels, width and height.*/ +typedef struct LodePNGInfo { + /*header (IHDR), palette (PLTE) and transparency (tRNS) chunks*/ + unsigned compression_method;/*compression method of the original file. Always 0.*/ + unsigned filter_method; /*filter method of the original file*/ + unsigned interlace_method; /*interlace method of the original file: 0=none, 1=Adam7*/ + LodePNGColorMode color; /*color type and bits, palette and transparency of the PNG file*/ + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /* + Suggested background color chunk (bKGD) + + This uses the same color mode and bit depth as the PNG (except no alpha channel), + with values truncated to the bit depth in the unsigned integer. + + For grayscale and palette PNGs, the value is stored in background_r. The values + in background_g and background_b are then unused. + + So when decoding, you may get these in a different color mode than the one you requested + for the raw pixels. + + When encoding with auto_convert, you must use the color model defined in info_png.color for + these values. The encoder normally ignores info_png.color when auto_convert is on, but will + use it to interpret these values (and convert copies of them to its chosen color model). + + When encoding, avoid setting this to an expensive color, such as a non-gray value + when the image is gray, or the compression will be worse since it will be forced to + write the PNG with a more expensive color mode (when auto_convert is on). + + The decoder does not use this background color to edit the color of pixels. This is a + completely optional metadata feature. + */ + unsigned background_defined; /*is a suggested background color given?*/ + unsigned background_r; /*red/gray/palette component of suggested background color*/ + unsigned background_g; /*green component of suggested background color*/ + unsigned background_b; /*blue component of suggested background color*/ + + /* + Non-international text chunks (tEXt and zTXt) + + The char** arrays each contain num strings. The actual messages are in + text_strings, while text_keys are keywords that give a short description what + the actual text represents, e.g. Title, Author, Description, or anything else. + + All the string fields below including strings, keys, names and language tags are null terminated. + The PNG specification uses null characters for the keys, names and tags, and forbids null + characters to appear in the main text which is why we can use null termination everywhere here. + + A keyword is minimum 1 character and maximum 79 characters long (plus the + additional null terminator). It's discouraged to use a single line length + longer than 79 characters for texts. + + Don't allocate these text buffers yourself. Use the init/cleanup functions + correctly and use lodepng_add_text and lodepng_clear_text. + + Standard text chunk keywords and strings are encoded using Latin-1. + */ + size_t text_num; /*the amount of texts in these char** buffers (there may be more texts in itext)*/ + char** text_keys; /*the keyword of a text chunk (e.g. "Comment")*/ + char** text_strings; /*the actual text*/ + + /* + International text chunks (iTXt) + Similar to the non-international text chunks, but with additional strings + "langtags" and "transkeys", and the following text encodings are used: + keys: Latin-1, langtags: ASCII, transkeys and strings: UTF-8. + keys must be 1-79 characters (plus the additional null terminator), the other + strings are any length. + */ + size_t itext_num; /*the amount of international texts in this PNG*/ + char** itext_keys; /*the English keyword of the text chunk (e.g. "Comment")*/ + char** itext_langtags; /*language tag for this text's language, ISO/IEC 646 string, e.g. ISO 639 language tag*/ + char** itext_transkeys; /*keyword translated to the international language - UTF-8 string*/ + char** itext_strings; /*the actual international text - UTF-8 string*/ + + /*time chunk (tIME)*/ + unsigned time_defined; /*set to 1 to make the encoder generate a tIME chunk*/ + LodePNGTime time; + + /*phys chunk (pHYs)*/ + unsigned phys_defined; /*if 0, there is no pHYs chunk and the values below are undefined, if 1 else there is one*/ + unsigned phys_x; /*pixels per unit in x direction*/ + unsigned phys_y; /*pixels per unit in y direction*/ + unsigned phys_unit; /*may be 0 (unknown unit) or 1 (metre)*/ + + /* + Color profile related chunks: gAMA, cHRM, sRGB, iCPP + + LodePNG does not apply any color conversions on pixels in the encoder or decoder and does not interpret these color + profile values. It merely passes on the information. If you wish to use color profiles and convert colors, please + use these values with a color management library. + + See the PNG, ICC and sRGB specifications for more information about the meaning of these values. + */ + + /* gAMA chunk: optional, overridden by sRGB or iCCP if those are present. */ + unsigned gama_defined; /* Whether a gAMA chunk is present (0 = not present, 1 = present). */ + unsigned gama_gamma; /* Gamma exponent times 100000 */ + + /* cHRM chunk: optional, overridden by sRGB or iCCP if those are present. */ + unsigned chrm_defined; /* Whether a cHRM chunk is present (0 = not present, 1 = present). */ + unsigned chrm_white_x; /* White Point x times 100000 */ + unsigned chrm_white_y; /* White Point y times 100000 */ + unsigned chrm_red_x; /* Red x times 100000 */ + unsigned chrm_red_y; /* Red y times 100000 */ + unsigned chrm_green_x; /* Green x times 100000 */ + unsigned chrm_green_y; /* Green y times 100000 */ + unsigned chrm_blue_x; /* Blue x times 100000 */ + unsigned chrm_blue_y; /* Blue y times 100000 */ + + /* + sRGB chunk: optional. May not appear at the same time as iCCP. + If gAMA is also present gAMA must contain value 45455. + If cHRM is also present cHRM must contain respectively 31270,32900,64000,33000,30000,60000,15000,6000. + */ + unsigned srgb_defined; /* Whether an sRGB chunk is present (0 = not present, 1 = present). */ + unsigned srgb_intent; /* Rendering intent: 0=perceptual, 1=rel. colorimetric, 2=saturation, 3=abs. colorimetric */ + + /* + iCCP chunk: optional. May not appear at the same time as sRGB. + + LodePNG does not parse or use the ICC profile (except its color space header field for an edge case), a + separate library to handle the ICC data (not included in LodePNG) format is needed to use it for color + management and conversions. + + For encoding, if iCCP is present, gAMA and cHRM are recommended to be added as well with values that match the ICC + profile as closely as possible, if you wish to do this you should provide the correct values for gAMA and cHRM and + enable their '_defined' flags since LodePNG will not automatically compute them from the ICC profile. + + For encoding, the ICC profile is required by the PNG specification to be an "RGB" profile for non-gray + PNG color types and a "GRAY" profile for gray PNG color types. If you disable auto_convert, you must ensure + the ICC profile type matches your requested color type, else the encoder gives an error. If auto_convert is + enabled (the default), and the ICC profile is not a good match for the pixel data, this will result in an encoder + error if the pixel data has non-gray pixels for a GRAY profile, or a silent less-optimal compression of the pixel + data if the pixels could be encoded as grayscale but the ICC profile is RGB. + + To avoid this do not set an ICC profile in the image unless there is a good reason for it, and when doing so + make sure you compute it carefully to avoid the above problems. + */ + unsigned iccp_defined; /* Whether an iCCP chunk is present (0 = not present, 1 = present). */ + char* iccp_name; /* Null terminated string with profile name, 1-79 bytes */ + /* + The ICC profile in iccp_profile_size bytes. + Don't allocate this buffer yourself. Use the init/cleanup functions + correctly and use lodepng_set_icc and lodepng_clear_icc. + */ + unsigned char* iccp_profile; + unsigned iccp_profile_size; /* The size of iccp_profile in bytes */ + + /* End of color profile related chunks */ + + + /* + unknown chunks: chunks not known by LodePNG, passed on byte for byte. + + There are 3 buffers, one for each position in the PNG where unknown chunks can appear. + Each buffer contains all unknown chunks for that position consecutively. + The 3 positions are: + 0: between IHDR and PLTE, 1: between PLTE and IDAT, 2: between IDAT and IEND. + + For encoding, do not store critical chunks or known chunks that are enabled with a "_defined" flag + above in here, since the encoder will blindly follow this and could then encode an invalid PNG file + (such as one with two IHDR chunks or the disallowed combination of sRGB with iCCP). But do use + this if you wish to store an ancillary chunk that is not supported by LodePNG (such as sPLT or hIST), + or any non-standard PNG chunk. + + Do not allocate or traverse this data yourself. Use the chunk traversing functions declared + later, such as lodepng_chunk_next and lodepng_chunk_append, to read/write this struct. + */ + unsigned char* unknown_chunks_data[3]; + size_t unknown_chunks_size[3]; /*size in bytes of the unknown chunks, given for protection*/ +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGInfo; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_info_init(LodePNGInfo* info); +void lodepng_info_cleanup(LodePNGInfo* info); +/*return value is error code (0 means no error)*/ +unsigned lodepng_info_copy(LodePNGInfo* dest, const LodePNGInfo* source); + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS +unsigned lodepng_add_text(LodePNGInfo* info, const char* key, const char* str); /*push back both texts at once*/ +void lodepng_clear_text(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ + +unsigned lodepng_add_itext(LodePNGInfo* info, const char* key, const char* langtag, + const char* transkey, const char* str); /*push back the 4 texts of 1 chunk at once*/ +void lodepng_clear_itext(LodePNGInfo* info); /*use this to clear the itexts again after you filled them in*/ + +/*replaces if exists*/ +unsigned lodepng_set_icc(LodePNGInfo* info, const char* name, const unsigned char* profile, unsigned profile_size); +void lodepng_clear_icc(LodePNGInfo* info); /*use this to clear the texts again after you filled them in*/ +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ + +/* +Converts raw buffer from one color type to another color type, based on +LodePNGColorMode structs to describe the input and output color type. +See the reference manual at the end of this header file to see which color conversions are supported. +return value = LodePNG error code (0 if all went ok, an error if the conversion isn't supported) +The out buffer must have size (w * h * bpp + 7) / 8, where bpp is the bits per pixel +of the output color type (lodepng_get_bpp). +For < 8 bpp images, there should not be padding bits at the end of scanlines. +For 16-bit per channel colors, uses big endian format like PNG does. +Return value is LodePNG error code +*/ +unsigned lodepng_convert(unsigned char* out, const unsigned char* in, + const LodePNGColorMode* mode_out, const LodePNGColorMode* mode_in, + unsigned w, unsigned h); + +#ifdef LODEPNG_COMPILE_DECODER +/* +Settings for the decoder. This contains settings for the PNG and the Zlib +decoder, but not the Info settings from the Info structs. +*/ +typedef struct LodePNGDecoderSettings { + LodePNGDecompressSettings zlibsettings; /*in here is the setting to ignore Adler32 checksums*/ + + /* Check LodePNGDecompressSettings for more ignorable errors such as ignore_adler32 */ + unsigned ignore_crc; /*ignore CRC checksums*/ + unsigned ignore_critical; /*ignore unknown critical chunks*/ + unsigned ignore_end; /*ignore issues at end of file if possible (missing IEND chunk, too large chunk, ...)*/ + /* TODO: make a system involving warnings with levels and a strict mode instead. Other potentially recoverable + errors: srgb rendering intent value, size of content of ancillary chunks, more than 79 characters for some + strings, placement/combination rules for ancillary chunks, crc of unknown chunks, allowed characters + in string keys, etc... */ + + unsigned color_convert; /*whether to convert the PNG to the color type you want. Default: yes*/ + +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + unsigned read_text_chunks; /*if false but remember_unknown_chunks is true, they're stored in the unknown chunks*/ + + /*store all bytes from unknown chunks in the LodePNGInfo (off by default, useful for a png editor)*/ + unsigned remember_unknown_chunks; + + /* maximum size for decompressed text chunks. If a text chunk's text is larger than this, an error is returned, + unless reading text chunks is disabled or this limit is set higher or disabled. Set to 0 to allow any size. + By default it is a value that prevents unreasonably large strings from hogging memory. */ + size_t max_text_size; + + /* maximum size for compressed ICC chunks. If the ICC profile is larger than this, an error will be returned. Set to + 0 to allow any size. By default this is a value that prevents ICC profiles that would be much larger than any + legitimate profile could be to hog memory. */ + size_t max_icc_size; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGDecoderSettings; + +void lodepng_decoder_settings_init(LodePNGDecoderSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/*automatically use color type with less bits per pixel if losslessly possible. Default: AUTO*/ +typedef enum LodePNGFilterStrategy { + /*every filter at zero*/ + LFS_ZERO = 0, + /*every filter at 1, 2, 3 or 4 (paeth), unlike LFS_ZERO not a good choice, but for testing*/ + LFS_ONE = 1, + LFS_TWO = 2, + LFS_THREE = 3, + LFS_FOUR = 4, + /*Use filter that gives minimum sum, as described in the official PNG filter heuristic.*/ + LFS_MINSUM, + /*Use the filter type that gives smallest Shannon entropy for this scanline. Depending + on the image, this is better or worse than minsum.*/ + LFS_ENTROPY, + /* + Brute-force-search PNG filters by compressing each filter for each scanline. + Experimental, very slow, and only rarely gives better compression than MINSUM. + */ + LFS_BRUTE_FORCE, + /*use predefined_filters buffer: you specify the filter type for each scanline*/ + LFS_PREDEFINED +} LodePNGFilterStrategy; + +/*Gives characteristics about the integer RGBA colors of the image (count, alpha channel usage, bit depth, ...), +which helps decide which color model to use for encoding. +Used internally by default if "auto_convert" is enabled. Public because it's useful for custom algorithms.*/ +typedef struct LodePNGColorStats { + unsigned colored; /*not grayscale*/ + unsigned key; /*image is not opaque and color key is possible instead of full alpha*/ + unsigned short key_r; /*key values, always as 16-bit, in 8-bit case the byte is duplicated, e.g. 65535 means 255*/ + unsigned short key_g; + unsigned short key_b; + unsigned alpha; /*image is not opaque and alpha channel or alpha palette required*/ + unsigned numcolors; /*amount of colors, up to 257. Not valid if bits == 16 or allow_palette is disabled.*/ + unsigned char palette[1024]; /*Remembers up to the first 256 RGBA colors, in no particular order, only valid when numcolors is valid*/ + unsigned bits; /*bits per channel (not for palette). 1,2 or 4 for grayscale only. 16 if 16-bit per channel required.*/ + size_t numpixels; + + /*user settings for computing/using the stats*/ + unsigned allow_palette; /*default 1. if 0, disallow choosing palette colortype in auto_choose_color, and don't count numcolors*/ + unsigned allow_greyscale; /*default 1. if 0, choose RGB or RGBA even if the image only has gray colors*/ +} LodePNGColorStats; + +void lodepng_color_stats_init(LodePNGColorStats* stats); + +/*Get a LodePNGColorStats of the image. The stats must already have been inited. +Returns error code (e.g. alloc fail) or 0 if ok.*/ +unsigned lodepng_compute_color_stats(LodePNGColorStats* stats, + const unsigned char* image, unsigned w, unsigned h, + const LodePNGColorMode* mode_in); + +/*Settings for the encoder.*/ +typedef struct LodePNGEncoderSettings { + LodePNGCompressSettings zlibsettings; /*settings for the zlib encoder, such as window size, ...*/ + + unsigned auto_convert; /*automatically choose output PNG color type. Default: true*/ + + /*If true, follows the official PNG heuristic: if the PNG uses a palette or lower than + 8 bit depth, set all filters to zero. Otherwise use the filter_strategy. Note that to + completely follow the official PNG heuristic, filter_palette_zero must be true and + filter_strategy must be LFS_MINSUM*/ + unsigned filter_palette_zero; + /*Which filter strategy to use when not using zeroes due to filter_palette_zero. + Set filter_palette_zero to 0 to ensure always using your chosen strategy. Default: LFS_MINSUM*/ + LodePNGFilterStrategy filter_strategy; + /*used if filter_strategy is LFS_PREDEFINED. In that case, this must point to a buffer with + the same length as the amount of scanlines in the image, and each value must <= 5. You + have to cleanup this buffer, LodePNG will never free it. Don't forget that filter_palette_zero + must be set to 0 to ensure this is also used on palette or low bitdepth images.*/ + const unsigned char* predefined_filters; + + /*force creating a PLTE chunk if colortype is 2 or 6 (= a suggested palette). + If colortype is 3, PLTE is _always_ created.*/ + unsigned force_palette; +#ifdef LODEPNG_COMPILE_ANCILLARY_CHUNKS + /*add LodePNG identifier and version as a text chunk, for debugging*/ + unsigned add_id; + /*encode text chunks as zTXt chunks instead of tEXt chunks, and use compression in iTXt chunks*/ + unsigned text_compression; +#endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ +} LodePNGEncoderSettings; + +void lodepng_encoder_settings_init(LodePNGEncoderSettings* settings); +#endif /*LODEPNG_COMPILE_ENCODER*/ + + +#if defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) +/*The settings, state and information for extended encoding and decoding.*/ +typedef struct LodePNGState { +#ifdef LODEPNG_COMPILE_DECODER + LodePNGDecoderSettings decoder; /*the decoding settings*/ +#endif /*LODEPNG_COMPILE_DECODER*/ +#ifdef LODEPNG_COMPILE_ENCODER + LodePNGEncoderSettings encoder; /*the encoding settings*/ +#endif /*LODEPNG_COMPILE_ENCODER*/ + LodePNGColorMode info_raw; /*specifies the format in which you would like to get the raw pixel buffer*/ + LodePNGInfo info_png; /*info of the PNG image obtained after decoding*/ + unsigned error; +} LodePNGState; + +/*init, cleanup and copy functions to use with this struct*/ +void lodepng_state_init(LodePNGState* state); +void lodepng_state_cleanup(LodePNGState* state); +void lodepng_state_copy(LodePNGState* dest, const LodePNGState* source); +#endif /* defined(LODEPNG_COMPILE_DECODER) || defined(LODEPNG_COMPILE_ENCODER) */ + +#ifdef LODEPNG_COMPILE_DECODER +/* +Same as lodepng_decode_memory, but uses a LodePNGState to allow custom settings and +getting much more information about the PNG image and color mode. +*/ +unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h, + LodePNGState* state, + const unsigned char* in, size_t insize); + +/* +Read the PNG header, but not the actual data. This returns only the information +that is in the IHDR chunk of the PNG, such as width, height and color type. The +information is placed in the info_png field of the LodePNGState. +*/ +unsigned lodepng_inspect(unsigned* w, unsigned* h, + LodePNGState* state, + const unsigned char* in, size_t insize); +#endif /*LODEPNG_COMPILE_DECODER*/ + +/* +Reads one metadata chunk (other than IHDR) of the PNG file and outputs what it +read in the state. Returns error code on failure. +Use lodepng_inspect first with a new state, then e.g. lodepng_chunk_find_const +to find the desired chunk type, and if non null use lodepng_inspect_chunk (with +chunk_pointer - start_of_file as pos). +Supports most metadata chunks from the PNG standard (gAMA, bKGD, tEXt, ...). +Ignores unsupported, unknown, non-metadata or IHDR chunks (without error). +Requirements: &in[pos] must point to start of a chunk, must use regular +lodepng_inspect first since format of most other chunks depends on IHDR, and if +there is a PLTE chunk, that one must be inspected before tRNS or bKGD. +*/ +unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos, + const unsigned char* in, size_t insize); + +#ifdef LODEPNG_COMPILE_ENCODER +/*This function allocates the out buffer with standard malloc and stores the size in *outsize.*/ +unsigned lodepng_encode(unsigned char** out, size_t* outsize, + const unsigned char* image, unsigned w, unsigned h, + LodePNGState* state); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +/* +The lodepng_chunk functions are normally not needed, except to traverse the +unknown chunks stored in the LodePNGInfo struct, or add new ones to it. +It also allows traversing the chunks of an encoded PNG file yourself. + +The chunk pointer always points to the beginning of the chunk itself, that is +the first byte of the 4 length bytes. + +In the PNG file format, chunks have the following format: +-4 bytes length: length of the data of the chunk in bytes (chunk itself is 12 bytes longer) +-4 bytes chunk type (ASCII a-z,A-Z only, see below) +-length bytes of data (may be 0 bytes if length was 0) +-4 bytes of CRC, computed on chunk name + data + +The first chunk starts at the 8th byte of the PNG file, the entire rest of the file +exists out of concatenated chunks with the above format. + +PNG standard chunk ASCII naming conventions: +-First byte: uppercase = critical, lowercase = ancillary +-Second byte: uppercase = public, lowercase = private +-Third byte: must be uppercase +-Fourth byte: uppercase = unsafe to copy, lowercase = safe to copy +*/ + +/* +Gets the length of the data of the chunk. Total chunk length has 12 bytes more. +There must be at least 4 bytes to read from. If the result value is too large, +it may be corrupt data. +*/ +unsigned lodepng_chunk_length(const unsigned char* chunk); + +/*puts the 4-byte type in null terminated string*/ +void lodepng_chunk_type(char type[5], const unsigned char* chunk); + +/*check if the type is the given type*/ +unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type); + +/*0: it's one of the critical chunk types, 1: it's an ancillary chunk (see PNG standard)*/ +unsigned char lodepng_chunk_ancillary(const unsigned char* chunk); + +/*0: public, 1: private (see PNG standard)*/ +unsigned char lodepng_chunk_private(const unsigned char* chunk); + +/*0: the chunk is unsafe to copy, 1: the chunk is safe to copy (see PNG standard)*/ +unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk); + +/*get pointer to the data of the chunk, where the input points to the header of the chunk*/ +unsigned char* lodepng_chunk_data(unsigned char* chunk); +const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk); + +/*returns 0 if the crc is correct, 1 if it's incorrect (0 for OK as usual!)*/ +unsigned lodepng_chunk_check_crc(const unsigned char* chunk); + +/*generates the correct CRC from the data and puts it in the last 4 bytes of the chunk*/ +void lodepng_chunk_generate_crc(unsigned char* chunk); + +/* +Iterate to next chunks, allows iterating through all chunks of the PNG file. +Input must be at the beginning of a chunk (result of a previous lodepng_chunk_next call, +or the 8th byte of a PNG file which always has the first chunk), or alternatively may +point to the first byte of the PNG file (which is not a chunk but the magic header, the +function will then skip over it and return the first real chunk). +Will output pointer to the start of the next chunk, or at or beyond end of the file if there +is no more chunk after this or possibly if the chunk is corrupt. +Start this process at the 8th byte of the PNG file. +In a non-corrupt PNG file, the last chunk should have name "IEND". +*/ +unsigned char* lodepng_chunk_next(unsigned char* chunk, unsigned char* end); +const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk, const unsigned char* end); + +/*Finds the first chunk with the given type in the range [chunk, end), or returns NULL if not found.*/ +unsigned char* lodepng_chunk_find(unsigned char* chunk, unsigned char* end, const char type[5]); +const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const unsigned char* end, const char type[5]); + +/* +Appends chunk to the data in out. The given chunk should already have its chunk header. +The out variable and outsize are updated to reflect the new reallocated buffer. +Returns error code (0 if it went ok) +*/ +unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk); + +/* +Appends new chunk to out. The chunk to append is given by giving its length, type +and data separately. The type is a 4-letter string. +The out variable and outsize are updated to reflect the new reallocated buffer. +Returne error code (0 if it went ok) +*/ +unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, + const char* type, const unsigned char* data); + + +/*Calculate CRC32 of buffer*/ +unsigned lodepng_crc32(const unsigned char* buf, size_t len); +#endif /*LODEPNG_COMPILE_PNG*/ + + +#ifdef LODEPNG_COMPILE_ZLIB +/* +This zlib part can be used independently to zlib compress and decompress a +buffer. It cannot be used to create gzip files however, and it only supports the +part of zlib that is required for PNG, it does not support dictionaries. +*/ + +#ifdef LODEPNG_COMPILE_DECODER +/*Inflate a buffer. Inflate is the decompression step of deflate. Out buffer must be freed after use.*/ +unsigned lodepng_inflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings); + +/* +Decompresses Zlib data. Reallocates the out buffer and appends the data. The +data must be according to the zlib specification. +Either, *out must be NULL and *outsize must be 0, or, *out must be a valid +buffer and *outsize its size in bytes. out must be freed by user after usage. +*/ +unsigned lodepng_zlib_decompress(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGDecompressSettings* settings); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* +Compresses data with Zlib. Reallocates the out buffer and appends the data. +Zlib adds a small header and trailer around the deflate data. +The data is output in the format of the zlib specification. +Either, *out must be NULL and *outsize must be 0, or, *out must be a valid +buffer and *outsize its size in bytes. out must be freed by user after usage. +*/ +unsigned lodepng_zlib_compress(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings); + +/* +Find length-limited Huffman code for given frequencies. This function is in the +public interface only for tests, it's used internally by lodepng_deflate. +*/ +unsigned lodepng_huffman_code_lengths(unsigned* lengths, const unsigned* frequencies, + size_t numcodes, unsigned maxbitlen); + +/*Compress a buffer with deflate. See RFC 1951. Out buffer must be freed after use.*/ +unsigned lodepng_deflate(unsigned char** out, size_t* outsize, + const unsigned char* in, size_t insize, + const LodePNGCompressSettings* settings); + +#endif /*LODEPNG_COMPILE_ENCODER*/ +#endif /*LODEPNG_COMPILE_ZLIB*/ + +#ifdef LODEPNG_COMPILE_DISK +/* +Load a file from disk into buffer. The function allocates the out buffer, and +after usage you should free it. +out: output parameter, contains pointer to loaded buffer. +outsize: output parameter, size of the allocated out buffer +filename: the path to the file to load +return value: error code (0 means ok) +*/ +unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename); + +/* +Save a file from buffer to disk. Warning, if it exists, this function overwrites +the file without warning! +buffer: the buffer to write +buffersize: size of the buffer to write +filename: the path to the file to save to +return value: error code (0 means ok) +*/ +unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename); +#endif /*LODEPNG_COMPILE_DISK*/ + +#ifdef LODEPNG_COMPILE_CPP +/* The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. */ +namespace lodepng { +#ifdef LODEPNG_COMPILE_PNG +class State : public LodePNGState { + public: + State(); + State(const State& other); + ~State(); + State& operator=(const State& other); +}; + +#ifdef LODEPNG_COMPILE_DECODER +/* Same as other lodepng::decode, but using a State for more settings and information. */ +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + State& state, + const unsigned char* in, size_t insize); +unsigned decode(std::vector& out, unsigned& w, unsigned& h, + State& state, + const std::vector& in); +#endif /*LODEPNG_COMPILE_DECODER*/ + +#ifdef LODEPNG_COMPILE_ENCODER +/* Same as other lodepng::encode, but using a State for more settings and information. */ +unsigned encode(std::vector& out, + const unsigned char* in, unsigned w, unsigned h, + State& state); +unsigned encode(std::vector& out, + const std::vector& in, unsigned w, unsigned h, + State& state); +#endif /*LODEPNG_COMPILE_ENCODER*/ + +#ifdef LODEPNG_COMPILE_DISK +/* +Load a file from disk into an std::vector. +return value: error code (0 means ok) +*/ +unsigned load_file(std::vector& buffer, const std::string& filename); + +/* +Save the binary data in an std::vector to a file on disk. The file is overwritten +without warning. +*/ +unsigned save_file(const std::vector& buffer, const std::string& filename); +#endif /* LODEPNG_COMPILE_DISK */ +#endif /* LODEPNG_COMPILE_PNG */ + +#ifdef LODEPNG_COMPILE_ZLIB +#ifdef LODEPNG_COMPILE_DECODER +/* Zlib-decompress an unsigned char buffer */ +unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, + const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); + +/* Zlib-decompress an std::vector */ +unsigned decompress(std::vector& out, const std::vector& in, + const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); +#endif /* LODEPNG_COMPILE_DECODER */ + +#ifdef LODEPNG_COMPILE_ENCODER +/* Zlib-compress an unsigned char buffer */ +unsigned compress(std::vector& out, const unsigned char* in, size_t insize, + const LodePNGCompressSettings& settings = lodepng_default_compress_settings); + +/* Zlib-compress an std::vector */ +unsigned compress(std::vector& out, const std::vector& in, + const LodePNGCompressSettings& settings = lodepng_default_compress_settings); +#endif /* LODEPNG_COMPILE_ENCODER */ +#endif /* LODEPNG_COMPILE_ZLIB */ +} /* namespace lodepng */ +#endif /*LODEPNG_COMPILE_CPP*/ + +/* +TODO: +[.] test if there are no memory leaks or security exploits - done a lot but needs to be checked often +[.] check compatibility with various compilers - done but needs to be redone for every newer version +[X] converting color to 16-bit per channel types +[X] support color profile chunk types (but never let them touch RGB values by default) +[ ] support all public PNG chunk types (almost done except sBIT, sPLT and hIST) +[ ] make sure encoder generates no chunks with size > (2^31)-1 +[ ] partial decoding (stream processing) +[X] let the "isFullyOpaque" function check color keys and transparent palettes too +[X] better name for the variables "codes", "codesD", "codelengthcodes", "clcl" and "lldl" +[ ] allow treating some errors like warnings, when image is recoverable (e.g. 69, 57, 58) +[ ] make warnings like: oob palette, checksum fail, data after iend, wrong/unknown crit chunk, no null terminator in text, ... +[ ] error messages with line numbers (and version) +[ ] errors in state instead of as return code? +[ ] new errors/warnings like suspiciously big decompressed ztxt or iccp chunk +[ ] let the C++ wrapper catch exceptions coming from the standard library and return LodePNG error codes +[ ] allow user to provide custom color conversion functions, e.g. for premultiplied alpha, padding bits or not, ... +[ ] allow user to give data (void*) to custom allocator +[X] provide alternatives for C library functions not present on some platforms (memcpy, ...) +*/ + +#endif /*LV_USE_PNG*/ + +#endif /*LODEPNG_H inclusion guard*/ + +/* +LodePNG Documentation +--------------------- + +0. table of contents +-------------------- + + 1. about + 1.1. supported features + 1.2. features not supported + 2. C and C++ version + 3. security + 4. decoding + 5. encoding + 6. color conversions + 6.1. PNG color types + 6.2. color conversions + 6.3. padding bits + 6.4. A note about 16-bits per channel and endianness + 7. error values + 8. chunks and PNG editing + 9. compiler support + 10. examples + 10.1. decoder C++ example + 10.2. decoder C example + 11. state settings reference + 12. changes + 13. contact information + + +1. about +-------- + +PNG is a file format to store raster images losslessly with good compression, +supporting different color types and alpha channel. + +LodePNG is a PNG codec according to the Portable Network Graphics (PNG) +Specification (Second Edition) - W3C Recommendation 10 November 2003. + +The specifications used are: + +*) Portable Network Graphics (PNG) Specification (Second Edition): + http://www.w3.org/TR/2003/REC-PNG-20031110 +*) RFC 1950 ZLIB Compressed Data Format version 3.3: + http://www.gzip.org/zlib/rfc-zlib.html +*) RFC 1951 DEFLATE Compressed Data Format Specification ver 1.3: + http://www.gzip.org/zlib/rfc-deflate.html + +The most recent version of LodePNG can currently be found at +http://lodev.org/lodepng/ + +LodePNG works both in C (ISO C90) and C++, with a C++ wrapper that adds +extra functionality. + +LodePNG exists out of two files: +-lodepng.h: the header file for both C and C++ +-lodepng.c(pp): give it the name lodepng.c or lodepng.cpp (or .cc) depending on your usage + +If you want to start using LodePNG right away without reading this doc, get the +examples from the LodePNG website to see how to use it in code, or check the +smaller examples in chapter 13 here. + +LodePNG is simple but only supports the basic requirements. To achieve +simplicity, the following design choices were made: There are no dependencies +on any external library. There are functions to decode and encode a PNG with +a single function call, and extended versions of these functions taking a +LodePNGState struct allowing to specify or get more information. By default +the colors of the raw image are always RGB or RGBA, no matter what color type +the PNG file uses. To read and write files, there are simple functions to +convert the files to/from buffers in memory. + +This all makes LodePNG suitable for loading textures in games, demos and small +programs, ... It's less suitable for full fledged image editors, loading PNGs +over network (it requires all the image data to be available before decoding can +begin), life-critical systems, ... + +1.1. supported features +----------------------- + +The following features are supported by the decoder: + +*) decoding of PNGs with any color type, bit depth and interlace mode, to a 24- or 32-bit color raw image, + or the same color type as the PNG +*) encoding of PNGs, from any raw image to 24- or 32-bit color, or the same color type as the raw image +*) Adam7 interlace and deinterlace for any color type +*) loading the image from harddisk or decoding it from a buffer from other sources than harddisk +*) support for alpha channels, including RGBA color model, translucent palettes and color keying +*) zlib decompression (inflate) +*) zlib compression (deflate) +*) CRC32 and ADLER32 checksums +*) colorimetric color profile conversions: currently experimentally available in lodepng_util.cpp only, + plus alternatively ability to pass on chroma/gamma/ICC profile information to other color management system. +*) handling of unknown chunks, allowing making a PNG editor that stores custom and unknown chunks. +*) the following chunks are supported by both encoder and decoder: + IHDR: header information + PLTE: color palette + IDAT: pixel data + IEND: the final chunk + tRNS: transparency for palettized images + tEXt: textual information + zTXt: compressed textual information + iTXt: international textual information + bKGD: suggested background color + pHYs: physical dimensions + tIME: modification time + cHRM: RGB chromaticities + gAMA: RGB gamma correction + iCCP: ICC color profile + sRGB: rendering intent + +1.2. features not supported +--------------------------- + +The following features are _not_ supported: + +*) some features needed to make a conformant PNG-Editor might be still missing. +*) partial loading/stream processing. All data must be available and is processed in one call. +*) The following public chunks are not (yet) supported but treated as unknown chunks by LodePNG: + sBIT + hIST + sPLT + + +2. C and C++ version +-------------------- + +The C version uses buffers allocated with alloc that you need to free() +yourself. You need to use init and cleanup functions for each struct whenever +using a struct from the C version to avoid exploits and memory leaks. + +The C++ version has extra functions with std::vectors in the interface and the +lodepng::State class which is a LodePNGState with constructor and destructor. + +These files work without modification for both C and C++ compilers because all +the additional C++ code is in "#ifdef __cplusplus" blocks that make C-compilers +ignore it, and the C code is made to compile both with strict ISO C90 and C++. + +To use the C++ version, you need to rename the source file to lodepng.cpp +(instead of lodepng.c), and compile it with a C++ compiler. + +To use the C version, you need to rename the source file to lodepng.c (instead +of lodepng.cpp), and compile it with a C compiler. + + +3. Security +----------- + +Even if carefully designed, it's always possible that LodePNG contains possible +exploits. If you discover one, please let me know, and it will be fixed. + +When using LodePNG, care has to be taken with the C version of LodePNG, as well +as the C-style structs when working with C++. The following conventions are used +for all C-style structs: + +-if a struct has a corresponding init function, always call the init function when making a new one +-if a struct has a corresponding cleanup function, call it before the struct disappears to avoid memory leaks +-if a struct has a corresponding copy function, use the copy function instead of "=". + The destination must also be inited already. + + +4. Decoding +----------- + +Decoding converts a PNG compressed image to a raw pixel buffer. + +Most documentation on using the decoder is at its declarations in the header +above. For C, simple decoding can be done with functions such as +lodepng_decode32, and more advanced decoding can be done with the struct +LodePNGState and lodepng_decode. For C++, all decoding can be done with the +various lodepng::decode functions, and lodepng::State can be used for advanced +features. + +When using the LodePNGState, it uses the following fields for decoding: +*) LodePNGInfo info_png: it stores extra information about the PNG (the input) in here +*) LodePNGColorMode info_raw: here you can say what color mode of the raw image (the output) you want to get +*) LodePNGDecoderSettings decoder: you can specify a few extra settings for the decoder to use + +LodePNGInfo info_png +-------------------- + +After decoding, this contains extra information of the PNG image, except the actual +pixels, width and height because these are already gotten directly from the decoder +functions. + +It contains for example the original color type of the PNG image, text comments, +suggested background color, etc... More details about the LodePNGInfo struct are +at its declaration documentation. + +LodePNGColorMode info_raw +------------------------- + +When decoding, here you can specify which color type you want +the resulting raw image to be. If this is different from the colortype of the +PNG, then the decoder will automatically convert the result. This conversion +always works, except if you want it to convert a color PNG to grayscale or to +a palette with missing colors. + +By default, 32-bit color is used for the result. + +LodePNGDecoderSettings decoder +------------------------------ + +The settings can be used to ignore the errors created by invalid CRC and Adler32 +chunks, and to disable the decoding of tEXt chunks. + +There's also a setting color_convert, true by default. If false, no conversion +is done, the resulting data will be as it was in the PNG (after decompression) +and you'll have to puzzle the colors of the pixels together yourself using the +color type information in the LodePNGInfo. + + +5. Encoding +----------- + +Encoding converts a raw pixel buffer to a PNG compressed image. + +Most documentation on using the encoder is at its declarations in the header +above. For C, simple encoding can be done with functions such as +lodepng_encode32, and more advanced decoding can be done with the struct +LodePNGState and lodepng_encode. For C++, all encoding can be done with the +various lodepng::encode functions, and lodepng::State can be used for advanced +features. + +Like the decoder, the encoder can also give errors. However it gives less errors +since the encoder input is trusted, the decoder input (a PNG image that could +be forged by anyone) is not trusted. + +When using the LodePNGState, it uses the following fields for encoding: +*) LodePNGInfo info_png: here you specify how you want the PNG (the output) to be. +*) LodePNGColorMode info_raw: here you say what color type of the raw image (the input) has +*) LodePNGEncoderSettings encoder: you can specify a few settings for the encoder to use + +LodePNGInfo info_png +-------------------- + +When encoding, you use this the opposite way as when decoding: for encoding, +you fill in the values you want the PNG to have before encoding. By default it's +not needed to specify a color type for the PNG since it's automatically chosen, +but it's possible to choose it yourself given the right settings. + +The encoder will not always exactly match the LodePNGInfo struct you give, +it tries as close as possible. Some things are ignored by the encoder. The +encoder uses, for example, the following settings from it when applicable: +colortype and bitdepth, text chunks, time chunk, the color key, the palette, the +background color, the interlace method, unknown chunks, ... + +When encoding to a PNG with colortype 3, the encoder will generate a PLTE chunk. +If the palette contains any colors for which the alpha channel is not 255 (so +there are translucent colors in the palette), it'll add a tRNS chunk. + +LodePNGColorMode info_raw +------------------------- + +You specify the color type of the raw image that you give to the input here, +including a possible transparent color key and palette you happen to be using in +your raw image data. + +By default, 32-bit color is assumed, meaning your input has to be in RGBA +format with 4 bytes (unsigned chars) per pixel. + +LodePNGEncoderSettings encoder +------------------------------ + +The following settings are supported (some are in sub-structs): +*) auto_convert: when this option is enabled, the encoder will +automatically choose the smallest possible color mode (including color key) that +can encode the colors of all pixels without information loss. +*) btype: the block type for LZ77. 0 = uncompressed, 1 = fixed huffman tree, + 2 = dynamic huffman tree (best compression). Should be 2 for proper + compression. +*) use_lz77: whether or not to use LZ77 for compressed block types. Should be + true for proper compression. +*) windowsize: the window size used by the LZ77 encoder (1 - 32768). Has value + 2048 by default, but can be set to 32768 for better, but slow, compression. +*) force_palette: if colortype is 2 or 6, you can make the encoder write a PLTE + chunk if force_palette is true. This can used as suggested palette to convert + to by viewers that don't support more than 256 colors (if those still exist) +*) add_id: add text chunk "Encoder: LodePNG " to the image. +*) text_compression: default 1. If 1, it'll store texts as zTXt instead of tEXt chunks. + zTXt chunks use zlib compression on the text. This gives a smaller result on + large texts but a larger result on small texts (such as a single program name). + It's all tEXt or all zTXt though, there's no separate setting per text yet. + + +6. color conversions +-------------------- + +An important thing to note about LodePNG, is that the color type of the PNG, and +the color type of the raw image, are completely independent. By default, when +you decode a PNG, you get the result as a raw image in the color type you want, +no matter whether the PNG was encoded with a palette, grayscale or RGBA color. +And if you encode an image, by default LodePNG will automatically choose the PNG +color type that gives good compression based on the values of colors and amount +of colors in the image. It can be configured to let you control it instead as +well, though. + +To be able to do this, LodePNG does conversions from one color mode to another. +It can convert from almost any color type to any other color type, except the +following conversions: RGB to grayscale is not supported, and converting to a +palette when the palette doesn't have a required color is not supported. This is +not supported on purpose: this is information loss which requires a color +reduction algorithm that is beyond the scope of a PNG encoder (yes, RGB to gray +is easy, but there are multiple ways if you want to give some channels more +weight). + +By default, when decoding, you get the raw image in 32-bit RGBA or 24-bit RGB +color, no matter what color type the PNG has. And by default when encoding, +LodePNG automatically picks the best color model for the output PNG, and expects +the input image to be 32-bit RGBA or 24-bit RGB. So, unless you want to control +the color format of the images yourself, you can skip this chapter. + +6.1. PNG color types +-------------------- + +A PNG image can have many color types, ranging from 1-bit color to 64-bit color, +as well as palettized color modes. After the zlib decompression and unfiltering +in the PNG image is done, the raw pixel data will have that color type and thus +a certain amount of bits per pixel. If you want the output raw image after +decoding to have another color type, a conversion is done by LodePNG. + +The PNG specification gives the following color types: + +0: grayscale, bit depths 1, 2, 4, 8, 16 +2: RGB, bit depths 8 and 16 +3: palette, bit depths 1, 2, 4 and 8 +4: grayscale with alpha, bit depths 8 and 16 +6: RGBA, bit depths 8 and 16 + +Bit depth is the amount of bits per pixel per color channel. So the total amount +of bits per pixel is: amount of channels * bitdepth. + +6.2. color conversions +---------------------- + +As explained in the sections about the encoder and decoder, you can specify +color types and bit depths in info_png and info_raw to change the default +behaviour. + +If, when decoding, you want the raw image to be something else than the default, +you need to set the color type and bit depth you want in the LodePNGColorMode, +or the parameters colortype and bitdepth of the simple decoding function. + +If, when encoding, you use another color type than the default in the raw input +image, you need to specify its color type and bit depth in the LodePNGColorMode +of the raw image, or use the parameters colortype and bitdepth of the simple +encoding function. + +If, when encoding, you don't want LodePNG to choose the output PNG color type +but control it yourself, you need to set auto_convert in the encoder settings +to false, and specify the color type you want in the LodePNGInfo of the +encoder (including palette: it can generate a palette if auto_convert is true, +otherwise not). + +If the input and output color type differ (whether user chosen or auto chosen), +LodePNG will do a color conversion, which follows the rules below, and may +sometimes result in an error. + +To avoid some confusion: +-the decoder converts from PNG to raw image +-the encoder converts from raw image to PNG +-the colortype and bitdepth in LodePNGColorMode info_raw, are those of the raw image +-the colortype and bitdepth in the color field of LodePNGInfo info_png, are those of the PNG +-when encoding, the color type in LodePNGInfo is ignored if auto_convert + is enabled, it is automatically generated instead +-when decoding, the color type in LodePNGInfo is set by the decoder to that of the original + PNG image, but it can be ignored since the raw image has the color type you requested instead +-if the color type of the LodePNGColorMode and PNG image aren't the same, a conversion + between the color types is done if the color types are supported. If it is not + supported, an error is returned. If the types are the same, no conversion is done. +-even though some conversions aren't supported, LodePNG supports loading PNGs from any + colortype and saving PNGs to any colortype, sometimes it just requires preparing + the raw image correctly before encoding. +-both encoder and decoder use the same color converter. + +The function lodepng_convert does the color conversion. It is available in the +interface but normally isn't needed since the encoder and decoder already call +it. + +Non supported color conversions: +-color to grayscale when non-gray pixels are present: no error is thrown, but +the result will look ugly because only the red channel is taken (it assumes all +three channels are the same in this case so ignores green and blue). The reason +no error is given is to allow converting from three-channel grayscale images to +one-channel even if there are numerical imprecisions. +-anything to palette when the palette does not have an exact match for a from-color +in it: in this case an error is thrown + +Supported color conversions: +-anything to 8-bit RGB, 8-bit RGBA, 16-bit RGB, 16-bit RGBA +-any gray or gray+alpha, to gray or gray+alpha +-anything to a palette, as long as the palette has the requested colors in it +-removing alpha channel +-higher to smaller bitdepth, and vice versa + +If you want no color conversion to be done (e.g. for speed or control): +-In the encoder, you can make it save a PNG with any color type by giving the +raw color mode and LodePNGInfo the same color mode, and setting auto_convert to +false. +-In the decoder, you can make it store the pixel data in the same color type +as the PNG has, by setting the color_convert setting to false. Settings in +info_raw are then ignored. + +6.3. padding bits +----------------- + +In the PNG file format, if a less than 8-bit per pixel color type is used and the scanlines +have a bit amount that isn't a multiple of 8, then padding bits are used so that each +scanline starts at a fresh byte. But that is NOT true for the LodePNG raw input and output. +The raw input image you give to the encoder, and the raw output image you get from the decoder +will NOT have these padding bits, e.g. in the case of a 1-bit image with a width +of 7 pixels, the first pixel of the second scanline will the 8th bit of the first byte, +not the first bit of a new byte. + +6.4. A note about 16-bits per channel and endianness +---------------------------------------------------- + +LodePNG uses unsigned char arrays for 16-bit per channel colors too, just like +for any other color format. The 16-bit values are stored in big endian (most +significant byte first) in these arrays. This is the opposite order of the +little endian used by x86 CPU's. + +LodePNG always uses big endian because the PNG file format does so internally. +Conversions to other formats than PNG uses internally are not supported by +LodePNG on purpose, there are myriads of formats, including endianness of 16-bit +colors, the order in which you store R, G, B and A, and so on. Supporting and +converting to/from all that is outside the scope of LodePNG. + +This may mean that, depending on your use case, you may want to convert the big +endian output of LodePNG to little endian with a for loop. This is certainly not +always needed, many applications and libraries support big endian 16-bit colors +anyway, but it means you cannot simply cast the unsigned char* buffer to an +unsigned short* buffer on x86 CPUs. + + +7. error values +--------------- + +All functions in LodePNG that return an error code, return 0 if everything went +OK, or a non-zero code if there was an error. + +The meaning of the LodePNG error values can be retrieved with the function +lodepng_error_text: given the numerical error code, it returns a description +of the error in English as a string. + +Check the implementation of lodepng_error_text to see the meaning of each code. + +It is not recommended to use the numerical values to programmatically make +different decisions based on error types as the numbers are not guaranteed to +stay backwards compatible. They are for human consumption only. Programmatically +only 0 or non-0 matter. + + +8. chunks and PNG editing +------------------------- + +If you want to add extra chunks to a PNG you encode, or use LodePNG for a PNG +editor that should follow the rules about handling of unknown chunks, or if your +program is able to read other types of chunks than the ones handled by LodePNG, +then that's possible with the chunk functions of LodePNG. + +A PNG chunk has the following layout: + +4 bytes length +4 bytes type name +length bytes data +4 bytes CRC + +8.1. iterating through chunks +----------------------------- + +If you have a buffer containing the PNG image data, then the first chunk (the +IHDR chunk) starts at byte number 8 of that buffer. The first 8 bytes are the +signature of the PNG and are not part of a chunk. But if you start at byte 8 +then you have a chunk, and can check the following things of it. + +NOTE: none of these functions check for memory buffer boundaries. To avoid +exploits, always make sure the buffer contains all the data of the chunks. +When using lodepng_chunk_next, make sure the returned value is within the +allocated memory. + +unsigned lodepng_chunk_length(const unsigned char* chunk): + +Get the length of the chunk's data. The total chunk length is this length + 12. + +void lodepng_chunk_type(char type[5], const unsigned char* chunk): +unsigned char lodepng_chunk_type_equals(const unsigned char* chunk, const char* type): + +Get the type of the chunk or compare if it's a certain type + +unsigned char lodepng_chunk_critical(const unsigned char* chunk): +unsigned char lodepng_chunk_private(const unsigned char* chunk): +unsigned char lodepng_chunk_safetocopy(const unsigned char* chunk): + +Check if the chunk is critical in the PNG standard (only IHDR, PLTE, IDAT and IEND are). +Check if the chunk is private (public chunks are part of the standard, private ones not). +Check if the chunk is safe to copy. If it's not, then, when modifying data in a critical +chunk, unsafe to copy chunks of the old image may NOT be saved in the new one if your +program doesn't handle that type of unknown chunk. + +unsigned char* lodepng_chunk_data(unsigned char* chunk): +const unsigned char* lodepng_chunk_data_const(const unsigned char* chunk): + +Get a pointer to the start of the data of the chunk. + +unsigned lodepng_chunk_check_crc(const unsigned char* chunk): +void lodepng_chunk_generate_crc(unsigned char* chunk): + +Check if the crc is correct or generate a correct one. + +unsigned char* lodepng_chunk_next(unsigned char* chunk): +const unsigned char* lodepng_chunk_next_const(const unsigned char* chunk): + +Iterate to the next chunk. This works if you have a buffer with consecutive chunks. Note that these +functions do no boundary checking of the allocated data whatsoever, so make sure there is enough +data available in the buffer to be able to go to the next chunk. + +unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk): +unsigned lodepng_chunk_create(unsigned char** out, size_t* outsize, unsigned length, + const char* type, const unsigned char* data): + +These functions are used to create new chunks that are appended to the data in *out that has +length *outsize. The append function appends an existing chunk to the new data. The create +function creates a new chunk with the given parameters and appends it. Type is the 4-letter +name of the chunk. + +8.2. chunks in info_png +----------------------- + +The LodePNGInfo struct contains fields with the unknown chunk in it. It has 3 +buffers (each with size) to contain 3 types of unknown chunks: +the ones that come before the PLTE chunk, the ones that come between the PLTE +and the IDAT chunks, and the ones that come after the IDAT chunks. +It's necessary to make the distinction between these 3 cases because the PNG +standard forces to keep the ordering of unknown chunks compared to the critical +chunks, but does not force any other ordering rules. + +info_png.unknown_chunks_data[0] is the chunks before PLTE +info_png.unknown_chunks_data[1] is the chunks after PLTE, before IDAT +info_png.unknown_chunks_data[2] is the chunks after IDAT + +The chunks in these 3 buffers can be iterated through and read by using the same +way described in the previous subchapter. + +When using the decoder to decode a PNG, you can make it store all unknown chunks +if you set the option settings.remember_unknown_chunks to 1. By default, this +option is off (0). + +The encoder will always encode unknown chunks that are stored in the info_png. +If you need it to add a particular chunk that isn't known by LodePNG, you can +use lodepng_chunk_append or lodepng_chunk_create to the chunk data in +info_png.unknown_chunks_data[x]. + +Chunks that are known by LodePNG should not be added in that way. E.g. to make +LodePNG add a bKGD chunk, set background_defined to true and add the correct +parameters there instead. + + +9. compiler support +------------------- + +No libraries other than the current standard C library are needed to compile +LodePNG. For the C++ version, only the standard C++ library is needed on top. +Add the files lodepng.c(pp) and lodepng.h to your project, include +lodepng.h where needed, and your program can read/write PNG files. + +It is compatible with C90 and up, and C++03 and up. + +If performance is important, use optimization when compiling! For both the +encoder and decoder, this makes a large difference. + +Make sure that LodePNG is compiled with the same compiler of the same version +and with the same settings as the rest of the program, or the interfaces with +std::vectors and std::strings in C++ can be incompatible. + +CHAR_BITS must be 8 or higher, because LodePNG uses unsigned chars for octets. + +*) gcc and g++ + +LodePNG is developed in gcc so this compiler is natively supported. It gives no +warnings with compiler options "-Wall -Wextra -pedantic -ansi", with gcc and g++ +version 4.7.1 on Linux, 32-bit and 64-bit. + +*) Clang + +Fully supported and warning-free. + +*) Mingw + +The Mingw compiler (a port of gcc for Windows) should be fully supported by +LodePNG. + +*) Visual Studio and Visual C++ Express Edition + +LodePNG should be warning-free with warning level W4. Two warnings were disabled +with pragmas though: warning 4244 about implicit conversions, and warning 4996 +where it wants to use a non-standard function fopen_s instead of the standard C +fopen. + +Visual Studio may want "stdafx.h" files to be included in each source file and +give an error "unexpected end of file while looking for precompiled header". +This is not standard C++ and will not be added to the stock LodePNG. You can +disable it for lodepng.cpp only by right clicking it, Properties, C/C++, +Precompiled Headers, and set it to Not Using Precompiled Headers there. + +NOTE: Modern versions of VS should be fully supported, but old versions, e.g. +VS6, are not guaranteed to work. + +*) Compilers on Macintosh + +LodePNG has been reported to work both with gcc and LLVM for Macintosh, both for +C and C++. + +*) Other Compilers + +If you encounter problems on any compilers, feel free to let me know and I may +try to fix it if the compiler is modern and standards compliant. + + +10. examples +------------ + +This decoder example shows the most basic usage of LodePNG. More complex +examples can be found on the LodePNG website. + +10.1. decoder C++ example +------------------------- + +#include "lodepng.h" +#include + +int main(int argc, char *argv[]) { + const char* filename = argc > 1 ? argv[1] : "test.png"; + + //load and decode + std::vector image; + unsigned width, height; + unsigned error = lodepng::decode(image, width, height, filename); + + //if there's an error, display it + if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl; + + //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ... +} + +10.2. decoder C example +----------------------- + +#include "lodepng.h" + +int main(int argc, char *argv[]) { + unsigned error; + unsigned char* image; + size_t width, height; + const char* filename = argc > 1 ? argv[1] : "test.png"; + + error = lodepng_decode32_file(&image, &width, &height, filename); + + if(error) printf("decoder error %u: %s\n", error, lodepng_error_text(error)); + + / * use image here * / + + free(image); + return 0; +} + +11. state settings reference +---------------------------- + +A quick reference of some settings to set on the LodePNGState + +For decoding: + +state.decoder.zlibsettings.ignore_adler32: ignore ADLER32 checksums +state.decoder.zlibsettings.custom_...: use custom inflate function +state.decoder.ignore_crc: ignore CRC checksums +state.decoder.ignore_critical: ignore unknown critical chunks +state.decoder.ignore_end: ignore missing IEND chunk. May fail if this corruption causes other errors +state.decoder.color_convert: convert internal PNG color to chosen one +state.decoder.read_text_chunks: whether to read in text metadata chunks +state.decoder.remember_unknown_chunks: whether to read in unknown chunks +state.info_raw.colortype: desired color type for decoded image +state.info_raw.bitdepth: desired bit depth for decoded image +state.info_raw....: more color settings, see struct LodePNGColorMode +state.info_png....: no settings for decoder but ouput, see struct LodePNGInfo + +For encoding: + +state.encoder.zlibsettings.btype: disable compression by setting it to 0 +state.encoder.zlibsettings.use_lz77: use LZ77 in compression +state.encoder.zlibsettings.windowsize: tweak LZ77 windowsize +state.encoder.zlibsettings.minmatch: tweak min LZ77 length to match +state.encoder.zlibsettings.nicematch: tweak LZ77 match where to stop searching +state.encoder.zlibsettings.lazymatching: try one more LZ77 matching +state.encoder.zlibsettings.custom_...: use custom deflate function +state.encoder.auto_convert: choose optimal PNG color type, if 0 uses info_png +state.encoder.filter_palette_zero: PNG filter strategy for palette +state.encoder.filter_strategy: PNG filter strategy to encode with +state.encoder.force_palette: add palette even if not encoding to one +state.encoder.add_id: add LodePNG identifier and version as a text chunk +state.encoder.text_compression: use compressed text chunks for metadata +state.info_raw.colortype: color type of raw input image you provide +state.info_raw.bitdepth: bit depth of raw input image you provide +state.info_raw: more color settings, see struct LodePNGColorMode +state.info_png.color.colortype: desired color type if auto_convert is false +state.info_png.color.bitdepth: desired bit depth if auto_convert is false +state.info_png.color....: more color settings, see struct LodePNGColorMode +state.info_png....: more PNG related settings, see struct LodePNGInfo + + +12. changes +----------- + +The version number of LodePNG is the date of the change given in the format +yyyymmdd. + +Some changes aren't backwards compatible. Those are indicated with a (!) +symbol. + +Not all changes are listed here, the commit history in github lists more: +https://github.com/lvandeve/lodepng + +*) 17 okt 2020: prevent decoding too large text/icc chunks by default. +*) 06 mar 2020: simplified some of the dynamic memory allocations. +*) 12 jan 2020: (!) added 'end' argument to lodepng_chunk_next to allow correct + overflow checks. +*) 14 aug 2019: around 25% faster decoding thanks to huffman lookup tables. +*) 15 jun 2019: (!) auto_choose_color API changed (for bugfix: don't use palette + if gray ICC profile) and non-ICC LodePNGColorProfile renamed to + LodePNGColorStats. +*) 30 dec 2018: code style changes only: removed newlines before opening braces. +*) 10 sep 2018: added way to inspect metadata chunks without full decoding. +*) 19 aug 2018: (!) fixed color mode bKGD is encoded with and made it use + palette index in case of palette. +*) 10 aug 2018: (!) added support for gAMA, cHRM, sRGB and iCCP chunks. This + change is backwards compatible unless you relied on unknown_chunks for those. +*) 11 jun 2018: less restrictive check for pixel size integer overflow +*) 14 jan 2018: allow optionally ignoring a few more recoverable errors +*) 17 sep 2017: fix memory leak for some encoder input error cases +*) 27 nov 2016: grey+alpha auto color model detection bugfix +*) 18 apr 2016: Changed qsort to custom stable sort (for platforms w/o qsort). +*) 09 apr 2016: Fixed colorkey usage detection, and better file loading (within + the limits of pure C90). +*) 08 dec 2015: Made load_file function return error if file can't be opened. +*) 24 okt 2015: Bugfix with decoding to palette output. +*) 18 apr 2015: Boundary PM instead of just package-merge for faster encoding. +*) 24 aug 2014: Moved to github +*) 23 aug 2014: Reduced needless memory usage of decoder. +*) 28 jun 2014: Removed fix_png setting, always support palette OOB for + simplicity. Made ColorProfile public. +*) 09 jun 2014: Faster encoder by fixing hash bug and more zeros optimization. +*) 22 dec 2013: Power of two windowsize required for optimization. +*) 15 apr 2013: Fixed bug with LAC_ALPHA and color key. +*) 25 mar 2013: Added an optional feature to ignore some PNG errors (fix_png). +*) 11 mar 2013: (!) Bugfix with custom free. Changed from "my" to "lodepng_" + prefix for the custom allocators and made it possible with a new #define to + use custom ones in your project without needing to change lodepng's code. +*) 28 jan 2013: Bugfix with color key. +*) 27 okt 2012: Tweaks in text chunk keyword length error handling. +*) 8 okt 2012: (!) Added new filter strategy (entropy) and new auto color mode. + (no palette). Better deflate tree encoding. New compression tweak settings. + Faster color conversions while decoding. Some internal cleanups. +*) 23 sep 2012: Reduced warnings in Visual Studio a little bit. +*) 1 sep 2012: (!) Removed #define's for giving custom (de)compression functions + and made it work with function pointers instead. +*) 23 jun 2012: Added more filter strategies. Made it easier to use custom alloc + and free functions and toggle #defines from compiler flags. Small fixes. +*) 6 may 2012: (!) Made plugging in custom zlib/deflate functions more flexible. +*) 22 apr 2012: (!) Made interface more consistent, renaming a lot. Removed + redundant C++ codec classes. Reduced amount of structs. Everything changed, + but it is cleaner now imho and functionality remains the same. Also fixed + several bugs and shrunk the implementation code. Made new samples. +*) 6 nov 2011: (!) By default, the encoder now automatically chooses the best + PNG color model and bit depth, based on the amount and type of colors of the + raw image. For this, autoLeaveOutAlphaChannel replaced by auto_choose_color. +*) 9 okt 2011: simpler hash chain implementation for the encoder. +*) 8 sep 2011: lz77 encoder lazy matching instead of greedy matching. +*) 23 aug 2011: tweaked the zlib compression parameters after benchmarking. + A bug with the PNG filtertype heuristic was fixed, so that it chooses much + better ones (it's quite significant). A setting to do an experimental, slow, + brute force search for PNG filter types is added. +*) 17 aug 2011: (!) changed some C zlib related function names. +*) 16 aug 2011: made the code less wide (max 120 characters per line). +*) 17 apr 2011: code cleanup. Bugfixes. Convert low to 16-bit per sample colors. +*) 21 feb 2011: fixed compiling for C90. Fixed compiling with sections disabled. +*) 11 dec 2010: encoding is made faster, based on suggestion by Peter Eastman + to optimize long sequences of zeros. +*) 13 nov 2010: added LodePNG_InfoColor_hasPaletteAlpha and + LodePNG_InfoColor_canHaveAlpha functions for convenience. +*) 7 nov 2010: added LodePNG_error_text function to get error code description. +*) 30 okt 2010: made decoding slightly faster +*) 26 okt 2010: (!) changed some C function and struct names (more consistent). + Reorganized the documentation and the declaration order in the header. +*) 08 aug 2010: only changed some comments and external samples. +*) 05 jul 2010: fixed bug thanks to warnings in the new gcc version. +*) 14 mar 2010: fixed bug where too much memory was allocated for char buffers. +*) 02 sep 2008: fixed bug where it could create empty tree that linux apps could + read by ignoring the problem but windows apps couldn't. +*) 06 jun 2008: added more error checks for out of memory cases. +*) 26 apr 2008: added a few more checks here and there to ensure more safety. +*) 06 mar 2008: crash with encoding of strings fixed +*) 02 feb 2008: support for international text chunks added (iTXt) +*) 23 jan 2008: small cleanups, and #defines to divide code in sections +*) 20 jan 2008: support for unknown chunks allowing using LodePNG for an editor. +*) 18 jan 2008: support for tIME and pHYs chunks added to encoder and decoder. +*) 17 jan 2008: ability to encode and decode compressed zTXt chunks added + Also various fixes, such as in the deflate and the padding bits code. +*) 13 jan 2008: Added ability to encode Adam7-interlaced images. Improved + filtering code of encoder. +*) 07 jan 2008: (!) changed LodePNG to use ISO C90 instead of C++. A + C++ wrapper around this provides an interface almost identical to before. + Having LodePNG be pure ISO C90 makes it more portable. The C and C++ code + are together in these files but it works both for C and C++ compilers. +*) 29 dec 2007: (!) changed most integer types to unsigned int + other tweaks +*) 30 aug 2007: bug fixed which makes this Borland C++ compatible +*) 09 aug 2007: some VS2005 warnings removed again +*) 21 jul 2007: deflate code placed in new namespace separate from zlib code +*) 08 jun 2007: fixed bug with 2- and 4-bit color, and small interlaced images +*) 04 jun 2007: improved support for Visual Studio 2005: crash with accessing + invalid std::vector element [0] fixed, and level 3 and 4 warnings removed +*) 02 jun 2007: made the encoder add a tag with version by default +*) 27 may 2007: zlib and png code separated (but still in the same file), + simple encoder/decoder functions added for more simple usage cases +*) 19 may 2007: minor fixes, some code cleaning, new error added (error 69), + moved some examples from here to lodepng_examples.cpp +*) 12 may 2007: palette decoding bug fixed +*) 24 apr 2007: changed the license from BSD to the zlib license +*) 11 mar 2007: very simple addition: ability to encode bKGD chunks. +*) 04 mar 2007: (!) tEXt chunk related fixes, and support for encoding + palettized PNG images. Plus little interface change with palette and texts. +*) 03 mar 2007: Made it encode dynamic Huffman shorter with repeat codes. + Fixed a bug where the end code of a block had length 0 in the Huffman tree. +*) 26 feb 2007: Huffman compression with dynamic trees (BTYPE 2) now implemented + and supported by the encoder, resulting in smaller PNGs at the output. +*) 27 jan 2007: Made the Adler-32 test faster so that a timewaste is gone. +*) 24 jan 2007: gave encoder an error interface. Added color conversion from any + greyscale type to 8-bit greyscale with or without alpha. +*) 21 jan 2007: (!) Totally changed the interface. It allows more color types + to convert to and is more uniform. See the manual for how it works now. +*) 07 jan 2007: Some cleanup & fixes, and a few changes over the last days: + encode/decode custom tEXt chunks, separate classes for zlib & deflate, and + at last made the decoder give errors for incorrect Adler32 or Crc. +*) 01 jan 2007: Fixed bug with encoding PNGs with less than 8 bits per channel. +*) 29 dec 2006: Added support for encoding images without alpha channel, and + cleaned out code as well as making certain parts faster. +*) 28 dec 2006: Added "Settings" to the encoder. +*) 26 dec 2006: The encoder now does LZ77 encoding and produces much smaller files now. + Removed some code duplication in the decoder. Fixed little bug in an example. +*) 09 dec 2006: (!) Placed output parameters of public functions as first parameter. + Fixed a bug of the decoder with 16-bit per color. +*) 15 okt 2006: Changed documentation structure +*) 09 okt 2006: Encoder class added. It encodes a valid PNG image from the + given image buffer, however for now it's not compressed. +*) 08 sep 2006: (!) Changed to interface with a Decoder class +*) 30 jul 2006: (!) LodePNG_InfoPng , width and height are now retrieved in different + way. Renamed decodePNG to decodePNGGeneric. +*) 29 jul 2006: (!) Changed the interface: image info is now returned as a + struct of type LodePNG::LodePNG_Info, instead of a vector, which was a bit clumsy. +*) 28 jul 2006: Cleaned the code and added new error checks. + Corrected terminology "deflate" into "inflate". +*) 23 jun 2006: Added SDL example in the documentation in the header, this + example allows easy debugging by displaying the PNG and its transparency. +*) 22 jun 2006: (!) Changed way to obtain error value. Added + loadFile function for convenience. Made decodePNG32 faster. +*) 21 jun 2006: (!) Changed type of info vector to unsigned. + Changed position of palette in info vector. Fixed an important bug that + happened on PNGs with an uncompressed block. +*) 16 jun 2006: Internally changed unsigned into unsigned where + needed, and performed some optimizations. +*) 07 jun 2006: (!) Renamed functions to decodePNG and placed them + in LodePNG namespace. Changed the order of the parameters. Rewrote the + documentation in the header. Renamed files to lodepng.cpp and lodepng.h +*) 22 apr 2006: Optimized and improved some code +*) 07 sep 2005: (!) Changed to std::vector interface +*) 12 aug 2005: Initial release (C++, decoder only) + + +13. contact information +----------------------- + +Feel free to contact me with suggestions, problems, comments, ... concerning +LodePNG. If you encounter a PNG image that doesn't work properly with this +decoder, feel free to send it and I'll use it to find and fix the problem. + +My email address is (puzzle the account and domain together with an @ symbol): +Domain: gmail dot com. +Account: lode dot vandevenne. + + +Copyright (c) 2005-2020 Lode Vandevenne +*/ diff --git a/include/liblvgl/extra/libs/png/lv_png.h b/include/liblvgl/extra/libs/png/lv_png.h new file mode 100644 index 00000000..ef634540 --- /dev/null +++ b/include/liblvgl/extra/libs/png/lv_png.h @@ -0,0 +1,46 @@ +/** + * @file lv_png.h + * + */ + +#ifndef LV_PNG_H +#define LV_PNG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_PNG + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Register the PNG decoder functions in LVGL + */ +void lv_png_init(void); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_PNG*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_PNG_H*/ diff --git a/include/liblvgl/extra/libs/qrcode/lv_qrcode.h b/include/liblvgl/extra/libs/qrcode/lv_qrcode.h new file mode 100644 index 00000000..c8db4e5e --- /dev/null +++ b/include/liblvgl/extra/libs/qrcode/lv_qrcode.h @@ -0,0 +1,69 @@ +/** + * @file lv_qrcode + * + */ + +#ifndef LV_QRCODE_H +#define LV_QRCODE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" +#if LV_USE_QRCODE + +/********************* + * DEFINES + *********************/ + +extern const lv_obj_class_t lv_qrcode_class; + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an empty QR code (an `lv_canvas`) object. + * @param parent point to an object where to create the QR code + * @param size width and height of the QR code + * @param dark_color dark color of the QR code + * @param light_color light color of the QR code + * @return pointer to the created QR code object + */ +lv_obj_t * lv_qrcode_create(lv_obj_t * parent, lv_coord_t size, lv_color_t dark_color, lv_color_t light_color); + +/** + * Set the data of a QR code object + * @param qrcode pointer to aQ code object + * @param data data to display + * @param data_len length of data in bytes + * @return LV_RES_OK: if no error; LV_RES_INV: on error + */ +lv_res_t lv_qrcode_update(lv_obj_t * qrcode, const void * data, uint32_t data_len); + +/** + * DEPRECATED: Use normal lv_obj_del instead + * Delete a QR code object + * @param qrcode pointer to a QR code object + */ +void lv_qrcode_delete(lv_obj_t * qrcode); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_QRCODE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_QRCODE_H*/ diff --git a/include/liblvgl/extra/libs/qrcode/qrcodegen.h b/include/liblvgl/extra/libs/qrcode/qrcodegen.h new file mode 100644 index 00000000..b484e917 --- /dev/null +++ b/include/liblvgl/extra/libs/qrcode/qrcodegen.h @@ -0,0 +1,319 @@ +/* + * QR Code generator library (C) + * + * Copyright (c) Project Nayuki. (MIT License) + * https://www.nayuki.io/page/qr-code-generator-library + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * - The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * - The Software is provided "as is", without warranty of any kind, express or + * implied, including but not limited to the warranties of merchantability, + * fitness for a particular purpose and noninfringement. In no event shall the + * authors or copyright holders be liable for any claim, damages or other + * liability, whether in an action of contract, tort or otherwise, arising from, + * out of or in connection with the Software or the use or other dealings in the + * Software. + */ + +#pragma once + +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * This library creates QR Code symbols, which is a type of two-dimension barcode. + * Invented by Denso Wave and described in the ISO/IEC 18004 standard. + * A QR Code structure is an immutable square grid of black and white cells. + * The library provides functions to create a QR Code from text or binary data. + * The library covers the QR Code Model 2 specification, supporting all versions (sizes) + * from 1 to 40, all 4 error correction levels, and 4 character encoding modes. + * + * Ways to create a QR Code object: + * - High level: Take the payload data and call qrcodegen_encodeText() or qrcodegen_encodeBinary(). + * - Low level: Custom-make the list of segments and call + * qrcodegen_encodeSegments() or qrcodegen_encodeSegmentsAdvanced(). + * (Note that all ways require supplying the desired error correction level and various byte buffers.) + */ + + +/*---- Enum and struct types----*/ + +/* + * The error correction level in a QR Code symbol. + */ +enum qrcodegen_Ecc { + // Must be declared in ascending order of error protection + // so that an internal qrcodegen function works properly + qrcodegen_Ecc_LOW = 0 , // The QR Code can tolerate about 7% erroneous codewords + qrcodegen_Ecc_MEDIUM , // The QR Code can tolerate about 15% erroneous codewords + qrcodegen_Ecc_QUARTILE, // The QR Code can tolerate about 25% erroneous codewords + qrcodegen_Ecc_HIGH , // The QR Code can tolerate about 30% erroneous codewords +}; + + +/* + * The mask pattern used in a QR Code symbol. + */ +enum qrcodegen_Mask { + // A special value to tell the QR Code encoder to + // automatically select an appropriate mask pattern + qrcodegen_Mask_AUTO = -1, + // The eight actual mask patterns + qrcodegen_Mask_0 = 0, + qrcodegen_Mask_1, + qrcodegen_Mask_2, + qrcodegen_Mask_3, + qrcodegen_Mask_4, + qrcodegen_Mask_5, + qrcodegen_Mask_6, + qrcodegen_Mask_7, +}; + + +/* + * Describes how a segment's data bits are interpreted. + */ +enum qrcodegen_Mode { + qrcodegen_Mode_NUMERIC = 0x1, + qrcodegen_Mode_ALPHANUMERIC = 0x2, + qrcodegen_Mode_BYTE = 0x4, + qrcodegen_Mode_KANJI = 0x8, + qrcodegen_Mode_ECI = 0x7, +}; + + +/* + * A segment of character/binary/control data in a QR Code symbol. + * The mid-level way to create a segment is to take the payload data + * and call a factory function such as qrcodegen_makeNumeric(). + * The low-level way to create a segment is to custom-make the bit buffer + * and initialize a qrcodegen_Segment struct with appropriate values. + * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. + * Any segment longer than this is meaningless for the purpose of generating QR Codes. + * Moreover, the maximum allowed bit length is 32767 because + * the largest QR Code (version 40) has 31329 modules. + */ +struct qrcodegen_Segment { + // The mode indicator of this segment. + enum qrcodegen_Mode mode; + + // The length of this segment's unencoded data. Measured in characters for + // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. + // Always zero or positive. Not the same as the data's bit length. + int numChars; + + // The data bits of this segment, packed in bitwise big endian. + // Can be null if the bit length is zero. + uint8_t *data; + + // The number of valid data bits used in the buffer. Requires + // 0 <= bitLength <= 32767, and bitLength <= (capacity of data array) * 8. + // The character count (numChars) must agree with the mode and the bit buffer length. + int bitLength; +}; + + + +/*---- Macro constants and functions ----*/ + +#define qrcodegen_VERSION_MIN 1 // The minimum version number supported in the QR Code Model 2 standard +#define qrcodegen_VERSION_MAX 40 // The maximum version number supported in the QR Code Model 2 standard + +// Calculates the number of bytes needed to store any QR Code up to and including the given version number, +// as a compile-time constant. For example, 'uint8_t buffer[qrcodegen_BUFFER_LEN_FOR_VERSION(25)];' +// can store any single QR Code from version 1 to 25 (inclusive). The result fits in an int (or int16). +// Requires qrcodegen_VERSION_MIN <= n <= qrcodegen_VERSION_MAX. +#define qrcodegen_BUFFER_LEN_FOR_VERSION(n) ((((n) * 4 + 17) * ((n) * 4 + 17) + 7) / 8 + 1) + +// The worst-case number of bytes needed to store one QR Code, up to and including +// version 40. This value equals 3918, which is just under 4 kilobytes. +// Use this more convenient value to avoid calculating tighter memory bounds for buffers. +#define qrcodegen_BUFFER_LEN_MAX qrcodegen_BUFFER_LEN_FOR_VERSION(qrcodegen_VERSION_MAX) + + + +/*---- Functions (high level) to generate QR Codes ----*/ + +/* + * Encodes the given text string to a QR Code, returning true if encoding succeeded. + * If the data is too long to fit in any version in the given range + * at the given ECC level, then false is returned. + * - The input text must be encoded in UTF-8 and contain no NULs. + * - The variables ecl and mask must correspond to enum constant values. + * - Requires 1 <= minVersion <= maxVersion <= 40. + * - The arrays tempBuffer and qrcode must each have a length + * of at least qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion). + * - After the function returns, tempBuffer contains no useful data. + * - If successful, the resulting QR Code may use numeric, + * alphanumeric, or byte mode to encode the text. + * - In the most optimistic case, a QR Code at version 40 with low ECC + * can hold any UTF-8 string up to 2953 bytes, or any alphanumeric string + * up to 4296 characters, or any digit string up to 7089 characters. + * These numbers represent the hard upper limit of the QR Code standard. + * - Please consult the QR Code specification for information on + * data capacities per version, ECC level, and text encoding mode. + */ +bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], + enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); + + +/* + * Encodes the given binary data to a QR Code, returning true if encoding succeeded. + * If the data is too long to fit in any version in the given range + * at the given ECC level, then false is returned. + * - The input array range dataAndTemp[0 : dataLen] should normally be + * valid UTF-8 text, but is not required by the QR Code standard. + * - The variables ecl and mask must correspond to enum constant values. + * - Requires 1 <= minVersion <= maxVersion <= 40. + * - The arrays dataAndTemp and qrcode must each have a length + * of at least qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion). + * - After the function returns, the contents of dataAndTemp may have changed, + * and does not represent useful data anymore. + * - If successful, the resulting QR Code will use byte mode to encode the data. + * - In the most optimistic case, a QR Code at version 40 with low ECC can hold any byte + * sequence up to length 2953. This is the hard upper limit of the QR Code standard. + * - Please consult the QR Code specification for information on + * data capacities per version, ECC level, and text encoding mode. + */ +bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcode[], + enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); + + +/*---- Functions (low level) to generate QR Codes ----*/ + +/* + * Renders a QR Code representing the given segments at the given error correction level. + * The smallest possible QR Code version is automatically chosen for the output. Returns true if + * QR Code creation succeeded, or false if the data is too long to fit in any version. The ECC level + * of the result may be higher than the ecl argument if it can be done without increasing the version. + * This function allows the user to create a custom sequence of segments that switches + * between modes (such as alphanumeric and byte) to encode text in less space. + * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary(). + * To save memory, the segments' data buffers can alias/overlap tempBuffer, and will + * result in them being clobbered, but the QR Code output will still be correct. + * But the qrcode array must not overlap tempBuffer or any segment's data buffer. + */ +bool qrcodegen_encodeSegments(const struct qrcodegen_Segment segs[], size_t len, + enum qrcodegen_Ecc ecl, uint8_t tempBuffer[], uint8_t qrcode[]); + + +/* + * Renders a QR Code representing the given segments with the given encoding parameters. + * Returns true if QR Code creation succeeded, or false if the data is too long to fit in the range of versions. + * The smallest possible QR Code version within the given range is automatically + * chosen for the output. Iff boostEcl is true, then the ECC level of the result + * may be higher than the ecl argument if it can be done without increasing the + * version. The mask number is either between 0 to 7 (inclusive) to force that + * mask, or -1 to automatically choose an appropriate mask (which may be slow). + * This function allows the user to create a custom sequence of segments that switches + * between modes (such as alphanumeric and byte) to encode text in less space. + * This is a low-level API; the high-level API is qrcodegen_encodeText() and qrcodegen_encodeBinary(). + * To save memory, the segments' data buffers can alias/overlap tempBuffer, and will + * result in them being clobbered, but the QR Code output will still be correct. + * But the qrcode array must not overlap tempBuffer or any segment's data buffer. + */ +bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], size_t len, enum qrcodegen_Ecc ecl, + int minVersion, int maxVersion, int mask, bool boostEcl, uint8_t tempBuffer[], uint8_t qrcode[]); + + +/* + * Tests whether the given string can be encoded as a segment in alphanumeric mode. + * A string is encodable iff each character is in the following set: 0 to 9, A to Z + * (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon. + */ +bool qrcodegen_isAlphanumeric(const char *text); + + +/* + * Tests whether the given string can be encoded as a segment in numeric mode. + * A string is encodable iff each character is in the range 0 to 9. + */ +bool qrcodegen_isNumeric(const char *text); + + +/* + * Returns the number of bytes (uint8_t) needed for the data buffer of a segment + * containing the given number of characters using the given mode. Notes: + * - Returns SIZE_MAX on failure, i.e. numChars > INT16_MAX or + * the number of needed bits exceeds INT16_MAX (i.e. 32767). + * - Otherwise, all valid results are in the range [0, ceil(INT16_MAX / 8)], i.e. at most 4096. + * - It is okay for the user to allocate more bytes for the buffer than needed. + * - For byte mode, numChars measures the number of bytes, not Unicode code points. + * - For ECI mode, numChars must be 0, and the worst-case number of bytes is returned. + * An actual ECI segment can have shorter data. For non-ECI modes, the result is exact. + */ +size_t qrcodegen_calcSegmentBufferSize(enum qrcodegen_Mode mode, size_t numChars); + + +/* + * Returns a segment representing the given binary data encoded in + * byte mode. All input byte arrays are acceptable. Any text string + * can be converted to UTF-8 bytes and encoded as a byte mode segment. + */ +struct qrcodegen_Segment qrcodegen_makeBytes(const uint8_t data[], size_t len, uint8_t buf[]); + + +/* + * Returns a segment representing the given string of decimal digits encoded in numeric mode. + */ +struct qrcodegen_Segment qrcodegen_makeNumeric(const char *digits, uint8_t buf[]); + + +/* + * Returns a segment representing the given text string encoded in alphanumeric mode. + * The characters allowed are: 0 to 9, A to Z (uppercase only), space, + * dollar, percent, asterisk, plus, hyphen, period, slash, colon. + */ +struct qrcodegen_Segment qrcodegen_makeAlphanumeric(const char *text, uint8_t buf[]); + + +/* + * Returns a segment representing an Extended Channel Interpretation + * (ECI) designator with the given assignment value. + */ +struct qrcodegen_Segment qrcodegen_makeEci(long assignVal, uint8_t buf[]); + + +/*---- Functions to extract raw data from QR Codes ----*/ + +/* + * Returns the side length of the given QR Code, assuming that encoding succeeded. + * The result is in the range [21, 177]. Note that the length of the array buffer + * is related to the side length - every 'uint8_t qrcode[]' must have length at least + * qrcodegen_BUFFER_LEN_FOR_VERSION(version), which equals ceil(size^2 / 8 + 1). + */ +int qrcodegen_getSize(const uint8_t qrcode[]); + + +/* + * Returns the color of the module (pixel) at the given coordinates, which is false + * for white or true for black. The top left corner has the coordinates (x=0, y=0). + * If the given coordinates are out of bounds, then false (white) is returned. + */ +bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y); + +/* + * Returns the qrcode size of the specified version. Returns -1 on failure + */ +int qrcodegen_version2size(int version); +/* + * Returns the min version of the data that can be stored. Returns -1 on failure + */ +int qrcodegen_getMinFitVersion(enum qrcodegen_Ecc ecl, size_t dataLen); + +#ifdef __cplusplus +} +#endif diff --git a/include/liblvgl/extra/libs/rlottie/lv_rlottie.h b/include/liblvgl/extra/libs/rlottie/lv_rlottie.h new file mode 100644 index 00000000..a8aca7bc --- /dev/null +++ b/include/liblvgl/extra/libs/rlottie/lv_rlottie.h @@ -0,0 +1,75 @@ +/** + * @file lv_rlottie.h + * + */ + +#ifndef LV_RLOTTIE_H +#define LV_RLOTTIE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" +#if LV_USE_RLOTTIE + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef enum { + LV_RLOTTIE_CTRL_FORWARD = 0, + LV_RLOTTIE_CTRL_BACKWARD = 1, + LV_RLOTTIE_CTRL_PAUSE = 2, + LV_RLOTTIE_CTRL_PLAY = 0, /* Yes, play = 0 is the default mode */ + LV_RLOTTIE_CTRL_LOOP = 8, +} lv_rlottie_ctrl_t; + +/** definition in lottieanimation_capi.c */ +struct Lottie_Animation_S; +typedef struct { + lv_img_t img_ext; + struct Lottie_Animation_S * animation; + lv_timer_t * task; + lv_img_dsc_t imgdsc; + size_t total_frames; + size_t current_frame; + size_t framerate; + uint32_t * allocated_buf; + size_t allocated_buffer_size; + size_t scanline_width; + lv_rlottie_ctrl_t play_ctrl; + size_t dest_frame; +} lv_rlottie_t; + +extern const lv_obj_class_t lv_rlottie_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_rlottie_create_from_file(lv_obj_t * parent, lv_coord_t width, lv_coord_t height, const char * path); + +lv_obj_t * lv_rlottie_create_from_raw(lv_obj_t * parent, lv_coord_t width, lv_coord_t height, + const char * rlottie_desc); + +void lv_rlottie_set_play_mode(lv_obj_t * rlottie, const lv_rlottie_ctrl_t ctrl); +void lv_rlottie_set_current_frame(lv_obj_t * rlottie, const size_t goto_frame); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_RLOTTIE*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_RLOTTIE_H*/ diff --git a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal.h b/include/liblvgl/extra/libs/sjpg/lv_sjpg.h similarity index 72% rename from EZ-Template-Example-Project/include/display/lv_hal/lv_hal.h rename to include/liblvgl/extra/libs/sjpg/lv_sjpg.h index 5ab28f2a..d06e80de 100644 --- a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal.h +++ b/include/liblvgl/extra/libs/sjpg/lv_sjpg.h @@ -1,10 +1,10 @@ /** - * @file hal.h + * @file lv_sjpg.h * */ -#ifndef HAL_H -#define HAL_H +#ifndef LV_SJPEG_H +#define LV_SJPEG_H #ifdef __cplusplus extern "C" { @@ -13,9 +13,8 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "lv_hal_disp.h" -#include "lv_hal_indev.h" -#include "lv_hal_tick.h" + +#if LV_USE_SJPG /********************* * DEFINES @@ -29,12 +28,16 @@ extern "C" { * GLOBAL PROTOTYPES **********************/ +void lv_split_jpeg_init(void); + /********************** * MACROS **********************/ +#endif /*LV_USE_SJPG*/ + #ifdef __cplusplus -} /* extern "C" */ +} #endif -#endif +#endif /* LV_SJPEG_H */ diff --git a/include/liblvgl/extra/libs/sjpg/tjpgd.h b/include/liblvgl/extra/libs/sjpg/tjpgd.h new file mode 100644 index 00000000..866e6b32 --- /dev/null +++ b/include/liblvgl/extra/libs/sjpg/tjpgd.h @@ -0,0 +1,93 @@ +/*----------------------------------------------------------------------------/ +/ TJpgDec - Tiny JPEG Decompressor R0.03 include file (C)ChaN, 2021 +/----------------------------------------------------------------------------*/ +#ifndef DEF_TJPGDEC +#define DEF_TJPGDEC + +#ifdef __cplusplus +extern "C" { +#endif + +#include "liblvgl/lv_conf_internal.h" +#if LV_USE_SJPG + +#include "tjpgdcnf.h" +#include +#include + +#if JD_FASTDECODE >= 1 +typedef int16_t jd_yuv_t; +#else +typedef uint8_t jd_yuv_t; +#endif + + +/* Error code */ +typedef enum { + JDR_OK = 0, /* 0: Succeeded */ + JDR_INTR, /* 1: Interrupted by output function */ + JDR_INP, /* 2: Device error or wrong termination of input stream */ + JDR_MEM1, /* 3: Insufficient memory pool for the image */ + JDR_MEM2, /* 4: Insufficient stream input buffer */ + JDR_PAR, /* 5: Parameter error */ + JDR_FMT1, /* 6: Data format error (may be broken data) */ + JDR_FMT2, /* 7: Right format but not supported */ + JDR_FMT3 /* 8: Not supported JPEG standard */ +} JRESULT; + +/* Rectangular region in the output image */ +typedef struct { + uint16_t left; /* Left end */ + uint16_t right; /* Right end */ + uint16_t top; /* Top end */ + uint16_t bottom; /* Bottom end */ +} JRECT; + +/* Decompressor object structure */ +typedef struct JDEC JDEC; +struct JDEC { + size_t dctr; /* Number of bytes available in the input buffer */ + uint8_t* dptr; /* Current data read ptr */ + uint8_t* inbuf; /* Bit stream input buffer */ + uint8_t dbit; /* Number of bits availavble in wreg or reading bit mask */ + uint8_t scale; /* Output scaling ratio */ + uint8_t msx, msy; /* MCU size in unit of block (width, height) */ + uint8_t qtid[3]; /* Quantization table ID of each component, Y, Cb, Cr */ + uint8_t ncomp; /* Number of color components 1:grayscale, 3:color */ + int16_t dcv[3]; /* Previous DC element of each component */ + uint16_t nrst; /* Restart inverval */ + uint16_t width, height; /* Size of the input image (pixel) */ + uint8_t* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */ + uint16_t* huffcode[2][2]; /* Huffman code word tables [id][dcac] */ + uint8_t* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */ + int32_t* qttbl[4]; /* Dequantizer tables [id] */ +#if JD_FASTDECODE >= 1 + uint32_t wreg; /* Working shift register */ + uint8_t marker; /* Detected marker (0:None) */ +#if JD_FASTDECODE == 2 + uint8_t longofs[2][2]; /* Table offset of long code [id][dcac] */ + uint16_t* hufflut_ac[2]; /* Fast huffman decode tables for AC short code [id] */ + uint8_t* hufflut_dc[2]; /* Fast huffman decode tables for DC short code [id] */ +#endif +#endif + void* workbuf; /* Working buffer for IDCT and RGB output */ + jd_yuv_t* mcubuf; /* Working buffer for the MCU */ + void* pool; /* Pointer to available memory pool */ + size_t sz_pool; /* Size of momory pool (bytes available) */ + size_t (*infunc)(JDEC*, uint8_t*, size_t); /* Pointer to jpeg stream input function */ + void* device; /* Pointer to I/O device identifiler for the session */ +}; + + + +/* TJpgDec API functions */ +JRESULT jd_prepare (JDEC* jd, size_t (*infunc)(JDEC*,uint8_t*,size_t), void* pool, size_t sz_pool, void* dev); +JRESULT jd_decomp (JDEC* jd, int (*outfunc)(JDEC*,void*,JRECT*), uint8_t scale); + +#endif /*LV_USE_SJPG*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _TJPGDEC */ diff --git a/include/liblvgl/extra/libs/sjpg/tjpgdcnf.h b/include/liblvgl/extra/libs/sjpg/tjpgdcnf.h new file mode 100644 index 00000000..6d425e6f --- /dev/null +++ b/include/liblvgl/extra/libs/sjpg/tjpgdcnf.h @@ -0,0 +1,33 @@ +/*----------------------------------------------*/ +/* TJpgDec System Configurations R0.03 */ +/*----------------------------------------------*/ + +#define JD_SZBUF 512 +/* Specifies size of stream input buffer */ + +#define JD_FORMAT 0 +/* Specifies output pixel format. +/ 0: RGB888 (24-bit/pix) +/ 1: RGB565 (16-bit/pix) +/ 2: Grayscale (8-bit/pix) +*/ + +#define JD_USE_SCALE 1 +/* Switches output descaling feature. +/ 0: Disable +/ 1: Enable +*/ + +#define JD_TBLCLIP 1 +/* Use table conversion for saturation arithmetic. A bit faster, but increases 1 KB of code size. +/ 0: Disable +/ 1: Enable +*/ + +#define JD_FASTDECODE 0 +/* Optimization level +/ 0: Basic optimization. Suitable for 8/16-bit MCUs. +/ 1: + 32-bit barrel shifter. Suitable for 32-bit MCUs. +/ 2: + Table conversion for huffman decoding (wants 6 << HUFF_BIT bytes of RAM) +*/ + diff --git a/include/liblvgl/extra/lv_extra.h b/include/liblvgl/extra/lv_extra.h new file mode 100644 index 00000000..c0306a98 --- /dev/null +++ b/include/liblvgl/extra/lv_extra.h @@ -0,0 +1,48 @@ +/** + * @file lv_extra.h + * + */ + +#ifndef LV_EXTRA_H +#define LV_EXTRA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "layouts/lv_layouts.h" +#include "libs/lv_libs.h" +#include "others/lv_others.h" +#include "themes/lv_themes.h" +#include "widgets/lv_widgets.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the extra components + */ +void lv_extra_init(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_EXTRA_H*/ diff --git a/include/liblvgl/extra/others/fragment/lv_fragment.h b/include/liblvgl/extra/others/fragment/lv_fragment.h new file mode 100644 index 00000000..9b7312f8 --- /dev/null +++ b/include/liblvgl/extra/others/fragment/lv_fragment.h @@ -0,0 +1,339 @@ +/** + * Public header for Fragment + * @file lv_fragment.h + */ + +#ifndef LV_FRAGMENT_H +#define LV_FRAGMENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_FRAGMENT + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct _lv_fragment_manager_t lv_fragment_manager_t; + +typedef struct _lv_fragment_t lv_fragment_t; +typedef struct _lv_fragment_class_t lv_fragment_class_t; +typedef struct _lv_fragment_managed_states_t lv_fragment_managed_states_t; + +struct _lv_fragment_t { + /** + * Class of this fragment + */ + const lv_fragment_class_t * cls; + /** + * Managed fragment states. If not null, then this fragment is managed. + * + * @warning Don't modify values inside this struct! + */ + lv_fragment_managed_states_t * managed; + /** + * Child fragment manager + */ + lv_fragment_manager_t * child_manager; + /** + * lv_obj returned by create_obj_cb + */ + lv_obj_t * obj; + +}; + +struct _lv_fragment_class_t { + /** + * Constructor function for fragment class + * @param self Fragment instance + * @param args Arguments assigned by fragment manager + */ + void (*constructor_cb)(lv_fragment_t * self, void * args); + + /** + * Destructor function for fragment class + * @param self Fragment instance, will be freed after this call + */ + void (*destructor_cb)(lv_fragment_t * self); + + /** + * Fragment attached to manager + * @param self Fragment instance + */ + void (*attached_cb)(lv_fragment_t * self); + + /** + * Fragment detached from manager + * @param self Fragment instance + */ + void (*detached_cb)(lv_fragment_t * self); + + /** + * Create objects + * @param self Fragment instance + * @param container Container of the objects should be created upon + * @return Created object, NULL if multiple objects has been created + */ + lv_obj_t * (*create_obj_cb)(lv_fragment_t * self, lv_obj_t * container); + + /** + * + * @param self Fragment instance + * @param obj lv_obj returned by create_obj_cb + */ + void (*obj_created_cb)(lv_fragment_t * self, lv_obj_t * obj); + + /** + * Called before objects in the fragment will be deleted. + * + * @param self Fragment instance + * @param obj object with this fragment + */ + void (*obj_will_delete_cb)(lv_fragment_t * self, lv_obj_t * obj); + + /** + * Called when the object created by fragment received `LV_EVENT_DELETE` event + * @param self Fragment instance + * @param obj object with this fragment + */ + void (*obj_deleted_cb)(lv_fragment_t * self, lv_obj_t * obj); + + /** + * Handle event + * @param self Fragment instance + * @param which User-defined ID of event + * @param data1 User-defined data + * @param data2 User-defined data + */ + bool (*event_cb)(lv_fragment_t * self, int code, void * userdata); + + /** + * *REQUIRED*: Allocation size of fragment + */ + size_t instance_size; +}; + +/** + * Fragment states + */ +typedef struct _lv_fragment_managed_states_t { + /** + * Class of the fragment + */ + const lv_fragment_class_t * cls; + /** + * Manager the fragment attached to + */ + lv_fragment_manager_t * manager; + /** + * Container object the fragment adding view to + */ + lv_obj_t * const * container; + /** + * Fragment instance + */ + lv_fragment_t * instance; + /** + * true between `create_obj_cb` and `obj_deleted_cb` + */ + bool obj_created; + /** + * true before `lv_fragment_del_obj` is called. Don't touch any object if this is true + */ + bool destroying_obj; + /** + * true if this fragment is in navigation stack that can be popped + */ + bool in_stack; +} lv_fragment_managed_states_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create fragment manager instance + * @param parent Parent fragment if this manager is placed inside another fragment, can be null. + * @return Fragment manager instance + */ +lv_fragment_manager_t * lv_fragment_manager_create(lv_fragment_t * parent); + +/** + * Destroy fragment manager instance + * @param manager Fragment manager instance + */ +void lv_fragment_manager_del(lv_fragment_manager_t * manager); + +/** + * Create object of all fragments managed by this manager. + * @param manager Fragment manager instance + */ +void lv_fragment_manager_create_obj(lv_fragment_manager_t * manager); + +/** + * Delete object created by all fragments managed by this manager. Instance of fragments will not be deleted. + * @param manager Fragment manager instance + */ +void lv_fragment_manager_del_obj(lv_fragment_manager_t * manager); + +/** + * Attach fragment to manager, and add to container. + * @param manager Fragment manager instance + * @param fragment Fragment instance + * @param container Pointer to container object for manager to add objects to + */ +void lv_fragment_manager_add(lv_fragment_manager_t * manager, lv_fragment_t * fragment, lv_obj_t * const * container); + +/** + * Detach and destroy fragment. If fragment is in navigation stack, remove from it. + * @param manager Fragment manager instance + * @param fragment Fragment instance + */ +void lv_fragment_manager_remove(lv_fragment_manager_t * manager, lv_fragment_t * fragment); + +/** + * Attach fragment to manager and add to navigation stack. + * @param manager Fragment manager instance + * @param fragment Fragment instance + * @param container Pointer to container object for manager to add objects to + */ +void lv_fragment_manager_push(lv_fragment_manager_t * manager, lv_fragment_t * fragment, lv_obj_t * const * container); + +/** + * Remove the top-most fragment for stack + * @param manager Fragment manager instance + * @return true if there is fragment to pop + */ +bool lv_fragment_manager_pop(lv_fragment_manager_t * manager); + +/** + * Replace fragment. Old item in the stack will be removed. + * @param manager Fragment manager instance + * @param fragment Fragment instance + * @param container Pointer to container object for manager to add objects to + */ +void lv_fragment_manager_replace(lv_fragment_manager_t * manager, lv_fragment_t * fragment, + lv_obj_t * const * container); + +/** + * Send event to top-most fragment + * @param manager Fragment manager instance + * @param code User-defined ID of event + * @param userdata User-defined data + * @return true if fragment returned true + */ +bool lv_fragment_manager_send_event(lv_fragment_manager_t * manager, int code, void * userdata); + +/** + * Get stack size of this fragment manager + * @param manager Fragment manager instance + * @return Stack size of this fragment manager + */ +size_t lv_fragment_manager_get_stack_size(lv_fragment_manager_t * manager); + +/** + * Get top most fragment instance + * @param manager Fragment manager instance + * @return Top most fragment instance + */ +lv_fragment_t * lv_fragment_manager_get_top(lv_fragment_manager_t * manager); + +/** + * Find first fragment instance in the container + * @param manager Fragment manager instance + * @param container Container which target fragment added to + * @return First fragment instance in the container + */ +lv_fragment_t * lv_fragment_manager_find_by_container(lv_fragment_manager_t * manager, const lv_obj_t * container); + +/** + * Get parent fragment + * @param manager Fragment manager instance + * @return Parent fragment instance + */ +lv_fragment_t * lv_fragment_manager_get_parent_fragment(lv_fragment_manager_t * manager); + + +/** + * Create a fragment instance. + * + * @param cls Fragment class. This fragment must return non null object. + * @param args Arguments assigned by fragment manager + * @return Fragment instance + */ +lv_fragment_t * lv_fragment_create(const lv_fragment_class_t * cls, void * args); + +/** + * Destroy a fragment. + * @param fragment Fragment instance. + */ +void lv_fragment_del(lv_fragment_t * fragment); + +/** + * Get associated manager of this fragment + * @param fragment Fragment instance + * @return Fragment manager instance + */ +lv_fragment_manager_t * lv_fragment_get_manager(lv_fragment_t * fragment); + +/** + * Get container object of this fragment + * @param fragment Fragment instance + * @return Reference to container object + */ +lv_obj_t * const * lv_fragment_get_container(lv_fragment_t * fragment); + +/** + * Get parent fragment of this fragment + * @param fragment Fragment instance + * @return Parent fragment + */ +lv_fragment_t * lv_fragment_get_parent(lv_fragment_t * fragment); + +/** + * Create object by fragment. + * + * @param fragment Fragment instance. + * @param container Container of the objects should be created upon. + * @return Created object + */ +lv_obj_t * lv_fragment_create_obj(lv_fragment_t * fragment, lv_obj_t * container); + +/** + * Delete created object of a fragment + * + * @param fragment Fragment instance. + */ +void lv_fragment_del_obj(lv_fragment_t * fragment); + +/** + * Destroy obj in fragment, and recreate them. + * @param fragment Fragment instance + */ +void lv_fragment_recreate_obj(lv_fragment_t * fragment); + + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_FRAGMENT*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FRAGMENT_H*/ diff --git a/include/liblvgl/extra/others/gridnav/lv_gridnav.h b/include/liblvgl/extra/others/gridnav/lv_gridnav.h new file mode 100644 index 00000000..89391208 --- /dev/null +++ b/include/liblvgl/extra/others/gridnav/lv_gridnav.h @@ -0,0 +1,123 @@ +/** + * @file lv_templ.c + * + */ + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*This typedef exists purely to keep -Wpedantic happy when the file is empty.*/ +/*It can be removed.*/ +typedef int _keep_pedantic_happy; + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/********************** + * STATIC FUNCTIONS + **********************/ +/** + * @file lv_gridnav.h + * + */ + +#ifndef LV_GRIDFOCUS_H +#define LV_GRIDFOCUS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_GRIDNAV + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef enum { + LV_GRIDNAV_CTRL_NONE = 0x0, + + /** + * If there is no next/previous object in a direction, + * the focus goes to the object in the next/previous row (on left/right keys) + * or first/last row (on up/down keys) + */ + LV_GRIDNAV_CTRL_ROLLOVER = 0x1, + + /** + * If an arrow is pressed and the focused object can be scrolled in that direction + * then it will be scrolled instead of going to the next/previous object. + * If there is no more room for scrolling the next/previous object will be focused normally */ + LV_GRIDNAV_CTRL_SCROLL_FIRST = 0x2, + +} lv_gridnav_ctrl_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Add grid navigation feature to an object. It expects the children to be arranged + * into a grid-like layout. Although it's not required to have pixel perfect alignment. + * This feature makes possible to use keys to navigate among the children and focus them. + * The keys other than arrows and press/release related events + * are forwarded to the focused child. + * @param obj pointer to an object on which navigation should be applied. + * @param ctrl control flags from `lv_gridnav_ctrl_t`. + */ +void lv_gridnav_add(lv_obj_t * obj, lv_gridnav_ctrl_t ctrl); + +/** + * Remove the grid navigation support from an object + * @param obj pointer to an object + */ +void lv_gridnav_remove(lv_obj_t * obj); + +/** + * Manually focus an object on gridnav container + * @param cont pointer to a gridnav container + * @param to_focus pointer to an object to focus + * @param anim_en LV_ANIM_ON/OFF + */ +void lv_gridnav_set_focused(lv_obj_t * cont, lv_obj_t * to_focus, lv_anim_enable_t anim_en); + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_GRIDNAV*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GRIDFOCUS_H*/ diff --git a/include/liblvgl/extra/others/ime/lv_ime_pinyin.h b/include/liblvgl/extra/others/ime/lv_ime_pinyin.h new file mode 100644 index 00000000..2d70d293 --- /dev/null +++ b/include/liblvgl/extra/others/ime/lv_ime_pinyin.h @@ -0,0 +1,145 @@ +/** + * @file lv_ime_pinyin.h + * + */ +#ifndef LV_IME_PINYIN_H +#define LV_IME_PINYIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_IME_PINYIN != 0 + +/********************* + * DEFINES + *********************/ +#define LV_IME_PINYIN_K9_MAX_INPUT 7 + +/********************** + * TYPEDEFS + **********************/ + +typedef enum { + LV_IME_PINYIN_MODE_K26, + LV_IME_PINYIN_MODE_K9, +} lv_ime_pinyin_mode_t; + +/*Data of pinyin_dict*/ +typedef struct { + const char * const py; + const char * const py_mb; +} lv_pinyin_dict_t; + +/*Data of 9-key input(k9) mode*/ +typedef struct { + char py_str[7]; +} ime_pinyin_k9_py_str_t; + +/*Data of lv_ime_pinyin*/ +typedef struct { + lv_obj_t obj; + lv_obj_t * kb; + lv_obj_t * cand_panel; + lv_pinyin_dict_t * dict; + lv_ll_t k9_legal_py_ll; + char * cand_str; /* Candidate string */ + char input_char[16]; /* Input box character */ +#if LV_IME_PINYIN_USE_K9_MODE + char k9_input_str[LV_IME_PINYIN_K9_MAX_INPUT]; /* 9-key input(k9) mode input string */ + uint16_t k9_py_ll_pos; /* Current pinyin map pages(k9) */ + uint16_t k9_legal_py_count; /* Count of legal Pinyin numbers(k9) */ + uint16_t k9_input_str_len; /* 9-key input(k9) mode input string max len */ +#endif + uint16_t ta_count; /* The number of characters entered in the text box this time */ + uint16_t cand_num; /* Number of candidates */ + uint16_t py_page; /* Current pinyin map pages(k26) */ + uint16_t py_num[26]; /* Number and length of Pinyin */ + uint16_t py_pos[26]; /* Pinyin position */ + uint8_t mode : 1; /* Set mode, 1: 26-key input(k26), 0: 9-key input(k9). Default: 1. */ +} lv_ime_pinyin_t; + +/*********************** + * GLOBAL VARIABLES + ***********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +lv_obj_t * lv_ime_pinyin_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the keyboard of Pinyin input method. + * @param obj pointer to a Pinyin input method object + * @param dict pointer to a Pinyin input method keyboard + */ +void lv_ime_pinyin_set_keyboard(lv_obj_t * obj, lv_obj_t * kb); + +/** + * Set the dictionary of Pinyin input method. + * @param obj pointer to a Pinyin input method object + * @param dict pointer to a Pinyin input method dictionary + */ +void lv_ime_pinyin_set_dict(lv_obj_t * obj, lv_pinyin_dict_t * dict); + +/** + * Set mode, 26-key input(k26) or 9-key input(k9). + * @param obj pointer to a Pinyin input method object + * @param mode the mode from 'lv_ime_pinyin_mode_t' + */ +void lv_ime_pinyin_set_mode(lv_obj_t * obj, lv_ime_pinyin_mode_t mode); + + +/*===================== + * Getter functions + *====================*/ + +/** + * Set the dictionary of Pinyin input method. + * @param obj pointer to a Pinyin IME object + * @return pointer to the Pinyin IME keyboard + */ +lv_obj_t * lv_ime_pinyin_get_kb(lv_obj_t * obj); + + +/** + * Set the dictionary of Pinyin input method. + * @param obj pointer to a Pinyin input method object + * @return pointer to the Pinyin input method candidate panel + */ +lv_obj_t * lv_ime_pinyin_get_cand_panel(lv_obj_t * obj); + + +/** + * Set the dictionary of Pinyin input method. + * @param obj pointer to a Pinyin input method object + * @return pointer to the Pinyin input method dictionary + */ +lv_pinyin_dict_t * lv_ime_pinyin_get_dict(lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_IME_PINYIN*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_USE_IME_PINYIN*/ + + diff --git a/include/liblvgl/extra/others/imgfont/lv_imgfont.h b/include/liblvgl/extra/others/imgfont/lv_imgfont.h new file mode 100644 index 00000000..4fb6f78b --- /dev/null +++ b/include/liblvgl/extra/others/imgfont/lv_imgfont.h @@ -0,0 +1,60 @@ +/** + * @file lv_imgfont.h + * + */ + +#ifndef LV_IMGFONT_H +#define LV_IMGFONT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_IMGFONT + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/* gets the image path name of this character */ +typedef bool (*lv_get_imgfont_path_cb_t)(const lv_font_t * font, void * img_src, + uint16_t len, uint32_t unicode, uint32_t unicode_next); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Creates a image font with info parameter specified. + * @param height font size + * @param path_cb a function to get the image path name of character. + * @return pointer to the new imgfont or NULL if create error. + */ +lv_font_t * lv_imgfont_create(uint16_t height, lv_get_imgfont_path_cb_t path_cb); + +/** + * Destroy a image font that has been created. + * @param font pointer to image font handle. + */ +void lv_imgfont_destroy(lv_font_t * font); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_IMGFONT*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /* LV_IMGFONT_H */ diff --git a/include/liblvgl/extra/others/lv_others.h b/include/liblvgl/extra/others/lv_others.h new file mode 100644 index 00000000..106d85e4 --- /dev/null +++ b/include/liblvgl/extra/others/lv_others.h @@ -0,0 +1,44 @@ +/** + * @file lv_others.h + * + */ + +#ifndef LV_OTHERS_H +#define LV_OTHERS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "snapshot/lv_snapshot.h" +#include "monkey/lv_monkey.h" +#include "gridnav/lv_gridnav.h" +#include "fragment/lv_fragment.h" +#include "imgfont/lv_imgfont.h" +#include "msg/lv_msg.h" +#include "ime/lv_ime_pinyin.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_OTHERS_H*/ diff --git a/include/liblvgl/extra/others/monkey/lv_monkey.h b/include/liblvgl/extra/others/monkey/lv_monkey.h new file mode 100644 index 00000000..589daf1d --- /dev/null +++ b/include/liblvgl/extra/others/monkey/lv_monkey.h @@ -0,0 +1,118 @@ +/** + * @file lv_monkey.h + * + */ +#ifndef LV_MONKEY_H +#define LV_MONKEY_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_MONKEY != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +struct _lv_monkey; +typedef struct _lv_monkey lv_monkey_t; + +typedef struct { + /**< Input device type*/ + lv_indev_type_t type; + + /**< Monkey execution period*/ + struct { + uint32_t min; + uint32_t max; + } period_range; + + /**< The range of input value*/ + struct { + int32_t min; + int32_t max; + } input_range; +} lv_monkey_config_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize a monkey config with default values + * @param config pointer to 'lv_monkey_config_t' variable to initialize + */ +void lv_monkey_config_init(lv_monkey_config_t * config); + +/** + * Create monkey for test + * @param config pointer to 'lv_monkey_config_t' variable + * @return pointer to the created monkey + */ +lv_monkey_t * lv_monkey_create(const lv_monkey_config_t * config); + +/** + * Get monkey input device + * @param monkey pointer to a monkey + * @return pointer to the input device + */ +lv_indev_t * lv_monkey_get_indev(lv_monkey_t * monkey); + +/** + * Enable monkey + * @param monkey pointer to a monkey + * @param en set to true to enable + */ +void lv_monkey_set_enable(lv_monkey_t * monkey, bool en); + +/** + * Get whether monkey is enabled + * @param monkey pointer to a monkey + * @return return true if monkey enabled + */ +bool lv_monkey_get_enable(lv_monkey_t * monkey); + +#if LV_USE_USER_DATA + +/** + * Set the user_data field of the monkey + * @param monkey pointer to a monkey + * @param user_data pointer to the new user_data. + */ +void lv_monkey_set_user_data(lv_monkey_t * monkey, void * user_data); + +/** + * Get the user_data field of the monkey + * @param monkey pointer to a monkey + * @return the pointer to the user_data of the monkey + */ +void * lv_monkey_get_user_data(lv_monkey_t * monkey); + +#endif/*LV_USE_USER_DATA*/ + +/** + * Delete monkey + * @param monkey pointer to monkey + */ +void lv_monkey_del(lv_monkey_t * monkey); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_MONKEY*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MONKEY_H*/ diff --git a/include/liblvgl/extra/others/msg/lv_msg.h b/include/liblvgl/extra/others/msg/lv_msg.h new file mode 100644 index 00000000..64dc0d45 --- /dev/null +++ b/include/liblvgl/extra/others/msg/lv_msg.h @@ -0,0 +1,124 @@ +/** + * @file lv_msg.h + * + */ + +#ifndef LV_MSG_H +#define LV_MSG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_MSG + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + uint32_t id; /*Identifier of the message*/ + void * user_data; /*Set the the user_data set in `lv_msg_subscribe`*/ + void * _priv_data; /*Used internally*/ + const void * payload; /*Pointer to the data of the message*/ +} lv_msg_t; + +typedef void (*lv_msg_subscribe_cb_t)(void * s, lv_msg_t * msg); + +typedef void (*lv_msg_request_cb_t)(void * r, uint32_t msg_id); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Called internally to initialize the message module + */ +void lv_msg_init(void); + +/** + * Subscribe to an `msg_id` + * @param msg_id the message ID to listen to + * @param cb callback to call if a message with `msg_id` was sent + * @param user_data arbitrary data which will be available in `cb` too + * @return pointer to a "subscribe object". It can be used the unsubscribe. + */ +void * lv_msg_subsribe(uint32_t msg_id, lv_msg_subscribe_cb_t cb, void * user_data); + +/** + * Subscribe an `lv_obj` to a message. + * `LV_EVENT_MSG_RECEIVED` will be triggered if a message with matching ID was sent + * @param msg_id the message ID to listen to + * @param obj pointer to an `lv_obj` + * @param user_data arbitrary data which will be available in `cb` too + * @return pointer to a "subscribe object". It can be used the unsubscribe. + */ +void * lv_msg_subsribe_obj(uint32_t msg_id, lv_obj_t * obj, void * user_data); + +/** + * Cancel a previous subscription + * @param s pointer to a "subscibe object". + * Return value of `lv_msg_subsribe` or `lv_msg_subsribe_obj` + */ +void lv_msg_unsubscribe(void * s); + +/** + * Send a message with a given ID and payload + * @param msg_id ID of the message to send + * @param data pointer to the data to send + */ +void lv_msg_send(uint32_t msg_id, const void * payload); + +/** + * Get the ID of a message object. Typically used in the subscriber callback. + * @param m pointer to a message object + * @return the ID of the message + */ +uint32_t lv_msg_get_id(lv_msg_t * m); + +/** + * Get the payload of a message object. Typically used in the subscriber callback. + * @param m pointer to a message object + * @return the payload of the message + */ +const void * lv_msg_get_payload(lv_msg_t * m); + +/** + * Get the user data of a message object. Typically used in the subscriber callback. + * @param m pointer to a message object + * @return the user data of the message + */ +void * lv_msg_get_user_data(lv_msg_t * m); + +/** + * Get the message object from an event object. Can be used in `LV_EVENT_MSG_RECEIVED` events. + * @param e pointer to an event object + * @return the message object or NULL if called with unrelated event code. + */ +lv_msg_t * lv_event_get_msg(lv_event_t * e); + +/********************** + * GLOBAL VARIABLES + **********************/ + +extern lv_event_code_t LV_EVENT_MSG_RECEIVED; + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_MSG*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MSG_H*/ diff --git a/include/liblvgl/extra/others/snapshot/lv_snapshot.h b/include/liblvgl/extra/others/snapshot/lv_snapshot.h new file mode 100644 index 00000000..33d97412 --- /dev/null +++ b/include/liblvgl/extra/others/snapshot/lv_snapshot.h @@ -0,0 +1,84 @@ +/** + * @file lv_snapshot.h + * + */ + +#ifndef LV_SNAPSHOT_H +#define LV_SNAPSHOT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include + +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +#if LV_USE_SNAPSHOT +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** Take snapshot for object with its children. + * + * @param obj The object to generate snapshot. + * @param cf color format for generated image. + * + * @return a pointer to an image descriptor, or NULL if failed. + */ +lv_img_dsc_t * lv_snapshot_take(lv_obj_t * obj, lv_img_cf_t cf); + +/** Free the snapshot image returned by @ref lv_snapshot_take + * + * It will firstly free the data image takes, then the image descriptor. + * + * @param dsc The image descriptor generated by lv_snapshot_take. + * + */ +void lv_snapshot_free(lv_img_dsc_t * dsc); + +/** Get the buffer needed for object snapshot image. + * + * @param obj The object to generate snapshot. + * @param cf color format for generated image. + * + * @return the buffer size needed in bytes + */ +uint32_t lv_snapshot_buf_size_needed(lv_obj_t * obj, lv_img_cf_t cf); + +/** Take snapshot for object with its children, save image info to provided buffer. + * + * @param obj The object to generate snapshot. + * @param cf color format for generated image. + * @param dsc image descriptor to store the image result. + * @param buff the buffer to store image data. + * @param buff_size provided buffer size in bytes. + * + * @return LV_RES_OK on success, LV_RES_INV on error. + */ +lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_img_cf_t cf, lv_img_dsc_t * dsc, void * buf, uint32_t buff_size); + + +/********************** + * MACROS + **********************/ +#endif /*LV_USE_SNAPSHOT*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/liblvgl/extra/themes/basic/lv_theme_basic.h b/include/liblvgl/extra/themes/basic/lv_theme_basic.h new file mode 100644 index 00000000..06d6828b --- /dev/null +++ b/include/liblvgl/extra/themes/basic/lv_theme_basic.h @@ -0,0 +1,55 @@ +/** + * @file lv_theme_basic.h + * + */ + +#ifndef LV_THEME_BASIC_H +#define LV_THEME_BASIC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_THEME_BASIC + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the theme + * @param disp pointer to display to attach the theme + * @return a pointer to reference this theme later + */ +lv_theme_t * lv_theme_basic_init(lv_disp_t * disp); + +/** +* Check if the theme is initialized +* @return true if default theme is initialized, false otherwise +*/ +bool lv_theme_basic_is_inited(void); + +/********************** + * MACROS + **********************/ + +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_THEME_BASIC_H*/ diff --git a/include/liblvgl/extra/themes/default/lv_theme_default.h b/include/liblvgl/extra/themes/default/lv_theme_default.h new file mode 100644 index 00000000..7fab5be4 --- /dev/null +++ b/include/liblvgl/extra/themes/default/lv_theme_default.h @@ -0,0 +1,64 @@ +/** + * @file lv_theme_default.h + * + */ + +#ifndef LV_THEME_DEFAULT_H +#define LV_THEME_DEFAULT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_THEME_DEFAULT + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the theme + * @param color_primary the primary color of the theme + * @param color_secondary the secondary color for the theme + * @param font pointer to a font to use. + * @return a pointer to reference this theme later + */ +lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark, + const lv_font_t * font); + +/** + * Get default theme + * @return a pointer to default theme, or NULL if this is not initialized + */ +lv_theme_t * lv_theme_default_get(void); + +/** + * Check if default theme is initialized + * @return true if default theme is initialized, false otherwise + */ +bool lv_theme_default_is_inited(void); + +/********************** + * MACROS + **********************/ + +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_THEME_DEFAULT_H*/ diff --git a/include/liblvgl/extra/themes/lv_themes.h b/include/liblvgl/extra/themes/lv_themes.h new file mode 100644 index 00000000..372f6260 --- /dev/null +++ b/include/liblvgl/extra/themes/lv_themes.h @@ -0,0 +1,40 @@ +/** + * @file lv_themes.h + * + */ + +#ifndef LV_THEMES_H +#define LV_THEMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "default/lv_theme_default.h" +#include "mono/lv_theme_mono.h" +#include "basic/lv_theme_basic.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_THEMES_H*/ diff --git a/include/liblvgl/extra/themes/mono/lv_theme_mono.h b/include/liblvgl/extra/themes/mono/lv_theme_mono.h new file mode 100644 index 00000000..3d907fff --- /dev/null +++ b/include/liblvgl/extra/themes/mono/lv_theme_mono.h @@ -0,0 +1,57 @@ +/** + * @file lv_theme_mono.h + * + */ + +#ifndef LV_USE_THEME_MONO_H +#define LV_USE_THEME_MONO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_THEME_MONO + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the theme + * @param color_primary the primary color of the theme + * @param color_secondary the secondary color for the theme + * @param font pointer to a font to use. + * @return a pointer to reference this theme later + */ +lv_theme_t * lv_theme_mono_init(lv_disp_t * disp, bool dark_bg, const lv_font_t * font); + +/** +* Check if the theme is initialized +* @return true if default theme is initialized, false otherwise +*/ +bool lv_theme_mono_is_inited(void); + +/********************** + * MACROS + **********************/ + +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_USE_THEME_MONO_H*/ diff --git a/include/liblvgl/extra/widgets/animimg/lv_animimg.h b/include/liblvgl/extra/widgets/animimg/lv_animimg.h new file mode 100644 index 00000000..9ffe6217 --- /dev/null +++ b/include/liblvgl/extra/widgets/animimg/lv_animimg.h @@ -0,0 +1,103 @@ +/** + * @file lv_animimg.h + * + */ + +#ifndef LV_ANIM_IMG_H +#define LV_ANIM_IMG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_ANIMIMG != 0 + +/*Testing of dependencies*/ +#if LV_USE_IMG == 0 +#error "lv_animimg: lv_img is required. Enable it in lv_conf.h (LV_USE_IMG 1)" +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +extern const lv_obj_class_t lv_animimg_class; + +/*Data of image*/ +typedef struct { + lv_img_t img; + lv_anim_t anim; + /*picture sequence */ + lv_img_dsc_t ** dsc; + int8_t pic_count; +} lv_animimg_t; + + +/*Image parts*/ +enum { + LV_ANIM_IMG_PART_MAIN, +}; +typedef uint8_t lv_animimg_part_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an animation image objects + * @param parent pointer to an object, it will be the parent of the new button + * @return pointer to the created animation image object + */ +lv_obj_t * lv_animimg_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the image animation images source. + * @param img pointer to an animation image object + * @param dsc pointer to a series images + * @param num images' number + */ +void lv_animimg_set_src(lv_obj_t * img, lv_img_dsc_t * dsc[], uint8_t num); + +/** + * Startup the image animation. + * @param obj pointer to an animation image object + */ +void lv_animimg_start(lv_obj_t * obj); + +/** + * Set the image animation duration time. unit:ms + * @param img pointer to an animation image object + */ +void lv_animimg_set_duration(lv_obj_t * img, uint32_t duration); + +/** + * Set the image animation reapeatly play times. + * @param img pointer to an animation image object + * @param count the number of times to repeat the animation + */ +void lv_animimg_set_repeat_count(lv_obj_t * img, uint16_t count); + +/*===================== + * Getter functions + *====================*/ + +#endif /*LV_USE_ANIMIMG*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_ANIM_IMG_H*/ diff --git a/include/liblvgl/extra/widgets/calendar/lv_calendar.h b/include/liblvgl/extra/widgets/calendar/lv_calendar.h new file mode 100644 index 00000000..ad157bf6 --- /dev/null +++ b/include/liblvgl/extra/widgets/calendar/lv_calendar.h @@ -0,0 +1,164 @@ +/** + * @file lv_calendar.h + * + */ + +#ifndef LV_CALENDAR_H +#define LV_CALENDAR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/widgets/lv_btnmatrix.h" + +#if LV_USE_CALENDAR + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Represents a date on the calendar object (platform-agnostic). + */ +typedef struct { + uint16_t year; + int8_t month; /** 1..12*/ + int8_t day; /** 1..31*/ +} lv_calendar_date_t; + +/*Data of calendar*/ +typedef struct { + lv_obj_t obj; + lv_obj_t * btnm; + /*New data for this type*/ + lv_calendar_date_t today; /*Date of today*/ + lv_calendar_date_t showed_date; /*Currently visible month (day is ignored)*/ + lv_calendar_date_t * + highlighted_dates; /*Apply different style on these days (pointer to an array defined by the user)*/ + uint16_t highlighted_dates_num; /*Number of elements in `highlighted_days`*/ + const char * map[8 * 7]; + char nums [7 * 6][4]; +} lv_calendar_t; + +extern const lv_obj_class_t lv_calendar_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_calendar_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the today's date + * @param obj pointer to a calendar object + * @param year today's year + * @param month today's month [1..12] + * @param day today's day [1..31] + */ +void lv_calendar_set_today_date(lv_obj_t * obj, uint32_t year, uint32_t month, uint32_t day); + +/** + * Set the currently showed + * @param obj pointer to a calendar object + * @param year today's year + * @param month today's month [1..12] + */ +void lv_calendar_set_showed_date(lv_obj_t * obj, uint32_t year, uint32_t month); + +/** + * Set the highlighted dates + * @param obj pointer to a calendar object + * @param highlighted pointer to an `lv_calendar_date_t` array containing the dates. + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + * @param date_num number of dates in the array + */ +void lv_calendar_set_highlighted_dates(lv_obj_t * obj, lv_calendar_date_t highlighted[], uint16_t date_num); + +/** + * Set the name of the days + * @param obj pointer to a calendar object + * @param day_names pointer to an array with the names. + * E.g. `const char * days[7] = {"Sun", "Mon", ...}` + * Only the pointer will be saved so this variable can't be local which will be destroyed later. + */ +void lv_calendar_set_day_names(lv_obj_t * obj, const char ** day_names); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the button matrix object of the calendar. + * It shows the dates and day names. + * @param obj pointer to a calendar object + * @return pointer to a the button matrix + */ +lv_obj_t * lv_calendar_get_btnmatrix(const lv_obj_t * obj); + +/** + * Get the today's date + * @param calendar pointer to a calendar object + * @return return pointer to an `lv_calendar_date_t` variable containing the date of today. + */ +const lv_calendar_date_t * lv_calendar_get_today_date(const lv_obj_t * calendar); + +/** + * Get the currently showed + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` variable containing the date is being shown. + */ +const lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar); + +/** + * Get the highlighted dates + * @param calendar pointer to a calendar object + * @return pointer to an `lv_calendar_date_t` array containing the dates. + */ +lv_calendar_date_t * lv_calendar_get_highlighted_dates(const lv_obj_t * calendar); + +/** + * Get the number of the highlighted dates + * @param calendar pointer to a calendar object + * @return number of highlighted days + */ +uint16_t lv_calendar_get_highlighted_dates_num(const lv_obj_t * calendar); + +/** + * Get the currently pressed day + * @param calendar pointer to a calendar object + * @param date store the pressed date here + * @return LV_RES_OK: there is a valid pressed date; LV_RES_INV: there is no pressed data + */ +lv_res_t lv_calendar_get_pressed_date(const lv_obj_t * calendar, lv_calendar_date_t * date); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CALENDAR*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CALENDAR_H*/ diff --git a/include/liblvgl/extra/widgets/calendar/lv_calendar_header_arrow.h b/include/liblvgl/extra/widgets/calendar/lv_calendar_header_arrow.h new file mode 100644 index 00000000..30639e85 --- /dev/null +++ b/include/liblvgl/extra/widgets/calendar/lv_calendar_header_arrow.h @@ -0,0 +1,49 @@ +/** + * @file lv_calendar_header_arrow.h + * + */ + +#ifndef LV_CALENDAR_HEADER_ARROW_H +#define LV_CALENDAR_HEADER_ARROW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_CALENDAR_HEADER_ARROW + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +extern const lv_obj_class_t lv_calendar_header_arrow_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a calendar header with drop-drowns to select the year and month + * @param parent pointer to a calendar object. + * @return the created header + */ +lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CALENDAR_HEADER_ARROW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CALENDAR_HEADER_ARROW_H*/ diff --git a/include/liblvgl/extra/widgets/calendar/lv_calendar_header_dropdown.h b/include/liblvgl/extra/widgets/calendar/lv_calendar_header_dropdown.h new file mode 100644 index 00000000..ba926a0b --- /dev/null +++ b/include/liblvgl/extra/widgets/calendar/lv_calendar_header_dropdown.h @@ -0,0 +1,49 @@ +/** + * @file lv_calendar_header_dropdown.h + * + */ + +#ifndef LV_CALENDAR_HEADER_DROPDOWN_H +#define LV_CALENDAR_HEADER_DROPDOWN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#if LV_USE_CALENDAR_HEADER_DROPDOWN + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +extern const lv_obj_class_t lv_calendar_header_dropdown_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a calendar header with drop-drowns to select the year and month + * @param parent pointer to a calendar object. + * @return the created header + */ +lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CALENDAR_HEADER_ARROW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CALENDAR_HEADER_DROPDOWN_H*/ diff --git a/include/liblvgl/extra/widgets/chart/lv_chart.h b/include/liblvgl/extra/widgets/chart/lv_chart.h new file mode 100644 index 00000000..14d70b9a --- /dev/null +++ b/include/liblvgl/extra/widgets/chart/lv_chart.h @@ -0,0 +1,460 @@ +/** + * @file lv_chart.h + * + */ + +#ifndef LV_CHART_H +#define LV_CHART_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_CHART != 0 + +/********************* + * DEFINES + *********************/ + +/**Default value of points. Can be used to not draw a point*/ +#if LV_USE_LARGE_COORD +#define LV_CHART_POINT_NONE (INT32_MAX) +#else +#define LV_CHART_POINT_NONE (INT16_MAX) +#endif +LV_EXPORT_CONST_INT(LV_CHART_POINT_NONE); + +/********************** + * TYPEDEFS + **********************/ + +/** + * Chart types + */ +enum { + LV_CHART_TYPE_NONE, /**< Don't draw the series*/ + LV_CHART_TYPE_LINE, /**< Connect the points with lines*/ + LV_CHART_TYPE_BAR, /**< Draw columns*/ + LV_CHART_TYPE_SCATTER, /**< Draw points and lines in 2D (x,y coordinates)*/ +}; +typedef uint8_t lv_chart_type_t; + +/** + * Chart update mode for `lv_chart_set_next` + */ +enum { + LV_CHART_UPDATE_MODE_SHIFT, /**< Shift old data to the left and add the new one the right*/ + LV_CHART_UPDATE_MODE_CIRCULAR, /**< Add the new data in a circular way*/ +}; +typedef uint8_t lv_chart_update_mode_t; + +/** + * Enumeration of the axis' + */ +enum { + LV_CHART_AXIS_PRIMARY_Y = 0x00, + LV_CHART_AXIS_SECONDARY_Y = 0x01, + LV_CHART_AXIS_PRIMARY_X = 0x02, + LV_CHART_AXIS_SECONDARY_X = 0x04, + _LV_CHART_AXIS_LAST +}; +typedef uint8_t lv_chart_axis_t; + +/** + * Descriptor a chart series + */ +typedef struct { + lv_coord_t * x_points; + lv_coord_t * y_points; + lv_color_t color; + uint16_t start_point; + uint8_t hidden : 1; + uint8_t x_ext_buf_assigned : 1; + uint8_t y_ext_buf_assigned : 1; + uint8_t x_axis_sec : 1; + uint8_t y_axis_sec : 1; +} lv_chart_series_t; + +typedef struct { + lv_point_t pos; + lv_coord_t point_id; + lv_color_t color; + lv_chart_series_t * ser; + lv_dir_t dir; + uint8_t pos_set: 1; /*1: pos is set; 0: point_id is set*/ +} lv_chart_cursor_t; + +typedef struct { + lv_coord_t major_len; + lv_coord_t minor_len; + lv_coord_t draw_size; + uint32_t minor_cnt : 15; + uint32_t major_cnt : 15; + uint32_t label_en : 1; +} lv_chart_tick_dsc_t; + + +typedef struct { + lv_obj_t obj; + lv_ll_t series_ll; /**< Linked list for the series (stores lv_chart_series_t)*/ + lv_ll_t cursor_ll; /**< Linked list for the cursors (stores lv_chart_cursor_t)*/ + lv_chart_tick_dsc_t tick[4]; + lv_coord_t ymin[2]; + lv_coord_t ymax[2]; + lv_coord_t xmin[2]; + lv_coord_t xmax[2]; + lv_coord_t pressed_point_id; + uint16_t hdiv_cnt; /**< Number of horizontal division lines*/ + uint16_t vdiv_cnt; /**< Number of vertical division lines*/ + uint16_t point_cnt; /**< Point number in a data line*/ + uint16_t zoom_x; + uint16_t zoom_y; + lv_chart_type_t type : 3; /**< Line or column chart*/ + lv_chart_update_mode_t update_mode : 1; +} lv_chart_t; + +extern const lv_obj_class_t lv_chart_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_chart_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_CHART_DRAW_PART_DIV_LINE_INIT, /**< Used before/after drawn the div lines*/ + LV_CHART_DRAW_PART_DIV_LINE_HOR, /**< Used for each horizontal division lines*/ + LV_CHART_DRAW_PART_DIV_LINE_VER, /**< Used for each vertical division lines*/ + LV_CHART_DRAW_PART_LINE_AND_POINT, /**< Used on line and scatter charts for lines and points*/ + LV_CHART_DRAW_PART_BAR, /**< Used on bar charts for the rectangles*/ + LV_CHART_DRAW_PART_CURSOR, /**< Used on cursor lines and points*/ + LV_CHART_DRAW_PART_TICK_LABEL, /**< Used on tick lines and labels*/ +} lv_chart_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a chart object + * @param parent pointer to an object, it will be the parent of the new chart + * @return pointer to the created chart + */ +lv_obj_t * lv_chart_create(lv_obj_t * parent); + +/** + * Set a new type for a chart + * @param obj pointer to a chart object + * @param type new type of the chart (from 'lv_chart_type_t' enum) + */ +void lv_chart_set_type(lv_obj_t * obj, lv_chart_type_t type); +/** + * Set the number of points on a data line on a chart + * @param obj pointer to a chart object + * @param cnt new number of points on the data lines + */ +void lv_chart_set_point_count(lv_obj_t * obj, uint16_t cnt); + +/** + * Set the minimal and maximal y values on an axis + * @param obj pointer to a chart object + * @param axis `LV_CHART_AXIS_PRIMARY_Y` or `LV_CHART_AXIS_SECONDARY_Y` + * @param min minimum value of the y axis + * @param max maximum value of the y axis + */ +void lv_chart_set_range(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t min, lv_coord_t max); + +/** + * Set update mode of the chart object. Affects + * @param obj pointer to a chart object + * @param mode the update mode + */ +void lv_chart_set_update_mode(lv_obj_t * obj, lv_chart_update_mode_t update_mode); + +/** + * Set the number of horizontal and vertical division lines + * @param obj pointer to a chart object + * @param hdiv number of horizontal division lines + * @param vdiv number of vertical division lines + */ +void lv_chart_set_div_line_count(lv_obj_t * obj, uint8_t hdiv, uint8_t vdiv); + +/** + * Zoom into the chart in X direction + * @param obj pointer to a chart object + * @param zoom_x zoom in x direction. LV_ZOOM_NONE or 256 for no zoom, 512 double zoom + */ +void lv_chart_set_zoom_x(lv_obj_t * obj, uint16_t zoom_x); + +/** + * Zoom into the chart in Y direction + * @param obj pointer to a chart object + * @param zoom_y zoom in y direction. LV_ZOOM_NONE or 256 for no zoom, 512 double zoom + */ +void lv_chart_set_zoom_y(lv_obj_t * obj, uint16_t zoom_y); + +/** + * Get X zoom of a chart + * @param obj pointer to a chart object + * @return the X zoom value + */ +uint16_t lv_chart_get_zoom_x(const lv_obj_t * obj); + +/** + * Get Y zoom of a chart + * @param obj pointer to a chart object + * @return the Y zoom value + */ +uint16_t lv_chart_get_zoom_y(const lv_obj_t * obj); + +/** + * Set the number of tick lines on an axis + * @param obj pointer to a chart object + * @param axis an axis which ticks count should be set + * @param major_len length of major ticks + * @param minor_len length of minor ticks + * @param major_cnt number of major ticks on the axis + * @param minor_cnt number of minor ticks between two major ticks + * @param label_en true: enable label drawing on major ticks + * @param draw_size extra size required to draw the tick and labels + * (start with 20 px and increase if the ticks/labels are clipped) + */ +void lv_chart_set_axis_tick(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t major_len, lv_coord_t minor_len, + lv_coord_t major_cnt, lv_coord_t minor_cnt, bool label_en, lv_coord_t draw_size); + +/** + * Get the type of a chart + * @param obj pointer to chart object + * @return type of the chart (from 'lv_chart_t' enum) + */ +lv_chart_type_t lv_chart_get_type(const lv_obj_t * obj); + +/** + * Get the data point number per data line on chart + * @param chart pointer to chart object + * @return point number on each data line + */ +uint16_t lv_chart_get_point_count(const lv_obj_t * obj); + +/** + * Get the current index of the x-axis start point in the data array + * @param chart pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @return the index of the current x start point in the data array + */ +uint16_t lv_chart_get_x_start_point(const lv_obj_t * obj, lv_chart_series_t * ser); + +/** + * Get the position of a point to the chart. + * @param chart pointer to a chart object + * @param ser pointer to series + * @param id the index. + * @param p_out store the result position here + */ +void lv_chart_get_point_pos_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_point_t * p_out); + +/** + * Refresh a chart if its data line has changed + * @param chart pointer to chart object + */ +void lv_chart_refresh(lv_obj_t * obj); + +/*====================== + * Series + *=====================*/ + +/** + * Allocate and add a data series to the chart + * @param obj pointer to a chart object + * @param color color of the data series + * @param axis the y axis to which the series should be attached (::LV_CHART_AXIS_PRIMARY_Y or ::LV_CHART_AXIS_SECONDARY_Y) + * @return pointer to the allocated data series + */ +lv_chart_series_t * lv_chart_add_series(lv_obj_t * obj, lv_color_t color, lv_chart_axis_t axis); + +/** + * Deallocate and remove a data series from a chart + * @param chart pointer to a chart object + * @param series pointer to a data series on 'chart' + */ +void lv_chart_remove_series(lv_obj_t * obj, lv_chart_series_t * series); + +/** + * Hide/Unhide a single series of a chart. + * @param obj pointer to a chart object. + * @param series pointer to a series object + * @param hide true: hide the series + */ +void lv_chart_hide_series(lv_obj_t * chart, lv_chart_series_t * series, bool hide); + +/** + * Change the color of a series + * @param obj pointer to a chart object. + * @param series pointer to a series object + * @param color the new color of the series + */ +void lv_chart_set_series_color(lv_obj_t * chart, lv_chart_series_t * series, lv_color_t color); + +/** + * Set the index of the x-axis start point in the data array. + * This point will be considers the first (left) point and the other points will be drawn after it. + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @param id the index of the x point in the data array + */ +void lv_chart_set_x_start_point(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id); + +/** + * Get the next series. + * @param chart pointer to a chart + * @param ser the previous series or NULL to get the first + * @return the next series or NULL if there is no more. + */ +lv_chart_series_t * lv_chart_get_series_next(const lv_obj_t * chart, const lv_chart_series_t * ser); + + + +/*===================== + * Cursor + *====================*/ + +/** + * Add a cursor with a given color + * @param obj pointer to chart object + * @param color color of the cursor + * @param dir direction of the cursor. `LV_DIR_RIGHT/LEFT/TOP/DOWN/HOR/VER/ALL`. OR-ed values are possible + * @return pointer to the created cursor + */ +lv_chart_cursor_t * lv_chart_add_cursor(lv_obj_t * obj, lv_color_t color, lv_dir_t dir); + +/** + * Set the coordinate of the cursor with respect to the paddings + * @param obj pointer to a chart object + * @param cursor pointer to the cursor + * @param pos the new coordinate of cursor relative to the chart + */ +void lv_chart_set_cursor_pos(lv_obj_t * chart, lv_chart_cursor_t * cursor, lv_point_t * pos); + +/** + * Stick the cursor to a point + * @param obj pointer to a chart object + * @param cursor pointer to the cursor + * @param ser pointer to a series + * @param point_id the point's index or `LV_CHART_POINT_NONE` to not assign to any points. + */ +void lv_chart_set_cursor_point(lv_obj_t * chart, lv_chart_cursor_t * cursor, lv_chart_series_t * ser, + uint16_t point_id); + +/** + * Get the coordinate of the cursor with respect to the paddings + * @param obj pointer to a chart object + * @param cursor pointer to cursor + * @return coordinate of the cursor as lv_point_t + */ +lv_point_t lv_chart_get_cursor_point(lv_obj_t * chart, lv_chart_cursor_t * cursor); + +/*===================== + * Set/Get value(s) + *====================*/ + +/** + * Initialize all data points of a series with a value + * @param obj pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param value the new value for all points. `LV_CHART_POINT_NONE` can be used to hide the points. + */ +void lv_chart_set_all_value(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t value); + +/** + * Set the next point's Y value according to the update mode policy. + * @param obj pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param value the new value of the next data + */ +void lv_chart_set_next_value(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t value); + +/** + * Set the next point's X and Y value according to the update mode policy. + * @param obj pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param x_value the new X value of the next data + * @param y_value the new Y value of the next data + */ +void lv_chart_set_next_value2(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t x_value, lv_coord_t y_value); + +/** + * Set an individual point's y value of a chart's series directly based on its index + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @param id the index of the x point in the array + * @param value value to assign to array point + */ +void lv_chart_set_value_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_coord_t value); + +/** + * Set an individual point's x and y value of a chart's series directly based on its index + * Can be used only with `LV_CHART_TYPE_SCATTER`. + * @param obj pointer to chart object + * @param ser pointer to a data series on 'chart' + * @param id the index of the x point in the array + * @param x_value the new X value of the next data + * @param y_value the new Y value of the next data + */ +void lv_chart_set_value_by_id2(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_coord_t x_value, + lv_coord_t y_value); + +/** + * Set an external array for the y data points to use for the chart + * NOTE: It is the users responsibility to make sure the `point_cnt` matches the external array size. + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @param array external array of points for chart + */ +void lv_chart_set_ext_y_array(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t array[]); + +/** + * Set an external array for the x data points to use for the chart + * NOTE: It is the users responsibility to make sure the `point_cnt` matches the external array size. + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @param array external array of points for chart + */ +void lv_chart_set_ext_x_array(lv_obj_t * obj, lv_chart_series_t * ser, lv_coord_t array[]); + +/** + * Get the array of y values of a series + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @return the array of values with 'point_count' elements + */ +lv_coord_t * lv_chart_get_y_array(const lv_obj_t * obj, lv_chart_series_t * ser); + +/** + * Get the array of x values of a series + * @param obj pointer to a chart object + * @param ser pointer to a data series on 'chart' + * @return the array of values with 'point_count' elements + */ +lv_coord_t * lv_chart_get_x_array(const lv_obj_t * obj, lv_chart_series_t * ser); + +/** + * Get the index of the currently pressed point. It's the same for every series. + * @param obj pointer to a chart object + * @return the index of the point [0 .. point count] or LV_CHART_POINT_ID_NONE if no point is being pressed + */ +uint32_t lv_chart_get_pressed_point(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CHART*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CHART_H*/ diff --git a/include/liblvgl/extra/widgets/colorwheel/lv_colorwheel.h b/include/liblvgl/extra/widgets/colorwheel/lv_colorwheel.h new file mode 100644 index 00000000..38266d01 --- /dev/null +++ b/include/liblvgl/extra/widgets/colorwheel/lv_colorwheel.h @@ -0,0 +1,142 @@ +/** + * @file lv_colorwheel.h + * + */ + +#ifndef LV_COLORWHEEL_H +#define LV_COLORWHEEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_COLORWHEEL + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_COLORWHEEL_MODE_HUE, + LV_COLORWHEEL_MODE_SATURATION, + LV_COLORWHEEL_MODE_VALUE +}; +typedef uint8_t lv_colorwheel_mode_t; + + +/*Data of color picker*/ +typedef struct { + lv_obj_t obj; + lv_color_hsv_t hsv; + struct { + lv_point_t pos; + uint8_t recolor : 1; + } knob; + uint32_t last_click_time; + uint32_t last_change_time; + lv_point_t last_press_point; + lv_colorwheel_mode_t mode : 2; + uint8_t mode_fixed : 1; +} lv_colorwheel_t; + +extern const lv_obj_class_t lv_colorwheel_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a color picker object with disc shape + * @param parent pointer to an object, it will be the parent of the new color picker + * @param knob_recolor true: set the knob's color to the current color + * @return pointer to the created color picker + */ +lv_obj_t * lv_colorwheel_create(lv_obj_t * parent, bool knob_recolor); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the current hsv of a color wheel. + * @param colorwheel pointer to color wheel object + * @param color current selected hsv + * @return true if changed, otherwise false + */ +bool lv_colorwheel_set_hsv(lv_obj_t * obj, lv_color_hsv_t hsv); + +/** + * Set the current color of a color wheel. + * @param colorwheel pointer to color wheel object + * @param color current selected color + * @return true if changed, otherwise false + */ +bool lv_colorwheel_set_rgb(lv_obj_t * obj, lv_color_t color); + +/** + * Set the current color mode. + * @param colorwheel pointer to color wheel object + * @param mode color mode (hue/sat/val) + */ +void lv_colorwheel_set_mode(lv_obj_t * obj, lv_colorwheel_mode_t mode); + +/** + * Set if the color mode is changed on long press on center + * @param colorwheel pointer to color wheel object + * @param fixed color mode cannot be changed on long press + */ +void lv_colorwheel_set_mode_fixed(lv_obj_t * obj, bool fixed); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current selected hsv of a color wheel. + * @param colorwheel pointer to color wheel object + * @return current selected hsv + */ +lv_color_hsv_t lv_colorwheel_get_hsv(lv_obj_t * obj); + +/** + * Get the current selected color of a color wheel. + * @param colorwheel pointer to color wheel object + * @return color current selected color + */ +lv_color_t lv_colorwheel_get_rgb(lv_obj_t * obj); + +/** + * Get the current color mode. + * @param colorwheel pointer to color wheel object + * @return color mode (hue/sat/val) + */ +lv_colorwheel_mode_t lv_colorwheel_get_color_mode(lv_obj_t * obj); + +/** + * Get if the color mode is changed on long press on center + * @param colorwheel pointer to color wheel object + * @return mode cannot be changed on long press + */ +bool lv_colorwheel_get_color_mode_fixed(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_COLORWHEEL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_COLORWHEEL_H*/ + diff --git a/include/liblvgl/extra/widgets/imgbtn/lv_imgbtn.h b/include/liblvgl/extra/widgets/imgbtn/lv_imgbtn.h new file mode 100644 index 00000000..38bcc033 --- /dev/null +++ b/include/liblvgl/extra/widgets/imgbtn/lv_imgbtn.h @@ -0,0 +1,131 @@ +/** + * @file lv_imgbtn.h + * + */ + +#ifndef LV_IMGBTN_H +#define LV_IMGBTN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_IMGBTN != 0 + +/********************* + * DEFINES + *********************/ +typedef enum { + LV_IMGBTN_STATE_RELEASED, + LV_IMGBTN_STATE_PRESSED, + LV_IMGBTN_STATE_DISABLED, + LV_IMGBTN_STATE_CHECKED_RELEASED, + LV_IMGBTN_STATE_CHECKED_PRESSED, + LV_IMGBTN_STATE_CHECKED_DISABLED, + _LV_IMGBTN_STATE_NUM, +} lv_imgbtn_state_t; + +/********************** + * TYPEDEFS + **********************/ +/*Data of image button*/ +typedef struct { + lv_obj_t obj; + const void * img_src_mid[_LV_IMGBTN_STATE_NUM]; /*Store center images to each state*/ + const void * img_src_left[_LV_IMGBTN_STATE_NUM]; /*Store left side images to each state*/ + const void * img_src_right[_LV_IMGBTN_STATE_NUM]; /*Store right side images to each state*/ + lv_img_cf_t act_cf; /*Color format of the currently active image*/ +} lv_imgbtn_t; + +extern const lv_obj_class_t lv_imgbtn_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an image button object + * @param parent pointer to an object, it will be the parent of the new image button + * @return pointer to the created image button + */ +lv_obj_t * lv_imgbtn_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/** + * Set images for a state of the image button + * @param imgbtn pointer to an image button object + * @param state for which state set the new image + * @param src_left pointer to an image source for the left side of the button (a C array or path to + * a file) + * @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C + * array or path to a file) + * @param src_right pointer to an image source for the right side of the button (a C array or path + * to a file) + */ +void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_imgbtn_state_t state, const void * src_left, const void * src_mid, + const void * src_right); + + +/** + * Use this function instead of `lv_obj_add/clear_state` to set a state manually + * @param imgbtn pointer to an image button object + * @param state the new state + */ +void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_imgbtn_state_t state); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the left image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the left image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_imgbtn_state_t state); + +/** + * Get the middle image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the middle image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_imgbtn_state_t state); + +/** + * Get the right image in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to the left image source (a C array or path to a file) + */ +const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_imgbtn_state_t state); + + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_IMGBTN*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMGBTN_H*/ diff --git a/include/liblvgl/extra/widgets/keyboard/lv_keyboard.h b/include/liblvgl/extra/widgets/keyboard/lv_keyboard.h new file mode 100644 index 00000000..64356a33 --- /dev/null +++ b/include/liblvgl/extra/widgets/keyboard/lv_keyboard.h @@ -0,0 +1,187 @@ +/** + * @file lv_keyboard.h + * + */ + +#ifndef LV_KEYBOARD_H +#define LV_KEYBOARD_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/widgets/lv_btnmatrix.h" + +#if LV_USE_KEYBOARD + +/*Testing of dependencies*/ +#if LV_USE_BTNMATRIX == 0 +#error "lv_kb: lv_btnm is required. Enable it in lv_conf.h (LV_USE_BTNMATRIX 1) " +#endif + +#if LV_USE_TEXTAREA == 0 +#error "lv_kb: lv_ta is required. Enable it in lv_conf.h (LV_USE_TEXTAREA 1) " +#endif + +/********************* + * DEFINES + *********************/ +#define LV_KEYBOARD_CTRL_BTN_FLAGS (LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_CHECKED) + +/********************** + * TYPEDEFS + **********************/ + +/** Current keyboard mode.*/ +enum { + LV_KEYBOARD_MODE_TEXT_LOWER, + LV_KEYBOARD_MODE_TEXT_UPPER, + LV_KEYBOARD_MODE_SPECIAL, + LV_KEYBOARD_MODE_NUMBER, + LV_KEYBOARD_MODE_USER_1, + LV_KEYBOARD_MODE_USER_2, + LV_KEYBOARD_MODE_USER_3, + LV_KEYBOARD_MODE_USER_4, +}; +typedef uint8_t lv_keyboard_mode_t; + +/*Data of keyboard*/ +typedef struct { + lv_btnmatrix_t btnm; + lv_obj_t * ta; /*Pointer to the assigned text area*/ + lv_keyboard_mode_t mode; /*Key map type*/ + uint8_t popovers : 1; /*Show button titles in popovers on press*/ +} lv_keyboard_t; + +extern const lv_obj_class_t lv_keyboard_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Keyboard object + * @param parent pointer to an object, it will be the parent of the new keyboard + * @return pointer to the created keyboard + */ +lv_obj_t * lv_keyboard_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @param ta pointer to a Text Area object to write there + */ +void lv_keyboard_set_textarea(lv_obj_t * kb, lv_obj_t * ta); + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @param mode the mode from 'lv_keyboard_mode_t' + */ +void lv_keyboard_set_mode(lv_obj_t * kb, lv_keyboard_mode_t mode); + +/** + * Show the button title in a popover when pressed. + * @param kb pointer to a Keyboard object + * @param en whether "popovers" mode is enabled + */ +void lv_keyboard_set_popovers(lv_obj_t * kb, bool en); + +/** + * Set a new map for the keyboard + * @param kb pointer to a Keyboard object + * @param mode keyboard map to alter 'lv_keyboard_mode_t' + * @param map pointer to a string array to describe the map. + * See 'lv_btnmatrix_set_map()' for more info. + */ +void lv_keyboard_set_map(lv_obj_t * kb, lv_keyboard_mode_t mode, const char * map[], + const lv_btnmatrix_ctrl_t ctrl_map[]); + +/*===================== + * Getter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @return pointer to the assigned Text Area object + */ +lv_obj_t * lv_keyboard_get_textarea(const lv_obj_t * kb); + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @return the current mode from 'lv_keyboard_mode_t' + */ +lv_keyboard_mode_t lv_keyboard_get_mode(const lv_obj_t * kb); + +/** + * Tell whether "popovers" mode is enabled or not. + * @param kb pointer to a Keyboard object + * @return true: "popovers" mode is enabled; false: disabled + */ +bool lv_btnmatrix_get_popovers(const lv_obj_t * obj); + +/** + * Get the current map of a keyboard + * @param kb pointer to a keyboard object + * @return the current map + */ +static inline const char ** lv_keyboard_get_map_array(const lv_obj_t * kb) +{ + return lv_btnmatrix_get_map(kb); +} + +/** + * Get the index of the lastly "activated" button by the user (pressed, released, focused etc) + * Useful in the `event_cb` to get the text of the button, check if hidden etc. + * @param obj pointer to button matrix object + * @return index of the last released button (LV_BTNMATRIX_BTN_NONE: if unset) + */ +static inline uint16_t lv_keyboard_get_selected_btn(const lv_obj_t * obj) +{ + return lv_btnmatrix_get_selected_btn(obj); +} + +/** + * Get the button's text + * @param obj pointer to button matrix object + * @param btn_id the index a button not counting new line characters. + * @return text of btn_index` button + */ +static inline const char * lv_keyboard_get_btn_text(const lv_obj_t * obj, uint16_t btn_id) +{ + return lv_btnmatrix_get_btn_text(obj, btn_id); +} + +/*===================== + * Other functions + *====================*/ + +/** + * Default keyboard event to add characters to the Text area and change the map. + * If a custom `event_cb` is added to the keyboard this function can be called from it to handle the + * button clicks + * @param kb pointer to a keyboard + * @param event the triggering event + */ +void lv_keyboard_def_event_cb(lv_event_t * e); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_KEYBOARD*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_KEYBOARD_H*/ diff --git a/include/liblvgl/extra/widgets/led/lv_led.h b/include/liblvgl/extra/widgets/led/lv_led.h new file mode 100644 index 00000000..f188b8e9 --- /dev/null +++ b/include/liblvgl/extra/widgets/led/lv_led.h @@ -0,0 +1,116 @@ +/** + * @file lv_led.h + * + */ + +#ifndef LV_LED_H +#define LV_LED_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_LED + + +/********************* + * DEFINES + *********************/ +/** Brightness when the LED if OFF */ +#ifndef LV_LED_BRIGHT_MIN +# define LV_LED_BRIGHT_MIN 80 +#endif + +/** Brightness when the LED if ON */ +#ifndef LV_LED_BRIGHT_MAX +# define LV_LED_BRIGHT_MAX 255 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/*Data of led*/ +typedef struct { + lv_obj_t obj; + lv_color_t color; + uint8_t bright; /**< Current brightness of the LED (0..255)*/ +} lv_led_t; + +extern const lv_obj_class_t lv_led_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_led_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_LED_DRAW_PART_RECTANGLE, /**< The main rectangle*/ +} lv_led_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a led object + * @param parent pointer to an object, it will be the parent of the new led + * @return pointer to the created led + */ +lv_obj_t * lv_led_create(lv_obj_t * parent); + +/** + * Set the color of the LED + * @param led pointer to a LED object + * @param color the color of the LED + */ +void lv_led_set_color(lv_obj_t * led, lv_color_t color); + +/** + * Set the brightness of a LED object + * @param led pointer to a LED object + * @param bright LV_LED_BRIGHT_MIN (max. dark) ... LV_LED_BRIGHT_MAX (max. light) + */ +void lv_led_set_brightness(lv_obj_t * led, uint8_t bright); + +/** + * Light on a LED + * @param led pointer to a LED object + */ +void lv_led_on(lv_obj_t * led); + +/** + * Light off a LED + * @param led pointer to a LED object + */ +void lv_led_off(lv_obj_t * led); + +/** + * Toggle the state of a LED + * @param led pointer to a LED object + */ +void lv_led_toggle(lv_obj_t * led); + +/** + * Get the brightness of a LEd object + * @param led pointer to LED object + * @return bright 0 (max. dark) ... 255 (max. light) + */ +uint8_t lv_led_get_brightness(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_LED*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + + +#endif /*LV_LED_H*/ diff --git a/include/liblvgl/extra/widgets/list/lv_list.h b/include/liblvgl/extra/widgets/list/lv_list.h new file mode 100644 index 00000000..e9bb6266 --- /dev/null +++ b/include/liblvgl/extra/widgets/list/lv_list.h @@ -0,0 +1,54 @@ +/** + * @file lv_win.h + * + */ + +#ifndef LV_LIST_H +#define LV_LIST_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/extra/layouts/flex/lv_flex.h" + +#if LV_USE_LIST + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +extern const lv_obj_class_t lv_list_class; +extern const lv_obj_class_t lv_list_text_class; +extern const lv_obj_class_t lv_list_btn_class; +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_list_create(lv_obj_t * parent); + +lv_obj_t * lv_list_add_text(lv_obj_t * list, const char * txt); + +lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * icon, const char * txt); + +const char * lv_list_get_btn_text(lv_obj_t * list, lv_obj_t * btn); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_LIST*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LIST_H*/ diff --git a/include/liblvgl/extra/widgets/lv_widgets.h b/include/liblvgl/extra/widgets/lv_widgets.h new file mode 100644 index 00000000..11418102 --- /dev/null +++ b/include/liblvgl/extra/widgets/lv_widgets.h @@ -0,0 +1,56 @@ +/** + * @file lv_widgets.h + * + */ + +#ifndef LV_WIDGETS_H +#define LV_WIDGETS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "animimg/lv_animimg.h" +#include "calendar/lv_calendar.h" +#include "calendar/lv_calendar_header_arrow.h" +#include "calendar/lv_calendar_header_dropdown.h" +#include "chart/lv_chart.h" +#include "keyboard/lv_keyboard.h" +#include "list/lv_list.h" +#include "menu/lv_menu.h" +#include "msgbox/lv_msgbox.h" +#include "meter/lv_meter.h" +#include "spinbox/lv_spinbox.h" +#include "spinner/lv_spinner.h" +#include "tabview/lv_tabview.h" +#include "tileview/lv_tileview.h" +#include "win/lv_win.h" +#include "colorwheel/lv_colorwheel.h" +#include "led/lv_led.h" +#include "imgbtn/lv_imgbtn.h" +#include "span/lv_span.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_WIDGETS_H*/ diff --git a/include/liblvgl/extra/widgets/menu/lv_menu.h b/include/liblvgl/extra/widgets/menu/lv_menu.h new file mode 100644 index 00000000..42099792 --- /dev/null +++ b/include/liblvgl/extra/widgets/menu/lv_menu.h @@ -0,0 +1,233 @@ +/** + * @file lv_menu.h + * + */ + +#ifndef LV_MENU_H +#define LV_MENU_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_MENU + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_MENU_HEADER_TOP_FIXED, /* Header is positioned at the top */ + LV_MENU_HEADER_TOP_UNFIXED, /* Header is positioned at the top and can be scrolled out of view*/ + LV_MENU_HEADER_BOTTOM_FIXED /* Header is positioned at the bottom */ +}; +typedef uint8_t lv_menu_mode_header_t; + +enum { + LV_MENU_ROOT_BACK_BTN_DISABLED, + LV_MENU_ROOT_BACK_BTN_ENABLED +}; +typedef uint8_t lv_menu_mode_root_back_btn_t; + +typedef struct lv_menu_load_page_event_data_t { + lv_obj_t * menu; + lv_obj_t * page; +} lv_menu_load_page_event_data_t; + +typedef struct { + lv_obj_t * page; +} lv_menu_history_t; + +typedef struct { + lv_obj_t obj; + lv_obj_t * storage; /* a pointer to obj that is the parent of all pages not displayed */ + lv_obj_t * main; + lv_obj_t * main_page; + lv_obj_t * main_header; + lv_obj_t * + main_header_back_btn; /* a pointer to obj that on click triggers back btn event handler, can be same as 'main_header' */ + lv_obj_t * main_header_title; + lv_obj_t * sidebar; + lv_obj_t * sidebar_page; + lv_obj_t * sidebar_header; + lv_obj_t * + sidebar_header_back_btn; /* a pointer to obj that on click triggers back btn event handler, can be same as 'sidebar_header' */ + lv_obj_t * sidebar_header_title; + lv_obj_t * selected_tab; + lv_ll_t history_ll; + uint8_t cur_depth; + uint8_t prev_depth; + uint8_t sidebar_generated : 1; + lv_menu_mode_header_t mode_header : 2; + lv_menu_mode_root_back_btn_t mode_root_back_btn : 1; +} lv_menu_t; + +typedef struct { + lv_obj_t obj; + char * title; +} lv_menu_page_t; + +extern const lv_obj_class_t lv_menu_class; +extern const lv_obj_class_t lv_menu_page_class; +extern const lv_obj_class_t lv_menu_cont_class; +extern const lv_obj_class_t lv_menu_section_class; +extern const lv_obj_class_t lv_menu_separator_class; +extern const lv_obj_class_t lv_menu_sidebar_cont_class; +extern const lv_obj_class_t lv_menu_main_cont_class; +extern const lv_obj_class_t lv_menu_sidebar_header_cont_class; +extern const lv_obj_class_t lv_menu_main_header_cont_class; +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a menu object + * @param parent pointer to an object, it will be the parent of the new menu + * @return pointer to the created menu + */ +lv_obj_t * lv_menu_create(lv_obj_t * parent); + +/** + * Create a menu page object + * @param parent pointer to menu object + * @param title pointer to text for title in header (NULL to not display title) + * @return pointer to the created menu page + */ +lv_obj_t * lv_menu_page_create(lv_obj_t * parent, char * title); + +/** + * Create a menu cont object + * @param parent pointer to an object, it will be the parent of the new menu cont object + * @return pointer to the created menu cont + */ +lv_obj_t * lv_menu_cont_create(lv_obj_t * parent); + +/** + * Create a menu section object + * @param parent pointer to an object, it will be the parent of the new menu section object + * @return pointer to the created menu section + */ +lv_obj_t * lv_menu_section_create(lv_obj_t * parent); + +/** + * Create a menu separator object + * @param parent pointer to an object, it will be the parent of the new menu separator object + * @return pointer to the created menu separator + */ +lv_obj_t * lv_menu_separator_create(lv_obj_t * parent); +/*===================== + * Setter functions + *====================*/ +/** + * Set menu page to display in main + * @param obj pointer to the menu + * @param page pointer to the menu page to set (NULL to clear main and clear menu history) + */ +void lv_menu_set_page(lv_obj_t * obj, lv_obj_t * page); + +/** + * Set menu page to display in sidebar + * @param obj pointer to the menu + * @param page pointer to the menu page to set (NULL to clear sidebar) + */ +void lv_menu_set_sidebar_page(lv_obj_t * obj, lv_obj_t * page); + +/** + * Set the how the header should behave and its position + * @param obj pointer to a menu + * @param mode_header + */ +void lv_menu_set_mode_header(lv_obj_t * obj, lv_menu_mode_header_t mode_header); + +/** + * Set whether back button should appear at root + * @param obj pointer to a menu + * @param mode_root_back_btn + */ +void lv_menu_set_mode_root_back_btn(lv_obj_t * obj, lv_menu_mode_root_back_btn_t mode_root_back_btn); + +/** + * Add menu to the menu item + * @param menu pointer to the menu + * @param obj pointer to the obj + * @param page pointer to the page to load when obj is clicked + */ +void lv_menu_set_load_page_event(lv_obj_t * menu, lv_obj_t * obj, lv_obj_t * page); + +/*===================== + * Getter functions + *====================*/ +/** +* Get a pointer to menu page that is currently displayed in main +* @param obj pointer to the menu +* @return pointer to current page +*/ +lv_obj_t * lv_menu_get_cur_main_page(lv_obj_t * obj); + +/** +* Get a pointer to menu page that is currently displayed in sidebar +* @param obj pointer to the menu +* @return pointer to current page +*/ +lv_obj_t * lv_menu_get_cur_sidebar_page(lv_obj_t * obj); + +/** +* Get a pointer to main header obj +* @param obj pointer to the menu +* @return pointer to main header obj +*/ +lv_obj_t * lv_menu_get_main_header(lv_obj_t * obj); + +/** +* Get a pointer to main header back btn obj +* @param obj pointer to the menu +* @return pointer to main header back btn obj +*/ +lv_obj_t * lv_menu_get_main_header_back_btn(lv_obj_t * obj); + +/** +* Get a pointer to sidebar header obj +* @param obj pointer to the menu +* @return pointer to sidebar header obj +*/ +lv_obj_t * lv_menu_get_sidebar_header(lv_obj_t * obj); + +/** +* Get a pointer to sidebar header obj +* @param obj pointer to the menu +* @return pointer to sidebar header back btn obj +*/ +lv_obj_t * lv_menu_get_sidebar_header_back_btn(lv_obj_t * obj); + +/** + * Check if an obj is a root back btn + * @param menu pointer to the menu + * @return true if it is a root back btn + */ +bool lv_menu_back_btn_is_root(lv_obj_t * menu, lv_obj_t * obj); + +/** + * Clear menu history + * @param obj pointer to the menu + */ +void lv_menu_clear_history(lv_obj_t * obj); +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_MENU*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MENU_H*/ diff --git a/include/liblvgl/extra/widgets/meter/lv_meter.h b/include/liblvgl/extra/widgets/meter/lv_meter.h new file mode 100644 index 00000000..d64ad0d5 --- /dev/null +++ b/include/liblvgl/extra/widgets/meter/lv_meter.h @@ -0,0 +1,267 @@ +/** + * @file lv_meter.h + * + */ + +#ifndef LV_METER_H +#define LV_METER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_METER != 0 + +/*Testing of dependencies*/ +#if LV_DRAW_COMPLEX == 0 +#error "lv_meter: Complex drawing is required. Enable it in lv_conf.h (LV_DRAW_COMPLEX 1)" +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_color_t tick_color; + uint16_t tick_cnt; + uint16_t tick_length; + uint16_t tick_width; + + lv_color_t tick_major_color; + uint16_t tick_major_nth; + uint16_t tick_major_length; + uint16_t tick_major_width; + + int16_t label_gap; + int16_t label_color; + + int32_t min; + int32_t max; + int16_t r_mod; + uint16_t angle_range; + int16_t rotation; +} lv_meter_scale_t; + +enum { + LV_METER_INDICATOR_TYPE_NEEDLE_IMG, + LV_METER_INDICATOR_TYPE_NEEDLE_LINE, + LV_METER_INDICATOR_TYPE_SCALE_LINES, + LV_METER_INDICATOR_TYPE_ARC, +}; +typedef uint8_t lv_meter_indicator_type_t; + +typedef struct { + lv_meter_scale_t * scale; + lv_meter_indicator_type_t type; + lv_opa_t opa; + int32_t start_value; + int32_t end_value; + union { + struct { + const void * src; + lv_point_t pivot; + } needle_img; + struct { + uint16_t width; + int16_t r_mod; + lv_color_t color; + } needle_line; + struct { + uint16_t width; + const void * src; + lv_color_t color; + int16_t r_mod; + } arc; + struct { + int16_t width_mod; + lv_color_t color_start; + lv_color_t color_end; + uint8_t local_grad : 1; + } scale_lines; + } type_data; +} lv_meter_indicator_t; + +/*Data of line meter*/ +typedef struct { + lv_obj_t obj; + lv_ll_t scale_ll; + lv_ll_t indicator_ll; +} lv_meter_t; + +extern const lv_obj_class_t lv_meter_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_meter_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_METER_DRAW_PART_ARC, /**< The arc indicator*/ + LV_METER_DRAW_PART_NEEDLE_LINE, /**< The needle lines*/ + LV_METER_DRAW_PART_NEEDLE_IMG, /**< The needle images*/ + LV_METER_DRAW_PART_TICK, /**< The tick lines and labels*/ +} lv_meter_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Meter object + * @param parent pointer to an object, it will be the parent of the new bar. + * @return pointer to the created meter + */ +lv_obj_t * lv_meter_create(lv_obj_t * parent); + +/*===================== + * Add scale + *====================*/ + +/** + * Add a new scale to the meter. + * @param obj pointer to a meter object + * @return the new scale + * @note Indicators can be attached to scales. + */ +lv_meter_scale_t * lv_meter_add_scale(lv_obj_t * obj); + +/** + * Set the properties of the ticks of a scale + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param cnt number of tick lines + * @param width width of tick lines + * @param len length of tick lines + * @param color color of tick lines + */ +void lv_meter_set_scale_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t cnt, uint16_t width, uint16_t len, + lv_color_t color); + +/** + * Make some "normal" ticks major ticks and set their attributes. + * Texts with the current value are also added to the major ticks. + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param nth make every Nth normal tick major tick. (start from the first on the left) + * @param width width of the major ticks + * @param len length of the major ticks + * @param color color of the major ticks + * @param label_gap gap between the major ticks and the labels + */ +void lv_meter_set_scale_major_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t nth, uint16_t width, + uint16_t len, lv_color_t color, int16_t label_gap); + +/** + * Set the value and angular range of a scale. + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param min the minimum value + * @param max the maximal value + * @param angle_range the angular range of the scale + * @param rotation the angular offset from the 3 o'clock position (clock-wise) + */ +void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t min, int32_t max, uint32_t angle_range, + uint32_t rotation); + +/*===================== + * Add indicator + *====================*/ + +/** + * Add a needle line indicator the scale + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param width width of the line + * @param color color of the line + * @param r_mod the radius modifier (added to the scale's radius) to get the lines length + * @return the new indicator + */ +lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, + lv_color_t color, int16_t r_mod); + +/** + * Add a needle image indicator the scale + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param src the image source of the indicator. path or pointer to ::lv_img_dsc_t + * @param pivot_x the X pivot point of the needle + * @param pivot_y the Y pivot point of the needle + * @return the new indicator + * @note the needle image should point to the right, like -O-----> + */ +lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t * scale, const void * src, + lv_coord_t pivot_x, lv_coord_t pivot_y); + +/** + * Add an arc indicator the scale + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param width width of the arc + * @param color color of the arc + * @param r_mod the radius modifier (added to the scale's radius) to get the outer radius of the arc + * @return the new indicator + */ +lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, + int16_t r_mod); + + +/** + * Add a scale line indicator the scale. It will modify the ticks. + * @param obj pointer to a meter object + * @param scale pointer to scale (added to `meter`) + * @param color_start the start color + * @param color_end the end color + * @param local tell how to map start and end color. true: the indicator's start and end_value; false: the scale's min max value + * @param width_mod add this the affected tick's width + * @return the new indicator + */ +lv_meter_indicator_t * lv_meter_add_scale_lines(lv_obj_t * obj, lv_meter_scale_t * scale, lv_color_t color_start, + lv_color_t color_end, bool local, int16_t width_mod); + +/*===================== + * Set indicator value + *====================*/ + +/** + * Set the value of the indicator. It will set start and and value to the same value + * @param obj pointer to a meter object + * @param indic pointer to an indicator + * @param value the new value + */ +void lv_meter_set_indicator_value(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value); + +/** + * Set the start value of the indicator. + * @param obj pointer to a meter object + * @param indic pointer to an indicator + * @param value the new value + */ +void lv_meter_set_indicator_start_value(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value); + +/** + * Set the start value of the indicator. + * @param obj pointer to a meter object + * @param indic pointer to an indicator + * @param value the new value + */ +void lv_meter_set_indicator_end_value(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_METER*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_METER_H*/ diff --git a/include/liblvgl/extra/widgets/msgbox/lv_msgbox.h b/include/liblvgl/extra/widgets/msgbox/lv_msgbox.h new file mode 100644 index 00000000..6b8ccd61 --- /dev/null +++ b/include/liblvgl/extra/widgets/msgbox/lv_msgbox.h @@ -0,0 +1,99 @@ +/** + * @file lv_mbox.h + * + */ + +#ifndef LV_MSGBOX_H +#define LV_MSGBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_MSGBOX + +/*Testing of dependencies*/ +#if LV_USE_BTNMATRIX == 0 +#error "lv_mbox: lv_btnm is required. Enable it in lv_conf.h (LV_USE_BTNMATRIX 1) " +#endif + +#if LV_USE_LABEL == 0 +#error "lv_mbox: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) " +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + lv_obj_t * title; + lv_obj_t * close_btn; + lv_obj_t * content; + lv_obj_t * text; + lv_obj_t * btns; +} lv_msgbox_t; + +extern const lv_obj_class_t lv_msgbox_class; +extern const lv_obj_class_t lv_msgbox_content_class; +extern const lv_obj_class_t lv_msgbox_backdrop_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a message box object + * @param parent pointer to parent or NULL to create a full screen modal message box + * @param title the title of the message box + * @param txt the text of the message box + * @param btn_txts the buttons as an array of texts terminated by an "" element. E.g. {"btn1", "btn2", ""} + * @param add_close_btn true: add a close button + * @return pointer to the message box object + */ +lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char * txt, const char * btn_txts[], + bool add_close_btn); + +lv_obj_t * lv_msgbox_get_title(lv_obj_t * obj); + +lv_obj_t * lv_msgbox_get_close_btn(lv_obj_t * obj); + +lv_obj_t * lv_msgbox_get_text(lv_obj_t * obj); + +lv_obj_t * lv_msgbox_get_content(lv_obj_t * obj); + +lv_obj_t * lv_msgbox_get_btns(lv_obj_t * obj); + +/** + * Get the index of the selected button + * @param mbox message box object + * @return index of the button (LV_BTNMATRIX_BTN_NONE: if unset) + */ +uint16_t lv_msgbox_get_active_btn(lv_obj_t * mbox); + +const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox); + +void lv_msgbox_close(lv_obj_t * mbox); + +void lv_msgbox_close_async(lv_obj_t * mbox); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_MSGBOX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MSGBOX_H*/ diff --git a/include/liblvgl/extra/widgets/span/lv_span.h b/include/liblvgl/extra/widgets/span/lv_span.h new file mode 100644 index 00000000..bbf65acb --- /dev/null +++ b/include/liblvgl/extra/widgets/span/lv_span.h @@ -0,0 +1,245 @@ +/** + * @file lv_span.h + * + */ + +#ifndef LV_SPAN_H +#define LV_SPAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_SPAN != 0 + +/********************* + * DEFINES + *********************/ +#ifndef LV_SPAN_SNIPPET_STACK_SIZE +#define LV_SPAN_SNIPPET_STACK_SIZE 64 +#endif + +/********************** + * TYPEDEFS + **********************/ +enum { + LV_SPAN_OVERFLOW_CLIP, + LV_SPAN_OVERFLOW_ELLIPSIS, +}; +typedef uint8_t lv_span_overflow_t; + +enum { + LV_SPAN_MODE_FIXED, /**< fixed the obj size*/ + LV_SPAN_MODE_EXPAND, /**< Expand the object size to the text size*/ + LV_SPAN_MODE_BREAK, /**< Keep width, break the too long lines and expand height*/ +}; +typedef uint8_t lv_span_mode_t; + +typedef struct { + char * txt; /* a pointer to display text */ + lv_obj_t * spangroup; /* a pointer to spangroup */ + lv_style_t style; /* display text style */ + uint8_t static_flag : 1;/* the text is static flag */ +} lv_span_t; + +/** Data of label*/ +typedef struct { + lv_obj_t obj; + int32_t lines; + lv_coord_t indent; /* first line indent */ + lv_coord_t cache_w; /* the cache automatically calculates the width */ + lv_coord_t cache_h; /* similar cache_w */ + lv_ll_t child_ll; + uint8_t mode : 2; /* details see lv_span_mode_t */ + uint8_t overflow : 1; /* details see lv_span_overflow_t */ + uint8_t refresh : 1; /* the spangroup need refresh cache_w and cache_h */ +} lv_spangroup_t; + +extern const lv_obj_class_t lv_spangroup_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a spangroup object + * @param par pointer to an object, it will be the parent of the new spangroup + * @return pointer to the created spangroup + */ +lv_obj_t * lv_spangroup_create(lv_obj_t * par); + +/** + * Create a span string descriptor and add to spangroup. + * @param obj pointer to a spangroup object. + * @return pointer to the created span. + */ +lv_span_t * lv_spangroup_new_span(lv_obj_t * obj); + +/** + * Remove the span from the spangroup and free memory. + * @param obj pointer to a spangroup object. + * @param span pointer to a span. + */ +void lv_spangroup_del_span(lv_obj_t * obj, lv_span_t * span); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new text for a span. Memory will be allocated to store the text by the span. + * @param span pointer to a span. + * @param text pointer to a text. + */ +void lv_span_set_text(lv_span_t * span, const char * text); + +/** + * Set a static text. It will not be saved by the span so the 'text' variable + * has to be 'alive' while the span exist. + * @param span pointer to a span. + * @param text pointer to a text. + */ +void lv_span_set_text_static(lv_span_t * span, const char * text); + +/** + * Set the align of the spangroup. + * @param obj pointer to a spangroup object. + * @param align see lv_text_align_t for details. + */ +void lv_spangroup_set_align(lv_obj_t * obj, lv_text_align_t align); + +/** + * Set the overflow of the spangroup. + * @param obj pointer to a spangroup object. + * @param overflow see lv_span_overflow_t for details. + */ +void lv_spangroup_set_overflow(lv_obj_t * obj, lv_span_overflow_t overflow); + +/** + * Set the indent of the spangroup. + * @param obj pointer to a spangroup object. + * @param indent The first line indentation + */ +void lv_spangroup_set_indent(lv_obj_t * obj, lv_coord_t indent); + +/** + * Set the mode of the spangroup. + * @param obj pointer to a spangroup object. + * @param mode see lv_span_mode_t for details. + */ +void lv_spangroup_set_mode(lv_obj_t * obj, lv_span_mode_t mode); + +/** + * Set lines of the spangroup. + * @param obj pointer to a spangroup object. + * @param lines max lines that can be displayed in LV_SPAN_MODE_BREAK mode. < 0 means no limit. + */ +void lv_spangroup_set_lines(lv_obj_t * obj, int32_t lines); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get a spangroup child by its index. + * + * @param obj The spangroup object + * @param id the index of the child. + * 0: the oldest (firstly created) child + * 1: the second oldest + * child count-1: the youngest + * -1: the youngest + * -2: the second youngest + * @return The child span at index `id`, or NULL if the ID does not exist + */ +lv_span_t * lv_spangroup_get_child(const lv_obj_t * obj, int32_t id); + +/** + * + * @param obj The spangroup object to get the child count of. + * @return The span count of the spangroup. + */ +uint32_t lv_spangroup_get_child_cnt(const lv_obj_t * obj); + +/** + * get the align of the spangroup. + * @param obj pointer to a spangroup object. + * @return the align value. + */ +lv_text_align_t lv_spangroup_get_align(lv_obj_t * obj); + +/** + * get the overflow of the spangroup. + * @param obj pointer to a spangroup object. + * @return the overflow value. + */ +lv_span_overflow_t lv_spangroup_get_overflow(lv_obj_t * obj); + +/** + * get the indent of the spangroup. + * @param obj pointer to a spangroup object. + * @return the indent value. + */ +lv_coord_t lv_spangroup_get_indent(lv_obj_t * obj); + +/** + * get the mode of the spangroup. + * @param obj pointer to a spangroup object. + */ +lv_span_mode_t lv_spangroup_get_mode(lv_obj_t * obj); + +/** + * get lines of the spangroup. + * @param obj pointer to a spangroup object. + * @return the lines value. + */ +int32_t lv_spangroup_get_lines(lv_obj_t * obj); + +/** + * get max line height of all span in the spangroup. + * @param obj pointer to a spangroup object. + */ +lv_coord_t lv_spangroup_get_max_line_h(lv_obj_t * obj); + +/** + * get the text content width when all span of spangroup on a line. + * @param obj pointer to a spangroup object. + * @param max_width if text content width >= max_width, return max_width + * to reduce computation, if max_width == 0, returns the text content width. + * @return text content width or max_width. + */ +uint32_t lv_spangroup_get_expand_width(lv_obj_t * obj, uint32_t max_width); + +/** + * get the text content height with width fixed. + * @param obj pointer to a spangroup object. + */ +lv_coord_t lv_spangroup_get_expand_height(lv_obj_t * obj, lv_coord_t width); + + +/*===================== + * Other functions + *====================*/ + +/** + * update the mode of the spangroup. + * @param obj pointer to a spangroup object. + */ +void lv_spangroup_refr_mode(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_SPAN*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_SPAN_H*/ diff --git a/include/liblvgl/extra/widgets/spinbox/lv_spinbox.h b/include/liblvgl/extra/widgets/spinbox/lv_spinbox.h new file mode 100644 index 00000000..830178fa --- /dev/null +++ b/include/liblvgl/extra/widgets/spinbox/lv_spinbox.h @@ -0,0 +1,182 @@ +/** + * @file lv_spinbox.h + * + */ + +#ifndef LV_SPINBOX_H +#define LV_SPINBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_SPINBOX + +/*Testing of dependencies*/ +#if LV_USE_TEXTAREA == 0 +#error "lv_spinbox: lv_ta is required. Enable it in lv_conf.h (LV_USE_TEXTAREA 1) " +#endif + +/********************* + * DEFINES + *********************/ +#define LV_SPINBOX_MAX_DIGIT_COUNT 10 + +/********************** + * TYPEDEFS + **********************/ + +/*Data of spinbox*/ +typedef struct { + lv_textarea_t ta; /*Ext. of ancestor*/ + /*New data for this type*/ + int32_t value; + int32_t range_max; + int32_t range_min; + int32_t step; + uint16_t digit_count : 4; + uint16_t dec_point_pos : 4; /*if 0, there is no separator and the number is an integer*/ + uint16_t rollover : 1; // Set to true for rollover functionality + uint16_t digit_step_dir : 2; // the direction the digit will step on encoder button press when editing +} lv_spinbox_t; + +extern const lv_obj_class_t lv_spinbox_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Spinbox object + * @param parent pointer to an object, it will be the parent of the new spinbox + * @return pointer to the created spinbox + */ +lv_obj_t * lv_spinbox_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set spinbox value + * @param obj pointer to spinbox + * @param i value to be set + */ +void lv_spinbox_set_value(lv_obj_t * obj, int32_t i); + +/** + * Set spinbox rollover function + * @param obj pointer to spinbox + * @param b true or false to enable or disable (default) + */ +void lv_spinbox_set_rollover(lv_obj_t * obj, bool b); + +/** + * Set spinbox digit format (digit count and decimal format) + * @param obj pointer to spinbox + * @param digit_count number of digit excluding the decimal separator and the sign + * @param separator_position number of digit before the decimal point. If 0, decimal point is not + * shown + */ +void lv_spinbox_set_digit_format(lv_obj_t * obj, uint8_t digit_count, uint8_t separator_position); + +/** + * Set spinbox step + * @param obj pointer to spinbox + * @param step steps on increment/decrement. Can be 1, 10, 100, 1000, etc the digit that will change. + */ +void lv_spinbox_set_step(lv_obj_t * obj, uint32_t step); + +/** + * Set spinbox value range + * @param obj pointer to spinbox + * @param range_min maximum value, inclusive + * @param range_max minimum value, inclusive + */ +void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max); + +/** + * Set cursor position to a specific digit for edition + * @param obj pointer to spinbox + * @param pos selected position in spinbox + */ +void lv_spinbox_set_cursor_pos(lv_obj_t * obj, uint8_t pos); + +/** + * Set direction of digit step when clicking an encoder button while in editing mode + * @param obj pointer to spinbox + * @param direction the direction (LV_DIR_RIGHT or LV_DIR_LEFT) + */ +void lv_spinbox_set_digit_step_direction(lv_obj_t * obj, lv_dir_t direction); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get spinbox rollover function status + * @param obj pointer to spinbox + */ +bool lv_spinbox_get_rollover(lv_obj_t * obj); + +/** + * Get the spinbox numeral value (user has to convert to float according to its digit format) + * @param obj pointer to spinbox + * @return value integer value of the spinbox + */ +int32_t lv_spinbox_get_value(lv_obj_t * obj); + +/** + * Get the spinbox step value (user has to convert to float according to its digit format) + * @param obj pointer to spinbox + * @return value integer step value of the spinbox + */ +int32_t lv_spinbox_get_step(lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Select next lower digit for edition by dividing the step by 10 + * @param obj pointer to spinbox + */ +void lv_spinbox_step_next(lv_obj_t * obj); + +/** + * Select next higher digit for edition by multiplying the step by 10 + * @param obj pointer to spinbox + */ +void lv_spinbox_step_prev(lv_obj_t * obj); + +/** + * Increment spinbox value by one step + * @param obj pointer to spinbox + */ +void lv_spinbox_increment(lv_obj_t * obj); + +/** + * Decrement spinbox value by one step + * @param obj pointer to spinbox + */ +void lv_spinbox_decrement(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +/* It was ambiguous in MicroPython. See https://github.com/lvgl/lvgl/issues/3301 + * TODO remove in v9*/ +#define lv_spinbox_set_pos lv_spinbox_set_cursor_pos + +#endif /*LV_USE_SPINBOX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif +#endif /*LV_SPINBOX_H*/ diff --git a/include/liblvgl/extra/widgets/spinner/lv_spinner.h b/include/liblvgl/extra/widgets/spinner/lv_spinner.h new file mode 100644 index 00000000..794f7363 --- /dev/null +++ b/include/liblvgl/extra/widgets/spinner/lv_spinner.h @@ -0,0 +1,50 @@ +/** + * @file lv_spinner.h + * + */ + +#ifndef LV_SPINNER_H +#define LV_SPINNER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_SPINNER + +/*Testing of dependencies*/ +#if LV_USE_ARC == 0 +#error "lv_spinner: lv_arc is required. Enable it in lv_conf.h (LV_USE_ARC 1) " +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +extern const lv_obj_class_t lv_spinner_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_spinner_create(lv_obj_t * parent, uint32_t time, uint32_t arc_length); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_SPINNER*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_SPINNER_H*/ diff --git a/include/liblvgl/extra/widgets/tabview/lv_tabview.h b/include/liblvgl/extra/widgets/tabview/lv_tabview.h new file mode 100644 index 00000000..bcee5a13 --- /dev/null +++ b/include/liblvgl/extra/widgets/tabview/lv_tabview.h @@ -0,0 +1,65 @@ +/** + * @file lv_templ.h + * + */ + +#ifndef LV_TABVIEW_H +#define LV_TABVIEW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +#if LV_USE_TABVIEW + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + char ** map; + uint16_t tab_cnt; + uint16_t tab_cur; + lv_dir_t tab_pos; +} lv_tabview_t; + +extern const lv_obj_class_t lv_tabview_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ +lv_obj_t * lv_tabview_create(lv_obj_t * parent, lv_dir_t tab_pos, lv_coord_t tab_size); + +lv_obj_t * lv_tabview_add_tab(lv_obj_t * tv, const char * name); + +void lv_tabview_rename_tab(lv_obj_t * obj, uint32_t tab_id, const char * new_name); + +lv_obj_t * lv_tabview_get_content(lv_obj_t * tv); + +lv_obj_t * lv_tabview_get_tab_btns(lv_obj_t * tv); + +void lv_tabview_set_act(lv_obj_t * obj, uint32_t id, lv_anim_enable_t anim_en); + +uint16_t lv_tabview_get_tab_act(lv_obj_t * tv); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TABVIEW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TABVIEW_H*/ diff --git a/include/liblvgl/extra/widgets/tileview/lv_tileview.h b/include/liblvgl/extra/widgets/tileview/lv_tileview.h new file mode 100644 index 00000000..34a1bf18 --- /dev/null +++ b/include/liblvgl/extra/widgets/tileview/lv_tileview.h @@ -0,0 +1,72 @@ +/** + * @file lv_tileview.h + * + */ + +#ifndef LV_TILEVIEW_H +#define LV_TILEVIEW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_TILEVIEW + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_obj_t obj; + lv_obj_t * tile_act; +} lv_tileview_t; + +typedef struct { + lv_obj_t obj; + lv_dir_t dir; +} lv_tileview_tile_t; + +extern const lv_obj_class_t lv_tileview_class; +extern const lv_obj_class_t lv_tileview_tile_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Tileview object + * @param parent pointer to an object, it will be the parent of the new tileview + * @return pointer to the created tileview + */ +lv_obj_t * lv_tileview_create(lv_obj_t * parent); + +lv_obj_t * lv_tileview_add_tile(lv_obj_t * tv, uint8_t col_id, uint8_t row_id, lv_dir_t dir); + +void lv_obj_set_tile(lv_obj_t * tv, lv_obj_t * tile_obj, lv_anim_enable_t anim_en); +void lv_obj_set_tile_id(lv_obj_t * tv, uint32_t col_id, uint32_t row_id, lv_anim_enable_t anim_en); + +lv_obj_t * lv_tileview_get_tile_act(lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TILEVIEW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TILEVIEW_H*/ diff --git a/include/liblvgl/extra/widgets/win/lv_win.h b/include/liblvgl/extra/widgets/win/lv_win.h new file mode 100644 index 00000000..2ea907d3 --- /dev/null +++ b/include/liblvgl/extra/widgets/win/lv_win.h @@ -0,0 +1,51 @@ +/** + * @file lv_win.h + * + */ + +#ifndef LV_WIN_H +#define LV_WIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + lv_obj_t obj; +} lv_win_t; + +extern const lv_obj_class_t lv_win_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_obj_t * lv_win_create(lv_obj_t * parent, lv_coord_t header_height); + + +lv_obj_t * lv_win_add_title(lv_obj_t * win, const char * txt); +lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * icon, lv_coord_t btn_w); + +lv_obj_t * lv_win_get_header(lv_obj_t * win); +lv_obj_t * lv_win_get_content(lv_obj_t * win); +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_WIN_H*/ diff --git a/include/liblvgl/font/lv_font.h b/include/liblvgl/font/lv_font.h new file mode 100644 index 00000000..3c0a689e --- /dev/null +++ b/include/liblvgl/font/lv_font.h @@ -0,0 +1,287 @@ +/** + * @file lv_font.h + * + */ + +#ifndef LV_FONT_H +#define LV_FONT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include +#include +#include + +#include "lv_symbol_def.h" +#include "liblvgl/misc/lv_area.h" + +/********************* + * DEFINES + *********************/ + +/* imgfont identifier */ +#define LV_IMGFONT_BPP 9 + +/********************** + * TYPEDEFS + **********************/ + +/*------------------ + * General types + *-----------------*/ + +struct _lv_font_t; +/** Describes the properties of a glyph.*/ +typedef struct { + const struct _lv_font_t * + resolved_font; /**< Pointer to a font where the glyph was actually found after handling fallbacks*/ + uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width.*/ + uint16_t box_w; /**< Width of the glyph's bounding box*/ + uint16_t box_h; /**< Height of the glyph's bounding box*/ + int16_t ofs_x; /**< x offset of the bounding box*/ + int16_t ofs_y; /**< y offset of the bounding box*/ + uint8_t bpp: 4; /**< Bit-per-pixel: 1, 2, 4, 8*/ + uint8_t is_placeholder: 1; /** Glyph is missing. But placeholder will still be displayed */ +} lv_font_glyph_dsc_t; + +/** The bitmaps might be upscaled by 3 to achieve subpixel rendering.*/ +enum { + LV_FONT_SUBPX_NONE, + LV_FONT_SUBPX_HOR, + LV_FONT_SUBPX_VER, + LV_FONT_SUBPX_BOTH, +}; + +typedef uint8_t lv_font_subpx_t; + +/** Describe the properties of a font*/ +typedef struct _lv_font_t { + /** Get a glyph's descriptor from a font*/ + bool (*get_glyph_dsc)(const struct _lv_font_t *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next); + + /** Get a glyph's bitmap from a font*/ + const uint8_t * (*get_glyph_bitmap)(const struct _lv_font_t *, uint32_t); + + /*Pointer to the font in a font pack (must have the same line height)*/ + lv_coord_t line_height; /**< The real line height where any text fits*/ + lv_coord_t base_line; /**< Base line measured from the top of the line_height*/ + uint8_t subpx : 2; /**< An element of `lv_font_subpx_t`*/ + + int8_t underline_position; /**< Distance between the top of the underline and base line (< 0 means below the base line)*/ + int8_t underline_thickness; /**< Thickness of the underline*/ + + const void * dsc; /**< Store implementation specific or run_time data or caching here*/ + const struct _lv_font_t * fallback; /**< Fallback font for missing glyph. Resolved recursively */ +#if LV_USE_USER_DATA + void * user_data; /**< Custom user data for font.*/ +#endif +} lv_font_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Return with the bitmap of a font. + * @param font_p pointer to a font + * @param letter a UNICODE character code + * @return pointer to the bitmap of the letter + */ +const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t letter); + +/** + * Get the descriptor of a glyph + * @param font_p pointer to font + * @param dsc_out store the result descriptor here + * @param letter a UNICODE letter code + * @param letter_next the next letter after `letter`. Used for kerning + * @return true: descriptor is successfully loaded into `dsc_out`. + * false: the letter was not found, no data is loaded to `dsc_out` + */ +bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, + uint32_t letter_next); + +/** + * Get the width of a glyph with kerning + * @param font pointer to a font + * @param letter a UNICODE letter + * @param letter_next the next letter after `letter`. Used for kerning + * @return the width of the glyph + */ +uint16_t lv_font_get_glyph_width(const lv_font_t * font, uint32_t letter, uint32_t letter_next); + +/** + * Get the line height of a font. All characters fit into this height + * @param font_p pointer to a font + * @return the height of a font + */ +static inline lv_coord_t lv_font_get_line_height(const lv_font_t * font_p) +{ + return font_p->line_height; +} + +/********************** + * MACROS + **********************/ + +#define LV_FONT_DECLARE(font_name) extern const lv_font_t font_name; + +#if LV_FONT_MONTSERRAT_8 +LV_FONT_DECLARE(lv_font_montserrat_8) +#endif + +#if LV_FONT_MONTSERRAT_10 +LV_FONT_DECLARE(lv_font_montserrat_10) +#endif + +#if LV_FONT_MONTSERRAT_12 +LV_FONT_DECLARE(lv_font_montserrat_12) +#endif + +#if LV_FONT_MONTSERRAT_14 +LV_FONT_DECLARE(lv_font_montserrat_14) +#endif + +#if LV_FONT_MONTSERRAT_16 +LV_FONT_DECLARE(lv_font_montserrat_16) +#endif + +#if LV_FONT_MONTSERRAT_18 +LV_FONT_DECLARE(lv_font_montserrat_18) +#endif + +#if LV_FONT_MONTSERRAT_20 +LV_FONT_DECLARE(lv_font_montserrat_20) +#endif + +#if LV_FONT_MONTSERRAT_22 +LV_FONT_DECLARE(lv_font_montserrat_22) +#endif + +#if LV_FONT_MONTSERRAT_24 +LV_FONT_DECLARE(lv_font_montserrat_24) +#endif + +#if LV_FONT_MONTSERRAT_26 +LV_FONT_DECLARE(lv_font_montserrat_26) +#endif + +#if LV_FONT_MONTSERRAT_28 +LV_FONT_DECLARE(lv_font_montserrat_28) +#endif + +#if LV_FONT_MONTSERRAT_30 +LV_FONT_DECLARE(lv_font_montserrat_30) +#endif + +#if LV_FONT_MONTSERRAT_32 +LV_FONT_DECLARE(lv_font_montserrat_32) +#endif + +#if LV_FONT_MONTSERRAT_34 +LV_FONT_DECLARE(lv_font_montserrat_34) +#endif + +#if LV_FONT_MONTSERRAT_36 +LV_FONT_DECLARE(lv_font_montserrat_36) +#endif + +#if LV_FONT_MONTSERRAT_38 +LV_FONT_DECLARE(lv_font_montserrat_38) +#endif + +#if LV_FONT_MONTSERRAT_40 +LV_FONT_DECLARE(lv_font_montserrat_40) +#endif + +#if LV_FONT_MONTSERRAT_42 +LV_FONT_DECLARE(lv_font_montserrat_42) +#endif + +#if LV_FONT_MONTSERRAT_44 +LV_FONT_DECLARE(lv_font_montserrat_44) +#endif + +#if LV_FONT_MONTSERRAT_46 +LV_FONT_DECLARE(lv_font_montserrat_46) +#endif + +#if LV_FONT_MONTSERRAT_48 +LV_FONT_DECLARE(lv_font_montserrat_48) +#endif + +#if LV_FONT_MONTSERRAT_12_SUBPX +LV_FONT_DECLARE(lv_font_montserrat_12_subpx) +#endif + +#if LV_FONT_MONTSERRAT_28_COMPRESSED +LV_FONT_DECLARE(lv_font_montserrat_28_compressed) +#endif + +#if LV_FONT_DEJAVU_16_PERSIAN_HEBREW +LV_FONT_DECLARE(lv_font_dejavu_16_persian_hebrew) +#endif + +#if LV_FONT_SIMSUN_16_CJK +LV_FONT_DECLARE(lv_font_simsun_16_cjk) +#endif + +#if LV_FONT_UNSCII_8 +LV_FONT_DECLARE(lv_font_unscii_8) +#endif + +#if LV_FONT_UNSCII_16 +LV_FONT_DECLARE(lv_font_unscii_16) +#endif + +// TODO: reimplement some of the '_LATIN_SUP' fonts as custom fonts + +/*Declare the custom (user defined) fonts*/ +#ifdef LV_FONT_CUSTOM_DECLARE +LV_FONT_CUSTOM_DECLARE +#endif +#if USE_PROS_FONT_DEJAVU_MONO_10 +LV_FONT_DECLARE(pros_font_dejavu_mono_10); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_10_LATIN_SUP +LV_FONT_DECLARE(pros_font_dejavu_mono_10_latin_sup); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_18 +LV_FONT_DECLARE(pros_font_dejavu_mono_18); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_18_LATIN_SUP +LV_FONT_DECLARE(pros_font_dejavu_mono_18_latin_sup); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_30 +LV_FONT_DECLARE(pros_font_dejavu_mono_30); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_30_LATIN_SUP +LV_FONT_DECLARE(pros_font_dejavu_mono_30_latin_sup); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_40 +LV_FONT_DECLARE(pros_font_dejavu_mono_40); +#endif +#if USE_PROS_FONT_DEJAVU_MONO_40_LATIN_SUP +LV_FONT_DECLARE(pros_font_dejavu_mono_40_latin_sup); +#endif + +/** + * Just a wrapper around LV_FONT_DEFAULT because it might be more convenient to use a function in some cases + * @return pointer to LV_FONT_DEFAULT + */ +static inline const lv_font_t * lv_font_default(void) +{ + return LV_FONT_DEFAULT; +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*USE_FONT*/ diff --git a/include/liblvgl/font/lv_font_fmt_txt.h b/include/liblvgl/font/lv_font_fmt_txt.h new file mode 100644 index 00000000..86546a35 --- /dev/null +++ b/include/liblvgl/font/lv_font_fmt_txt.h @@ -0,0 +1,240 @@ +/** + * @file lv_font_fmt_txt.h + * + */ + +#ifndef LV_FONT_FMT_TXT_H +#define LV_FONT_FMT_TXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include +#include +#include "lv_font.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** This describes a glyph.*/ +typedef struct { +#if LV_FONT_FMT_TXT_LARGE == 0 + uint32_t bitmap_index : 20; /**< Start index of the bitmap. A font can be max 1 MB.*/ + uint32_t adv_w : 12; /**< Draw the next glyph after this width. 8.4 format (real_value * 16 is stored).*/ + uint8_t box_w; /**< Width of the glyph's bounding box*/ + uint8_t box_h; /**< Height of the glyph's bounding box*/ + int8_t ofs_x; /**< x offset of the bounding box*/ + int8_t ofs_y; /**< y offset of the bounding box. Measured from the top of the line*/ +#else + uint32_t bitmap_index; /**< Start index of the bitmap. A font can be max 4 GB.*/ + uint32_t adv_w; /**< Draw the next glyph after this width. 28.4 format (real_value * 16 is stored).*/ + uint16_t box_w; /**< Width of the glyph's bounding box*/ + uint16_t box_h; /**< Height of the glyph's bounding box*/ + int16_t ofs_x; /**< x offset of the bounding box*/ + int16_t ofs_y; /**< y offset of the bounding box. Measured from the top of the line*/ +#endif +} lv_font_fmt_txt_glyph_dsc_t; + +/** Format of font character map.*/ +enum { + LV_FONT_FMT_TXT_CMAP_FORMAT0_FULL, + LV_FONT_FMT_TXT_CMAP_SPARSE_FULL, + LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY, + LV_FONT_FMT_TXT_CMAP_SPARSE_TINY, +}; + +typedef uint8_t lv_font_fmt_txt_cmap_type_t; + +/** + * Map codepoints to a `glyph_dsc`s + * Several formats are supported to optimize memory usage + * See https://github.com/lvgl/lv_font_conv/blob/master/doc/font_spec.md + */ +typedef struct { + /** First Unicode character for this range*/ + uint32_t range_start; + + /** Number of Unicode characters related to this range. + * Last Unicode character = range_start + range_length - 1*/ + uint16_t range_length; + + /** First glyph ID (array index of `glyph_dsc`) for this range*/ + uint16_t glyph_id_start; + + /* + According the specification there are 4 formats: + https://github.com/lvgl/lv_font_conv/blob/master/doc/font_spec.md + + For simplicity introduce "relative code point": + rcp = codepoint - range_start + + and a search function: + search a "value" in an "array" and returns the index of "value". + + Format 0 tiny + unicode_list == NULL && glyph_id_ofs_list == NULL + glyph_id = glyph_id_start + rcp + + Format 0 full + unicode_list == NULL && glyph_id_ofs_list != NULL + glyph_id = glyph_id_start + glyph_id_ofs_list[rcp] + + Sparse tiny + unicode_list != NULL && glyph_id_ofs_list == NULL + glyph_id = glyph_id_start + search(unicode_list, rcp) + + Sparse full + unicode_list != NULL && glyph_id_ofs_list != NULL + glyph_id = glyph_id_start + glyph_id_ofs_list[search(unicode_list, rcp)] + */ + + const uint16_t * unicode_list; + + /** if(type == LV_FONT_FMT_TXT_CMAP_FORMAT0_...) it's `uint8_t *` + * if(type == LV_FONT_FMT_TXT_CMAP_SPARSE_...) it's `uint16_t *` + */ + const void * glyph_id_ofs_list; + + /** Length of `unicode_list` and/or `glyph_id_ofs_list`*/ + uint16_t list_length; + + /** Type of this character map*/ + lv_font_fmt_txt_cmap_type_t type; +} lv_font_fmt_txt_cmap_t; + +/** A simple mapping of kern values from pairs*/ +typedef struct { + /*To get a kern value of two code points: + 1. Get the `glyph_id_left` and `glyph_id_right` from `lv_font_fmt_txt_cmap_t + 2. for(i = 0; i < pair_cnt * 2; i += 2) + if(gylph_ids[i] == glyph_id_left && + gylph_ids[i+1] == glyph_id_right) + return values[i / 2]; + */ + const void * glyph_ids; + const int8_t * values; + uint32_t pair_cnt : 30; + uint32_t glyph_ids_size : 2; /*0: `glyph_ids` is stored as `uint8_t`; 1: as `uint16_t`*/ +} lv_font_fmt_txt_kern_pair_t; + +/** More complex but more optimal class based kern value storage*/ +typedef struct { + /*To get a kern value of two code points: + 1. Get the `glyph_id_left` and `glyph_id_right` from `lv_font_fmt_txt_cmap_t + 2. Get the class of the left and right glyphs as `left_class` and `right_class` + left_class = left_class_mapping[glyph_id_left]; + right_class = right_class_mapping[glyph_id_right]; + 3. value = class_pair_values[(left_class-1)*right_class_cnt + (right_class-1)] + */ + + const int8_t * class_pair_values; /*left_class_cnt * right_class_cnt value*/ + const uint8_t * left_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/ + const uint8_t * right_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/ + uint8_t left_class_cnt; + uint8_t right_class_cnt; +} lv_font_fmt_txt_kern_classes_t; + +/** Bitmap formats*/ +typedef enum { + LV_FONT_FMT_TXT_PLAIN = 0, + LV_FONT_FMT_TXT_COMPRESSED = 1, + LV_FONT_FMT_TXT_COMPRESSED_NO_PREFILTER = 1, +} lv_font_fmt_txt_bitmap_format_t; + +typedef struct { + uint32_t last_letter; + uint32_t last_glyph_id; +} lv_font_fmt_txt_glyph_cache_t; + +/*Describe store additional data for fonts*/ +typedef struct { + /*The bitmaps of all glyphs*/ + const uint8_t * glyph_bitmap; + + /*Describe the glyphs*/ + const lv_font_fmt_txt_glyph_dsc_t * glyph_dsc; + + /*Map the glyphs to Unicode characters. + *Array of `lv_font_cmap_fmt_txt_t` variables*/ + const lv_font_fmt_txt_cmap_t * cmaps; + + /** + * Store kerning values. + * Can be `lv_font_fmt_txt_kern_pair_t * or `lv_font_kern_classes_fmt_txt_t *` + * depending on `kern_classes` + */ + const void * kern_dsc; + + /*Scale kern values in 12.4 format*/ + uint16_t kern_scale; + + /*Number of cmap tables*/ + uint16_t cmap_num : 9; + + /*Bit per pixel: 1, 2, 3, 4, 8*/ + uint16_t bpp : 4; + + /*Type of `kern_dsc`*/ + uint16_t kern_classes : 1; + + /* + * storage format of the bitmap + * from `lv_font_fmt_txt_bitmap_format_t` + */ + uint16_t bitmap_format : 2; + + /*Cache the last letter and is glyph id*/ + lv_font_fmt_txt_glyph_cache_t * cache; +} lv_font_fmt_txt_dsc_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Used as `get_glyph_bitmap` callback in LittelvGL's native font format if the font is uncompressed. + * @param font pointer to font + * @param unicode_letter a unicode letter which bitmap should be get + * @return pointer to the bitmap or NULL if not found + */ +const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t letter); + +/** + * Used as `get_glyph_dsc` callback in LittelvGL's native font format if the font is uncompressed. + * @param font_p pointer to font + * @param dsc_out store the result descriptor here + * @param letter a UNICODE letter code + * @return true: descriptor is successfully loaded into `dsc_out`. + * false: the letter was not found, no data is loaded to `dsc_out` + */ +bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, + uint32_t unicode_letter_next); + +/** + * Free the allocated memories. + */ +void _lv_font_clean_up_fmt_txt(void); + +/********************** + * MACROS + **********************/ + +/********************** + * ADD BUILT IN FONTS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FONT_FMT_TXT_H*/ diff --git a/include/liblvgl/font/lv_font_loader.h b/include/liblvgl/font/lv_font_loader.h new file mode 100644 index 00000000..783cb2e7 --- /dev/null +++ b/include/liblvgl/font/lv_font_loader.h @@ -0,0 +1,40 @@ +/** + * @file lv_font_loader.h + * + */ + +#ifndef LV_FONT_LOADER_H +#define LV_FONT_LOADER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_font_t * lv_font_load(const char * fontName); +void lv_font_free(lv_font_t * font); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FONT_LOADER_H*/ diff --git a/include/liblvgl/font/lv_symbol_def.h b/include/liblvgl/font/lv_symbol_def.h new file mode 100644 index 00000000..1055392d --- /dev/null +++ b/include/liblvgl/font/lv_symbol_def.h @@ -0,0 +1,353 @@ +#ifndef LV_SYMBOL_DEF_H +#define LV_SYMBOL_DEF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "liblvgl/lv_conf_internal.h" + +/*------------------------------- + * Symbols from "normal" font + *-----------------------------*/ +#if !defined LV_SYMBOL_BULLET +#define LV_SYMBOL_BULLET "\xE2\x80\xA2" /*20042, 0x2022*/ +#endif + +/*------------------------------- + * Symbols from FontAwesome font + *-----------------------------*/ + +/*In the font converter use this list as range: + 61441, 61448, 61451, 61452, 61453, 61457, 61459, 61461, 61465, 61468, + 61473, 61478, 61479, 61480, 61502, 61507, 61512, 61515, 61516, 61517, + 61521, 61522, 61523, 61524, 61543, 61544, 61550, 61552, 61553, 61556, + 61559, 61560, 61561, 61563, 61587, 61589, 61636, 61637, 61639, 61641, + 61664, 61671, 61674, 61683, 61724, 61732, 61787, 61931, 62016, 62017, + 62018, 62019, 62020, 62087, 62099, 62189, 62212, 62810, 63426, 63650 +*/ + +/* These symbols can be prefined in the lv_conf.h file. + * If they are not predefined, they will use the following values + */ + + +#if !defined LV_SYMBOL_AUDIO +#define LV_SYMBOL_AUDIO "\xEF\x80\x81" /*61441, 0xF001*/ +#endif + +#if !defined LV_SYMBOL_VIDEO +#define LV_SYMBOL_VIDEO "\xEF\x80\x88" /*61448, 0xF008*/ +#endif + +#if !defined LV_SYMBOL_LIST +#define LV_SYMBOL_LIST "\xEF\x80\x8B" /*61451, 0xF00B*/ +#endif + +#if !defined LV_SYMBOL_OK +#define LV_SYMBOL_OK "\xEF\x80\x8C" /*61452, 0xF00C*/ +#endif + +#if !defined LV_SYMBOL_CLOSE +#define LV_SYMBOL_CLOSE "\xEF\x80\x8D" /*61453, 0xF00D*/ +#endif + +#if !defined LV_SYMBOL_POWER +#define LV_SYMBOL_POWER "\xEF\x80\x91" /*61457, 0xF011*/ +#endif + +#if !defined LV_SYMBOL_SETTINGS +#define LV_SYMBOL_SETTINGS "\xEF\x80\x93" /*61459, 0xF013*/ +#endif + +#if !defined LV_SYMBOL_HOME +#define LV_SYMBOL_HOME "\xEF\x80\x95" /*61461, 0xF015*/ +#endif + +#if !defined LV_SYMBOL_DOWNLOAD +#define LV_SYMBOL_DOWNLOAD "\xEF\x80\x99" /*61465, 0xF019*/ +#endif + +#if !defined LV_SYMBOL_DRIVE +#define LV_SYMBOL_DRIVE "\xEF\x80\x9C" /*61468, 0xF01C*/ +#endif + +#if !defined LV_SYMBOL_REFRESH +#define LV_SYMBOL_REFRESH "\xEF\x80\xA1" /*61473, 0xF021*/ +#endif + +#if !defined LV_SYMBOL_MUTE +#define LV_SYMBOL_MUTE "\xEF\x80\xA6" /*61478, 0xF026*/ +#endif + +#if !defined LV_SYMBOL_VOLUME_MID +#define LV_SYMBOL_VOLUME_MID "\xEF\x80\xA7" /*61479, 0xF027*/ +#endif + +#if !defined LV_SYMBOL_VOLUME_MAX +#define LV_SYMBOL_VOLUME_MAX "\xEF\x80\xA8" /*61480, 0xF028*/ +#endif + +#if !defined LV_SYMBOL_IMAGE +#define LV_SYMBOL_IMAGE "\xEF\x80\xBE" /*61502, 0xF03E*/ +#endif + +#if !defined LV_SYMBOL_TINT +#define LV_SYMBOL_TINT "\xEF\x81\x83" /*61507, 0xF043*/ +#endif + +#if !defined LV_SYMBOL_PREV +#define LV_SYMBOL_PREV "\xEF\x81\x88" /*61512, 0xF048*/ +#endif + +#if !defined LV_SYMBOL_PLAY +#define LV_SYMBOL_PLAY "\xEF\x81\x8B" /*61515, 0xF04B*/ +#endif + +#if !defined LV_SYMBOL_PAUSE +#define LV_SYMBOL_PAUSE "\xEF\x81\x8C" /*61516, 0xF04C*/ +#endif + +#if !defined LV_SYMBOL_STOP +#define LV_SYMBOL_STOP "\xEF\x81\x8D" /*61517, 0xF04D*/ +#endif + +#if !defined LV_SYMBOL_NEXT +#define LV_SYMBOL_NEXT "\xEF\x81\x91" /*61521, 0xF051*/ +#endif + +#if !defined LV_SYMBOL_EJECT +#define LV_SYMBOL_EJECT "\xEF\x81\x92" /*61522, 0xF052*/ +#endif + +#if !defined LV_SYMBOL_LEFT +#define LV_SYMBOL_LEFT "\xEF\x81\x93" /*61523, 0xF053*/ +#endif + +#if !defined LV_SYMBOL_RIGHT +#define LV_SYMBOL_RIGHT "\xEF\x81\x94" /*61524, 0xF054*/ +#endif + +#if !defined LV_SYMBOL_PLUS +#define LV_SYMBOL_PLUS "\xEF\x81\xA7" /*61543, 0xF067*/ +#endif + +#if !defined LV_SYMBOL_MINUS +#define LV_SYMBOL_MINUS "\xEF\x81\xA8" /*61544, 0xF068*/ +#endif + +#if !defined LV_SYMBOL_EYE_OPEN +#define LV_SYMBOL_EYE_OPEN "\xEF\x81\xAE" /*61550, 0xF06E*/ +#endif + +#if !defined LV_SYMBOL_EYE_CLOSE +#define LV_SYMBOL_EYE_CLOSE "\xEF\x81\xB0" /*61552, 0xF070*/ +#endif + +#if !defined LV_SYMBOL_WARNING +#define LV_SYMBOL_WARNING "\xEF\x81\xB1" /*61553, 0xF071*/ +#endif + +#if !defined LV_SYMBOL_SHUFFLE +#define LV_SYMBOL_SHUFFLE "\xEF\x81\xB4" /*61556, 0xF074*/ +#endif + +#if !defined LV_SYMBOL_UP +#define LV_SYMBOL_UP "\xEF\x81\xB7" /*61559, 0xF077*/ +#endif + +#if !defined LV_SYMBOL_DOWN +#define LV_SYMBOL_DOWN "\xEF\x81\xB8" /*61560, 0xF078*/ +#endif + +#if !defined LV_SYMBOL_LOOP +#define LV_SYMBOL_LOOP "\xEF\x81\xB9" /*61561, 0xF079*/ +#endif + +#if !defined LV_SYMBOL_DIRECTORY +#define LV_SYMBOL_DIRECTORY "\xEF\x81\xBB" /*61563, 0xF07B*/ +#endif + +#if !defined LV_SYMBOL_UPLOAD +#define LV_SYMBOL_UPLOAD "\xEF\x82\x93" /*61587, 0xF093*/ +#endif + +#if !defined LV_SYMBOL_CALL +#define LV_SYMBOL_CALL "\xEF\x82\x95" /*61589, 0xF095*/ +#endif + +#if !defined LV_SYMBOL_CUT +#define LV_SYMBOL_CUT "\xEF\x83\x84" /*61636, 0xF0C4*/ +#endif + +#if !defined LV_SYMBOL_COPY +#define LV_SYMBOL_COPY "\xEF\x83\x85" /*61637, 0xF0C5*/ +#endif + +#if !defined LV_SYMBOL_SAVE +#define LV_SYMBOL_SAVE "\xEF\x83\x87" /*61639, 0xF0C7*/ +#endif + +#if !defined LV_SYMBOL_BARS +#define LV_SYMBOL_BARS "\xEF\x83\x89" /*61641, 0xF0C9*/ +#endif + +#if !defined LV_SYMBOL_ENVELOPE +#define LV_SYMBOL_ENVELOPE "\xEF\x83\xA0" /*61664, 0xF0E0*/ +#endif + +#if !defined LV_SYMBOL_CHARGE +#define LV_SYMBOL_CHARGE "\xEF\x83\xA7" /*61671, 0xF0E7*/ +#endif + +#if !defined LV_SYMBOL_PASTE +#define LV_SYMBOL_PASTE "\xEF\x83\xAA" /*61674, 0xF0EA*/ +#endif + +#if !defined LV_SYMBOL_BELL +#define LV_SYMBOL_BELL "\xEF\x83\xB3" /*61683, 0xF0F3*/ +#endif + +#if !defined LV_SYMBOL_KEYBOARD +#define LV_SYMBOL_KEYBOARD "\xEF\x84\x9C" /*61724, 0xF11C*/ +#endif + +#if !defined LV_SYMBOL_GPS +#define LV_SYMBOL_GPS "\xEF\x84\xA4" /*61732, 0xF124*/ +#endif + +#if !defined LV_SYMBOL_FILE +#define LV_SYMBOL_FILE "\xEF\x85\x9B" /*61787, 0xF158*/ +#endif + +#if !defined LV_SYMBOL_WIFI +#define LV_SYMBOL_WIFI "\xEF\x87\xAB" /*61931, 0xF1EB*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_FULL +#define LV_SYMBOL_BATTERY_FULL "\xEF\x89\x80" /*62016, 0xF240*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_3 +#define LV_SYMBOL_BATTERY_3 "\xEF\x89\x81" /*62017, 0xF241*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_2 +#define LV_SYMBOL_BATTERY_2 "\xEF\x89\x82" /*62018, 0xF242*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_1 +#define LV_SYMBOL_BATTERY_1 "\xEF\x89\x83" /*62019, 0xF243*/ +#endif + +#if !defined LV_SYMBOL_BATTERY_EMPTY +#define LV_SYMBOL_BATTERY_EMPTY "\xEF\x89\x84" /*62020, 0xF244*/ +#endif + +#if !defined LV_SYMBOL_USB +#define LV_SYMBOL_USB "\xEF\x8a\x87" /*62087, 0xF287*/ +#endif + +#if !defined LV_SYMBOL_BLUETOOTH +#define LV_SYMBOL_BLUETOOTH "\xEF\x8a\x93" /*62099, 0xF293*/ +#endif + +#if !defined LV_SYMBOL_TRASH +#define LV_SYMBOL_TRASH "\xEF\x8B\xAD" /*62189, 0xF2ED*/ +#endif + +#if !defined LV_SYMBOL_EDIT +#define LV_SYMBOL_EDIT "\xEF\x8C\x84" /*62212, 0xF304*/ +#endif + +#if !defined LV_SYMBOL_BACKSPACE +#define LV_SYMBOL_BACKSPACE "\xEF\x95\x9A" /*62810, 0xF55A*/ +#endif + +#if !defined LV_SYMBOL_SD_CARD +#define LV_SYMBOL_SD_CARD "\xEF\x9F\x82" /*63426, 0xF7C2*/ +#endif + +#if !defined LV_SYMBOL_NEW_LINE +#define LV_SYMBOL_NEW_LINE "\xEF\xA2\xA2" /*63650, 0xF8A2*/ +#endif + +#if !defined LV_SYMBOL_DUMMY +/** Invalid symbol at (U+F8FF). If written before a string then `lv_img` will show it as a label*/ +#define LV_SYMBOL_DUMMY "\xEF\xA3\xBF" +#endif + +/* + * The following list is generated using + * cat src/font/lv_symbol_def.h | sed -E -n 's/^#define\s+LV_(SYMBOL_\w+).*".*$/ _LV_STR_\1,/p' + */ +enum { + _LV_STR_SYMBOL_BULLET, + _LV_STR_SYMBOL_AUDIO, + _LV_STR_SYMBOL_VIDEO, + _LV_STR_SYMBOL_LIST, + _LV_STR_SYMBOL_OK, + _LV_STR_SYMBOL_CLOSE, + _LV_STR_SYMBOL_POWER, + _LV_STR_SYMBOL_SETTINGS, + _LV_STR_SYMBOL_HOME, + _LV_STR_SYMBOL_DOWNLOAD, + _LV_STR_SYMBOL_DRIVE, + _LV_STR_SYMBOL_REFRESH, + _LV_STR_SYMBOL_MUTE, + _LV_STR_SYMBOL_VOLUME_MID, + _LV_STR_SYMBOL_VOLUME_MAX, + _LV_STR_SYMBOL_IMAGE, + _LV_STR_SYMBOL_TINT, + _LV_STR_SYMBOL_PREV, + _LV_STR_SYMBOL_PLAY, + _LV_STR_SYMBOL_PAUSE, + _LV_STR_SYMBOL_STOP, + _LV_STR_SYMBOL_NEXT, + _LV_STR_SYMBOL_EJECT, + _LV_STR_SYMBOL_LEFT, + _LV_STR_SYMBOL_RIGHT, + _LV_STR_SYMBOL_PLUS, + _LV_STR_SYMBOL_MINUS, + _LV_STR_SYMBOL_EYE_OPEN, + _LV_STR_SYMBOL_EYE_CLOSE, + _LV_STR_SYMBOL_WARNING, + _LV_STR_SYMBOL_SHUFFLE, + _LV_STR_SYMBOL_UP, + _LV_STR_SYMBOL_DOWN, + _LV_STR_SYMBOL_LOOP, + _LV_STR_SYMBOL_DIRECTORY, + _LV_STR_SYMBOL_UPLOAD, + _LV_STR_SYMBOL_CALL, + _LV_STR_SYMBOL_CUT, + _LV_STR_SYMBOL_COPY, + _LV_STR_SYMBOL_SAVE, + _LV_STR_SYMBOL_BARS, + _LV_STR_SYMBOL_ENVELOPE, + _LV_STR_SYMBOL_CHARGE, + _LV_STR_SYMBOL_PASTE, + _LV_STR_SYMBOL_BELL, + _LV_STR_SYMBOL_KEYBOARD, + _LV_STR_SYMBOL_GPS, + _LV_STR_SYMBOL_FILE, + _LV_STR_SYMBOL_WIFI, + _LV_STR_SYMBOL_BATTERY_FULL, + _LV_STR_SYMBOL_BATTERY_3, + _LV_STR_SYMBOL_BATTERY_2, + _LV_STR_SYMBOL_BATTERY_1, + _LV_STR_SYMBOL_BATTERY_EMPTY, + _LV_STR_SYMBOL_USB, + _LV_STR_SYMBOL_BLUETOOTH, + _LV_STR_SYMBOL_TRASH, + _LV_STR_SYMBOL_EDIT, + _LV_STR_SYMBOL_BACKSPACE, + _LV_STR_SYMBOL_SD_CARD, + _LV_STR_SYMBOL_NEW_LINE, + _LV_STR_SYMBOL_DUMMY, +}; + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_SYMBOL_DEF_H*/ diff --git a/include/liblvgl/hal/lv_hal.h b/include/liblvgl/hal/lv_hal.h new file mode 100644 index 00000000..167da1f4 --- /dev/null +++ b/include/liblvgl/hal/lv_hal.h @@ -0,0 +1,48 @@ +/** + * @file lv_hal.h + * + */ + +#ifndef LV_HAL_H +#define LV_HAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_hal_disp.h" +#include "lv_hal_indev.h" +#include "lv_hal_tick.h" + +/********************* + * DEFINES + *********************/ +/** + * Same as Android's DIP. (Different name is chosen to avoid mistype between LV_DPI and LV_DIP) + * 1 dip is 1 px on a 160 DPI screen + * 1 dip is 2 px on a 320 DPI screen + * https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dip-dp-and-sp + */ +#define _LV_DPX_CALC(dpi, n) ((n) == 0 ? 0 :LV_MAX((( (dpi) * (n) + 80) / 160), 1)) /*+80 for rounding*/ +#define LV_DPX(n) _LV_DPX_CALC(lv_disp_get_dpi(NULL), n) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/liblvgl/hal/lv_hal_disp.h b/include/liblvgl/hal/lv_hal_disp.h new file mode 100644 index 00000000..5b36916c --- /dev/null +++ b/include/liblvgl/hal/lv_hal_disp.h @@ -0,0 +1,371 @@ +/** + * @file lv_hal_disp.h + * + * @description Display Driver HAL interface header file + * + */ + +#ifndef LV_HAL_DISP_H +#define LV_HAL_DISP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include +#include "lv_hal.h" +#include "liblvgl/draw/lv_draw.h" +#include "liblvgl/misc/lv_color.h" +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_ll.h" +#include "liblvgl/misc/lv_timer.h" + +/********************* + * DEFINES + *********************/ +#ifndef LV_INV_BUF_SIZE +#define LV_INV_BUF_SIZE 32 /*Buffer size for invalid areas*/ +#endif + +#ifndef LV_ATTRIBUTE_FLUSH_READY +#define LV_ATTRIBUTE_FLUSH_READY +#endif + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_disp_t; +struct _lv_disp_drv_t; +struct _lv_theme_t; + +/** + * Structure for holding display buffer information. + */ +typedef struct _lv_disp_draw_buf_t { + void * buf1; /**< First display buffer.*/ + void * buf2; /**< Second display buffer.*/ + + /*Internal, used by the library*/ + void * buf_act; + uint32_t size; /*In pixel count*/ + /*1: flushing is in progress. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ + volatile int flushing; + /*1: It was the last chunk to flush. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ + volatile int flushing_last; + volatile uint32_t last_area : 1; /*1: the last area is being rendered*/ + volatile uint32_t last_part : 1; /*1: the last part of the current area is being rendered*/ +} lv_disp_draw_buf_t; + +typedef enum { + LV_DISP_ROT_NONE = 0, + LV_DISP_ROT_90, + LV_DISP_ROT_180, + LV_DISP_ROT_270 +} lv_disp_rot_t; + +/** + * Display Driver structure to be registered by HAL. + * Only its pointer will be saved in `lv_disp_t` so it should be declared as + * `static lv_disp_drv_t my_drv` or allocated dynamically. + */ +typedef struct _lv_disp_drv_t { + + lv_coord_t hor_res; /**< Horizontal resolution.*/ + lv_coord_t ver_res; /**< Vertical resolution.*/ + + lv_coord_t + physical_hor_res; /**< Horizontal resolution of the full / physical display. Set to -1 for fullscreen mode.*/ + lv_coord_t + physical_ver_res; /**< Vertical resolution of the full / physical display. Set to -1 for fullscreen mode.*/ + lv_coord_t + offset_x; /**< Horizontal offset from the full / physical display. Set to 0 for fullscreen mode.*/ + lv_coord_t offset_y; /**< Vertical offset from the full / physical display. Set to 0 for fullscreen mode.*/ + + /** Pointer to a buffer initialized with `lv_disp_draw_buf_init()`. + * LVGL will use this buffer(s) to draw the screens contents*/ + lv_disp_draw_buf_t * draw_buf; + + uint32_t direct_mode : 1; /**< 1: Use screen-sized buffers and draw to absolute coordinates*/ + uint32_t full_refresh : 1; /**< 1: Always make the whole screen redrawn*/ + uint32_t sw_rotate : 1; /**< 1: use software rotation (slower)*/ + uint32_t antialiasing : 1; /**< 1: anti-aliasing is enabled on this display.*/ + uint32_t rotated : 2; /**< 1: turn the display by 90 degree. @warning Does not update coordinates for you!*/ + uint32_t screen_transp : 1; /**Handle if the screen doesn't have a solid (opa == LV_OPA_COVER) background. + * Use only if required because it's slower.*/ + + uint32_t dpi : 10; /** DPI (dot per inch) of the display. Default value is `LV_DPI_DEF`.*/ + + /** MANDATORY: Write the internal buffer (draw_buf) to the display. 'lv_disp_flush_ready()' has to be + * called when finished*/ + void (*flush_cb)(struct _lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); + + /** OPTIONAL: Extend the invalidated areas to match with the display drivers requirements + * E.g. round `y` to, 8, 16 ..) on a monochrome display*/ + void (*rounder_cb)(struct _lv_disp_drv_t * disp_drv, lv_area_t * area); + + /** OPTIONAL: Set a pixel in a buffer according to the special requirements of the display + * Can be used for color format not supported in LittelvGL. E.g. 2 bit -> 4 gray scales + * @note Much slower then drawing with supported color formats.*/ + void (*set_px_cb)(struct _lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, + lv_color_t color, lv_opa_t opa); + + void (*clear_cb)(struct _lv_disp_drv_t * disp_drv, uint8_t * buf, uint32_t size); + + + /** OPTIONAL: Called after every refresh cycle to tell the rendering and flushing time + the + * number of flushed pixels*/ + void (*monitor_cb)(struct _lv_disp_drv_t * disp_drv, uint32_t time, uint32_t px); + + /** OPTIONAL: Called periodically while lvgl waits for operation to be completed. + * For example flushing or GPU + * User can execute very simple tasks here or yield the task*/ + void (*wait_cb)(struct _lv_disp_drv_t * disp_drv); + + /** OPTIONAL: Called when lvgl needs any CPU cache that affects rendering to be cleaned*/ + void (*clean_dcache_cb)(struct _lv_disp_drv_t * disp_drv); + + /** OPTIONAL: called when driver parameters are updated */ + void (*drv_update_cb)(struct _lv_disp_drv_t * disp_drv); + + /** OPTIONAL: called when start rendering */ + void (*render_start_cb)(struct _lv_disp_drv_t * disp_drv); + + /** On CHROMA_KEYED images this color will be transparent. + * `LV_COLOR_CHROMA_KEY` by default. (lv_conf.h)*/ + lv_color_t color_chroma_key; + + lv_draw_ctx_t * draw_ctx; + void (*draw_ctx_init)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); + void (*draw_ctx_deinit)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); + size_t draw_ctx_size; + +#if LV_USE_USER_DATA + void * user_data; /**< Custom display driver user data*/ +#endif + +} lv_disp_drv_t; + +/** + * Display structure. + * @note `lv_disp_drv_t` should be the first member of the structure. + */ +typedef struct _lv_disp_t { + /**< Driver to the display*/ + struct _lv_disp_drv_t * driver; + + /**< A timer which periodically checks the dirty areas and refreshes them*/ + lv_timer_t * refr_timer; + + /**< The theme assigned to the screen*/ + struct _lv_theme_t * theme; + + /** Screens of the display*/ + struct _lv_obj_t ** screens; /**< Array of screen objects.*/ + struct _lv_obj_t * act_scr; /**< Currently active screen on this display*/ + struct _lv_obj_t * prev_scr; /**< Previous screen. Used during screen animations*/ + struct _lv_obj_t * scr_to_load; /**< The screen prepared to load in lv_scr_load_anim*/ + struct _lv_obj_t * top_layer; /**< @see lv_disp_get_layer_top*/ + struct _lv_obj_t * sys_layer; /**< @see lv_disp_get_layer_sys*/ + uint32_t screen_cnt; +uint8_t draw_prev_over_act : + 1; /**< 1: Draw previous screen over active screen*/ +uint8_t del_prev : + 1; /**< 1: Automatically delete the previous screen when the screen load animation is ready*/ + uint8_t rendering_in_progress : 1; /**< 1: The current screen rendering is in progress*/ + + lv_opa_t bg_opa; /**flush` you should use DMA or similar hardware to send + * the image to the display in the background. + * It lets LVGL to render next frame into the other buffer while previous is being + * sent. Set to `NULL` if unused. + * @param size_in_px_cnt size of the `buf1` and `buf2` in pixel count. + */ +void lv_disp_draw_buf_init(lv_disp_draw_buf_t * draw_buf, void * buf1, void * buf2, uint32_t size_in_px_cnt); + +/** + * Register an initialized display driver. + * Automatically set the first display as active. + * @param driver pointer to an initialized 'lv_disp_drv_t' variable. Only its pointer is saved! + * @return pointer to the new display or NULL on error + */ +lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver); + +/** + * Update the driver in run time. + * @param disp pointer to a display. (return value of `lv_disp_drv_register`) + * @param new_drv pointer to the new driver + */ +void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv); + +/** + * Remove a display + * @param disp pointer to display + */ +void lv_disp_remove(lv_disp_t * disp); + +/** + * Set a default display. The new screens will be created on it by default. + * @param disp pointer to a display + */ +void lv_disp_set_default(lv_disp_t * disp); + +/** + * Get the default display + * @return pointer to the default display + */ +lv_disp_t * lv_disp_get_default(void); + +/** + * Get the horizontal resolution of a display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal resolution of the display + */ +lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp); + +/** + * Get the vertical resolution of a display + * @param disp pointer to a display (NULL to use the default display) + * @return the vertical resolution of the display + */ +lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp); + +/** + * Get the full / physical horizontal resolution of a display + * @param disp pointer to a display (NULL to use the default display) + * @return the full / physical horizontal resolution of the display + */ +lv_coord_t lv_disp_get_physical_hor_res(lv_disp_t * disp); + +/** + * Get the full / physical vertical resolution of a display + * @param disp pointer to a display (NULL to use the default display) + * @return the full / physical vertical resolution of the display + */ +lv_coord_t lv_disp_get_physical_ver_res(lv_disp_t * disp); + +/** + * Get the horizontal offset from the full / physical display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal offset from the full / physical display + */ +lv_coord_t lv_disp_get_offset_x(lv_disp_t * disp); + +/** + * Get the vertical offset from the full / physical display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal offset from the full / physical display + */ +lv_coord_t lv_disp_get_offset_y(lv_disp_t * disp); + +/** + * Get if anti-aliasing is enabled for a display or not + * @param disp pointer to a display (NULL to use the default display) + * @return true: anti-aliasing is enabled; false: disabled + */ +bool lv_disp_get_antialiasing(lv_disp_t * disp); + +/** + * Get the DPI of the display + * @param disp pointer to a display (NULL to use the default display) + * @return dpi of the display + */ +lv_coord_t lv_disp_get_dpi(const lv_disp_t * disp); + + +/** + * Set the rotation of this display. + * @param disp pointer to a display (NULL to use the default display) + * @param rotation rotation angle + */ +void lv_disp_set_rotation(lv_disp_t * disp, lv_disp_rot_t rotation); + +/** + * Get the current rotation of this display. + * @param disp pointer to a display (NULL to use the default display) + * @return rotation angle + */ +lv_disp_rot_t lv_disp_get_rotation(lv_disp_t * disp); + +//! @cond Doxygen_Suppress + +/** + * Call in the display driver's `flush_cb` function when the flushing is finished + * @param disp_drv pointer to display driver in `flush_cb` where this function is called + */ +LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv); + +/** + * Tell if it's the last area of the refreshing process. + * Can be called from `flush_cb` to execute some special display refreshing if needed when all areas area flushed. + * @param disp_drv pointer to display driver + * @return true: it's the last area to flush; false: there are other areas too which will be refreshed soon + */ +LV_ATTRIBUTE_FLUSH_READY bool lv_disp_flush_is_last(lv_disp_drv_t * disp_drv); + +//! @endcond + +/** + * Get the next display. + * @param disp pointer to the current display. NULL to initialize. + * @return the next display or NULL if no more. Give the first display when the parameter is NULL + */ +lv_disp_t * lv_disp_get_next(lv_disp_t * disp); + +/** + * Get the internal buffer of a display + * @param disp pointer to a display + * @return pointer to the internal buffers + */ +lv_disp_draw_buf_t * lv_disp_get_draw_buf(lv_disp_t * disp); + +void lv_disp_drv_use_generic_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/liblvgl/hal/lv_hal_indev.h b/include/liblvgl/hal/lv_hal_indev.h new file mode 100644 index 00000000..630d471a --- /dev/null +++ b/include/liblvgl/hal/lv_hal_indev.h @@ -0,0 +1,239 @@ +/** + * @file lv_hal_indev.h + * + * @description Input Device HAL interface layer header file + * + */ + +#ifndef LV_HAL_INDEV_H +#define LV_HAL_INDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include "liblvgl/misc/lv_area.h" +#include "liblvgl/misc/lv_timer.h" + +/********************* + * DEFINES + *********************/ + +/*Drag threshold in pixels*/ +#define LV_INDEV_DEF_SCROLL_LIMIT 10 + +/*Drag throw slow-down in [%]. Greater value -> faster slow-down*/ +#define LV_INDEV_DEF_SCROLL_THROW 10 + +/*Long press time in milliseconds. + *Time to send `LV_EVENT_LONG_PRESSSED`)*/ +#define LV_INDEV_DEF_LONG_PRESS_TIME 400 + +/*Repeated trigger period in long press [ms] + *Time between `LV_EVENT_LONG_PRESSED_REPEAT*/ +#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100 + + +/*Gesture threshold in pixels*/ +#define LV_INDEV_DEF_GESTURE_LIMIT 50 + +/*Gesture min velocity at release before swipe (pixels)*/ +#define LV_INDEV_DEF_GESTURE_MIN_VELOCITY 3 + + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_obj_t; +struct _lv_disp_t; +struct _lv_group_t; +struct _lv_indev_t; +struct _lv_indev_drv_t; + +/** Possible input device types*/ +typedef enum { + LV_INDEV_TYPE_NONE, /**< Uninitialized state*/ + LV_INDEV_TYPE_POINTER, /**< Touch pad, mouse, external button*/ + LV_INDEV_TYPE_KEYPAD, /**< Keypad or keyboard*/ + LV_INDEV_TYPE_BUTTON, /**< External (hardware button) which is assigned to a specific point of the screen*/ + LV_INDEV_TYPE_ENCODER, /**< Encoder with only Left, Right turn and a Button*/ +} lv_indev_type_t; + +/** States for input devices*/ +typedef enum { + LV_INDEV_STATE_RELEASED = 0, + LV_INDEV_STATE_PRESSED +} lv_indev_state_t; + +/** Data structure passed to an input driver to fill*/ +typedef struct { + lv_point_t point; /**< For LV_INDEV_TYPE_POINTER the currently pressed point*/ + uint32_t key; /**< For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ + uint32_t btn_id; /**< For LV_INDEV_TYPE_BUTTON the currently pressed button*/ + int16_t enc_diff; /**< For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/ + + lv_indev_state_t state; /**< LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ + bool continue_reading; /**< If set to true, the read callback is invoked again*/ +} lv_indev_data_t; + +/** Initialized by the user and registered by 'lv_indev_add()'*/ +typedef struct _lv_indev_drv_t { + + /**< Input device type*/ + lv_indev_type_t type; + + /**< Function pointer to read input device data.*/ + void (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data); + + /** Called when an action happened on the input device. + * The second parameter is the event from `lv_event_t`*/ + void (*feedback_cb)(struct _lv_indev_drv_t *, uint8_t); + +#if LV_USE_USER_DATA + void * user_data; +#endif + + /**< Pointer to the assigned display*/ + struct _lv_disp_t * disp; + + /**< Timer to periodically read the input device*/ + lv_timer_t * read_timer; + + /**< Number of pixels to slide before actually drag the object*/ + uint8_t scroll_limit; + + /**< Drag throw slow-down in [%]. Greater value means faster slow-down*/ + uint8_t scroll_throw; + + /**< At least this difference should be between two points to evaluate as gesture*/ + uint8_t gesture_min_velocity; + + /**< At least this difference should be to send a gesture*/ + uint8_t gesture_limit; + + /**< Long press time in milliseconds*/ + uint16_t long_press_time; + + /**< Repeated trigger period in long press [ms]*/ + uint16_t long_press_repeat_time; +} lv_indev_drv_t; + +/** Run time data of input devices + * Internally used by the library, you should not need to touch it. + */ +typedef struct _lv_indev_proc_t { + lv_indev_state_t state; /**< Current state of the input device.*/ + /*Flags*/ + uint8_t long_pr_sent : 1; + uint8_t reset_query : 1; + uint8_t disabled : 1; + uint8_t wait_until_release : 1; + + union { + struct { + /*Pointer and button data*/ + lv_point_t act_point; /**< Current point of input device.*/ + lv_point_t last_point; /**< Last point of input device.*/ + lv_point_t last_raw_point; /**< Last point read from read_cb. */ + lv_point_t vect; /**< Difference between `act_point` and `last_point`.*/ + lv_point_t scroll_sum; /*Count the dragged pixels to check LV_INDEV_DEF_SCROLL_LIMIT*/ + lv_point_t scroll_throw_vect; + lv_point_t scroll_throw_vect_ori; + struct _lv_obj_t * act_obj; /*The object being pressed*/ + struct _lv_obj_t * last_obj; /*The last object which was pressed*/ + struct _lv_obj_t * scroll_obj; /*The object being scrolled*/ + struct _lv_obj_t * last_pressed; /*The lastly pressed object*/ + lv_area_t scroll_area; + + lv_point_t gesture_sum; /*Count the gesture pixels to check LV_INDEV_DEF_GESTURE_LIMIT*/ + /*Flags*/ + lv_dir_t scroll_dir : 4; + lv_dir_t gesture_dir : 4; + uint8_t gesture_sent : 1; + } pointer; + struct { + /*Keypad data*/ + lv_indev_state_t last_state; + uint32_t last_key; + } keypad; + } types; + + uint32_t pr_timestamp; /**< Pressed time stamp*/ + uint32_t longpr_rep_timestamp; /**< Long press repeat time stamp*/ +} _lv_indev_proc_t; + +/** The main input device descriptor with driver, runtime data ('proc') and some additional + * information*/ +typedef struct _lv_indev_t { + struct _lv_indev_drv_t * driver; + _lv_indev_proc_t proc; + struct _lv_obj_t * cursor; /**< Cursor for LV_INPUT_TYPE_POINTER*/ + struct _lv_group_t * group; /**< Keypad destination group*/ + const lv_point_t * btn_points; /**< Array points assigned to the button ()screen will be pressed + here by the buttons*/ +} lv_indev_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize an input device driver with default values. + * It is used to surely have known values in the fields and not memory junk. + * After it you can set the fields. + * @param driver pointer to driver variable to initialize + */ +void lv_indev_drv_init(struct _lv_indev_drv_t * driver); + +/** + * Register an initialized input device driver. + * @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable) + * @return pointer to the new input device or NULL on error + */ +lv_indev_t * lv_indev_drv_register(struct _lv_indev_drv_t * driver); + +/** + * Update the driver in run time. + * @param indev pointer to an input device. (return value of `lv_indev_drv_register`) + * @param new_drv pointer to the new driver + */ +void lv_indev_drv_update(lv_indev_t * indev, struct _lv_indev_drv_t * new_drv); + +/** +* Remove the provided input device. Make sure not to use the provided input device afterwards anymore. +* @param indev pointer to delete +*/ +void lv_indev_delete(lv_indev_t * indev); + +/** + * Get the next input device. + * @param indev pointer to the current input device. NULL to initialize. + * @return the next input device or NULL if there are no more. Provide the first input device when + * the parameter is NULL + */ +lv_indev_t * lv_indev_get_next(lv_indev_t * indev); + +/** + * Read data from an input device. + * @param indev pointer to an input device + * @param data input device will write its data here + */ +void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal_tick.h b/include/liblvgl/hal/lv_hal_tick.h similarity index 84% rename from EZ-Template-Example-Project/include/display/lv_hal/lv_hal_tick.h rename to include/liblvgl/hal/lv_hal_tick.h index c59ed0b2..407fa427 100644 --- a/EZ-Template-Example-Project/include/display/lv_hal/lv_hal_tick.h +++ b/include/liblvgl/hal/lv_hal_tick.h @@ -13,11 +13,8 @@ extern "C" { /********************* * INCLUDES *********************/ -#ifdef LV_CONF_INCLUDE_SIMPLE -#include "lv_conf.h" -#else -#include "display/lv_conf.h" -#endif +#include "liblvgl/lv_conf_internal.h" + #include #include @@ -36,11 +33,17 @@ extern "C" { * GLOBAL PROTOTYPES **********************/ +//! @cond Doxygen_Suppress + +#if !LV_TICK_CUSTOM /** * You have to call this function periodically * @param tick_period the call period of this function in milliseconds */ LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period); +#endif + +//! @endcond /** * Get the elapsed milliseconds since start up @@ -50,7 +53,7 @@ uint32_t lv_tick_get(void); /** * Get the elapsed milliseconds since a previous time stamp - * @param prev_tick a previous time stamp (return value of systick_get() ) + * @param prev_tick a previous time stamp (return value of lv_tick_get() ) * @return the elapsed milliseconds since 'prev_tick' */ uint32_t lv_tick_elaps(uint32_t prev_tick); @@ -60,7 +63,7 @@ uint32_t lv_tick_elaps(uint32_t prev_tick); **********************/ #ifdef __cplusplus -} /* extern "C" */ +} /*extern "C"*/ #endif -#endif /*LV_HAL_TICK_H*/ +#endif /*LV_HAL_TICK_H*/ diff --git a/include/liblvgl/llemu.h b/include/liblvgl/llemu.h new file mode 100644 index 00000000..c3c4e6dc --- /dev/null +++ b/include/liblvgl/llemu.h @@ -0,0 +1,438 @@ +/** + * \file liblvgl/llemu.h + * \ingroup c-llemu + * + * Legacy LCD Emulator + * + * \details This file defines a high-level API for emulating the three-button, UART-based + * VEX LCD, containing a set of functions that facilitate the use of a software- + * emulated version of the classic VEX LCD module. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-llemu LLEMU C API + * @{ + * LLEMU - Legacy Lcd EMUlator + * + * \image html llemu/llemu-3.8.png + * + * LLEMU provides a virtual 40x8 LCD screen with 3 buttons. The user can set the + * text of the screen and set create functions that are run when the buttons are + * pressed. + * + * LLEMU is a emulation of the UART-based LCD screens that were available with + * VEX's cortex product line. + * @} + */ + +#ifndef _LIBLVGL_LLEMU_H_ +#define _LIBLVGL_LLEMU_H_ + +#include +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#include "liblvgl/lvgl.h" +#pragma GCC diagnostic pop + +#ifdef __cplusplus +extern "C" { +namespace pros { +#endif + +typedef void (*lcd_btn_cb_fn_t)(void); + +#define LCD_BTN_LEFT 4 +#define LCD_BTN_CENTER 2 +#define LCD_BTN_RIGHT 1 + +typedef struct lcd_s { + lv_obj_t* frame; + lv_obj_t* screen; + lv_obj_t* lcd_text[8]; + lv_obj_t* btn_container; + lv_obj_t* btns[3]; // < 0 => left; 1 => center; 2 => right + lcd_btn_cb_fn_t callbacks[3]; // < 0 => left; 1 => center; 2 => right + volatile uint8_t touch_bits; // < 4 => left; 2 => center; 1 => right (no + // multitouch support) +} lcd_s_t; + +/** + * \ingroup c-llemu + */ + +/** + * \addtogroup c-llemu + * @{ + */ + +/** + * \enum lcd_text_align_e + * + * @brief Represents how to align the text in the LCD + */ +typedef enum lcd_text_align_e { + /// Align the text to the left side of LCD line + LCD_TEXT_ALIGN_LEFT = 0, + /// Align the text to the center of the LCD line + LCD_TEXT_ALIGN_CENTER = 1, + /// Align the text to the right side of the LCD line + LCD_TEXT_ALIGN_RIGHT = 2 +} text_align_e_t; + +/// @} + +#ifdef __cplusplus + +/** + * \ingroup c-llemu + */ +namespace c { +#endif + +/** + * \ingroup c-llemu + */ + +/** + * \addtogroup c-llemu + * @{ + */ + +/** + * Checks whether the emulated three-button LCD has already been initialized. + * + * \return True if the LCD has been initialized or false if not. + * + * \b Example + * \code + * if (pros::c::lcd_is_initialized()) { + * pros::c::lcd_print("LLEMU!"); + * } + * else { + * printf("Error: LLEMU is not initialized\n"); + * } + * \endcode + */ +bool lcd_is_initialized(void); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * if (pros::c::lcd_initialize()) { + * pros::c::lcd_print("LLEMU!"); + * } + * else { + * printf("Error: LLEMU could not initailize\n"); + * } + * } + * \endcode + */ +bool lcd_initialize(void); + +/** + * Turns 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 lcd_initialize. + * + * 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. + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void disabled() { + * pros::c::lcd_shutdown(); + * } + * \endcode + */ +bool lcd_shutdown(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. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_print(0, "My formatted text: %d!", 2); + * } + * \endcode + */ +bool lcd_print(int16_t line, const char* fmt, ...); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_set_text(0, "My custom LLEMU text!"); + * } + * \endcode + */ +bool lcd_set_text(int16_t line, const char* text); + +/** + * Clears the contents 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] + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_clear(); // Clear the LCD screen + * } + * \endcode + */ +bool lcd_clear(void); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_clear_line(0); // Clear line 0 + * } + * \endcode + */ +bool lcd_clear_line(int16_t line); + +/** + * Registers 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. + * + * 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void left_callback() { + * static int i = 0; + * + * i++; + * pros::c::lcd_print(0, "Left button pressed %i times", i); + * } + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_register_btn0_cb(); + * } + * \endcode + */ +bool lcd_register_btn0_cb(lcd_btn_cb_fn_t cb); + +/** + * Registers 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. + * + * 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void center_callback() { + * static int i = 0; + * + * i++; + * pros::c::lcd_print(0, "Center button pressed %i times", i); + * } + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_register_btn1_cb(); + * } + * \endcode + */ +bool lcd_register_btn1_cb(lcd_btn_cb_fn_t cb); + +/** + * 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. + * + * 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void right_callback() { + * static int i = 0; + * + * i++; + * pros::c::lcd_print(0, "Right button pressed %i times", i); + * } + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_register_btn2_cb(); + * } + * \endcode + */ +bool lcd_register_btn2_cb(lcd_btn_cb_fn_t cb); + +/** + * 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 + */ +uint8_t lcd_read_buttons(void); + +/** + * Changes the alignment of text on the LCD background + * + * \param alignment + * An enum specifying the alignment. Available alignments are: + * TEXT_ALIGN_LEFT + * TEXT_ALIGN_RIGHT + * TEXT_ALIGN_CENTER + * + * \b Example + * \code + * #include "pros/llemu.h" + * + * void initialize() { + * pros::c::lcd_initialize(); + * pros::c::lcd_set_alignment(pros::c::lcd_Text_Align::LEFT); + * pros::c::lcd_print(0, "Left Aligned Text"); + * pros::c::lcd_set_alignment(pros::c::lcd_Text_Align::CENTER); + * pros::c::lcd_print(1, "Center Aligned Text"); + * pros::c::lcd_set_alignment(pros::c::lcd_Text_Align::RIGHT); + * pros::c::lcd_print(2, "Right Aligned Text"); + * } + * \endcode + */ +void lcd_set_text_align(text_align_e_t alignment); + + +///@} + +#ifdef __cplusplus +} // namespace c +} // namespace pros +} // extern "C" +#endif +#endif // _LIBLVGL_LLEMU_H_ diff --git a/include/liblvgl/llemu.hpp b/include/liblvgl/llemu.hpp new file mode 100644 index 00000000..78d31934 --- /dev/null +++ b/include/liblvgl/llemu.hpp @@ -0,0 +1,373 @@ +/** + * \file liblvgl/llemu.hpp + * + * \ingroup cpp-llemu + * + * Legacy LCD Emulator + * + * \details This file defines a high-level API for emulating the three-button, UART-based + * VEX LCD, containing a set of functions that facilitate the use of a software- + * emulated version of the classic VEX LCD module. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-llemu LLEMU C++ API + * @{ + * LLEMU - Legacy Lcd EMUlator + * + * \image html llemu/llemu-3.8.png + * + * LLEMU provides a virtual 40x8 LCD screen with 3 buttons. The user can set the + * text of the screen and set create functions that are run when the buttons are + * pressed. + * + * LLEMU is a emulation of the UART-based LCD screens that were available with + * VEX's cortex product line. + * @} + */ + +#ifndef _LIBLVGL_LLEMU_HPP_ +#define _LIBLVGL_LLEMU_HPP_ + +#include +#include + +#include "liblvgl/llemu.h" + +namespace pros { + +/** + * \ingroup cpp-llemu + */ +namespace lcd { + +/** + * \ingroup cpp-llemu + */ + +/** + * \addtogroup cpp-llemu + * @{ + */ + +/** + * \enum Text_Align + * + * @brief Represents how to align the text in the LCD + */ +enum class Text_Align { + /// Align the text to the left side of LCD line + LEFT = 0, + /// Align the text to the center of the LCD line + CENTER = 1, + /// Align the text to the right side of the LCD line + RIGHT = 2 +}; + +/** + * Checks whether the emulated three-button LCD has already been initialized. + * + * \return True if the LCD has been initialized or false if not. + * + * \b Example + * \code + * if (pros::lcd::is_initialized()) { + * pros::lcd::print("LLEMU!"); + * } + * else { + * printf("Error: LLEMU is not initialized\n"); + * } + * \endcode + */ +bool is_initialized(void); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * if (pros::lcd::initialize()) { + * pros::lcd::print("LLEMU!"); + * } + * else { + * printf("Error: LLEMU could not initailize\n"); + * } + * } + * \endcode + */ +bool initialize(void); + +/** + * Turns 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 lcd_initialize. + * + * 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. + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void disabled() { + * pros::lcd::shutdown(); + * } + * \endcode + */ +bool shutdown(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. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::set_text(0, "My custom LLEMU text!"); + * } + * \endcode + */ +bool set_text(std::int16_t line, std::string text); + +/** + * Clears the contents 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] + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::clear(); // Clear the LCD screen + * } + * \endcode + */ +bool clear(void); + +/** + * 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. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::clear_line(0); // Clear line 0 + * } + * \endcode + */ +bool clear_line(std::int16_t line); + +using lcd_btn_cb_fn_t = void (*)(void); + +/** + * Registers 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t(void (*cb)(void)) + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void left_callback() { + * static int i = 0; + * + * pros::lcd::print(0, "Left button pressed %i times", i); + * i++ + * } + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::register_btn0_cb(); + * } + * \endcode + */ +void register_btn0_cb(lcd_btn_cb_fn_t cb); + +/** + * Registers 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. + * + * \param cb + * A callback function of type lcd_btn_cb_fn_t(void (*cb)(void)) + * + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void center_callback() { + * static int i = 0; + * + * pros::lcd::print(0, "Center button pressed %i times", i); + * i++ + * } + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::register_btn1_cb(); + * } + * \endcode + */ +void register_btn1_cb(lcd_btn_cb_fn_t cb); + +/** + * 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)) + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void right_callback() { + * static int i = 0; + * + * pros::lcd::print(0, "Right button pressed %i times", i); + * i++ + * } + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::register_btn2_cb(); + * } + * \endcode + */ +void register_btn2_cb(lcd_btn_cb_fn_t cb); + +/** + * Sets the alignment to use for subsequent calls that print text to a line. + * + * \param alignment + * An enum specifying the alignment. Available alignments are: + * TEXT_ALIGN_LEFT + * TEXT_ALIGN_RIGHT + * TEXT_ALIGN_CENTER + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::set_alignment(pros::lcd::Text_Align::LEFT); + * pros::lcd::print(0, "Left Aligned Text"); + * pros::lcd::set_alignment(pros::lcd::Text_Align::CENTER); + * pros::lcd::print(1, "Center Aligned Text"); + * pros::lcd::set_alignment(pros::lcd::Text_Align::RIGHT); + * pros::lcd::print(2, "Right Aligned Text"); + * } + * \endcode + */ +void set_text_align(Text_Align alignment); + +/** + * 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 + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * } + * + * void opcontrol() { + * while(true) { + * std::uint8_t state = pros::lcd::read_buttons(); + * pros::lcd::print(0, "%d %d %d", + * (state & LCD_BTN_LEFT) >> 2 + * (state & LCD_BTN_CENTER) >> 1, + * (state & LCD_BTN_RIGHT) >> 0 + * ); + * + * pros::delay(10); + * } + * } + * \endcode + */ +std::uint8_t read_buttons(void); + +///@} + +} // namespace lcd +} // namespace pros + + +#endif // _LIBLVGL_LLEMU_HPP_ diff --git a/include/liblvgl/lv_api_map.h b/include/liblvgl/lv_api_map.h new file mode 100644 index 00000000..c1b9e8d8 --- /dev/null +++ b/include/liblvgl/lv_api_map.h @@ -0,0 +1,88 @@ +/** + * @file lv_api_map.h + * + */ + +#ifndef LV_API_MAP_H +#define LV_API_MAP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lvgl.h" + +/********************* + * DEFINES + *********************/ + +#define LV_NO_TASK_READY LV_NO_TIMER_READY +#define LV_INDEV_STATE_REL LV_INDEV_STATE_RELEASED +#define LV_INDEV_STATE_PR LV_INDEV_STATE_PRESSED +#define LV_OBJ_FLAG_SNAPABLE LV_OBJ_FLAG_SNAPPABLE /*Fixed typo*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_task_handler(void) +{ + return lv_timer_handler(); +} + +/********************** + * MACROS + **********************/ + + +/********************** + * INLINE FUNCTIONS + **********************/ + +/** + * Move the object to the foreground. + * It will look like if it was created as the last child of its parent. + * It also means it can cover any of the siblings. + * @param obj pointer to an object + */ +static inline void lv_obj_move_foreground(lv_obj_t * obj) +{ + lv_obj_t * parent = lv_obj_get_parent(obj); + lv_obj_move_to_index(obj, lv_obj_get_child_cnt(parent) - 1); +} + +/** + * Move the object to the background. + * It will look like if it was created as the first child of its parent. + * It also means any of the siblings can cover the object. + * @param obj pointer to an object + */ +static inline void lv_obj_move_background(lv_obj_t * obj) +{ + lv_obj_move_to_index(obj, 0); +} + + + +/********************** + * DEPRECATED FUNCTIONS + **********************/ + +static inline uint32_t lv_obj_get_child_id(const struct _lv_obj_t * obj) +{ + LV_LOG_WARN("lv_obj_get_child_id(obj) is deprecated, please use lv_obj_get_index(obj)."); + return lv_obj_get_index(obj); +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_API_MAP_H*/ diff --git a/include/liblvgl/lv_conf.h b/include/liblvgl/lv_conf.h new file mode 100644 index 00000000..a7b8bf08 --- /dev/null +++ b/include/liblvgl/lv_conf.h @@ -0,0 +1,777 @@ +/** + * @file lv_conf.h + * Configuration file for v7.11.0 + */ + +/* + * COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER + */ + +#if 1 /*Set it to "1" to enable content*/ + +#ifndef LV_CONF_H +#define LV_CONF_H +/* clang-format off */ + +#include + +/*==================== + Graphical settings + *====================*/ + +/* Maximal horizontal and vertical resolution to support by the library.*/ +#define LV_HOR_RES_MAX (480) +#define LV_VER_RES_MAX (240) + +/* Color depth: + * - 1: 1 byte per pixel + * - 8: RGB332 + * - 16: RGB565 + * - 32: ARGB8888 + */ +#define LV_COLOR_DEPTH 32 + +/* Swap the 2 bytes of RGB565 color. + * Useful if the display has a 8 bit interface (e.g. SPI)*/ +#define LV_COLOR_16_SWAP 0 + +/* 1: Enable screen transparency. + * Useful for OSD or other overlapping GUIs. + * Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/ +#define LV_COLOR_SCREEN_TRANSP 0 + +/*Images pixels with this color will not be drawn (with chroma keying)*/ +#define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/ + +/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ +#define LV_ANTIALIAS 1 + +/* Default display refresh period. + * Can be changed in the display driver (`lv_disp_drv_t`).*/ +#define LV_DISP_DEF_REFR_PERIOD 40 /*[ms]*/ + +/* Dot Per Inch: used to initialize default sizes. + * E.g. a button with width = LV_DPI / 2 -> half inch wide + * (Not so important, you can adjust it to modify default sizes and spaces)*/ +#define LV_DPI 126 /*[px]*/ + +/* The the real width of the display changes some default values: + * default object sizes, layout of examples, etc. + * According to the width of the display (hor. res. / dpi) + * the displays fall in 4 categories. + * The 4th is extra large which has no upper limit so not listed here + * The upper limit of the categories are set below in 0.1 inch unit. + */ +#define LV_DISP_SMALL_LIMIT 30 +#define LV_DISP_MEDIUM_LIMIT 50 +#define LV_DISP_LARGE_LIMIT 70 + +/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */ +typedef int16_t lv_coord_t; + +/* Maximum buffer size to allocate for rotation. Only used if software rotation is enabled. */ +#define LV_DISP_ROT_MAX_BUF (10U * 1024U) + +/*========================= + Memory manager settings + *=========================*/ + +/* LittelvGL's internal memory manager's settings. + * The graphical objects and other related data are stored here. */ + +/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */ +#define LV_MEM_CUSTOM 0 +#if LV_MEM_CUSTOM == 0 +/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ +# define LV_MEM_SIZE (32U * 1024U) + +/* Compiler prefix for a big array declaration */ +# define LV_MEM_ATTR + +/* Set an address for the memory pool instead of allocating it as an array. + * Can be in external SRAM too. */ +# define LV_MEM_ADR 0 + +/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */ +# define LV_MEM_AUTO_DEFRAG 1 +#else /*LV_MEM_CUSTOM*/ +# define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ +# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ +# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ +#endif /*LV_MEM_CUSTOM*/ + +/* Use the standard memcpy and memset instead of LVGL's own functions. + * The standard functions might or might not be faster depending on their implementation. */ +#define LV_MEMCPY_MEMSET_STD 0 + +/* Garbage Collector settings + * Used if lvgl is binded to higher level language and the memory is managed by that language */ +#define LV_ENABLE_GC 0 +#if LV_ENABLE_GC != 0 +# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ +# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/ +# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/ +#endif /* LV_ENABLE_GC */ + +/*======================= + Input device settings + *=======================*/ + +/* Input device default settings. + * Can be changed in the Input device driver (`lv_indev_drv_t`)*/ + +/* Input device read period in milliseconds */ +#define LV_INDEV_DEF_READ_PERIOD 50 + +/* Drag threshold in pixels */ +#define LV_INDEV_DEF_DRAG_LIMIT 10 + +/* Drag throw slow-down in [%]. Greater value -> faster slow-down */ +#define LV_INDEV_DEF_DRAG_THROW 20 + +/* Long press time in milliseconds. + * Time to send `LV_EVENT_LONG_PRESSED`) */ +#define LV_INDEV_DEF_LONG_PRESS_TIME 400 + +/* Repeated trigger period in long press [ms] + * Time between `LV_EVENT_LONG_PRESSED_REPEAT */ +#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100 + +/* Gesture threshold in pixels */ +#define LV_INDEV_DEF_GESTURE_LIMIT 50 + +/* Gesture min velocity at release before swipe (pixels)*/ +#define LV_INDEV_DEF_GESTURE_MIN_VELOCITY 3 + +/*================== + * Feature usage + *==================*/ + +/*1: Enable the Animations */ +#define LV_USE_ANIMATION 1 +#if LV_USE_ANIMATION + +/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_anim_user_data_t; + +#endif + +/* 1: Enable shadow drawing on rectangles*/ +#define LV_USE_SHADOW 1 +#if LV_USE_SHADOW +/* Allow buffering some shadow calculation + * LV_SHADOW_CACHE_SIZE is the max. shadow size to buffer, + * where shadow size is `shadow_width + radius` + * Caching has LV_SHADOW_CACHE_SIZE^2 RAM cost*/ +#define LV_SHADOW_CACHE_SIZE 0 +#endif + +/*1: enable outline drawing on rectangles*/ +#define LV_USE_OUTLINE 1 + +/*1: enable pattern drawing on rectangles*/ +#define LV_USE_PATTERN 1 + +/*1: enable value string drawing on rectangles*/ +#define LV_USE_VALUE_STR 1 + +/* 1: Use other blend modes than normal (`LV_BLEND_MODE_...`)*/ +#define LV_USE_BLEND_MODES 1 + +/* 1: Use the `opa_scale` style property to set the opacity of an object and its children at once*/ +#define LV_USE_OPA_SCALE 1 + +/* 1: Use image zoom and rotation*/ +#define LV_USE_IMG_TRANSFORM 1 + +/* 1: Enable object groups (for keyboard/encoder navigation) */ +#define LV_USE_GROUP 1 +#if LV_USE_GROUP +typedef void * lv_group_user_data_t; +#endif /*LV_USE_GROUP*/ + +/* 1: Enable GPU interface*/ +#define LV_USE_GPU 0 /*Only enables `gpu_fill_cb` and `gpu_blend_cb` in the disp. drv- */ +#define LV_USE_GPU_STM32_DMA2D 0 +/*If enabling LV_USE_GPU_STM32_DMA2D, LV_GPU_DMA2D_CMSIS_INCLUDE must be defined to include path of CMSIS header of target processor +e.g. "stm32f769xx.h" or "stm32f429xx.h" */ +#define LV_GPU_DMA2D_CMSIS_INCLUDE + +/*1: Use PXP for CPU off-load on NXP RTxxx platforms */ +#define LV_USE_GPU_NXP_PXP 0 + +/*1: Add default bare metal and FreeRTOS interrupt handling routines for PXP (lv_gpu_nxp_pxp_osa.c) + * and call lv_gpu_nxp_pxp_init() automatically during lv_init(). Note that symbol FSL_RTOS_FREE_RTOS + * has to be defined in order to use FreeRTOS OSA, otherwise bare-metal implementation is selected. + *0: lv_gpu_nxp_pxp_init() has to be called manually before lv_init() + * */ +#define LV_USE_GPU_NXP_PXP_AUTO_INIT 0 + +/*1: Use VG-Lite for CPU offload on NXP RTxxx platforms */ +#define LV_USE_GPU_NXP_VG_LITE 0 + +/* 1: Enable file system (might be required for images */ +#define LV_USE_FILESYSTEM 1 +#if LV_USE_FILESYSTEM +/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_fs_drv_user_data_t; +#endif + +/*1: Add a `user_data` to drivers and objects*/ +#define LV_USE_USER_DATA 1 + +/*1: Show CPU usage and FPS count in the right bottom corner*/ +#define LV_USE_PERF_MONITOR 0 + +/*1: Use the functions and types from the older API if possible */ +#define LV_USE_API_EXTENSION_V6 1 +#define LV_USE_API_EXTENSION_V7 1 + +/*======================== + * Image decoder and cache + *========================*/ + +/* 1: Enable indexed (palette) images */ +#define LV_IMG_CF_INDEXED 1 + +/* 1: Enable alpha indexed images */ +#define LV_IMG_CF_ALPHA 1 + +/* Default image cache size. Image caching keeps the images opened. + * If only the built-in image formats are used there is no real advantage of caching. + * (I.e. no new image decoder is added) + * With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images. + * However the opened images might consume additional RAM. + * Set it to 0 to disable caching */ +#define LV_IMG_CACHE_DEF_SIZE 1 + +/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_img_decoder_user_data_t; + +/*===================== + * Compiler settings + *====================*/ + +/* For big endian systems set to 1 */ +#define LV_BIG_ENDIAN_SYSTEM 0 + +/* Define a custom attribute to `lv_tick_inc` function */ +#define LV_ATTRIBUTE_TICK_INC + +/* Define a custom attribute to `lv_task_handler` function */ +#define LV_ATTRIBUTE_TASK_HANDLER + +/* Define a custom attribute to `lv_disp_flush_ready` function */ +#define LV_ATTRIBUTE_FLUSH_READY + +/* Required alignment size for buffers */ +#define LV_ATTRIBUTE_MEM_ALIGN_SIZE + +/* With size optimization (-Os) the compiler might not align data to + * 4 or 8 byte boundary. Some HW may need even 32 or 64 bytes. + * This alignment will be explicitly applied where needed. + * LV_ATTRIBUTE_MEM_ALIGN_SIZE should be used to specify required align size. + * E.g. __attribute__((aligned(LV_ATTRIBUTE_MEM_ALIGN_SIZE))) */ +#define LV_ATTRIBUTE_MEM_ALIGN + +/* Attribute to mark large constant arrays for example + * font's bitmaps */ +#define LV_ATTRIBUTE_LARGE_CONST + +/* Prefix performance critical functions to place them into a faster memory (e.g RAM) + * Uses 15-20 kB extra memory */ +#define LV_ATTRIBUTE_FAST_MEM + +/* Export integer constant to binding. + * This macro is used with constants in the form of LV_ that + * should also appear on lvgl binding API such as Micropython + * + * The default value just prevents a GCC warning. + */ +#define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning + +/* Prefix variables that are used in GPU accelerated operations, often these need to be + * placed in RAM sections that are DMA accessible */ +#define LV_ATTRIBUTE_DMA + +/*=================== + * HAL settings + *==================*/ + +/* 1: use a custom tick source. + * It removes the need to manually update the tick with `lv_tick_inc`) */ +#define LV_TICK_CUSTOM 0 +#if LV_TICK_CUSTOM == 1 +#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ +#endif /*LV_TICK_CUSTOM*/ + +typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ +typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/ + +/*================ + * Log settings + *===============*/ + +/*1: Enable the log module*/ +#define LV_USE_LOG 0 +#if LV_USE_LOG +/* How important log should be added: + * LV_LOG_LEVEL_TRACE A lot of logs to give detailed information + * LV_LOG_LEVEL_INFO Log important events + * LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem + * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail + * LV_LOG_LEVEL_NONE Do not log anything + */ +# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN + +/* 1: Print the log with 'printf'; + * 0: user need to register a callback with `lv_log_register_print_cb`*/ +# define LV_LOG_PRINTF 0 +#endif /*LV_USE_LOG*/ + +/*================= + * Debug settings + *================*/ + +/* If Debug is enabled LittelvGL validates the parameters of the functions. + * If an invalid parameter is found an error log message is printed and + * the MCU halts at the error. (`LV_USE_LOG` should be enabled) + * If you are debugging the MCU you can pause + * the debugger to see exactly where the issue is. + * + * The behavior of asserts can be overwritten by redefining them here. + * E.g. #define LV_ASSERT_MEM(p) + */ +#define LV_USE_DEBUG 1 +#if LV_USE_DEBUG + +/*Check if the parameter is NULL. (Quite fast) */ +#define LV_USE_ASSERT_NULL 1 + +/*Checks is the memory is successfully allocated or no. (Quite fast)*/ +#define LV_USE_ASSERT_MEM 1 + +/*Check the integrity of `lv_mem` after critical operations. (Slow)*/ +#define LV_USE_ASSERT_MEM_INTEGRITY 0 + +/* Check the strings. + * Search for NULL, very long strings, invalid characters, and unnatural repetitions. (Slow) + * If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) */ +#define LV_USE_ASSERT_STR 0 + +/* Check NULL, the object's type and existence (e.g. not deleted). (Quite slow) + * If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) */ +#define LV_USE_ASSERT_OBJ 0 + +/*Check if the styles are properly initialized. (Fast)*/ +#define LV_USE_ASSERT_STYLE 0 + +#endif /*LV_USE_DEBUG*/ + +/*================== + * FONT USAGE + *===================*/ + +/* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel. + * The symbols are available via `LV_SYMBOL_...` defines + * More info about fonts: https://docs.lvgl.io/v7/en/html/overview/font.html + * To create a new font go to: https://lvgl.com/ttf-font-to-c-array + */ + +/* Montserrat fonts with bpp = 4 + * https://fonts.google.com/specimen/Montserrat */ +#define LV_FONT_MONTSERRAT_8 0 +#define LV_FONT_MONTSERRAT_10 1 +#define LV_FONT_MONTSERRAT_12 1 +#define LV_FONT_MONTSERRAT_14 1 +#define LV_FONT_MONTSERRAT_16 1 +#define LV_FONT_MONTSERRAT_18 1 +#define LV_FONT_MONTSERRAT_20 1 +#define LV_FONT_MONTSERRAT_22 0 +#define LV_FONT_MONTSERRAT_24 1 +#define LV_FONT_MONTSERRAT_26 0 +#define LV_FONT_MONTSERRAT_28 0 +#define LV_FONT_MONTSERRAT_30 1 +#define LV_FONT_MONTSERRAT_32 0 +#define LV_FONT_MONTSERRAT_34 0 +#define LV_FONT_MONTSERRAT_36 1 +#define LV_FONT_MONTSERRAT_38 0 +#define LV_FONT_MONTSERRAT_40 1 +#define LV_FONT_MONTSERRAT_42 1 +#define LV_FONT_MONTSERRAT_44 0 +#define LV_FONT_MONTSERRAT_46 0 +#define LV_FONT_MONTSERRAT_48 1 + +/* Demonstrate special features */ +#define LV_FONT_MONTSERRAT_12_SUBPX 0 +#define LV_FONT_MONTSERRAT_28_COMPRESSED 0 /*bpp = 3*/ +#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0 /*Hebrew, Arabic, PErisan letters and all their forms*/ +#define LV_FONT_SIMSUN_16_CJK 0 /*1000 most common CJK radicals*/ + +/*Pixel perfect monospace font + * http://pelulamu.net/unscii/ */ +#define LV_FONT_UNSCII_8 1 +#define LV_FONT_UNSCII_16 1 + +/* Optionally declare your custom fonts here. + * You can use these fonts as default font too + * and they will be available globally. E.g. + * #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \ + * LV_FONT_DECLARE(my_font_2) + */ +#define LV_FONT_CUSTOM_DECLARE + +/* Enable it if you have fonts with a lot of characters. + * The limit depends on the font size, font face and bpp + * but with > 10,000 characters if you see issues probably you need to enable it.*/ +#define LV_FONT_FMT_TXT_LARGE 0 + +/* Enables/disables support for compressed fonts. If it's disabled, compressed + * glyphs cannot be processed by the library and won't be rendered. + */ +#define LV_USE_FONT_COMPRESSED 1 + +/* Enable subpixel rendering */ +#define LV_USE_FONT_SUBPX 1 +#if LV_USE_FONT_SUBPX +/* Set the pixel order of the display. + * Important only if "subpx fonts" are used. + * With "normal" font it doesn't matter. + */ +#define LV_FONT_SUBPX_BGR 0 + +/* PROS adds the mono variant of DejaVu sans */ +#define USE_PROS_FONT_DEJAVU_MONO_10 1 + +#define USE_PROS_FONT_DEJAVU_MONO_18 1 // llemu font + +#define USE_PROS_FONT_DEJAVU_MONO_30 0 + +#define USE_PROS_FONT_DEJAVU_MONO_40 0 + +#endif + +/*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_font_user_data_t; + +/*================ + * THEME USAGE + *================*/ + +/*Always enable at least on theme*/ + +/* No theme, you can apply your styles as you need + * No flags. Set LV_THEME_DEFAULT_FLAG 0 */ +#define LV_USE_THEME_EMPTY 1 + +/*Simple to the create your theme based on it + * No flags. Set LV_THEME_DEFAULT_FLAG 0 */ +#define LV_USE_THEME_TEMPLATE 1 + +/* A fast and impressive theme. + * Flags: + * LV_THEME_MATERIAL_FLAG_LIGHT: light theme + * LV_THEME_MATERIAL_FLAG_DARK: dark theme + * LV_THEME_MATERIAL_FLAG_NO_TRANSITION: disable transitions (state change animations) + * LV_THEME_MATERIAL_FLAG_NO_FOCUS: disable indication of focused state) + * */ +#define LV_USE_THEME_MATERIAL 1 + +/* Mono-color theme for monochrome displays. + * If LV_THEME_DEFAULT_COLOR_PRIMARY is LV_COLOR_BLACK the + * texts and borders will be black and the background will be + * white. Else the colors are inverted. + * No flags. Set LV_THEME_DEFAULT_FLAG 0 */ +#define LV_USE_THEME_MONO 1 + +#define LV_THEME_DEFAULT_INCLUDE /*Include a header for the init. function*/ +#define LV_THEME_DEFAULT_INIT lv_theme_material_init +#define LV_THEME_DEFAULT_COLOR_PRIMARY lv_color_hex(0x01a2b1) +#define LV_THEME_DEFAULT_COLOR_SECONDARY lv_color_hex(0x44d1b6) +#define LV_THEME_DEFAULT_FLAG LV_THEME_MATERIAL_FLAG_DARK +#define LV_THEME_DEFAULT_FONT_SMALL &lv_font_montserrat_10 +#define LV_THEME_DEFAULT_FONT_NORMAL &lv_font_montserrat_20 +#define LV_THEME_DEFAULT_FONT_SUBTITLE &lv_font_montserrat_10 +#define LV_THEME_DEFAULT_FONT_TITLE &lv_font_montserrat_30 + +#define CONFIG_LV_THEME_DEFAULT_DARK 1 + +/*================= + * Text settings + *=================*/ + +/* Select a character encoding for strings. + * Your IDE or editor should have the same character encoding + * - LV_TXT_ENC_UTF8 + * - LV_TXT_ENC_ASCII + * */ +#define LV_TXT_ENC LV_TXT_ENC_UTF8 + + /*Can break (wrap) texts on these chars*/ +#define LV_TXT_BREAK_CHARS " ,.;:-_" + +/* If a word is at least this long, will break wherever "prettiest" + * To disable, set to a value <= 0 */ +#define LV_TXT_LINE_BREAK_LONG_LEN 0 + +/* Minimum number of characters in a long word to put on a line before a break. + * Depends on LV_TXT_LINE_BREAK_LONG_LEN. */ +#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 + +/* Minimum number of characters in a long word to put on a line after a break. + * Depends on LV_TXT_LINE_BREAK_LONG_LEN. */ +#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3 + +/* The control character to use for signalling text recoloring. */ +#define LV_TXT_COLOR_CMD "#" + +/* Support bidirectional texts. + * Allows mixing Left-to-Right and Right-to-Left texts. + * The direction will be processed according to the Unicode Bidirectional Algorithm: + * https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/ +#define LV_USE_BIDI 0 +#if LV_USE_BIDI +/* Set the default direction. Supported values: + * `LV_BIDI_DIR_LTR` Left-to-Right + * `LV_BIDI_DIR_RTL` Right-to-Left + * `LV_BIDI_DIR_AUTO` detect texts base direction */ +#define LV_BIDI_BASE_DIR_DEF LV_BIDI_DIR_AUTO +#endif + +/* Enable Arabic/Persian processing + * In these languages characters should be replaced with + * an other form based on their position in the text */ +#define LV_USE_ARABIC_PERSIAN_CHARS 0 + +/*Change the built in (v)snprintf functions*/ +#define LV_SPRINTF_CUSTOM 0 +#if LV_SPRINTF_CUSTOM +# define LV_SPRINTF_INCLUDE +# define lv_snprintf snprintf +# define lv_vsnprintf vsnprintf +#else /*!LV_SPRINTF_CUSTOM*/ +# define LV_SPRINTF_DISABLE_FLOAT 1 +#endif /*LV_SPRINTF_CUSTOM*/ + +/*=================== + * LV_OBJ SETTINGS + *==================*/ + +#if LV_USE_USER_DATA +/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/ +typedef void * lv_obj_user_data_t; +/*Provide a function to free user data*/ +#define LV_USE_USER_DATA_FREE 0 +#if LV_USE_USER_DATA_FREE +# define LV_USER_DATA_FREE_INCLUDE "something.h" /*Header for user data free function*/ +/* Function prototype : void user_data_free(lv_obj_t * obj); */ +# define LV_USER_DATA_FREE (user_data_free) /*Invoking for user data free function*/ +#endif +#endif + +/*1: enable `lv_obj_realign()` based on `lv_obj_align()` parameters*/ +#define LV_USE_OBJ_REALIGN 1 + +/* Enable to make the object clickable on a larger area. + * LV_EXT_CLICK_AREA_OFF or 0: Disable this feature + * LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px) + * LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px) + */ +#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_TINY + +/*================== + * LV OBJ X USAGE + *================*/ +/* + * Documentation of the object types: https://docs.lvgl.com/#Object-types + */ + +/*Arc (dependencies: -)*/ +#define LV_USE_ARC 1 + +/*Bar (dependencies: -)*/ +#define LV_USE_BAR 1 + +/*Button (dependencies: lv_cont*/ +#define LV_USE_BTN 1 + +/*Button matrix (dependencies: -)*/ +#define LV_USE_BTNMATRIX 1 + +/*Calendar (dependencies: -)*/ +#define LV_USE_CALENDAR 1 +#if LV_USE_CALENDAR +# define LV_CALENDAR_WEEK_STARTS_MONDAY 0 +#endif + +/*Canvas (dependencies: lv_img)*/ +#define LV_USE_CANVAS 1 + +/*Check box (dependencies: lv_btn, lv_label)*/ +#define LV_USE_CHECKBOX 1 + +/*Chart (dependencies: -)*/ +#define LV_USE_CHART 1 +#if LV_USE_CHART +# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 256 +#endif + +/*Container (dependencies: -*/ +#define LV_USE_CONT 1 + +/*Color picker (dependencies: -*/ +#define LV_USE_CPICKER 1 + +/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ +#define LV_USE_DROPDOWN 1 +#if LV_USE_DROPDOWN != 0 +/*Open and close default animation time [ms] (0: no animation)*/ +# define LV_DROPDOWN_DEF_ANIM_TIME 200 +#endif + +/*Gauge (dependencies:lv_bar, lv_linemeter)*/ +#define LV_USE_GAUGE 1 + +/*Image (dependencies: lv_label*/ +#define LV_USE_IMG 1 + +/*Image Button (dependencies: lv_btn*/ +#define LV_USE_IMGBTN 1 +#if LV_USE_IMGBTN +/*1: The imgbtn requires left, mid and right parts and the width can be set freely*/ +# define LV_IMGBTN_TILED 0 +#endif + +/*Keyboard (dependencies: lv_btnm)*/ +#define LV_USE_KEYBOARD 1 + +/*Label (dependencies: -*/ +#define LV_USE_LABEL 1 +#if LV_USE_LABEL != 0 +/*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/ +# define LV_LABEL_DEF_SCROLL_SPEED 25 + +/* Waiting period at beginning/end of animation cycle */ +# define LV_LABEL_WAIT_CHAR_COUNT 3 + +/*Enable selecting text of the label */ +# define LV_LABEL_TEXT_SEL 0 + +/*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/ +# define LV_LABEL_LONG_TXT_HINT 0 +#endif + +/*LED (dependencies: -)*/ +#define LV_USE_LED 1 +#if LV_USE_LED +# define LV_LED_BRIGHT_MIN 120 /*Minimal brightness*/ +# define LV_LED_BRIGHT_MAX 255 /*Maximal brightness*/ +#endif + +/*Line (dependencies: -*/ +#define LV_USE_LINE 1 + +/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ +#define LV_USE_LIST 1 +#if LV_USE_LIST != 0 +/*Default animation time of focusing to a list element [ms] (0: no animation) */ +# define LV_LIST_DEF_ANIM_TIME 100 +#endif + +/*Line meter (dependencies: *;)*/ +#define LV_USE_LINEMETER 1 +#if LV_USE_LINEMETER +/* Draw line more precisely at cost of performance. + * Useful if there are lot of lines any minor are visible + * 0: No extra precision + * 1: Some extra precision + * 2: Best precision + */ +# define LV_LINEMETER_PRECISE 1 +#endif + +/*Mask (dependencies: -)*/ +#define LV_USE_OBJMASK 1 + +/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ +#define LV_USE_MSGBOX 1 + +/*Page (dependencies: lv_cont)*/ +#define LV_USE_PAGE 1 +#if LV_USE_PAGE != 0 +/*Focus default animation time [ms] (0: no animation)*/ +# define LV_PAGE_DEF_ANIM_TIME 400 +#endif + +/*Preload (dependencies: lv_arc, lv_anim)*/ +#define LV_USE_SPINNER 1 +#if LV_USE_SPINNER != 0 +# define LV_SPINNER_DEF_ARC_LENGTH 60 /*[deg]*/ +# define LV_SPINNER_DEF_SPIN_TIME 1000 /*[ms]*/ +# define LV_SPINNER_DEF_ANIM LV_SPINNER_TYPE_SPINNING_ARC +#endif + +/*Roller (dependencies: lv_ddlist)*/ +#define LV_USE_ROLLER 1 +#if LV_USE_ROLLER != 0 +/*Focus animation time [ms] (0: no animation)*/ +# define LV_ROLLER_DEF_ANIM_TIME 200 + +/*Number of extra "pages" when the roller is infinite*/ +# define LV_ROLLER_INF_PAGES 7 +#endif + +/*Slider (dependencies: lv_bar)*/ +#define LV_USE_SLIDER 1 + +/*Spinbox (dependencies: lv_ta)*/ +#define LV_USE_SPINBOX 1 + +/*Switch (dependencies: lv_slider)*/ +#define LV_USE_SWITCH 1 + +/*Text area (dependencies: lv_label, lv_page)*/ +#define LV_USE_TEXTAREA 1 +#if LV_USE_TEXTAREA != 0 +# define LV_TEXTAREA_DEF_CURSOR_BLINK_TIME 400 /*ms*/ +# define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/ +#endif + +/*Table (dependencies: lv_label)*/ +#define LV_USE_TABLE 1 +#if LV_USE_TABLE +# define LV_TABLE_COL_MAX 12 +# define LV_TABLE_CELL_STYLE_CNT 4 +#endif + +/*Tab (dependencies: lv_page, lv_btnm)*/ +#define LV_USE_TABVIEW 1 +# if LV_USE_TABVIEW != 0 +/*Time of slide animation [ms] (0: no animation)*/ +# define LV_TABVIEW_DEF_ANIM_TIME 300 +#endif + +/*Tileview (dependencies: lv_page) */ +#define LV_USE_TILEVIEW 1 +#if LV_USE_TILEVIEW +/*Time of slide animation [ms] (0: no animation)*/ +# define LV_TILEVIEW_DEF_ANIM_TIME 300 +#endif + +/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ +#define LV_USE_WIN 1 + +/*================== + * Non-user section + *==================*/ + +#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ +# define _CRT_SECURE_NO_WARNINGS +#endif + +/*--END OF LV_CONF_H--*/ + +#endif /*LV_CONF_H*/ + +#endif /*End of "Content enable"*/ diff --git a/include/display/lv_conf.h b/include/liblvgl/lv_conf.old.h similarity index 98% rename from include/display/lv_conf.h rename to include/liblvgl/lv_conf.old.h index 0b1a1626..16deedde 100644 --- a/include/display/lv_conf.h +++ b/include/liblvgl/lv_conf.old.h @@ -13,7 +13,7 @@ /* Memory size which will be used by the library * to store the graphical objects and other data */ #define LV_MEM_CUSTOM \ - 1 /*1: use custom malloc/free, 0: use the built-in \ + 0 /*1: use custom malloc/free, 0: use the built-in \ lv_mem_alloc/lv_mem_free*/ #if LV_MEM_CUSTOM == 0 #define LV_MEM_SIZE \ @@ -22,7 +22,7 @@ #define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/ #else /*LV_MEM_CUSTOM*/ #define LV_MEM_CUSTOM_INCLUDE \ - "kapi.h" /*Header for the dynamic memory function*/ + /*Header for the dynamic memory function*/ #define LV_MEM_CUSTOM_ALLOC kmalloc /*Wrapper to malloc*/ #define LV_MEM_CUSTOM_FREE kfree /*Wrapper to free*/ #endif /*LV_MEM_CUSTOM*/ @@ -337,5 +337,5 @@ #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) # define _CRT_SECURE_NO_WARNINGS #endif -#include "display/lv_conf_checker.h" +#include "liblvgl/lv_conf_checker.h" #endif /*LV_CONF_H*/ diff --git a/include/display/lv_conf_checker.h b/include/liblvgl/lv_conf_checker.h similarity index 100% rename from include/display/lv_conf_checker.h rename to include/liblvgl/lv_conf_checker.h diff --git a/include/liblvgl/lv_conf_internal.h b/include/liblvgl/lv_conf_internal.h new file mode 100644 index 00000000..97807fe3 --- /dev/null +++ b/include/liblvgl/lv_conf_internal.h @@ -0,0 +1,2469 @@ +/** + * GENERATED FILE, DO NOT EDIT IT! + * @file lv_conf_internal.h + * Make sure all the defines of lv_conf.h have a default value +**/ + +#ifndef LV_CONF_INTERNAL_H +#define LV_CONF_INTERNAL_H +/* clang-format off */ + +#include + +/* Handle special Kconfig options */ +#ifndef LV_KCONFIG_IGNORE + #include "lv_conf_kconfig.h" + #ifdef CONFIG_LV_CONF_SKIP + #define LV_CONF_SKIP + #endif +#endif + +/*If "lv_conf.h" is available from here try to use it later.*/ +#ifdef __has_include + #if __has_include("lv_conf.h") + #ifndef LV_CONF_INCLUDE_SIMPLE + #define LV_CONF_INCLUDE_SIMPLE + #endif + #endif +#endif + +/*If lv_conf.h is not skipped include it*/ +#ifndef LV_CONF_SKIP + #ifdef LV_CONF_PATH /*If there is a path defined for lv_conf.h use it*/ + #define __LV_TO_STR_AUX(x) #x + #define __LV_TO_STR(x) __LV_TO_STR_AUX(x) + #include __LV_TO_STR(LV_CONF_PATH) + #undef __LV_TO_STR_AUX + #undef __LV_TO_STR + #elif defined(LV_CONF_INCLUDE_SIMPLE) /*Or simply include lv_conf.h is enabled*/ + #include "lv_conf.h" + #else + #include "../../lv_conf.h" /*Else assume lv_conf.h is next to the lvgl folder*/ + #endif + #if !defined(LV_CONF_H) && !defined(LV_CONF_SUPPRESS_DEFINE_CHECK) + /* #include will sometimes silently fail when __has_include is used */ + /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80753 */ + #pragma message("Possible failure to include lv_conf.h, please read the comment in this file if you get errors") + #endif +#endif + +#ifdef CONFIG_LV_COLOR_DEPTH + #define _LV_KCONFIG_PRESENT +#endif + +/*---------------------------------- + * Start parsing lv_conf_template.h + -----------------------------------*/ + +#include + +/*==================== + COLOR SETTINGS + *====================*/ + +/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/ +#ifndef LV_COLOR_DEPTH + #ifdef CONFIG_LV_COLOR_DEPTH + #define LV_COLOR_DEPTH CONFIG_LV_COLOR_DEPTH + #else + #define LV_COLOR_DEPTH 16 + #endif +#endif + +/*Swap the 2 bytes of RGB565 color. Useful if the display has an 8-bit interface (e.g. SPI)*/ +#ifndef LV_COLOR_16_SWAP + #ifdef CONFIG_LV_COLOR_16_SWAP + #define LV_COLOR_16_SWAP CONFIG_LV_COLOR_16_SWAP + #else + #define LV_COLOR_16_SWAP 0 + #endif +#endif + +/*Enable features to draw on transparent background. + *It's required if opa, and transform_* style properties are used. + *Can be also used if the UI is above another layer, e.g. an OSD menu or video player.*/ +#ifndef LV_COLOR_SCREEN_TRANSP + #ifdef CONFIG_LV_COLOR_SCREEN_TRANSP + #define LV_COLOR_SCREEN_TRANSP CONFIG_LV_COLOR_SCREEN_TRANSP + #else + #define LV_COLOR_SCREEN_TRANSP 0 + #endif +#endif + +/* Adjust color mix functions rounding. GPUs might calculate color mix (blending) differently. + * 0: round down, 64: round up from x.75, 128: round up from half, 192: round up from x.25, 254: round up */ +#ifndef LV_COLOR_MIX_ROUND_OFS + #ifdef CONFIG_LV_COLOR_MIX_ROUND_OFS + #define LV_COLOR_MIX_ROUND_OFS CONFIG_LV_COLOR_MIX_ROUND_OFS + #else + #define LV_COLOR_MIX_ROUND_OFS 0 + #endif +#endif + +/*Images pixels with this color will not be drawn if they are chroma keyed)*/ +#ifndef LV_COLOR_CHROMA_KEY + #ifdef CONFIG_LV_COLOR_CHROMA_KEY + #define LV_COLOR_CHROMA_KEY CONFIG_LV_COLOR_CHROMA_KEY + #else + #define LV_COLOR_CHROMA_KEY lv_color_hex(0x00ff00) /*pure green*/ + #endif +#endif + +/*========================= + MEMORY SETTINGS + *=========================*/ + +/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/ +#ifndef LV_MEM_CUSTOM + #ifdef CONFIG_LV_MEM_CUSTOM + #define LV_MEM_CUSTOM CONFIG_LV_MEM_CUSTOM + #else + #define LV_MEM_CUSTOM 0 + #endif +#endif +#if LV_MEM_CUSTOM == 0 + /*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/ + #ifndef LV_MEM_SIZE + #ifdef CONFIG_LV_MEM_SIZE + #define LV_MEM_SIZE CONFIG_LV_MEM_SIZE + #else + #define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/ + #endif + #endif + + /*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/ + #ifndef LV_MEM_ADR + #ifdef CONFIG_LV_MEM_ADR + #define LV_MEM_ADR CONFIG_LV_MEM_ADR + #else + #define LV_MEM_ADR 0 /*0: unused*/ + #endif + #endif + /*Instead of an address give a memory allocator that will be called to get a memory pool for LVGL. E.g. my_malloc*/ + #if LV_MEM_ADR == 0 + #ifndef LV_MEM_POOL_INCLUDE + #ifdef CONFIG_LV_MEM_POOL_INCLUDE + #define LV_MEM_POOL_INCLUDE CONFIG_LV_MEM_POOL_INCLUDE + #else + #undef LV_MEM_POOL_INCLUDE + #endif + #endif + #ifndef LV_MEM_POOL_ALLOC + #ifdef CONFIG_LV_MEM_POOL_ALLOC + #define LV_MEM_POOL_ALLOC CONFIG_LV_MEM_POOL_ALLOC + #else + #undef LV_MEM_POOL_ALLOC + #endif + #endif + #endif + +#else /*LV_MEM_CUSTOM*/ + #ifndef LV_MEM_CUSTOM_INCLUDE + #ifdef CONFIG_LV_MEM_CUSTOM_INCLUDE + #define LV_MEM_CUSTOM_INCLUDE CONFIG_LV_MEM_CUSTOM_INCLUDE + #else + #define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ + #endif + #endif + #ifndef LV_MEM_CUSTOM_ALLOC + #ifdef CONFIG_LV_MEM_CUSTOM_ALLOC + #define LV_MEM_CUSTOM_ALLOC CONFIG_LV_MEM_CUSTOM_ALLOC + #else + #define LV_MEM_CUSTOM_ALLOC malloc + #endif + #endif + #ifndef LV_MEM_CUSTOM_FREE + #ifdef CONFIG_LV_MEM_CUSTOM_FREE + #define LV_MEM_CUSTOM_FREE CONFIG_LV_MEM_CUSTOM_FREE + #else + #define LV_MEM_CUSTOM_FREE free + #endif + #endif + #ifndef LV_MEM_CUSTOM_REALLOC + #ifdef CONFIG_LV_MEM_CUSTOM_REALLOC + #define LV_MEM_CUSTOM_REALLOC CONFIG_LV_MEM_CUSTOM_REALLOC + #else + #define LV_MEM_CUSTOM_REALLOC realloc + #endif + #endif +#endif /*LV_MEM_CUSTOM*/ + +/*Number of the intermediate memory buffer used during rendering and other internal processing mechanisms. + *You will see an error log message if there wasn't enough buffers. */ +#ifndef LV_MEM_BUF_MAX_NUM + #ifdef CONFIG_LV_MEM_BUF_MAX_NUM + #define LV_MEM_BUF_MAX_NUM CONFIG_LV_MEM_BUF_MAX_NUM + #else + #define LV_MEM_BUF_MAX_NUM 16 + #endif +#endif + +/*Use the standard `memcpy` and `memset` instead of LVGL's own functions. (Might or might not be faster).*/ +#ifndef LV_MEMCPY_MEMSET_STD + #ifdef CONFIG_LV_MEMCPY_MEMSET_STD + #define LV_MEMCPY_MEMSET_STD CONFIG_LV_MEMCPY_MEMSET_STD + #else + #define LV_MEMCPY_MEMSET_STD 0 + #endif +#endif + +/*==================== + HAL SETTINGS + *====================*/ + +/*Default display refresh period. LVG will redraw changed areas with this period time*/ +#ifndef LV_DISP_DEF_REFR_PERIOD + #ifdef CONFIG_LV_DISP_DEF_REFR_PERIOD + #define LV_DISP_DEF_REFR_PERIOD CONFIG_LV_DISP_DEF_REFR_PERIOD + #else + #define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/ + #endif +#endif + +/*Input device read period in milliseconds*/ +#ifndef LV_INDEV_DEF_READ_PERIOD + #ifdef CONFIG_LV_INDEV_DEF_READ_PERIOD + #define LV_INDEV_DEF_READ_PERIOD CONFIG_LV_INDEV_DEF_READ_PERIOD + #else + #define LV_INDEV_DEF_READ_PERIOD 30 /*[ms]*/ + #endif +#endif + +/*Use a custom tick source that tells the elapsed time in milliseconds. + *It removes the need to manually update the tick with `lv_tick_inc()`)*/ +#ifndef LV_TICK_CUSTOM + #ifdef CONFIG_LV_TICK_CUSTOM + #define LV_TICK_CUSTOM CONFIG_LV_TICK_CUSTOM + #else + #define LV_TICK_CUSTOM 0 + #endif +#endif +#if LV_TICK_CUSTOM + #ifndef LV_TICK_CUSTOM_INCLUDE + #ifdef CONFIG_LV_TICK_CUSTOM_INCLUDE + #define LV_TICK_CUSTOM_INCLUDE CONFIG_LV_TICK_CUSTOM_INCLUDE + #else + #define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/ + #endif + #endif + #ifndef LV_TICK_CUSTOM_SYS_TIME_EXPR + #ifdef CONFIG_LV_TICK_CUSTOM_SYS_TIME_EXPR + #define LV_TICK_CUSTOM_SYS_TIME_EXPR CONFIG_LV_TICK_CUSTOM_SYS_TIME_EXPR + #else + #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ + #endif + #endif +#endif /*LV_TICK_CUSTOM*/ + +/*Default Dot Per Inch. Used to initialize default sizes such as widgets sized, style paddings. + *(Not so important, you can adjust it to modify default sizes and spaces)*/ +#ifndef LV_DPI_DEF + #ifdef CONFIG_LV_DPI_DEF + #define LV_DPI_DEF CONFIG_LV_DPI_DEF + #else + #define LV_DPI_DEF 130 /*[px/inch]*/ + #endif +#endif + +/*======================= + * FEATURE CONFIGURATION + *=======================*/ + +/*------------- + * Drawing + *-----------*/ + +/*Enable complex draw engine. + *Required to draw shadow, gradient, rounded corners, circles, arc, skew lines, image transformations or any masks*/ +#ifndef LV_DRAW_COMPLEX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_DRAW_COMPLEX + #define LV_DRAW_COMPLEX CONFIG_LV_DRAW_COMPLEX + #else + #define LV_DRAW_COMPLEX 0 + #endif + #else + #define LV_DRAW_COMPLEX 1 + #endif +#endif +#if LV_DRAW_COMPLEX != 0 + + /*Allow buffering some shadow calculation. + *LV_SHADOW_CACHE_SIZE is the max. shadow size to buffer, where shadow size is `shadow_width + radius` + *Caching has LV_SHADOW_CACHE_SIZE^2 RAM cost*/ + #ifndef LV_SHADOW_CACHE_SIZE + #ifdef CONFIG_LV_SHADOW_CACHE_SIZE + #define LV_SHADOW_CACHE_SIZE CONFIG_LV_SHADOW_CACHE_SIZE + #else + #define LV_SHADOW_CACHE_SIZE 0 + #endif + #endif + + /* Set number of maximally cached circle data. + * The circumference of 1/4 circle are saved for anti-aliasing + * radius * 4 bytes are used per circle (the most often used radiuses are saved) + * 0: to disable caching */ + #ifndef LV_CIRCLE_CACHE_SIZE + #ifdef CONFIG_LV_CIRCLE_CACHE_SIZE + #define LV_CIRCLE_CACHE_SIZE CONFIG_LV_CIRCLE_CACHE_SIZE + #else + #define LV_CIRCLE_CACHE_SIZE 4 + #endif + #endif +#endif /*LV_DRAW_COMPLEX*/ + +/** + * "Simple layers" are used when a widget has `style_opa < 255` to buffer the widget into a layer + * and blend it as an image with the given opacity. + * Note that `bg_opa`, `text_opa` etc don't require buffering into layer) + * The widget can be buffered in smaller chunks to avoid using large buffers. + * + * - LV_LAYER_SIMPLE_BUF_SIZE: [bytes] the optimal target buffer size. LVGL will try to allocate it + * - LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE: [bytes] used if `LV_LAYER_SIMPLE_BUF_SIZE` couldn't be allocated. + * + * Both buffer sizes are in bytes. + * "Transformed layers" (where transform_angle/zoom properties are used) use larger buffers + * and can't be drawn in chunks. So these settings affects only widgets with opacity. + */ +#ifndef LV_LAYER_SIMPLE_BUF_SIZE + #ifdef CONFIG_LV_LAYER_SIMPLE_BUF_SIZE + #define LV_LAYER_SIMPLE_BUF_SIZE CONFIG_LV_LAYER_SIMPLE_BUF_SIZE + #else + #define LV_LAYER_SIMPLE_BUF_SIZE (24 * 1024) + #endif +#endif +#ifndef LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE + #ifdef CONFIG_LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE + #define LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE CONFIG_LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE + #else + #define LV_LAYER_SIMPLE_FALLBACK_BUF_SIZE (3 * 1024) + #endif +#endif + +/*Default image cache size. Image caching keeps the images opened. + *If only the built-in image formats are used there is no real advantage of caching. (I.e. if no new image decoder is added) + *With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images. + *However the opened images might consume additional RAM. + *0: to disable caching*/ +#ifndef LV_IMG_CACHE_DEF_SIZE + #ifdef CONFIG_LV_IMG_CACHE_DEF_SIZE + #define LV_IMG_CACHE_DEF_SIZE CONFIG_LV_IMG_CACHE_DEF_SIZE + #else + #define LV_IMG_CACHE_DEF_SIZE 0 + #endif +#endif + +/*Number of stops allowed per gradient. Increase this to allow more stops. + *This adds (sizeof(lv_color_t) + 1) bytes per additional stop*/ +#ifndef LV_GRADIENT_MAX_STOPS + #ifdef CONFIG_LV_GRADIENT_MAX_STOPS + #define LV_GRADIENT_MAX_STOPS CONFIG_LV_GRADIENT_MAX_STOPS + #else + #define LV_GRADIENT_MAX_STOPS 2 + #endif +#endif + +/*Default gradient buffer size. + *When LVGL calculates the gradient "maps" it can save them into a cache to avoid calculating them again. + *LV_GRAD_CACHE_DEF_SIZE sets the size of this cache in bytes. + *If the cache is too small the map will be allocated only while it's required for the drawing. + *0 mean no caching.*/ +#ifndef LV_GRAD_CACHE_DEF_SIZE + #ifdef CONFIG_LV_GRAD_CACHE_DEF_SIZE + #define LV_GRAD_CACHE_DEF_SIZE CONFIG_LV_GRAD_CACHE_DEF_SIZE + #else + #define LV_GRAD_CACHE_DEF_SIZE 0 + #endif +#endif + +/*Allow dithering the gradients (to achieve visual smooth color gradients on limited color depth display) + *LV_DITHER_GRADIENT implies allocating one or two more lines of the object's rendering surface + *The increase in memory consumption is (32 bits * object width) plus 24 bits * object width if using error diffusion */ +#ifndef LV_DITHER_GRADIENT + #ifdef CONFIG_LV_DITHER_GRADIENT + #define LV_DITHER_GRADIENT CONFIG_LV_DITHER_GRADIENT + #else + #define LV_DITHER_GRADIENT 0 + #endif +#endif +#if LV_DITHER_GRADIENT + /*Add support for error diffusion dithering. + *Error diffusion dithering gets a much better visual result, but implies more CPU consumption and memory when drawing. + *The increase in memory consumption is (24 bits * object's width)*/ + #ifndef LV_DITHER_ERROR_DIFFUSION + #ifdef CONFIG_LV_DITHER_ERROR_DIFFUSION + #define LV_DITHER_ERROR_DIFFUSION CONFIG_LV_DITHER_ERROR_DIFFUSION + #else + #define LV_DITHER_ERROR_DIFFUSION 0 + #endif + #endif +#endif + +/*Maximum buffer size to allocate for rotation. + *Only used if software rotation is enabled in the display driver.*/ +#ifndef LV_DISP_ROT_MAX_BUF + #ifdef CONFIG_LV_DISP_ROT_MAX_BUF + #define LV_DISP_ROT_MAX_BUF CONFIG_LV_DISP_ROT_MAX_BUF + #else + #define LV_DISP_ROT_MAX_BUF (10*1024) + #endif +#endif + +/*------------- + * GPU + *-----------*/ + +/*Use Arm's 2D acceleration library Arm-2D */ +#ifndef LV_USE_GPU_ARM2D + #ifdef CONFIG_LV_USE_GPU_ARM2D + #define LV_USE_GPU_ARM2D CONFIG_LV_USE_GPU_ARM2D + #else + #define LV_USE_GPU_ARM2D 0 + #endif +#endif + +/*Use STM32's DMA2D (aka Chrom Art) GPU*/ +#ifndef LV_USE_GPU_STM32_DMA2D + #ifdef CONFIG_LV_USE_GPU_STM32_DMA2D + #define LV_USE_GPU_STM32_DMA2D CONFIG_LV_USE_GPU_STM32_DMA2D + #else + #define LV_USE_GPU_STM32_DMA2D 0 + #endif +#endif +#if LV_USE_GPU_STM32_DMA2D + /*Must be defined to include path of CMSIS header of target processor + e.g. "stm32f769xx.h" or "stm32f429xx.h"*/ + #ifndef LV_GPU_DMA2D_CMSIS_INCLUDE + #ifdef CONFIG_LV_GPU_DMA2D_CMSIS_INCLUDE + #define LV_GPU_DMA2D_CMSIS_INCLUDE CONFIG_LV_GPU_DMA2D_CMSIS_INCLUDE + #else + #define LV_GPU_DMA2D_CMSIS_INCLUDE + #endif + #endif +#endif + +/*Use SWM341's DMA2D GPU*/ +#ifndef LV_USE_GPU_SWM341_DMA2D + #ifdef CONFIG_LV_USE_GPU_SWM341_DMA2D + #define LV_USE_GPU_SWM341_DMA2D CONFIG_LV_USE_GPU_SWM341_DMA2D + #else + #define LV_USE_GPU_SWM341_DMA2D 0 + #endif +#endif +#if LV_USE_GPU_SWM341_DMA2D + #ifndef LV_GPU_SWM341_DMA2D_INCLUDE + #ifdef CONFIG_LV_GPU_SWM341_DMA2D_INCLUDE + #define LV_GPU_SWM341_DMA2D_INCLUDE CONFIG_LV_GPU_SWM341_DMA2D_INCLUDE + #else + #define LV_GPU_SWM341_DMA2D_INCLUDE "SWM341.h" + #endif + #endif +#endif + +/*Use NXP's PXP GPU iMX RTxxx platforms*/ +#ifndef LV_USE_GPU_NXP_PXP + #ifdef CONFIG_LV_USE_GPU_NXP_PXP + #define LV_USE_GPU_NXP_PXP CONFIG_LV_USE_GPU_NXP_PXP + #else + #define LV_USE_GPU_NXP_PXP 0 + #endif +#endif +#if LV_USE_GPU_NXP_PXP + /*1: Add default bare metal and FreeRTOS interrupt handling routines for PXP (lv_gpu_nxp_pxp_osa.c) + * and call lv_gpu_nxp_pxp_init() automatically during lv_init(). Note that symbol SDK_OS_FREE_RTOS + * has to be defined in order to use FreeRTOS OSA, otherwise bare-metal implementation is selected. + *0: lv_gpu_nxp_pxp_init() has to be called manually before lv_init() + */ + #ifndef LV_USE_GPU_NXP_PXP_AUTO_INIT + #ifdef CONFIG_LV_USE_GPU_NXP_PXP_AUTO_INIT + #define LV_USE_GPU_NXP_PXP_AUTO_INIT CONFIG_LV_USE_GPU_NXP_PXP_AUTO_INIT + #else + #define LV_USE_GPU_NXP_PXP_AUTO_INIT 0 + #endif + #endif +#endif + +/*Use NXP's VG-Lite GPU iMX RTxxx platforms*/ +#ifndef LV_USE_GPU_NXP_VG_LITE + #ifdef CONFIG_LV_USE_GPU_NXP_VG_LITE + #define LV_USE_GPU_NXP_VG_LITE CONFIG_LV_USE_GPU_NXP_VG_LITE + #else + #define LV_USE_GPU_NXP_VG_LITE 0 + #endif +#endif + +/*Use SDL renderer API*/ +#ifndef LV_USE_GPU_SDL + #ifdef CONFIG_LV_USE_GPU_SDL + #define LV_USE_GPU_SDL CONFIG_LV_USE_GPU_SDL + #else + #define LV_USE_GPU_SDL 0 + #endif +#endif +#if LV_USE_GPU_SDL + #ifndef LV_GPU_SDL_INCLUDE_PATH + #ifdef CONFIG_LV_GPU_SDL_INCLUDE_PATH + #define LV_GPU_SDL_INCLUDE_PATH CONFIG_LV_GPU_SDL_INCLUDE_PATH + #else + #define LV_GPU_SDL_INCLUDE_PATH + #endif + #endif + /*Texture cache size, 8MB by default*/ + #ifndef LV_GPU_SDL_LRU_SIZE + #ifdef CONFIG_LV_GPU_SDL_LRU_SIZE + #define LV_GPU_SDL_LRU_SIZE CONFIG_LV_GPU_SDL_LRU_SIZE + #else + #define LV_GPU_SDL_LRU_SIZE (1024 * 1024 * 8) + #endif + #endif + /*Custom blend mode for mask drawing, disable if you need to link with older SDL2 lib*/ + #ifndef LV_GPU_SDL_CUSTOM_BLEND_MODE + #ifdef CONFIG_LV_GPU_SDL_CUSTOM_BLEND_MODE + #define LV_GPU_SDL_CUSTOM_BLEND_MODE CONFIG_LV_GPU_SDL_CUSTOM_BLEND_MODE + #else + #define LV_GPU_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6)) + #endif + #endif +#endif + +/*------------- + * Logging + *-----------*/ + +/*Enable the log module*/ +#ifndef LV_USE_LOG + #ifdef CONFIG_LV_USE_LOG + #define LV_USE_LOG CONFIG_LV_USE_LOG + #else + #define LV_USE_LOG 0 + #endif +#endif +#if LV_USE_LOG + + /*How important log should be added: + *LV_LOG_LEVEL_TRACE A lot of logs to give detailed information + *LV_LOG_LEVEL_INFO Log important events + *LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem + *LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail + *LV_LOG_LEVEL_USER Only logs added by the user + *LV_LOG_LEVEL_NONE Do not log anything*/ + #ifndef LV_LOG_LEVEL + #ifdef CONFIG_LV_LOG_LEVEL + #define LV_LOG_LEVEL CONFIG_LV_LOG_LEVEL + #else + #define LV_LOG_LEVEL LV_LOG_LEVEL_WARN + #endif + #endif + + /*1: Print the log with 'printf'; + *0: User need to register a callback with `lv_log_register_print_cb()`*/ + #ifndef LV_LOG_PRINTF + #ifdef CONFIG_LV_LOG_PRINTF + #define LV_LOG_PRINTF CONFIG_LV_LOG_PRINTF + #else + #define LV_LOG_PRINTF 0 + #endif + #endif + + /*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/ + #ifndef LV_LOG_TRACE_MEM + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_MEM + #define LV_LOG_TRACE_MEM CONFIG_LV_LOG_TRACE_MEM + #else + #define LV_LOG_TRACE_MEM 0 + #endif + #else + #define LV_LOG_TRACE_MEM 1 + #endif + #endif + #ifndef LV_LOG_TRACE_TIMER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_TIMER + #define LV_LOG_TRACE_TIMER CONFIG_LV_LOG_TRACE_TIMER + #else + #define LV_LOG_TRACE_TIMER 0 + #endif + #else + #define LV_LOG_TRACE_TIMER 1 + #endif + #endif + #ifndef LV_LOG_TRACE_INDEV + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_INDEV + #define LV_LOG_TRACE_INDEV CONFIG_LV_LOG_TRACE_INDEV + #else + #define LV_LOG_TRACE_INDEV 0 + #endif + #else + #define LV_LOG_TRACE_INDEV 1 + #endif + #endif + #ifndef LV_LOG_TRACE_DISP_REFR + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_DISP_REFR + #define LV_LOG_TRACE_DISP_REFR CONFIG_LV_LOG_TRACE_DISP_REFR + #else + #define LV_LOG_TRACE_DISP_REFR 0 + #endif + #else + #define LV_LOG_TRACE_DISP_REFR 1 + #endif + #endif + #ifndef LV_LOG_TRACE_EVENT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_EVENT + #define LV_LOG_TRACE_EVENT CONFIG_LV_LOG_TRACE_EVENT + #else + #define LV_LOG_TRACE_EVENT 0 + #endif + #else + #define LV_LOG_TRACE_EVENT 1 + #endif + #endif + #ifndef LV_LOG_TRACE_OBJ_CREATE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_OBJ_CREATE + #define LV_LOG_TRACE_OBJ_CREATE CONFIG_LV_LOG_TRACE_OBJ_CREATE + #else + #define LV_LOG_TRACE_OBJ_CREATE 0 + #endif + #else + #define LV_LOG_TRACE_OBJ_CREATE 1 + #endif + #endif + #ifndef LV_LOG_TRACE_LAYOUT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_LAYOUT + #define LV_LOG_TRACE_LAYOUT CONFIG_LV_LOG_TRACE_LAYOUT + #else + #define LV_LOG_TRACE_LAYOUT 0 + #endif + #else + #define LV_LOG_TRACE_LAYOUT 1 + #endif + #endif + #ifndef LV_LOG_TRACE_ANIM + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LOG_TRACE_ANIM + #define LV_LOG_TRACE_ANIM CONFIG_LV_LOG_TRACE_ANIM + #else + #define LV_LOG_TRACE_ANIM 0 + #endif + #else + #define LV_LOG_TRACE_ANIM 1 + #endif + #endif + +#endif /*LV_USE_LOG*/ + +/*------------- + * Asserts + *-----------*/ + +/*Enable asserts if an operation is failed or an invalid data is found. + *If LV_USE_LOG is enabled an error message will be printed on failure*/ +#ifndef LV_USE_ASSERT_NULL + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ASSERT_NULL + #define LV_USE_ASSERT_NULL CONFIG_LV_USE_ASSERT_NULL + #else + #define LV_USE_ASSERT_NULL 0 + #endif + #else + #define LV_USE_ASSERT_NULL 1 /*Check if the parameter is NULL. (Very fast, recommended)*/ + #endif +#endif +#ifndef LV_USE_ASSERT_MALLOC + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ASSERT_MALLOC + #define LV_USE_ASSERT_MALLOC CONFIG_LV_USE_ASSERT_MALLOC + #else + #define LV_USE_ASSERT_MALLOC 0 + #endif + #else + #define LV_USE_ASSERT_MALLOC 1 /*Checks is the memory is successfully allocated or no. (Very fast, recommended)*/ + #endif +#endif +#ifndef LV_USE_ASSERT_STYLE + #ifdef CONFIG_LV_USE_ASSERT_STYLE + #define LV_USE_ASSERT_STYLE CONFIG_LV_USE_ASSERT_STYLE + #else + #define LV_USE_ASSERT_STYLE 0 /*Check if the styles are properly initialized. (Very fast, recommended)*/ + #endif +#endif +#ifndef LV_USE_ASSERT_MEM_INTEGRITY + #ifdef CONFIG_LV_USE_ASSERT_MEM_INTEGRITY + #define LV_USE_ASSERT_MEM_INTEGRITY CONFIG_LV_USE_ASSERT_MEM_INTEGRITY + #else + #define LV_USE_ASSERT_MEM_INTEGRITY 0 /*Check the integrity of `lv_mem` after critical operations. (Slow)*/ + #endif +#endif +#ifndef LV_USE_ASSERT_OBJ + #ifdef CONFIG_LV_USE_ASSERT_OBJ + #define LV_USE_ASSERT_OBJ CONFIG_LV_USE_ASSERT_OBJ + #else + #define LV_USE_ASSERT_OBJ 0 /*Check the object's type and existence (e.g. not deleted). (Slow)*/ + #endif +#endif + +/*Add a custom handler when assert happens e.g. to restart the MCU*/ +#ifndef LV_ASSERT_HANDLER_INCLUDE + #ifdef CONFIG_LV_ASSERT_HANDLER_INCLUDE + #define LV_ASSERT_HANDLER_INCLUDE CONFIG_LV_ASSERT_HANDLER_INCLUDE + #else + #define LV_ASSERT_HANDLER_INCLUDE + #endif +#endif +#ifndef LV_ASSERT_HANDLER + #ifdef CONFIG_LV_ASSERT_HANDLER + #define LV_ASSERT_HANDLER CONFIG_LV_ASSERT_HANDLER + #else + #define LV_ASSERT_HANDLER while(1); /*Halt by default*/ + #endif +#endif + +/*------------- + * Others + *-----------*/ + +/*1: Show CPU usage and FPS count*/ +#ifndef LV_USE_PERF_MONITOR + #ifdef CONFIG_LV_USE_PERF_MONITOR + #define LV_USE_PERF_MONITOR CONFIG_LV_USE_PERF_MONITOR + #else + #define LV_USE_PERF_MONITOR 0 + #endif +#endif +#if LV_USE_PERF_MONITOR + #ifndef LV_USE_PERF_MONITOR_POS + #ifdef CONFIG_LV_USE_PERF_MONITOR_POS + #define LV_USE_PERF_MONITOR_POS CONFIG_LV_USE_PERF_MONITOR_POS + #else + #define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT + #endif + #endif +#endif + +/*1: Show the used memory and the memory fragmentation + * Requires LV_MEM_CUSTOM = 0*/ +#ifndef LV_USE_MEM_MONITOR + #ifdef CONFIG_LV_USE_MEM_MONITOR + #define LV_USE_MEM_MONITOR CONFIG_LV_USE_MEM_MONITOR + #else + #define LV_USE_MEM_MONITOR 0 + #endif +#endif +#if LV_USE_MEM_MONITOR + #ifndef LV_USE_MEM_MONITOR_POS + #ifdef CONFIG_LV_USE_MEM_MONITOR_POS + #define LV_USE_MEM_MONITOR_POS CONFIG_LV_USE_MEM_MONITOR_POS + #else + #define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT + #endif + #endif +#endif + +/*1: Draw random colored rectangles over the redrawn areas*/ +#ifndef LV_USE_REFR_DEBUG + #ifdef CONFIG_LV_USE_REFR_DEBUG + #define LV_USE_REFR_DEBUG CONFIG_LV_USE_REFR_DEBUG + #else + #define LV_USE_REFR_DEBUG 0 + #endif +#endif + +/*Change the built in (v)snprintf functions*/ +#ifndef LV_SPRINTF_CUSTOM + #ifdef CONFIG_LV_SPRINTF_CUSTOM + #define LV_SPRINTF_CUSTOM CONFIG_LV_SPRINTF_CUSTOM + #else + #define LV_SPRINTF_CUSTOM 0 + #endif +#endif +#if LV_SPRINTF_CUSTOM + #ifndef LV_SPRINTF_INCLUDE + #ifdef CONFIG_LV_SPRINTF_INCLUDE + #define LV_SPRINTF_INCLUDE CONFIG_LV_SPRINTF_INCLUDE + #else + #define LV_SPRINTF_INCLUDE + #endif + #endif + #ifndef lv_snprintf + #ifdef CONFIG_LV_SNPRINTF + #define lv_snprintf CONFIG_LV_SNPRINTF + #else + #define lv_snprintf snprintf + #endif + #endif + #ifndef lv_vsnprintf + #ifdef CONFIG_LV_VSNPRINTF + #define lv_vsnprintf CONFIG_LV_VSNPRINTF + #else + #define lv_vsnprintf vsnprintf + #endif + #endif +#else /*LV_SPRINTF_CUSTOM*/ + #ifndef LV_SPRINTF_USE_FLOAT + #ifdef CONFIG_LV_SPRINTF_USE_FLOAT + #define LV_SPRINTF_USE_FLOAT CONFIG_LV_SPRINTF_USE_FLOAT + #else + #define LV_SPRINTF_USE_FLOAT 0 + #endif + #endif +#endif /*LV_SPRINTF_CUSTOM*/ + +#ifndef LV_USE_USER_DATA + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_USER_DATA + #define LV_USE_USER_DATA CONFIG_LV_USE_USER_DATA + #else + #define LV_USE_USER_DATA 0 + #endif + #else + #define LV_USE_USER_DATA 1 + #endif +#endif + +/*Garbage Collector settings + *Used if lvgl is bound to higher level language and the memory is managed by that language*/ +#ifndef LV_ENABLE_GC + #ifdef CONFIG_LV_ENABLE_GC + #define LV_ENABLE_GC CONFIG_LV_ENABLE_GC + #else + #define LV_ENABLE_GC 0 + #endif +#endif +#if LV_ENABLE_GC != 0 + #ifndef LV_GC_INCLUDE + #ifdef CONFIG_LV_GC_INCLUDE + #define LV_GC_INCLUDE CONFIG_LV_GC_INCLUDE + #else + #define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ + #endif + #endif +#endif /*LV_ENABLE_GC*/ + +/*===================== + * COMPILER SETTINGS + *====================*/ + +/*For big endian systems set to 1*/ +#ifndef LV_BIG_ENDIAN_SYSTEM + #ifdef CONFIG_LV_BIG_ENDIAN_SYSTEM + #define LV_BIG_ENDIAN_SYSTEM CONFIG_LV_BIG_ENDIAN_SYSTEM + #else + #define LV_BIG_ENDIAN_SYSTEM 0 + #endif +#endif + +/*Define a custom attribute to `lv_tick_inc` function*/ +#ifndef LV_ATTRIBUTE_TICK_INC + #ifdef CONFIG_LV_ATTRIBUTE_TICK_INC + #define LV_ATTRIBUTE_TICK_INC CONFIG_LV_ATTRIBUTE_TICK_INC + #else + #define LV_ATTRIBUTE_TICK_INC + #endif +#endif + +/*Define a custom attribute to `lv_timer_handler` function*/ +#ifndef LV_ATTRIBUTE_TIMER_HANDLER + #ifdef CONFIG_LV_ATTRIBUTE_TIMER_HANDLER + #define LV_ATTRIBUTE_TIMER_HANDLER CONFIG_LV_ATTRIBUTE_TIMER_HANDLER + #else + #define LV_ATTRIBUTE_TIMER_HANDLER + #endif +#endif + +/*Define a custom attribute to `lv_disp_flush_ready` function*/ +#ifndef LV_ATTRIBUTE_FLUSH_READY + #ifdef CONFIG_LV_ATTRIBUTE_FLUSH_READY + #define LV_ATTRIBUTE_FLUSH_READY CONFIG_LV_ATTRIBUTE_FLUSH_READY + #else + #define LV_ATTRIBUTE_FLUSH_READY + #endif +#endif + +/*Required alignment size for buffers*/ +#ifndef LV_ATTRIBUTE_MEM_ALIGN_SIZE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_ATTRIBUTE_MEM_ALIGN_SIZE + #define LV_ATTRIBUTE_MEM_ALIGN_SIZE CONFIG_LV_ATTRIBUTE_MEM_ALIGN_SIZE + #else + #define LV_ATTRIBUTE_MEM_ALIGN_SIZE 0 + #endif + #else + #define LV_ATTRIBUTE_MEM_ALIGN_SIZE 1 + #endif +#endif + +/*Will be added where memories needs to be aligned (with -Os data might not be aligned to boundary by default). + * E.g. __attribute__((aligned(4)))*/ +#ifndef LV_ATTRIBUTE_MEM_ALIGN + #ifdef CONFIG_LV_ATTRIBUTE_MEM_ALIGN + #define LV_ATTRIBUTE_MEM_ALIGN CONFIG_LV_ATTRIBUTE_MEM_ALIGN + #else + #define LV_ATTRIBUTE_MEM_ALIGN + #endif +#endif + +/*Attribute to mark large constant arrays for example font's bitmaps*/ +#ifndef LV_ATTRIBUTE_LARGE_CONST + #ifdef CONFIG_LV_ATTRIBUTE_LARGE_CONST + #define LV_ATTRIBUTE_LARGE_CONST CONFIG_LV_ATTRIBUTE_LARGE_CONST + #else + #define LV_ATTRIBUTE_LARGE_CONST + #endif +#endif + +/*Compiler prefix for a big array declaration in RAM*/ +#ifndef LV_ATTRIBUTE_LARGE_RAM_ARRAY + #ifdef CONFIG_LV_ATTRIBUTE_LARGE_RAM_ARRAY + #define LV_ATTRIBUTE_LARGE_RAM_ARRAY CONFIG_LV_ATTRIBUTE_LARGE_RAM_ARRAY + #else + #define LV_ATTRIBUTE_LARGE_RAM_ARRAY + #endif +#endif + +/*Place performance critical functions into a faster memory (e.g RAM)*/ +#ifndef LV_ATTRIBUTE_FAST_MEM + #ifdef CONFIG_LV_ATTRIBUTE_FAST_MEM + #define LV_ATTRIBUTE_FAST_MEM CONFIG_LV_ATTRIBUTE_FAST_MEM + #else + #define LV_ATTRIBUTE_FAST_MEM + #endif +#endif + +/*Prefix variables that are used in GPU accelerated operations, often these need to be placed in RAM sections that are DMA accessible*/ +#ifndef LV_ATTRIBUTE_DMA + #ifdef CONFIG_LV_ATTRIBUTE_DMA + #define LV_ATTRIBUTE_DMA CONFIG_LV_ATTRIBUTE_DMA + #else + #define LV_ATTRIBUTE_DMA + #endif +#endif + +/*Export integer constant to binding. This macro is used with constants in the form of LV_ that + *should also appear on LVGL binding API such as Micropython.*/ +#ifndef LV_EXPORT_CONST_INT + #ifdef CONFIG_LV_EXPORT_CONST_INT + #define LV_EXPORT_CONST_INT CONFIG_LV_EXPORT_CONST_INT + #else + #define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning /*The default value just prevents GCC warning*/ + #endif +#endif + +/*Extend the default -32k..32k coordinate range to -4M..4M by using int32_t for coordinates instead of int16_t*/ +#ifndef LV_USE_LARGE_COORD + #ifdef CONFIG_LV_USE_LARGE_COORD + #define LV_USE_LARGE_COORD CONFIG_LV_USE_LARGE_COORD + #else + #define LV_USE_LARGE_COORD 0 + #endif +#endif + +/*================== + * FONT USAGE + *===================*/ + +/*Montserrat fonts with ASCII range and some symbols using bpp = 4 + *https://fonts.google.com/specimen/Montserrat*/ +#ifndef LV_FONT_MONTSERRAT_8 + #ifdef CONFIG_LV_FONT_MONTSERRAT_8 + #define LV_FONT_MONTSERRAT_8 CONFIG_LV_FONT_MONTSERRAT_8 + #else + #define LV_FONT_MONTSERRAT_8 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_10 + #ifdef CONFIG_LV_FONT_MONTSERRAT_10 + #define LV_FONT_MONTSERRAT_10 CONFIG_LV_FONT_MONTSERRAT_10 + #else + #define LV_FONT_MONTSERRAT_10 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_12 + #ifdef CONFIG_LV_FONT_MONTSERRAT_12 + #define LV_FONT_MONTSERRAT_12 CONFIG_LV_FONT_MONTSERRAT_12 + #else + #define LV_FONT_MONTSERRAT_12 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_14 + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_FONT_MONTSERRAT_14 + #define LV_FONT_MONTSERRAT_14 CONFIG_LV_FONT_MONTSERRAT_14 + #else + #define LV_FONT_MONTSERRAT_14 0 + #endif + #else + #define LV_FONT_MONTSERRAT_14 1 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_16 + #ifdef CONFIG_LV_FONT_MONTSERRAT_16 + #define LV_FONT_MONTSERRAT_16 CONFIG_LV_FONT_MONTSERRAT_16 + #else + #define LV_FONT_MONTSERRAT_16 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_18 + #ifdef CONFIG_LV_FONT_MONTSERRAT_18 + #define LV_FONT_MONTSERRAT_18 CONFIG_LV_FONT_MONTSERRAT_18 + #else + #define LV_FONT_MONTSERRAT_18 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_20 + #ifdef CONFIG_LV_FONT_MONTSERRAT_20 + #define LV_FONT_MONTSERRAT_20 CONFIG_LV_FONT_MONTSERRAT_20 + #else + #define LV_FONT_MONTSERRAT_20 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_22 + #ifdef CONFIG_LV_FONT_MONTSERRAT_22 + #define LV_FONT_MONTSERRAT_22 CONFIG_LV_FONT_MONTSERRAT_22 + #else + #define LV_FONT_MONTSERRAT_22 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_24 + #ifdef CONFIG_LV_FONT_MONTSERRAT_24 + #define LV_FONT_MONTSERRAT_24 CONFIG_LV_FONT_MONTSERRAT_24 + #else + #define LV_FONT_MONTSERRAT_24 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_26 + #ifdef CONFIG_LV_FONT_MONTSERRAT_26 + #define LV_FONT_MONTSERRAT_26 CONFIG_LV_FONT_MONTSERRAT_26 + #else + #define LV_FONT_MONTSERRAT_26 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_28 + #ifdef CONFIG_LV_FONT_MONTSERRAT_28 + #define LV_FONT_MONTSERRAT_28 CONFIG_LV_FONT_MONTSERRAT_28 + #else + #define LV_FONT_MONTSERRAT_28 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_30 + #ifdef CONFIG_LV_FONT_MONTSERRAT_30 + #define LV_FONT_MONTSERRAT_30 CONFIG_LV_FONT_MONTSERRAT_30 + #else + #define LV_FONT_MONTSERRAT_30 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_32 + #ifdef CONFIG_LV_FONT_MONTSERRAT_32 + #define LV_FONT_MONTSERRAT_32 CONFIG_LV_FONT_MONTSERRAT_32 + #else + #define LV_FONT_MONTSERRAT_32 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_34 + #ifdef CONFIG_LV_FONT_MONTSERRAT_34 + #define LV_FONT_MONTSERRAT_34 CONFIG_LV_FONT_MONTSERRAT_34 + #else + #define LV_FONT_MONTSERRAT_34 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_36 + #ifdef CONFIG_LV_FONT_MONTSERRAT_36 + #define LV_FONT_MONTSERRAT_36 CONFIG_LV_FONT_MONTSERRAT_36 + #else + #define LV_FONT_MONTSERRAT_36 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_38 + #ifdef CONFIG_LV_FONT_MONTSERRAT_38 + #define LV_FONT_MONTSERRAT_38 CONFIG_LV_FONT_MONTSERRAT_38 + #else + #define LV_FONT_MONTSERRAT_38 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_40 + #ifdef CONFIG_LV_FONT_MONTSERRAT_40 + #define LV_FONT_MONTSERRAT_40 CONFIG_LV_FONT_MONTSERRAT_40 + #else + #define LV_FONT_MONTSERRAT_40 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_42 + #ifdef CONFIG_LV_FONT_MONTSERRAT_42 + #define LV_FONT_MONTSERRAT_42 CONFIG_LV_FONT_MONTSERRAT_42 + #else + #define LV_FONT_MONTSERRAT_42 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_44 + #ifdef CONFIG_LV_FONT_MONTSERRAT_44 + #define LV_FONT_MONTSERRAT_44 CONFIG_LV_FONT_MONTSERRAT_44 + #else + #define LV_FONT_MONTSERRAT_44 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_46 + #ifdef CONFIG_LV_FONT_MONTSERRAT_46 + #define LV_FONT_MONTSERRAT_46 CONFIG_LV_FONT_MONTSERRAT_46 + #else + #define LV_FONT_MONTSERRAT_46 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_48 + #ifdef CONFIG_LV_FONT_MONTSERRAT_48 + #define LV_FONT_MONTSERRAT_48 CONFIG_LV_FONT_MONTSERRAT_48 + #else + #define LV_FONT_MONTSERRAT_48 0 + #endif +#endif + +/*Demonstrate special features*/ +#ifndef LV_FONT_MONTSERRAT_12_SUBPX + #ifdef CONFIG_LV_FONT_MONTSERRAT_12_SUBPX + #define LV_FONT_MONTSERRAT_12_SUBPX CONFIG_LV_FONT_MONTSERRAT_12_SUBPX + #else + #define LV_FONT_MONTSERRAT_12_SUBPX 0 + #endif +#endif +#ifndef LV_FONT_MONTSERRAT_28_COMPRESSED + #ifdef CONFIG_LV_FONT_MONTSERRAT_28_COMPRESSED + #define LV_FONT_MONTSERRAT_28_COMPRESSED CONFIG_LV_FONT_MONTSERRAT_28_COMPRESSED + #else + #define LV_FONT_MONTSERRAT_28_COMPRESSED 0 /*bpp = 3*/ + #endif +#endif +#ifndef LV_FONT_DEJAVU_16_PERSIAN_HEBREW + #ifdef CONFIG_LV_FONT_DEJAVU_16_PERSIAN_HEBREW + #define LV_FONT_DEJAVU_16_PERSIAN_HEBREW CONFIG_LV_FONT_DEJAVU_16_PERSIAN_HEBREW + #else + #define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0 /*Hebrew, Arabic, Persian letters and all their forms*/ + #endif +#endif +#ifndef LV_FONT_SIMSUN_16_CJK + #ifdef CONFIG_LV_FONT_SIMSUN_16_CJK + #define LV_FONT_SIMSUN_16_CJK CONFIG_LV_FONT_SIMSUN_16_CJK + #else + #define LV_FONT_SIMSUN_16_CJK 0 /*1000 most common CJK radicals*/ + #endif +#endif + +/*Pixel perfect monospace fonts*/ +#ifndef LV_FONT_UNSCII_8 + #ifdef CONFIG_LV_FONT_UNSCII_8 + #define LV_FONT_UNSCII_8 CONFIG_LV_FONT_UNSCII_8 + #else + #define LV_FONT_UNSCII_8 0 + #endif +#endif +#ifndef LV_FONT_UNSCII_16 + #ifdef CONFIG_LV_FONT_UNSCII_16 + #define LV_FONT_UNSCII_16 CONFIG_LV_FONT_UNSCII_16 + #else + #define LV_FONT_UNSCII_16 0 + #endif +#endif + +/*Optionally declare custom fonts here. + *You can use these fonts as default font too and they will be available globally. + *E.g. #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) LV_FONT_DECLARE(my_font_2)*/ +#ifndef LV_FONT_CUSTOM_DECLARE + #ifdef CONFIG_LV_FONT_CUSTOM_DECLARE + #define LV_FONT_CUSTOM_DECLARE CONFIG_LV_FONT_CUSTOM_DECLARE + #else + #define LV_FONT_CUSTOM_DECLARE + #endif +#endif + +/*Always set a default font*/ +#ifndef LV_FONT_DEFAULT + #ifdef CONFIG_LV_FONT_DEFAULT + #define LV_FONT_DEFAULT CONFIG_LV_FONT_DEFAULT + #else + #define LV_FONT_DEFAULT &lv_font_montserrat_14 + #endif +#endif + +/*Enable handling large font and/or fonts with a lot of characters. + *The limit depends on the font size, font face and bpp. + *Compiler error will be triggered if a font needs it.*/ +#ifndef LV_FONT_FMT_TXT_LARGE + #ifdef CONFIG_LV_FONT_FMT_TXT_LARGE + #define LV_FONT_FMT_TXT_LARGE CONFIG_LV_FONT_FMT_TXT_LARGE + #else + #define LV_FONT_FMT_TXT_LARGE 0 + #endif +#endif + +/*Enables/disables support for compressed fonts.*/ +#ifndef LV_USE_FONT_COMPRESSED + #ifdef CONFIG_LV_USE_FONT_COMPRESSED + #define LV_USE_FONT_COMPRESSED CONFIG_LV_USE_FONT_COMPRESSED + #else + #define LV_USE_FONT_COMPRESSED 0 + #endif +#endif + +/*Enable subpixel rendering*/ +#ifndef LV_USE_FONT_SUBPX + #ifdef CONFIG_LV_USE_FONT_SUBPX + #define LV_USE_FONT_SUBPX CONFIG_LV_USE_FONT_SUBPX + #else + #define LV_USE_FONT_SUBPX 0 + #endif +#endif +#if LV_USE_FONT_SUBPX + /*Set the pixel order of the display. Physical order of RGB channels. Doesn't matter with "normal" fonts.*/ + #ifndef LV_FONT_SUBPX_BGR + #ifdef CONFIG_LV_FONT_SUBPX_BGR + #define LV_FONT_SUBPX_BGR CONFIG_LV_FONT_SUBPX_BGR + #else + #define LV_FONT_SUBPX_BGR 0 /*0: RGB; 1:BGR order*/ + #endif + #endif +#endif + +/*Enable drawing placeholders when glyph dsc is not found*/ +#ifndef LV_USE_FONT_PLACEHOLDER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_FONT_PLACEHOLDER + #define LV_USE_FONT_PLACEHOLDER CONFIG_LV_USE_FONT_PLACEHOLDER + #else + #define LV_USE_FONT_PLACEHOLDER 0 + #endif + #else + #define LV_USE_FONT_PLACEHOLDER 1 + #endif +#endif + +/*================= + * TEXT SETTINGS + *=================*/ + +/** + * Select a character encoding for strings. + * Your IDE or editor should have the same character encoding + * - LV_TXT_ENC_UTF8 + * - LV_TXT_ENC_ASCII + */ +#ifndef LV_TXT_ENC + #ifdef CONFIG_LV_TXT_ENC + #define LV_TXT_ENC CONFIG_LV_TXT_ENC + #else + #define LV_TXT_ENC LV_TXT_ENC_UTF8 + #endif +#endif + +/*Can break (wrap) texts on these chars*/ +#ifndef LV_TXT_BREAK_CHARS + #ifdef CONFIG_LV_TXT_BREAK_CHARS + #define LV_TXT_BREAK_CHARS CONFIG_LV_TXT_BREAK_CHARS + #else + #define LV_TXT_BREAK_CHARS " ,.;:-_" + #endif +#endif + +/*If a word is at least this long, will break wherever "prettiest" + *To disable, set to a value <= 0*/ +#ifndef LV_TXT_LINE_BREAK_LONG_LEN + #ifdef CONFIG_LV_TXT_LINE_BREAK_LONG_LEN + #define LV_TXT_LINE_BREAK_LONG_LEN CONFIG_LV_TXT_LINE_BREAK_LONG_LEN + #else + #define LV_TXT_LINE_BREAK_LONG_LEN 0 + #endif +#endif + +/*Minimum number of characters in a long word to put on a line before a break. + *Depends on LV_TXT_LINE_BREAK_LONG_LEN.*/ +#ifndef LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN + #ifdef CONFIG_LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN + #define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN CONFIG_LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN + #else + #define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 + #endif +#endif + +/*Minimum number of characters in a long word to put on a line after a break. + *Depends on LV_TXT_LINE_BREAK_LONG_LEN.*/ +#ifndef LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN + #ifdef CONFIG_LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN + #define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN CONFIG_LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN + #else + #define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3 + #endif +#endif + +/*The control character to use for signalling text recoloring.*/ +#ifndef LV_TXT_COLOR_CMD + #ifdef CONFIG_LV_TXT_COLOR_CMD + #define LV_TXT_COLOR_CMD CONFIG_LV_TXT_COLOR_CMD + #else + #define LV_TXT_COLOR_CMD "#" + #endif +#endif + +/*Support bidirectional texts. Allows mixing Left-to-Right and Right-to-Left texts. + *The direction will be processed according to the Unicode Bidirectional Algorithm: + *https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/ +#ifndef LV_USE_BIDI + #ifdef CONFIG_LV_USE_BIDI + #define LV_USE_BIDI CONFIG_LV_USE_BIDI + #else + #define LV_USE_BIDI 0 + #endif +#endif +#if LV_USE_BIDI + /*Set the default direction. Supported values: + *`LV_BASE_DIR_LTR` Left-to-Right + *`LV_BASE_DIR_RTL` Right-to-Left + *`LV_BASE_DIR_AUTO` detect texts base direction*/ + #ifndef LV_BIDI_BASE_DIR_DEF + #ifdef CONFIG_LV_BIDI_BASE_DIR_DEF + #define LV_BIDI_BASE_DIR_DEF CONFIG_LV_BIDI_BASE_DIR_DEF + #else + #define LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_AUTO + #endif + #endif +#endif + +/*Enable Arabic/Persian processing + *In these languages characters should be replaced with an other form based on their position in the text*/ +#ifndef LV_USE_ARABIC_PERSIAN_CHARS + #ifdef CONFIG_LV_USE_ARABIC_PERSIAN_CHARS + #define LV_USE_ARABIC_PERSIAN_CHARS CONFIG_LV_USE_ARABIC_PERSIAN_CHARS + #else + #define LV_USE_ARABIC_PERSIAN_CHARS 0 + #endif +#endif + +/*================== + * WIDGET USAGE + *================*/ + +/*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/ + +#ifndef LV_USE_ARC + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ARC + #define LV_USE_ARC CONFIG_LV_USE_ARC + #else + #define LV_USE_ARC 0 + #endif + #else + #define LV_USE_ARC 1 + #endif +#endif + +#ifndef LV_USE_BAR + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_BAR + #define LV_USE_BAR CONFIG_LV_USE_BAR + #else + #define LV_USE_BAR 0 + #endif + #else + #define LV_USE_BAR 1 + #endif +#endif + +#ifndef LV_USE_BTN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_BTN + #define LV_USE_BTN CONFIG_LV_USE_BTN + #else + #define LV_USE_BTN 0 + #endif + #else + #define LV_USE_BTN 1 + #endif +#endif + +#ifndef LV_USE_BTNMATRIX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_BTNMATRIX + #define LV_USE_BTNMATRIX CONFIG_LV_USE_BTNMATRIX + #else + #define LV_USE_BTNMATRIX 0 + #endif + #else + #define LV_USE_BTNMATRIX 1 + #endif +#endif + +#ifndef LV_USE_CANVAS + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CANVAS + #define LV_USE_CANVAS CONFIG_LV_USE_CANVAS + #else + #define LV_USE_CANVAS 0 + #endif + #else + #define LV_USE_CANVAS 1 + #endif +#endif + +#ifndef LV_USE_CHECKBOX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CHECKBOX + #define LV_USE_CHECKBOX CONFIG_LV_USE_CHECKBOX + #else + #define LV_USE_CHECKBOX 0 + #endif + #else + #define LV_USE_CHECKBOX 1 + #endif +#endif + +#ifndef LV_USE_DROPDOWN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_DROPDOWN + #define LV_USE_DROPDOWN CONFIG_LV_USE_DROPDOWN + #else + #define LV_USE_DROPDOWN 0 + #endif + #else + #define LV_USE_DROPDOWN 1 /*Requires: lv_label*/ + #endif +#endif + +#ifndef LV_USE_IMG + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_IMG + #define LV_USE_IMG CONFIG_LV_USE_IMG + #else + #define LV_USE_IMG 0 + #endif + #else + #define LV_USE_IMG 1 /*Requires: lv_label*/ + #endif +#endif + +#ifndef LV_USE_LABEL + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_LABEL + #define LV_USE_LABEL CONFIG_LV_USE_LABEL + #else + #define LV_USE_LABEL 0 + #endif + #else + #define LV_USE_LABEL 1 + #endif +#endif +#if LV_USE_LABEL + #ifndef LV_LABEL_TEXT_SELECTION + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LABEL_TEXT_SELECTION + #define LV_LABEL_TEXT_SELECTION CONFIG_LV_LABEL_TEXT_SELECTION + #else + #define LV_LABEL_TEXT_SELECTION 0 + #endif + #else + #define LV_LABEL_TEXT_SELECTION 1 /*Enable selecting text of the label*/ + #endif + #endif + #ifndef LV_LABEL_LONG_TXT_HINT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_LABEL_LONG_TXT_HINT + #define LV_LABEL_LONG_TXT_HINT CONFIG_LV_LABEL_LONG_TXT_HINT + #else + #define LV_LABEL_LONG_TXT_HINT 0 + #endif + #else + #define LV_LABEL_LONG_TXT_HINT 1 /*Store some extra info in labels to speed up drawing of very long texts*/ + #endif + #endif +#endif + +#ifndef LV_USE_LINE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_LINE + #define LV_USE_LINE CONFIG_LV_USE_LINE + #else + #define LV_USE_LINE 0 + #endif + #else + #define LV_USE_LINE 1 + #endif +#endif + +#ifndef LV_USE_ROLLER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ROLLER + #define LV_USE_ROLLER CONFIG_LV_USE_ROLLER + #else + #define LV_USE_ROLLER 0 + #endif + #else + #define LV_USE_ROLLER 1 /*Requires: lv_label*/ + #endif +#endif +#if LV_USE_ROLLER + #ifndef LV_ROLLER_INF_PAGES + #ifdef CONFIG_LV_ROLLER_INF_PAGES + #define LV_ROLLER_INF_PAGES CONFIG_LV_ROLLER_INF_PAGES + #else + #define LV_ROLLER_INF_PAGES 7 /*Number of extra "pages" when the roller is infinite*/ + #endif + #endif +#endif + +#ifndef LV_USE_SLIDER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SLIDER + #define LV_USE_SLIDER CONFIG_LV_USE_SLIDER + #else + #define LV_USE_SLIDER 0 + #endif + #else + #define LV_USE_SLIDER 1 /*Requires: lv_bar*/ + #endif +#endif + +#ifndef LV_USE_SWITCH + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SWITCH + #define LV_USE_SWITCH CONFIG_LV_USE_SWITCH + #else + #define LV_USE_SWITCH 0 + #endif + #else + #define LV_USE_SWITCH 1 + #endif +#endif + +#ifndef LV_USE_TEXTAREA + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_TEXTAREA + #define LV_USE_TEXTAREA CONFIG_LV_USE_TEXTAREA + #else + #define LV_USE_TEXTAREA 0 + #endif + #else + #define LV_USE_TEXTAREA 1 /*Requires: lv_label*/ + #endif +#endif +#if LV_USE_TEXTAREA != 0 + #ifndef LV_TEXTAREA_DEF_PWD_SHOW_TIME + #ifdef CONFIG_LV_TEXTAREA_DEF_PWD_SHOW_TIME + #define LV_TEXTAREA_DEF_PWD_SHOW_TIME CONFIG_LV_TEXTAREA_DEF_PWD_SHOW_TIME + #else + #define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/ + #endif + #endif +#endif + +#ifndef LV_USE_TABLE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_TABLE + #define LV_USE_TABLE CONFIG_LV_USE_TABLE + #else + #define LV_USE_TABLE 0 + #endif + #else + #define LV_USE_TABLE 1 + #endif +#endif + +/*================== + * EXTRA COMPONENTS + *==================*/ + +/*----------- + * Widgets + *----------*/ +#ifndef LV_USE_ANIMIMG + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_ANIMIMG + #define LV_USE_ANIMIMG CONFIG_LV_USE_ANIMIMG + #else + #define LV_USE_ANIMIMG 0 + #endif + #else + #define LV_USE_ANIMIMG 1 + #endif +#endif + +#ifndef LV_USE_CALENDAR + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CALENDAR + #define LV_USE_CALENDAR CONFIG_LV_USE_CALENDAR + #else + #define LV_USE_CALENDAR 0 + #endif + #else + #define LV_USE_CALENDAR 1 + #endif +#endif +#if LV_USE_CALENDAR + #ifndef LV_CALENDAR_WEEK_STARTS_MONDAY + #ifdef CONFIG_LV_CALENDAR_WEEK_STARTS_MONDAY + #define LV_CALENDAR_WEEK_STARTS_MONDAY CONFIG_LV_CALENDAR_WEEK_STARTS_MONDAY + #else + #define LV_CALENDAR_WEEK_STARTS_MONDAY 0 + #endif + #endif + #if LV_CALENDAR_WEEK_STARTS_MONDAY + #ifndef LV_CALENDAR_DEFAULT_DAY_NAMES + #ifdef CONFIG_LV_CALENDAR_DEFAULT_DAY_NAMES + #define LV_CALENDAR_DEFAULT_DAY_NAMES CONFIG_LV_CALENDAR_DEFAULT_DAY_NAMES + #else + #define LV_CALENDAR_DEFAULT_DAY_NAMES {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"} + #endif + #endif + #else + #ifndef LV_CALENDAR_DEFAULT_DAY_NAMES + #ifdef CONFIG_LV_CALENDAR_DEFAULT_DAY_NAMES + #define LV_CALENDAR_DEFAULT_DAY_NAMES CONFIG_LV_CALENDAR_DEFAULT_DAY_NAMES + #else + #define LV_CALENDAR_DEFAULT_DAY_NAMES {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"} + #endif + #endif + #endif + + #ifndef LV_CALENDAR_DEFAULT_MONTH_NAMES + #ifdef CONFIG_LV_CALENDAR_DEFAULT_MONTH_NAMES + #define LV_CALENDAR_DEFAULT_MONTH_NAMES CONFIG_LV_CALENDAR_DEFAULT_MONTH_NAMES + #else + #define LV_CALENDAR_DEFAULT_MONTH_NAMES {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} + #endif + #endif + #ifndef LV_USE_CALENDAR_HEADER_ARROW + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CALENDAR_HEADER_ARROW + #define LV_USE_CALENDAR_HEADER_ARROW CONFIG_LV_USE_CALENDAR_HEADER_ARROW + #else + #define LV_USE_CALENDAR_HEADER_ARROW 0 + #endif + #else + #define LV_USE_CALENDAR_HEADER_ARROW 1 + #endif + #endif + #ifndef LV_USE_CALENDAR_HEADER_DROPDOWN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CALENDAR_HEADER_DROPDOWN + #define LV_USE_CALENDAR_HEADER_DROPDOWN CONFIG_LV_USE_CALENDAR_HEADER_DROPDOWN + #else + #define LV_USE_CALENDAR_HEADER_DROPDOWN 0 + #endif + #else + #define LV_USE_CALENDAR_HEADER_DROPDOWN 1 + #endif + #endif +#endif /*LV_USE_CALENDAR*/ + +#ifndef LV_USE_CHART + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_CHART + #define LV_USE_CHART CONFIG_LV_USE_CHART + #else + #define LV_USE_CHART 0 + #endif + #else + #define LV_USE_CHART 1 + #endif +#endif + +#ifndef LV_USE_COLORWHEEL + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_COLORWHEEL + #define LV_USE_COLORWHEEL CONFIG_LV_USE_COLORWHEEL + #else + #define LV_USE_COLORWHEEL 0 + #endif + #else + #define LV_USE_COLORWHEEL 1 + #endif +#endif + +#ifndef LV_USE_IMGBTN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_IMGBTN + #define LV_USE_IMGBTN CONFIG_LV_USE_IMGBTN + #else + #define LV_USE_IMGBTN 0 + #endif + #else + #define LV_USE_IMGBTN 1 + #endif +#endif + +#ifndef LV_USE_KEYBOARD + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_KEYBOARD + #define LV_USE_KEYBOARD CONFIG_LV_USE_KEYBOARD + #else + #define LV_USE_KEYBOARD 0 + #endif + #else + #define LV_USE_KEYBOARD 1 + #endif +#endif + +#ifndef LV_USE_LED + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_LED + #define LV_USE_LED CONFIG_LV_USE_LED + #else + #define LV_USE_LED 0 + #endif + #else + #define LV_USE_LED 1 + #endif +#endif + +#ifndef LV_USE_LIST + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_LIST + #define LV_USE_LIST CONFIG_LV_USE_LIST + #else + #define LV_USE_LIST 0 + #endif + #else + #define LV_USE_LIST 1 + #endif +#endif + +#ifndef LV_USE_MENU + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_MENU + #define LV_USE_MENU CONFIG_LV_USE_MENU + #else + #define LV_USE_MENU 0 + #endif + #else + #define LV_USE_MENU 1 + #endif +#endif + +#ifndef LV_USE_METER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_METER + #define LV_USE_METER CONFIG_LV_USE_METER + #else + #define LV_USE_METER 0 + #endif + #else + #define LV_USE_METER 1 + #endif +#endif + +#ifndef LV_USE_MSGBOX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_MSGBOX + #define LV_USE_MSGBOX CONFIG_LV_USE_MSGBOX + #else + #define LV_USE_MSGBOX 0 + #endif + #else + #define LV_USE_MSGBOX 1 + #endif +#endif + +#ifndef LV_USE_SPAN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SPAN + #define LV_USE_SPAN CONFIG_LV_USE_SPAN + #else + #define LV_USE_SPAN 0 + #endif + #else + #define LV_USE_SPAN 1 + #endif +#endif +#if LV_USE_SPAN + /*A line text can contain maximum num of span descriptor */ + #ifndef LV_SPAN_SNIPPET_STACK_SIZE + #ifdef CONFIG_LV_SPAN_SNIPPET_STACK_SIZE + #define LV_SPAN_SNIPPET_STACK_SIZE CONFIG_LV_SPAN_SNIPPET_STACK_SIZE + #else + #define LV_SPAN_SNIPPET_STACK_SIZE 64 + #endif + #endif +#endif + +#ifndef LV_USE_SPINBOX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SPINBOX + #define LV_USE_SPINBOX CONFIG_LV_USE_SPINBOX + #else + #define LV_USE_SPINBOX 0 + #endif + #else + #define LV_USE_SPINBOX 1 + #endif +#endif + +#ifndef LV_USE_SPINNER + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_SPINNER + #define LV_USE_SPINNER CONFIG_LV_USE_SPINNER + #else + #define LV_USE_SPINNER 0 + #endif + #else + #define LV_USE_SPINNER 1 + #endif +#endif + +#ifndef LV_USE_TABVIEW + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_TABVIEW + #define LV_USE_TABVIEW CONFIG_LV_USE_TABVIEW + #else + #define LV_USE_TABVIEW 0 + #endif + #else + #define LV_USE_TABVIEW 1 + #endif +#endif + +#ifndef LV_USE_TILEVIEW + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_TILEVIEW + #define LV_USE_TILEVIEW CONFIG_LV_USE_TILEVIEW + #else + #define LV_USE_TILEVIEW 0 + #endif + #else + #define LV_USE_TILEVIEW 1 + #endif +#endif + +#ifndef LV_USE_WIN + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_WIN + #define LV_USE_WIN CONFIG_LV_USE_WIN + #else + #define LV_USE_WIN 0 + #endif + #else + #define LV_USE_WIN 1 + #endif +#endif + +/*----------- + * Themes + *----------*/ + +/*A simple, impressive and very complete theme*/ +#ifndef LV_USE_THEME_DEFAULT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_THEME_DEFAULT + #define LV_USE_THEME_DEFAULT CONFIG_LV_USE_THEME_DEFAULT + #else + #define LV_USE_THEME_DEFAULT 0 + #endif + #else + #define LV_USE_THEME_DEFAULT 1 + #endif +#endif +#if LV_USE_THEME_DEFAULT + + /*0: Light mode; 1: Dark mode*/ + #ifndef LV_THEME_DEFAULT_DARK + #ifdef CONFIG_LV_THEME_DEFAULT_DARK + #define LV_THEME_DEFAULT_DARK CONFIG_LV_THEME_DEFAULT_DARK + #else + #define LV_THEME_DEFAULT_DARK 0 + #endif + #endif + + /*1: Enable grow on press*/ + #ifndef LV_THEME_DEFAULT_GROW + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_THEME_DEFAULT_GROW + #define LV_THEME_DEFAULT_GROW CONFIG_LV_THEME_DEFAULT_GROW + #else + #define LV_THEME_DEFAULT_GROW 0 + #endif + #else + #define LV_THEME_DEFAULT_GROW 1 + #endif + #endif + + /*Default transition time in [ms]*/ + #ifndef LV_THEME_DEFAULT_TRANSITION_TIME + #ifdef CONFIG_LV_THEME_DEFAULT_TRANSITION_TIME + #define LV_THEME_DEFAULT_TRANSITION_TIME CONFIG_LV_THEME_DEFAULT_TRANSITION_TIME + #else + #define LV_THEME_DEFAULT_TRANSITION_TIME 80 + #endif + #endif +#endif /*LV_USE_THEME_DEFAULT*/ + +/*A very simple theme that is a good starting point for a custom theme*/ +#ifndef LV_USE_THEME_BASIC + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_THEME_BASIC + #define LV_USE_THEME_BASIC CONFIG_LV_USE_THEME_BASIC + #else + #define LV_USE_THEME_BASIC 0 + #endif + #else + #define LV_USE_THEME_BASIC 1 + #endif +#endif + +/*A theme designed for monochrome displays*/ +#ifndef LV_USE_THEME_MONO + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_THEME_MONO + #define LV_USE_THEME_MONO CONFIG_LV_USE_THEME_MONO + #else + #define LV_USE_THEME_MONO 0 + #endif + #else + #define LV_USE_THEME_MONO 1 + #endif +#endif + +/*----------- + * Layouts + *----------*/ + +/*A layout similar to Flexbox in CSS.*/ +#ifndef LV_USE_FLEX + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_FLEX + #define LV_USE_FLEX CONFIG_LV_USE_FLEX + #else + #define LV_USE_FLEX 0 + #endif + #else + #define LV_USE_FLEX 1 + #endif +#endif + +/*A layout similar to Grid in CSS.*/ +#ifndef LV_USE_GRID + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_USE_GRID + #define LV_USE_GRID CONFIG_LV_USE_GRID + #else + #define LV_USE_GRID 0 + #endif + #else + #define LV_USE_GRID 1 + #endif +#endif + +/*--------------------- + * 3rd party libraries + *--------------------*/ + +/*File system interfaces for common APIs */ + +/*API for fopen, fread, etc*/ +#ifndef LV_USE_FS_STDIO + #ifdef CONFIG_LV_USE_FS_STDIO + #define LV_USE_FS_STDIO CONFIG_LV_USE_FS_STDIO + #else + #define LV_USE_FS_STDIO 0 + #endif +#endif +#if LV_USE_FS_STDIO + #ifndef LV_FS_STDIO_LETTER + #ifdef CONFIG_LV_FS_STDIO_LETTER + #define LV_FS_STDIO_LETTER CONFIG_LV_FS_STDIO_LETTER + #else + #define LV_FS_STDIO_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #endif + #endif + #ifndef LV_FS_STDIO_PATH + #ifdef CONFIG_LV_FS_STDIO_PATH + #define LV_FS_STDIO_PATH CONFIG_LV_FS_STDIO_PATH + #else + #define LV_FS_STDIO_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #endif + #endif + #ifndef LV_FS_STDIO_CACHE_SIZE + #ifdef CONFIG_LV_FS_STDIO_CACHE_SIZE + #define LV_FS_STDIO_CACHE_SIZE CONFIG_LV_FS_STDIO_CACHE_SIZE + #else + #define LV_FS_STDIO_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ + #endif + #endif +#endif + +/*API for open, read, etc*/ +#ifndef LV_USE_FS_POSIX + #ifdef CONFIG_LV_USE_FS_POSIX + #define LV_USE_FS_POSIX CONFIG_LV_USE_FS_POSIX + #else + #define LV_USE_FS_POSIX 0 + #endif +#endif +#if LV_USE_FS_POSIX + #ifndef LV_FS_POSIX_LETTER + #ifdef CONFIG_LV_FS_POSIX_LETTER + #define LV_FS_POSIX_LETTER CONFIG_LV_FS_POSIX_LETTER + #else + #define LV_FS_POSIX_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #endif + #endif + #ifndef LV_FS_POSIX_PATH + #ifdef CONFIG_LV_FS_POSIX_PATH + #define LV_FS_POSIX_PATH CONFIG_LV_FS_POSIX_PATH + #else + #define LV_FS_POSIX_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #endif + #endif + #ifndef LV_FS_POSIX_CACHE_SIZE + #ifdef CONFIG_LV_FS_POSIX_CACHE_SIZE + #define LV_FS_POSIX_CACHE_SIZE CONFIG_LV_FS_POSIX_CACHE_SIZE + #else + #define LV_FS_POSIX_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ + #endif + #endif +#endif + +/*API for CreateFile, ReadFile, etc*/ +#ifndef LV_USE_FS_WIN32 + #ifdef CONFIG_LV_USE_FS_WIN32 + #define LV_USE_FS_WIN32 CONFIG_LV_USE_FS_WIN32 + #else + #define LV_USE_FS_WIN32 0 + #endif +#endif +#if LV_USE_FS_WIN32 + #ifndef LV_FS_WIN32_LETTER + #ifdef CONFIG_LV_FS_WIN32_LETTER + #define LV_FS_WIN32_LETTER CONFIG_LV_FS_WIN32_LETTER + #else + #define LV_FS_WIN32_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #endif + #endif + #ifndef LV_FS_WIN32_PATH + #ifdef CONFIG_LV_FS_WIN32_PATH + #define LV_FS_WIN32_PATH CONFIG_LV_FS_WIN32_PATH + #else + #define LV_FS_WIN32_PATH "" /*Set the working directory. File/directory paths will be appended to it.*/ + #endif + #endif + #ifndef LV_FS_WIN32_CACHE_SIZE + #ifdef CONFIG_LV_FS_WIN32_CACHE_SIZE + #define LV_FS_WIN32_CACHE_SIZE CONFIG_LV_FS_WIN32_CACHE_SIZE + #else + #define LV_FS_WIN32_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ + #endif + #endif +#endif + +/*API for FATFS (needs to be added separately). Uses f_open, f_read, etc*/ +#ifndef LV_USE_FS_FATFS + #ifdef CONFIG_LV_USE_FS_FATFS + #define LV_USE_FS_FATFS CONFIG_LV_USE_FS_FATFS + #else + #define LV_USE_FS_FATFS 0 + #endif +#endif +#if LV_USE_FS_FATFS + #ifndef LV_FS_FATFS_LETTER + #ifdef CONFIG_LV_FS_FATFS_LETTER + #define LV_FS_FATFS_LETTER CONFIG_LV_FS_FATFS_LETTER + #else + #define LV_FS_FATFS_LETTER '\0' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/ + #endif + #endif + #ifndef LV_FS_FATFS_CACHE_SIZE + #ifdef CONFIG_LV_FS_FATFS_CACHE_SIZE + #define LV_FS_FATFS_CACHE_SIZE CONFIG_LV_FS_FATFS_CACHE_SIZE + #else + #define LV_FS_FATFS_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/ + #endif + #endif +#endif + +/*PNG decoder library*/ +#ifndef LV_USE_PNG + #ifdef CONFIG_LV_USE_PNG + #define LV_USE_PNG CONFIG_LV_USE_PNG + #else + #define LV_USE_PNG 0 + #endif +#endif + +/*BMP decoder library*/ +#ifndef LV_USE_BMP + #ifdef CONFIG_LV_USE_BMP + #define LV_USE_BMP CONFIG_LV_USE_BMP + #else + #define LV_USE_BMP 0 + #endif +#endif + +/* JPG + split JPG decoder library. + * Split JPG is a custom format optimized for embedded systems. */ +#ifndef LV_USE_SJPG + #ifdef CONFIG_LV_USE_SJPG + #define LV_USE_SJPG CONFIG_LV_USE_SJPG + #else + #define LV_USE_SJPG 0 + #endif +#endif + +/*GIF decoder library*/ +#ifndef LV_USE_GIF + #ifdef CONFIG_LV_USE_GIF + #define LV_USE_GIF CONFIG_LV_USE_GIF + #else + #define LV_USE_GIF 0 + #endif +#endif + +/*QR code library*/ +#ifndef LV_USE_QRCODE + #ifdef CONFIG_LV_USE_QRCODE + #define LV_USE_QRCODE CONFIG_LV_USE_QRCODE + #else + #define LV_USE_QRCODE 0 + #endif +#endif + +/*FreeType library*/ +#ifndef LV_USE_FREETYPE + #ifdef CONFIG_LV_USE_FREETYPE + #define LV_USE_FREETYPE CONFIG_LV_USE_FREETYPE + #else + #define LV_USE_FREETYPE 0 + #endif +#endif +#if LV_USE_FREETYPE + /*Memory used by FreeType to cache characters [bytes] (-1: no caching)*/ + #ifndef LV_FREETYPE_CACHE_SIZE + #ifdef CONFIG_LV_FREETYPE_CACHE_SIZE + #define LV_FREETYPE_CACHE_SIZE CONFIG_LV_FREETYPE_CACHE_SIZE + #else + #define LV_FREETYPE_CACHE_SIZE (16 * 1024) + #endif + #endif + #if LV_FREETYPE_CACHE_SIZE >= 0 + /* 1: bitmap cache use the sbit cache, 0:bitmap cache use the image cache. */ + /* sbit cache:it is much more memory efficient for small bitmaps(font size < 256) */ + /* if font size >= 256, must be configured as image cache */ + #ifndef LV_FREETYPE_SBIT_CACHE + #ifdef CONFIG_LV_FREETYPE_SBIT_CACHE + #define LV_FREETYPE_SBIT_CACHE CONFIG_LV_FREETYPE_SBIT_CACHE + #else + #define LV_FREETYPE_SBIT_CACHE 0 + #endif + #endif + /* Maximum number of opened FT_Face/FT_Size objects managed by this cache instance. */ + /* (0:use system defaults) */ + #ifndef LV_FREETYPE_CACHE_FT_FACES + #ifdef CONFIG_LV_FREETYPE_CACHE_FT_FACES + #define LV_FREETYPE_CACHE_FT_FACES CONFIG_LV_FREETYPE_CACHE_FT_FACES + #else + #define LV_FREETYPE_CACHE_FT_FACES 0 + #endif + #endif + #ifndef LV_FREETYPE_CACHE_FT_SIZES + #ifdef CONFIG_LV_FREETYPE_CACHE_FT_SIZES + #define LV_FREETYPE_CACHE_FT_SIZES CONFIG_LV_FREETYPE_CACHE_FT_SIZES + #else + #define LV_FREETYPE_CACHE_FT_SIZES 0 + #endif + #endif + #endif +#endif + +/*Rlottie library*/ +#ifndef LV_USE_RLOTTIE + #ifdef CONFIG_LV_USE_RLOTTIE + #define LV_USE_RLOTTIE CONFIG_LV_USE_RLOTTIE + #else + #define LV_USE_RLOTTIE 0 + #endif +#endif + +/*FFmpeg library for image decoding and playing videos + *Supports all major image formats so do not enable other image decoder with it*/ +#ifndef LV_USE_FFMPEG + #ifdef CONFIG_LV_USE_FFMPEG + #define LV_USE_FFMPEG CONFIG_LV_USE_FFMPEG + #else + #define LV_USE_FFMPEG 0 + #endif +#endif +#if LV_USE_FFMPEG + /*Dump input information to stderr*/ + #ifndef LV_FFMPEG_DUMP_FORMAT + #ifdef CONFIG_LV_FFMPEG_DUMP_FORMAT + #define LV_FFMPEG_DUMP_FORMAT CONFIG_LV_FFMPEG_DUMP_FORMAT + #else + #define LV_FFMPEG_DUMP_FORMAT 0 + #endif + #endif +#endif + +/*----------- + * Others + *----------*/ + +/*1: Enable API to take snapshot for object*/ +#ifndef LV_USE_SNAPSHOT + #ifdef CONFIG_LV_USE_SNAPSHOT + #define LV_USE_SNAPSHOT CONFIG_LV_USE_SNAPSHOT + #else + #define LV_USE_SNAPSHOT 0 + #endif +#endif + +/*1: Enable Monkey test*/ +#ifndef LV_USE_MONKEY + #ifdef CONFIG_LV_USE_MONKEY + #define LV_USE_MONKEY CONFIG_LV_USE_MONKEY + #else + #define LV_USE_MONKEY 0 + #endif +#endif + +/*1: Enable grid navigation*/ +#ifndef LV_USE_GRIDNAV + #ifdef CONFIG_LV_USE_GRIDNAV + #define LV_USE_GRIDNAV CONFIG_LV_USE_GRIDNAV + #else + #define LV_USE_GRIDNAV 0 + #endif +#endif + +/*1: Enable lv_obj fragment*/ +#ifndef LV_USE_FRAGMENT + #ifdef CONFIG_LV_USE_FRAGMENT + #define LV_USE_FRAGMENT CONFIG_LV_USE_FRAGMENT + #else + #define LV_USE_FRAGMENT 0 + #endif +#endif + +/*1: Support using images as font in label or span widgets */ +#ifndef LV_USE_IMGFONT + #ifdef CONFIG_LV_USE_IMGFONT + #define LV_USE_IMGFONT CONFIG_LV_USE_IMGFONT + #else + #define LV_USE_IMGFONT 0 + #endif +#endif + +/*1: Enable a published subscriber based messaging system */ +#ifndef LV_USE_MSG + #ifdef CONFIG_LV_USE_MSG + #define LV_USE_MSG CONFIG_LV_USE_MSG + #else + #define LV_USE_MSG 0 + #endif +#endif + +/*1: Enable Pinyin input method*/ +/*Requires: lv_keyboard*/ +#ifndef LV_USE_IME_PINYIN + #ifdef CONFIG_LV_USE_IME_PINYIN + #define LV_USE_IME_PINYIN CONFIG_LV_USE_IME_PINYIN + #else + #define LV_USE_IME_PINYIN 0 + #endif +#endif +#if LV_USE_IME_PINYIN + /*1: Use default thesaurus*/ + /*If you do not use the default thesaurus, be sure to use `lv_ime_pinyin` after setting the thesauruss*/ + #ifndef LV_IME_PINYIN_USE_DEFAULT_DICT + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_IME_PINYIN_USE_DEFAULT_DICT + #define LV_IME_PINYIN_USE_DEFAULT_DICT CONFIG_LV_IME_PINYIN_USE_DEFAULT_DICT + #else + #define LV_IME_PINYIN_USE_DEFAULT_DICT 0 + #endif + #else + #define LV_IME_PINYIN_USE_DEFAULT_DICT 1 + #endif + #endif + /*Set the maximum number of candidate panels that can be displayed*/ + /*This needs to be adjusted according to the size of the screen*/ + #ifndef LV_IME_PINYIN_CAND_TEXT_NUM + #ifdef CONFIG_LV_IME_PINYIN_CAND_TEXT_NUM + #define LV_IME_PINYIN_CAND_TEXT_NUM CONFIG_LV_IME_PINYIN_CAND_TEXT_NUM + #else + #define LV_IME_PINYIN_CAND_TEXT_NUM 6 + #endif + #endif + + /*Use 9 key input(k9)*/ + #ifndef LV_IME_PINYIN_USE_K9_MODE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_IME_PINYIN_USE_K9_MODE + #define LV_IME_PINYIN_USE_K9_MODE CONFIG_LV_IME_PINYIN_USE_K9_MODE + #else + #define LV_IME_PINYIN_USE_K9_MODE 0 + #endif + #else + #define LV_IME_PINYIN_USE_K9_MODE 1 + #endif + #endif + #if LV_IME_PINYIN_USE_K9_MODE == 1 + #ifndef LV_IME_PINYIN_K9_CAND_TEXT_NUM + #ifdef CONFIG_LV_IME_PINYIN_K9_CAND_TEXT_NUM + #define LV_IME_PINYIN_K9_CAND_TEXT_NUM CONFIG_LV_IME_PINYIN_K9_CAND_TEXT_NUM + #else + #define LV_IME_PINYIN_K9_CAND_TEXT_NUM 3 + #endif + #endif + #endif // LV_IME_PINYIN_USE_K9_MODE +#endif + +/*================== +* EXAMPLES +*==================*/ + +/*Enable the examples to be built with the library*/ +#ifndef LV_BUILD_EXAMPLES + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_BUILD_EXAMPLES + #define LV_BUILD_EXAMPLES CONFIG_LV_BUILD_EXAMPLES + #else + #define LV_BUILD_EXAMPLES 0 + #endif + #else + #define LV_BUILD_EXAMPLES 1 + #endif +#endif + +/*=================== + * DEMO USAGE + ====================*/ + +/*Show some widget. It might be required to increase `LV_MEM_SIZE` */ +#ifndef LV_USE_DEMO_WIDGETS + #ifdef CONFIG_LV_USE_DEMO_WIDGETS + #define LV_USE_DEMO_WIDGETS CONFIG_LV_USE_DEMO_WIDGETS + #else + #define LV_USE_DEMO_WIDGETS 0 + #endif +#endif +#if LV_USE_DEMO_WIDGETS +#ifndef LV_DEMO_WIDGETS_SLIDESHOW + #ifdef CONFIG_LV_DEMO_WIDGETS_SLIDESHOW + #define LV_DEMO_WIDGETS_SLIDESHOW CONFIG_LV_DEMO_WIDGETS_SLIDESHOW + #else + #define LV_DEMO_WIDGETS_SLIDESHOW 0 + #endif +#endif +#endif + +/*Demonstrate the usage of encoder and keyboard*/ +#ifndef LV_USE_DEMO_KEYPAD_AND_ENCODER + #ifdef CONFIG_LV_USE_DEMO_KEYPAD_AND_ENCODER + #define LV_USE_DEMO_KEYPAD_AND_ENCODER CONFIG_LV_USE_DEMO_KEYPAD_AND_ENCODER + #else + #define LV_USE_DEMO_KEYPAD_AND_ENCODER 0 + #endif +#endif + +/*Benchmark your system*/ +#ifndef LV_USE_DEMO_BENCHMARK + #ifdef CONFIG_LV_USE_DEMO_BENCHMARK + #define LV_USE_DEMO_BENCHMARK CONFIG_LV_USE_DEMO_BENCHMARK + #else + #define LV_USE_DEMO_BENCHMARK 0 + #endif +#endif +#if LV_USE_DEMO_BENCHMARK +/*Use RGB565A8 images with 16 bit color depth instead of ARGB8565*/ +#ifndef LV_DEMO_BENCHMARK_RGB565A8 + #ifdef CONFIG_LV_DEMO_BENCHMARK_RGB565A8 + #define LV_DEMO_BENCHMARK_RGB565A8 CONFIG_LV_DEMO_BENCHMARK_RGB565A8 + #else + #define LV_DEMO_BENCHMARK_RGB565A8 0 + #endif +#endif +#endif + +/*Stress test for LVGL*/ +#ifndef LV_USE_DEMO_STRESS + #ifdef CONFIG_LV_USE_DEMO_STRESS + #define LV_USE_DEMO_STRESS CONFIG_LV_USE_DEMO_STRESS + #else + #define LV_USE_DEMO_STRESS 0 + #endif +#endif + +/*Music player demo*/ +#ifndef LV_USE_DEMO_MUSIC + #ifdef CONFIG_LV_USE_DEMO_MUSIC + #define LV_USE_DEMO_MUSIC CONFIG_LV_USE_DEMO_MUSIC + #else + #define LV_USE_DEMO_MUSIC 0 + #endif +#endif +#if LV_USE_DEMO_MUSIC + #ifndef LV_DEMO_MUSIC_SQUARE + #ifdef CONFIG_LV_DEMO_MUSIC_SQUARE + #define LV_DEMO_MUSIC_SQUARE CONFIG_LV_DEMO_MUSIC_SQUARE + #else + #define LV_DEMO_MUSIC_SQUARE 0 + #endif + #endif + #ifndef LV_DEMO_MUSIC_LANDSCAPE + #ifdef CONFIG_LV_DEMO_MUSIC_LANDSCAPE + #define LV_DEMO_MUSIC_LANDSCAPE CONFIG_LV_DEMO_MUSIC_LANDSCAPE + #else + #define LV_DEMO_MUSIC_LANDSCAPE 0 + #endif + #endif + #ifndef LV_DEMO_MUSIC_ROUND + #ifdef CONFIG_LV_DEMO_MUSIC_ROUND + #define LV_DEMO_MUSIC_ROUND CONFIG_LV_DEMO_MUSIC_ROUND + #else + #define LV_DEMO_MUSIC_ROUND 0 + #endif + #endif + #ifndef LV_DEMO_MUSIC_LARGE + #ifdef CONFIG_LV_DEMO_MUSIC_LARGE + #define LV_DEMO_MUSIC_LARGE CONFIG_LV_DEMO_MUSIC_LARGE + #else + #define LV_DEMO_MUSIC_LARGE 0 + #endif + #endif + #ifndef LV_DEMO_MUSIC_AUTO_PLAY + #ifdef CONFIG_LV_DEMO_MUSIC_AUTO_PLAY + #define LV_DEMO_MUSIC_AUTO_PLAY CONFIG_LV_DEMO_MUSIC_AUTO_PLAY + #else + #define LV_DEMO_MUSIC_AUTO_PLAY 0 + #endif + #endif +#endif + + + +/*---------------------------------- + * End of parsing lv_conf_template.h + -----------------------------------*/ + +LV_EXPORT_CONST_INT(LV_DPI_DEF); + +#undef _LV_KCONFIG_PRESENT + + +/*Set some defines if a dependency is disabled*/ +#if LV_USE_LOG == 0 + #define LV_LOG_LEVEL LV_LOG_LEVEL_NONE + #define LV_LOG_TRACE_MEM 0 + #define LV_LOG_TRACE_TIMER 0 + #define LV_LOG_TRACE_INDEV 0 + #define LV_LOG_TRACE_DISP_REFR 0 + #define LV_LOG_TRACE_EVENT 0 + #define LV_LOG_TRACE_OBJ_CREATE 0 + #define LV_LOG_TRACE_LAYOUT 0 + #define LV_LOG_TRACE_ANIM 0 +#endif /*LV_USE_LOG*/ + + +/*If running without lv_conf.h add typedefs with default value*/ +#ifdef LV_CONF_SKIP + #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /*Disable warnings for Visual Studio*/ + #define _CRT_SECURE_NO_WARNINGS + #endif +#endif /*defined(LV_CONF_SKIP)*/ + +#endif /*LV_CONF_INTERNAL_H*/ diff --git a/include/liblvgl/lv_conf_kconfig.h b/include/liblvgl/lv_conf_kconfig.h new file mode 100644 index 00000000..7742fe77 --- /dev/null +++ b/include/liblvgl/lv_conf_kconfig.h @@ -0,0 +1,182 @@ +/** * @file lv_conf_kconfig.h * Configs that need special handling when LVGL is used with Kconfig */ + +#ifndef LV_CONF_KCONFIG_H +#define LV_CONF_KCONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef LV_CONF_KCONFIG_EXTERNAL_INCLUDE +# include LV_CONF_KCONFIG_EXTERNAL_INCLUDE +#else + +# ifdef ESP_PLATFORM +# include "sdkconfig.h" +# include "esp_attr.h" +# endif + +# ifdef __NuttX__ +# include +# elif defined(__RTTHREAD__) +# define LV_CONF_INCLUDE_SIMPLE +# include +# endif + +#endif /*LV_CONF_KCONFIG_EXTERNAL_INCLUDE*/ + +/******************* + * LV COLOR CHROMA KEY + *******************/ + +#ifdef CONFIG_LV_COLOR_CHROMA_KEY_HEX +# define CONFIG_LV_COLOR_CHROMA_KEY lv_color_hex(CONFIG_LV_COLOR_CHROMA_KEY_HEX) +#endif + +/******************* + * LV_MEM_SIZE + *******************/ + +#ifdef CONFIG_LV_MEM_SIZE_KILOBYTES +# define CONFIG_LV_MEM_SIZE (CONFIG_LV_MEM_SIZE_KILOBYTES * 1024U) +#endif + +/*------------------ + * MONITOR POSITION + *-----------------*/ + +#ifdef CONFIG_LV_PERF_MONITOR_ALIGN_TOP_LEFT +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_LEFT +#elif defined(CONFIG_LV_USE_PERF_MONITOR_ALIGN_TOP_MID) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_MID +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_TOP_RIGHT) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_TOP_RIGHT +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_BOTTOM_LEFT) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_LEFT +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_BOTTOM_MID) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_MID +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_BOTTOM_RIGHT) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_LEFT_MID) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_LEFT_MID +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_RIGHT_MID) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_RIGHT_MID +#elif defined(CONFIG_LV_PERF_MONITOR_ALIGN_CENTER) +# define CONFIG_LV_USE_PERF_MONITOR_POS LV_ALIGN_CENTER +#endif + +#ifdef CONFIG_LV_MEM_MONITOR_ALIGN_TOP_LEFT +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_TOP_LEFT +#elif defined(CONFIG_LV_USE_MEM_MONITOR_ALIGN_TOP_MID) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_TOP_MID +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_TOP_RIGHT) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_TOP_RIGHT +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_BOTTOM_LEFT) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_BOTTOM_MID) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_MID +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_BOTTOM_RIGHT) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_LEFT_MID) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_LEFT_MID +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_RIGHT_MID) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_RIGHT_MID +#elif defined(CONFIG_LV_MEM_MONITOR_ALIGN_CENTER) +# define CONFIG_LV_USE_MEM_MONITOR_POS LV_ALIGN_CENTER +#endif + +/******************** + * FONT SELECTION + *******************/ + +/** + * NOTE: In Kconfig instead of `LV_DEFAULT_FONT` + * `CONFIG_LV_FONT_DEFAULT_` is defined + * hence the large selection with if-s + */ + +/*------------------ + * DEFAULT FONT + *-----------------*/ +#ifdef CONFIG_LV_FONT_DEFAULT_MONTSERRAT_8 +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_8 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_10) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_10 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_12) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_12 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_14) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_14 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_16) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_16 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_18) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_18 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_20) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_20 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_22) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_22 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_24) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_24 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_26) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_26 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_28) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_28 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_30) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_30 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_32 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_34) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_34 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_36) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_36 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_38) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_38 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_40) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_40 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_42) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_42 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_44) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_44 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_46) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_46 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_48) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_48 +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_12_SUBPX) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_12_subpx +#elif defined(CONFIG_LV_FONT_DEFAULT_MONTSERRAT_28_COMPRESSED) +# define CONFIG_LV_FONT_DEFAULT &lv_font_montserrat_28_compressed +#elif defined(CONFIG_LV_FONT_DEFAULT_DEJAVU_16_PERSIAN_HEBREW) +# define CONFIG_LV_FONT_DEFAULT &lv_font_dejavu_16_persian_hebrew +#elif defined(CONFIG_LV_FONT_DEFAULT_SIMSUN_16_CJK) +# define CONFIG_LV_FONT_DEFAULT &lv_font_simsun_16_cjk +#elif defined(CONFIG_LV_FONT_DEFAULT_UNSCII_8) +# define CONFIG_LV_FONT_DEFAULT &lv_font_unscii_8 +#elif defined(CONFIG_LV_FONT_DEFAULT_UNSCII_16) +# define CONFIG_LV_FONT_DEFAULT &lv_font_unscii_16 +#endif + +/*------------------ + * TEXT ENCODING + *-----------------*/ +#ifdef CONFIG_LV_TXT_ENC_UTF8 +# define CONFIG_LV_TXT_ENC LV_TXT_ENC_UTF8 +#elif defined(CONFIG_LV_TXT_ENC_ASCII) +# define CONFIG_LV_TXT_ENC LV_TXT_ENC_ASCII +#endif + +/*------------------ + * BIDI DIRECTION + *-----------------*/ + +#ifdef CONFIG_LV_BASE_DIR_LTR +# define CONFIG_LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_LTR +#elif defined(CONFIG_LV_BASE_DIR_RTL) +# define CONFIG_LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_RTL +#elif defined(CONFIG_LV_BASE_DIR_AUTO) +# define CONFIG_LV_BIDI_BASE_DIR_DEF LV_BASE_DIR_AUTO +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CONF_KCONFIG_H*/ diff --git a/include/liblvgl/lvgl.h b/include/liblvgl/lvgl.h new file mode 100644 index 00000000..60d29f5d --- /dev/null +++ b/include/liblvgl/lvgl.h @@ -0,0 +1,138 @@ +/** + * @file lvgl.h + * Include all LVGL related headers + */ + +#ifndef LVGL_H +#define LVGL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************** + * CURRENT VERSION OF LVGL + ***************************/ +#define LVGL_VERSION_MAJOR 8 +#define LVGL_VERSION_MINOR 3 +#define LVGL_VERSION_PATCH 4 +#define LVGL_VERSION_INFO "dev" + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/misc/lv_log.h" +#include "liblvgl/misc/lv_timer.h" +#include "liblvgl/misc/lv_math.h" +#include "liblvgl/misc/lv_mem.h" +#include "liblvgl/misc/lv_async.h" +#include "liblvgl/misc/lv_anim_timeline.h" +#include "liblvgl/misc/lv_printf.h" + +#include "liblvgl/hal/lv_hal.h" + +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/core/lv_group.h" +#include "liblvgl/core/lv_indev.h" +#include "liblvgl/core/lv_refr.h" +#include "liblvgl/core/lv_disp.h" +#include "liblvgl/core/lv_theme.h" + +#include "liblvgl/font/lv_font.h" +#include "liblvgl/font/lv_font_loader.h" +#include "liblvgl/font/lv_font_fmt_txt.h" + +#include "liblvgl/widgets/lv_arc.h" +#include "liblvgl/widgets/lv_btn.h" +#include "liblvgl/widgets/lv_img.h" +#include "liblvgl/widgets/lv_label.h" +#include "liblvgl/widgets/lv_line.h" +#include "liblvgl/widgets/lv_table.h" +#include "liblvgl/widgets/lv_checkbox.h" +#include "liblvgl/widgets/lv_bar.h" +#include "liblvgl/widgets/lv_slider.h" +#include "liblvgl/widgets/lv_btnmatrix.h" +#include "liblvgl/widgets/lv_dropdown.h" +#include "liblvgl/widgets/lv_roller.h" +#include "liblvgl/widgets/lv_textarea.h" +#include "liblvgl/widgets/lv_canvas.h" +#include "liblvgl/widgets/lv_switch.h" + +#include "liblvgl/draw/lv_draw.h" + +#include "liblvgl/lv_api_map.h" + +/*----------------- + * EXTRAS + *----------------*/ +#include "liblvgl/extra/lv_extra.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +/** Gives 1 if the x.y.z version is supported in the current version + * Usage: + * + * - Require v6 + * #if LV_VERSION_CHECK(6,0,0) + * new_func_in_v6(); + * #endif + * + * + * - Require at least v5.3 + * #if LV_VERSION_CHECK(5,3,0) + * new_feature_from_v5_3(); + * #endif + * + * + * - Require v5.3.2 bugfixes + * #if LV_VERSION_CHECK(5,3,2) + * bugfix_in_v5_3_2(); + * #endif + * + */ +#define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) + +/** + * Wrapper functions for VERSION macros + */ + +static inline int lv_version_major(void) +{ + return LVGL_VERSION_MAJOR; +} + +static inline int lv_version_minor(void) +{ + return LVGL_VERSION_MINOR; +} + +static inline int lv_version_patch(void) +{ + return LVGL_VERSION_PATCH; +} + +static inline const char *lv_version_info(void) +{ + return LVGL_VERSION_INFO; +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LVGL_H*/ diff --git a/include/liblvgl/misc/lv_anim.h b/include/liblvgl/misc/lv_anim.h new file mode 100644 index 00000000..cb460ab8 --- /dev/null +++ b/include/liblvgl/misc/lv_anim.h @@ -0,0 +1,484 @@ +/** + * @file lv_anim.h + * + */ + +#ifndef LV_ANIM_H +#define LV_ANIM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include + +/********************* + * DEFINES + *********************/ + +#define LV_ANIM_REPEAT_INFINITE 0xFFFF +#define LV_ANIM_PLAYTIME_INFINITE 0xFFFFFFFF + +LV_EXPORT_CONST_INT(LV_ANIM_REPEAT_INFINITE); +LV_EXPORT_CONST_INT(LV_ANIM_PLAYTIME_INFINITE); + +/********************** + * TYPEDEFS + **********************/ + +/** Can be used to indicate if animations are enabled or disabled in a case*/ +typedef enum { + LV_ANIM_OFF, + LV_ANIM_ON, +} lv_anim_enable_t; + +struct _lv_anim_t; +struct _lv_timer_t; + +/** Get the current value during an animation*/ +typedef int32_t (*lv_anim_path_cb_t)(const struct _lv_anim_t *); + +/** Generic prototype of "animator" functions. + * First parameter is the variable to animate. + * Second parameter is the value to set. + * Compatible with `lv_xxx_set_yyy(obj, value)` functions + * The `x` in `_xcb_t` means it's not a fully generic prototype because + * it doesn't receive `lv_anim_t *` as its first argument*/ +typedef void (*lv_anim_exec_xcb_t)(void *, int32_t); + +/** Same as `lv_anim_exec_xcb_t` but receives `lv_anim_t *` as the first parameter. + * It's more consistent but less convenient. Might be used by binding generator functions.*/ +typedef void (*lv_anim_custom_exec_cb_t)(struct _lv_anim_t *, int32_t); + +/** Callback to call when the animation is ready*/ +typedef void (*lv_anim_ready_cb_t)(struct _lv_anim_t *); + +/** Callback to call when the animation really stars (considering `delay`)*/ +typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *); + +/** Callback used when the animation values are relative to get the current value*/ +typedef int32_t (*lv_anim_get_value_cb_t)(struct _lv_anim_t *); + +/** Callback used when the animation is deleted*/ +typedef void (*lv_anim_deleted_cb_t)(struct _lv_anim_t *); + +/** Describes an animation*/ +typedef struct _lv_anim_t { + void * var; /**var = var; +} + +/** + * Set a function to animate `var` + * @param a pointer to an initialized `lv_anim_t` variable + * @param exec_cb a function to execute during animation + * LVGL's built-in functions can be used. + * E.g. lv_obj_set_x + */ +static inline void lv_anim_set_exec_cb(lv_anim_t * a, lv_anim_exec_xcb_t exec_cb) +{ + a->exec_cb = exec_cb; +} + +/** + * Set the duration of an animation + * @param a pointer to an initialized `lv_anim_t` variable + * @param duration duration of the animation in milliseconds + */ +static inline void lv_anim_set_time(lv_anim_t * a, uint32_t duration) +{ + a->time = duration; +} + +/** + * Set a delay before starting the animation + * @param a pointer to an initialized `lv_anim_t` variable + * @param delay delay before the animation in milliseconds + */ +static inline void lv_anim_set_delay(lv_anim_t * a, uint32_t delay) +{ + a->act_time = -(int32_t)(delay); +} + +/** + * Set the start and end values of an animation + * @param a pointer to an initialized `lv_anim_t` variable + * @param start the start value + * @param end the end value + */ +static inline void lv_anim_set_values(lv_anim_t * a, int32_t start, int32_t end) +{ + a->start_value = start; + a->current_value = start; + a->end_value = end; +} + +/** + * Similar to `lv_anim_set_exec_cb` but `lv_anim_custom_exec_cb_t` receives + * `lv_anim_t * ` as its first parameter instead of `void *`. + * This function might be used when LVGL is bound to other languages because + * it's more consistent to have `lv_anim_t *` as first parameter. + * The variable to animate can be stored in the animation's `user_data` + * @param a pointer to an initialized `lv_anim_t` variable + * @param exec_cb a function to execute. + */ +static inline void lv_anim_set_custom_exec_cb(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb) +{ + a->var = a; + a->exec_cb = (lv_anim_exec_xcb_t)exec_cb; +} + +/** + * Set the path (curve) of the animation. + * @param a pointer to an initialized `lv_anim_t` variable + * @param path_cb a function to set the current value of the animation. + */ +static inline void lv_anim_set_path_cb(lv_anim_t * a, lv_anim_path_cb_t path_cb) +{ + a->path_cb = path_cb; +} + +/** + * Set a function call when the animation really starts (considering `delay`) + * @param a pointer to an initialized `lv_anim_t` variable + * @param start_cb a function call when the animation starts + */ +static inline void lv_anim_set_start_cb(lv_anim_t * a, lv_anim_start_cb_t start_cb) +{ + a->start_cb = start_cb; +} + +/** + * Set a function to use the current value of the variable and make start and end value + * relative to the returned current value. + * @param a pointer to an initialized `lv_anim_t` variable + * @param get_value_cb a function call when the animation starts + */ +static inline void lv_anim_set_get_value_cb(lv_anim_t * a, lv_anim_get_value_cb_t get_value_cb) +{ + a->get_value_cb = get_value_cb; +} + +/** + * Set a function call when the animation is ready + * @param a pointer to an initialized `lv_anim_t` variable + * @param ready_cb a function call when the animation is ready + */ +static inline void lv_anim_set_ready_cb(lv_anim_t * a, lv_anim_ready_cb_t ready_cb) +{ + a->ready_cb = ready_cb; +} + +/** + * Set a function call when the animation is deleted. + * @param a pointer to an initialized `lv_anim_t` variable + * @param deleted_cb a function call when the animation is deleted + */ +static inline void lv_anim_set_deleted_cb(lv_anim_t * a, lv_anim_deleted_cb_t deleted_cb) +{ + a->deleted_cb = deleted_cb; +} + +/** + * Make the animation to play back to when the forward direction is ready + * @param a pointer to an initialized `lv_anim_t` variable + * @param time the duration of the playback animation in milliseconds. 0: disable playback + */ +static inline void lv_anim_set_playback_time(lv_anim_t * a, uint32_t time) +{ + a->playback_time = time; +} + +/** + * Make the animation to play back to when the forward direction is ready + * @param a pointer to an initialized `lv_anim_t` variable + * @param delay delay in milliseconds before starting the playback animation. + */ +static inline void lv_anim_set_playback_delay(lv_anim_t * a, uint32_t delay) +{ + a->playback_delay = delay; +} + +/** + * Make the animation repeat itself. + * @param a pointer to an initialized `lv_anim_t` variable + * @param cnt repeat count or `LV_ANIM_REPEAT_INFINITE` for infinite repetition. 0: to disable repetition. + */ +static inline void lv_anim_set_repeat_count(lv_anim_t * a, uint16_t cnt) +{ + a->repeat_cnt = cnt; +} + +/** + * Set a delay before repeating the animation. + * @param a pointer to an initialized `lv_anim_t` variable + * @param delay delay in milliseconds before repeating the animation. + */ +static inline void lv_anim_set_repeat_delay(lv_anim_t * a, uint32_t delay) +{ + a->repeat_delay = delay; +} + +/** + * Set a whether the animation's should be applied immediately or only when the delay expired. + * @param a pointer to an initialized `lv_anim_t` variable + * @param en true: apply the start value immediately in `lv_anim_start`; + * false: apply the start value only when `delay` ms is elapsed and the animations really starts + */ +static inline void lv_anim_set_early_apply(lv_anim_t * a, bool en) +{ + a->early_apply = en; +} + +/** + * Set the custom user data field of the animation. + * @param a pointer to an initialized `lv_anim_t` variable + * @param user_data pointer to the new user_data. + */ +#if LV_USE_USER_DATA +static inline void lv_anim_set_user_data(lv_anim_t * a, void * user_data) +{ + a->user_data = user_data; +} +#endif + +/** + * Create an animation + * @param a an initialized 'anim_t' variable. Not required after call. + * @return pointer to the created animation (different from the `a` parameter) + */ +lv_anim_t * lv_anim_start(const lv_anim_t * a); + +/** + * Get a delay before starting the animation + * @param a pointer to an initialized `lv_anim_t` variable + * @return delay before the animation in milliseconds + */ +static inline uint32_t lv_anim_get_delay(lv_anim_t * a) +{ + return -a->act_time; +} + +/** + * Get the time used to play the animation. + * @param a pointer to an animation. + * @return the play time in milliseconds. + */ +uint32_t lv_anim_get_playtime(lv_anim_t * a); + +/** + * Get the user_data field of the animation + * @param a pointer to an initialized `lv_anim_t` variable + * @return the pointer to the custom user_data of the animation + */ +#if LV_USE_USER_DATA +static inline void * lv_anim_get_user_data(lv_anim_t * a) +{ + return a->user_data; +} +#endif + +/** + * Delete an animation of a variable with a given animator function + * @param var pointer to variable + * @param exec_cb a function pointer which is animating 'var', + * or NULL to ignore it and delete all the animations of 'var + * @return true: at least 1 animation is deleted, false: no animation is deleted + */ +bool lv_anim_del(void * var, lv_anim_exec_xcb_t exec_cb); + +/** + * Delete all the animations + */ +void lv_anim_del_all(void); + +/** + * Get the animation of a variable and its `exec_cb`. + * @param var pointer to variable + * @param exec_cb a function pointer which is animating 'var', or NULL to return first matching 'var' + * @return pointer to the animation. + */ +lv_anim_t * lv_anim_get(void * var, lv_anim_exec_xcb_t exec_cb); + +/** + * Get global animation refresher timer. + * @return pointer to the animation refresher timer. + */ +struct _lv_timer_t * lv_anim_get_timer(void); + +/** + * Delete an animation by getting the animated variable from `a`. + * Only animations with `exec_cb` will be deleted. + * This function exists because it's logical that all anim. functions receives an + * `lv_anim_t` as their first parameter. It's not practical in C but might make + * the API more consequent and makes easier to generate bindings. + * @param a pointer to an animation. + * @param exec_cb a function pointer which is animating 'var', + * or NULL to ignore it and delete all the animations of 'var + * @return true: at least 1 animation is deleted, false: no animation is deleted + */ +static inline bool lv_anim_custom_del(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb) +{ + return lv_anim_del(a ? a->var : NULL, (lv_anim_exec_xcb_t)exec_cb); +} + +/** + * Get the animation of a variable and its `exec_cb`. + * This function exists because it's logical that all anim. functions receives an + * `lv_anim_t` as their first parameter. It's not practical in C but might make + * the API more consequent and makes easier to generate bindings. + * @param a pointer to an animation. + * @param exec_cb a function pointer which is animating 'var', or NULL to return first matching 'var' + * @return pointer to the animation. + */ +static inline lv_anim_t * lv_anim_custom_get(lv_anim_t * a, lv_anim_custom_exec_cb_t exec_cb) +{ + return lv_anim_get(a ? a->var : NULL, (lv_anim_exec_xcb_t)exec_cb); +} + +/** + * Get the number of currently running animations + * @return the number of running animations + */ +uint16_t lv_anim_count_running(void); + +/** + * Calculate the time of an animation with a given speed and the start and end values + * @param speed speed of animation in unit/sec + * @param start start value of the animation + * @param end end value of the animation + * @return the required time [ms] for the animation with the given parameters + */ +uint32_t lv_anim_speed_to_time(uint32_t speed, int32_t start, int32_t end); + +/** + * Manually refresh the state of the animations. + * Useful to make the animations running in a blocking process where + * `lv_timer_handler` can't run for a while. + * Shouldn't be used directly because it is called in `lv_refr_now()`. + */ +void lv_anim_refr_now(void); + +/** + * Calculate the current value of an animation applying linear characteristic + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_linear(const lv_anim_t * a); + +/** + * Calculate the current value of an animation slowing down the start phase + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_in(const lv_anim_t * a); + +/** + * Calculate the current value of an animation slowing down the end phase + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_out(const lv_anim_t * a); + +/** + * Calculate the current value of an animation applying an "S" characteristic (cosine) + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_ease_in_out(const lv_anim_t * a); + +/** + * Calculate the current value of an animation with overshoot at the end + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_overshoot(const lv_anim_t * a); + +/** + * Calculate the current value of an animation with 3 bounces + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_bounce(const lv_anim_t * a); + +/** + * Calculate the current value of an animation applying step characteristic. + * (Set end value on the end of the animation) + * @param a pointer to an animation + * @return the current value to set + */ +int32_t lv_anim_path_step(const lv_anim_t * a); + +/********************** + * GLOBAL VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ANIM_H*/ diff --git a/include/liblvgl/misc/lv_anim_timeline.h b/include/liblvgl/misc/lv_anim_timeline.h new file mode 100644 index 00000000..d4dd0fcf --- /dev/null +++ b/include/liblvgl/misc/lv_anim_timeline.h @@ -0,0 +1,103 @@ +/** + * @file lv_anim_timeline.h + * + */ + +#ifndef LV_ANIM_TIMELINE_H +#define LV_ANIM_TIMELINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_anim.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_anim_timeline_t; + +typedef struct _lv_anim_timeline_t lv_anim_timeline_t; + +/********************** +* GLOBAL PROTOTYPES +**********************/ + +/** + * Create an animation timeline. + * @return pointer to the animation timeline. + */ +lv_anim_timeline_t * lv_anim_timeline_create(void); + +/** + * Delete animation timeline. + * @param at pointer to the animation timeline. + */ +void lv_anim_timeline_del(lv_anim_timeline_t * at); + +/** + * Add animation to the animation timeline. + * @param at pointer to the animation timeline. + * @param start_time the time the animation started on the timeline, note that start_time will override the value of delay. + * @param a pointer to an animation. + */ +void lv_anim_timeline_add(lv_anim_timeline_t * at, uint32_t start_time, lv_anim_t * a); + +/** + * Start the animation timeline. + * @param at pointer to the animation timeline. + * @return total time spent in animation timeline. + */ +uint32_t lv_anim_timeline_start(lv_anim_timeline_t * at); + +/** + * Stop the animation timeline. + * @param at pointer to the animation timeline. + */ +void lv_anim_timeline_stop(lv_anim_timeline_t * at); + +/** + * Set the playback direction of the animation timeline. + * @param at pointer to the animation timeline. + * @param reverse whether to play in reverse. + */ +void lv_anim_timeline_set_reverse(lv_anim_timeline_t * at, bool reverse); + +/** + * Set the progress of the animation timeline. + * @param at pointer to the animation timeline. + * @param progress set value 0~65535 to map 0~100% animation progress. + */ +void lv_anim_timeline_set_progress(lv_anim_timeline_t * at, uint16_t progress); + +/** + * Get the time used to play the animation timeline. + * @param at pointer to the animation timeline. + * @return total time spent in animation timeline. + */ +uint32_t lv_anim_timeline_get_playtime(lv_anim_timeline_t * at); + +/** + * Get whether the animation timeline is played in reverse. + * @param at pointer to the animation timeline. + * @return return true if it is reverse playback. + */ +bool lv_anim_timeline_get_reverse(lv_anim_timeline_t * at); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ANIM_TIMELINE_H*/ diff --git a/include/liblvgl/misc/lv_area.h b/include/liblvgl/misc/lv_area.h new file mode 100644 index 00000000..036767b8 --- /dev/null +++ b/include/liblvgl/misc/lv_area.h @@ -0,0 +1,295 @@ +/** + * @file lv_area.h + * + */ + +#ifndef LV_AREA_H +#define LV_AREA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include +#include + +/********************* + * DEFINES + *********************/ + +#if LV_USE_LARGE_COORD +typedef int32_t lv_coord_t; +#else +typedef int16_t lv_coord_t; +#endif + +/********************** + * TYPEDEFS + **********************/ + +/** + * Represents a point on the screen. + */ +typedef struct { + lv_coord_t x; + lv_coord_t y; +} lv_point_t; + +/** Represents an area of the screen.*/ +typedef struct { + lv_coord_t x1; + lv_coord_t y1; + lv_coord_t x2; + lv_coord_t y2; +} lv_area_t; + +/** Alignments*/ +enum { + LV_ALIGN_DEFAULT = 0, + LV_ALIGN_TOP_LEFT, + LV_ALIGN_TOP_MID, + LV_ALIGN_TOP_RIGHT, + LV_ALIGN_BOTTOM_LEFT, + LV_ALIGN_BOTTOM_MID, + LV_ALIGN_BOTTOM_RIGHT, + LV_ALIGN_LEFT_MID, + LV_ALIGN_RIGHT_MID, + LV_ALIGN_CENTER, + + LV_ALIGN_OUT_TOP_LEFT, + LV_ALIGN_OUT_TOP_MID, + LV_ALIGN_OUT_TOP_RIGHT, + LV_ALIGN_OUT_BOTTOM_LEFT, + LV_ALIGN_OUT_BOTTOM_MID, + LV_ALIGN_OUT_BOTTOM_RIGHT, + LV_ALIGN_OUT_LEFT_TOP, + LV_ALIGN_OUT_LEFT_MID, + LV_ALIGN_OUT_LEFT_BOTTOM, + LV_ALIGN_OUT_RIGHT_TOP, + LV_ALIGN_OUT_RIGHT_MID, + LV_ALIGN_OUT_RIGHT_BOTTOM, +}; +typedef uint8_t lv_align_t; + +enum { + LV_DIR_NONE = 0x00, + LV_DIR_LEFT = (1 << 0), + LV_DIR_RIGHT = (1 << 1), + LV_DIR_TOP = (1 << 2), + LV_DIR_BOTTOM = (1 << 3), + LV_DIR_HOR = LV_DIR_LEFT | LV_DIR_RIGHT, + LV_DIR_VER = LV_DIR_TOP | LV_DIR_BOTTOM, + LV_DIR_ALL = LV_DIR_HOR | LV_DIR_VER, +}; + +typedef uint8_t lv_dir_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize an area + * @param area_p pointer to an area + * @param x1 left coordinate of the area + * @param y1 top coordinate of the area + * @param x2 right coordinate of the area + * @param y2 bottom coordinate of the area + */ +void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2); + +/** + * Copy an area + * @param dest pointer to the destination area + * @param src pointer to the source area + */ +inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src) +{ + dest->x1 = src->x1; + dest->y1 = src->y1; + dest->x2 = src->x2; + dest->y2 = src->y2; +} + +/** + * Get the width of an area + * @param area_p pointer to an area + * @return the width of the area (if x1 == x2 -> width = 1) + */ +static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p) +{ + return (lv_coord_t)(area_p->x2 - area_p->x1 + 1); +} + +/** + * Get the height of an area + * @param area_p pointer to an area + * @return the height of the area (if y1 == y2 -> height = 1) + */ +static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p) +{ + return (lv_coord_t)(area_p->y2 - area_p->y1 + 1); +} + +/** + * Set the width of an area + * @param area_p pointer to an area + * @param w the new width of the area (w == 1 makes x1 == x2) + */ +void lv_area_set_width(lv_area_t * area_p, lv_coord_t w); + +/** + * Set the height of an area + * @param area_p pointer to an area + * @param h the new height of the area (h == 1 makes y1 == y2) + */ +void lv_area_set_height(lv_area_t * area_p, lv_coord_t h); + +/** + * Set the position of an area (width and height will be kept) + * @param area_p pointer to an area + * @param x the new x coordinate of the area + * @param y the new y coordinate of the area + */ +void _lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y); + +/** + * Return with area of an area (x * y) + * @param area_p pointer to an area + * @return size of area + */ +uint32_t lv_area_get_size(const lv_area_t * area_p); + +void lv_area_increase(lv_area_t * area, lv_coord_t w_extra, lv_coord_t h_extra); + +void lv_area_move(lv_area_t * area, lv_coord_t x_ofs, lv_coord_t y_ofs); + +/** + * Get the common parts of two areas + * @param res_p pointer to an area, the result will be stored her + * @param a1_p pointer to the first area + * @param a2_p pointer to the second area + * @return false: the two area has NO common parts, res_p is invalid + */ +bool _lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Join two areas into a third which involves the other two + * @param res_p pointer to an area, the result will be stored here + * @param a1_p pointer to the first area + * @param a2_p pointer to the second area + */ +void _lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Check if a point is on an area + * @param a_p pointer to an area + * @param p_p pointer to a point + * @param radius radius of area (e.g. for rounded rectangle) + * @return false:the point is out of the area + */ +bool _lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord_t radius); + +/** + * Check if two area has common parts + * @param a1_p pointer to an area. + * @param a2_p pointer to an other area + * @return false: a1_p and a2_p has no common parts + */ +bool _lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p); + +/** + * Check if an area is fully on an other + * @param ain_p pointer to an area which could be in 'aholder_p' + * @param aholder_p pointer to an area which could involve 'ain_p' + * @param radius radius of `aholder_p` (e.g. for rounded rectangle) + * @return true: `ain_p` is fully inside `aholder_p` + */ +bool _lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, lv_coord_t radius); + + +/** + * Check if an area is fully out of an other + * @param aout_p pointer to an area which could be in 'aholder_p' + * @param aholder_p pointer to an area which could involve 'ain_p' + * @param radius radius of `aholder_p` (e.g. for rounded rectangle) + * @return true: `aout_p` is fully outside `aholder_p` + */ +bool _lv_area_is_out(const lv_area_t * aout_p, const lv_area_t * aholder_p, lv_coord_t radius); + +/** + * Check if 2 area is the same + * @param a pointer to an area + * @param b pointer to another area + */ +bool _lv_area_is_equal(const lv_area_t * a, const lv_area_t * b); + +/** + * Align an area to an other + * @param base an are where the other will be aligned + * @param to_align the area to align + * @param align `LV_ALIGN_...` + */ +void lv_area_align(const lv_area_t * base, lv_area_t * to_align, lv_align_t align, lv_coord_t ofs_x, lv_coord_t ofs_y); + +void lv_point_transform(lv_point_t * p, int32_t angle, int32_t zoom, const lv_point_t * pivot); + +/********************** + * MACROS + **********************/ + +#if LV_USE_LARGE_COORD +#define _LV_COORD_TYPE_SHIFT (29U) +#else +#define _LV_COORD_TYPE_SHIFT (13U) +#endif + +#define _LV_COORD_TYPE_MASK (3 << _LV_COORD_TYPE_SHIFT) +#define _LV_COORD_TYPE(x) ((x) & _LV_COORD_TYPE_MASK) /*Extract type specifiers*/ +#define _LV_COORD_PLAIN(x) ((x) & ~_LV_COORD_TYPE_MASK) /*Remove type specifiers*/ + +#define _LV_COORD_TYPE_PX (0 << _LV_COORD_TYPE_SHIFT) +#define _LV_COORD_TYPE_SPEC (1 << _LV_COORD_TYPE_SHIFT) +#define _LV_COORD_TYPE_PX_NEG (3 << _LV_COORD_TYPE_SHIFT) + +#define LV_COORD_IS_PX(x) (_LV_COORD_TYPE(x) == _LV_COORD_TYPE_PX || \ + _LV_COORD_TYPE(x) == _LV_COORD_TYPE_PX_NEG ? true : false) +#define LV_COORD_IS_SPEC(x) (_LV_COORD_TYPE(x) == _LV_COORD_TYPE_SPEC ? true : false) + +#define LV_COORD_SET_SPEC(x) ((x) | _LV_COORD_TYPE_SPEC) + +/*Special coordinates*/ +#define LV_PCT(x) (x < 0 ? LV_COORD_SET_SPEC(1000 - (x)) : LV_COORD_SET_SPEC(x)) +#define LV_COORD_IS_PCT(x) ((LV_COORD_IS_SPEC(x) && _LV_COORD_PLAIN(x) <= 2000) ? true : false) +#define LV_COORD_GET_PCT(x) (_LV_COORD_PLAIN(x) > 1000 ? 1000 - _LV_COORD_PLAIN(x) : _LV_COORD_PLAIN(x)) +#define LV_SIZE_CONTENT LV_COORD_SET_SPEC(2001) + +LV_EXPORT_CONST_INT(LV_SIZE_CONTENT); + +/*Max coordinate value*/ +#define LV_COORD_MAX ((1 << _LV_COORD_TYPE_SHIFT) - 1) +#define LV_COORD_MIN (-LV_COORD_MAX) + +LV_EXPORT_CONST_INT(LV_COORD_MAX); +LV_EXPORT_CONST_INT(LV_COORD_MIN); + +/** + * Convert a percentage value to `lv_coord_t`. + * Percentage values are stored in special range + * @param x the percentage (0..1000) + * @return a coordinate that stores the percentage + */ +static inline lv_coord_t lv_pct(lv_coord_t x) +{ + return LV_PCT(x); +} + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/liblvgl/misc/lv_assert.h b/include/liblvgl/misc/lv_assert.h new file mode 100644 index 00000000..4625297d --- /dev/null +++ b/include/liblvgl/misc/lv_assert.h @@ -0,0 +1,79 @@ +/** + * @file lv_assert.h + * + */ + +#ifndef LV_ASSERT_H +#define LV_ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "lv_log.h" +#include "lv_mem.h" +#include LV_ASSERT_HANDLER_INCLUDE + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#define LV_ASSERT(expr) \ + do { \ + if(!(expr)) { \ + LV_LOG_ERROR("Asserted at expression: %s", #expr); \ + LV_ASSERT_HANDLER \ + } \ + } while(0) + +#define LV_ASSERT_MSG(expr, msg) \ + do { \ + if(!(expr)) { \ + LV_LOG_ERROR("Asserted at expression: %s (%s)", #expr, msg); \ + LV_ASSERT_HANDLER \ + } \ + } while(0) + +/*----------------- + * ASSERTS + *-----------------*/ + +#if LV_USE_ASSERT_NULL +# define LV_ASSERT_NULL(p) LV_ASSERT_MSG(p != NULL, "NULL pointer"); +#else +# define LV_ASSERT_NULL(p) +#endif + +#if LV_USE_ASSERT_MALLOC +# define LV_ASSERT_MALLOC(p) LV_ASSERT_MSG(p != NULL, "Out of memory"); +#else +# define LV_ASSERT_MALLOC(p) +#endif + +#if LV_USE_ASSERT_MEM_INTEGRITY +# define LV_ASSERT_MEM_INTEGRITY() LV_ASSERT_MSG(lv_mem_test() == LV_RES_OK, "Memory integrity error"); +#else +# define LV_ASSERT_MEM_INTEGRITY() +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ASSERT_H*/ diff --git a/include/liblvgl/misc/lv_async.h b/include/liblvgl/misc/lv_async.h new file mode 100644 index 00000000..4ad5756d --- /dev/null +++ b/include/liblvgl/misc/lv_async.h @@ -0,0 +1,61 @@ +/** + * @file lv_async.h + * + */ + +#ifndef LV_ASYNC_H +#define LV_ASYNC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "lv_types.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Type for async callback. + */ +typedef void (*lv_async_cb_t)(void *); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Call an asynchronous function the next time lv_timer_handler() is run. This function is likely to return + * **before** the call actually happens! + * @param async_xcb a callback which is the task itself. + * (the 'x' in the argument name indicates that it's not a fully generic function because it not follows + * the `func_name(object, callback, ...)` convention) + * @param user_data custom parameter + */ +lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data); + +/** + * Cancel an asynchronous function call + * @param async_xcb a callback which is the task itself. + * @param user_data custom parameter + */ +lv_res_t lv_async_call_cancel(lv_async_cb_t async_xcb, void * user_data); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ASYNC_H*/ diff --git a/include/liblvgl/misc/lv_bidi.h b/include/liblvgl/misc/lv_bidi.h new file mode 100644 index 00000000..fafb4a28 --- /dev/null +++ b/include/liblvgl/misc/lv_bidi.h @@ -0,0 +1,141 @@ +/** + * @file lv_bidi.h + * + */ + +#ifndef LV_BIDI_H +#define LV_BIDI_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include "lv_txt.h" + +/********************* + * DEFINES + *********************/ +/*Special non printable strong characters. + *They can be inserted to texts to affect the run's direction*/ +#define LV_BIDI_LRO "\xE2\x80\xAD" /*U+202D*/ +#define LV_BIDI_RLO "\xE2\x80\xAE" /*U+202E*/ + +/********************** + * TYPEDEFS + **********************/ +enum { + LV_BASE_DIR_LTR = 0x00, + LV_BASE_DIR_RTL = 0x01, + LV_BASE_DIR_AUTO = 0x02, + + LV_BASE_DIR_NEUTRAL = 0x20, + LV_BASE_DIR_WEAK = 0x21, +}; + +typedef uint8_t lv_base_dir_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ +#if LV_USE_BIDI + +/** + * Convert a text to get the characters in the correct visual order according to + * Unicode Bidirectional Algorithm + * @param str_in the text to process + * @param str_out store the result here. Has the be `strlen(str_in)` length + * @param base_dir `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL` + */ +void _lv_bidi_process(const char * str_in, char * str_out, lv_base_dir_t base_dir); + +/** + * Auto-detect the direction of a text based on the first strong character + * @param txt the text to process + * @return `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL` + */ +lv_base_dir_t _lv_bidi_detect_base_dir(const char * txt); + +/** + * Get the logical position of a character in a line + * @param str_in the input string. Can be only one line. + * @param bidi_txt internally the text is bidi processed which buffer can be get here. + * If not required anymore has to freed with `lv_mem_free()` + * Can be `NULL` is unused + * @param len length of the line in character count + * @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL` + * @param visual_pos the visual character position which logical position should be get + * @param is_rtl tell the char at `visual_pos` is RTL or LTR context + * @return the logical character position + */ +uint16_t _lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_base_dir_t base_dir, + uint32_t visual_pos, bool * is_rtl); + +/** + * Get the visual position of a character in a line + * @param str_in the input string. Can be only one line. + * @param bidi_txt internally the text is bidi processed which buffer can be get here. + * If not required anymore has to freed with `lv_mem_free()` + * Can be `NULL` is unused + * @param len length of the line in character count + * @param base_dir base direction of the text: `LV_BASE_DIR_LTR` or `LV_BASE_DIR_RTL` + * @param logical_pos the logical character position which visual position should be get + * @param is_rtl tell the char at `logical_pos` is RTL or LTR context + * @return the visual character position + */ +uint16_t _lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_base_dir_t base_dir, + uint32_t logical_pos, bool * is_rtl); + +/** + * Bidi process a paragraph of text + * @param str_in the string to process + * @param str_out store the result here + * @param len length of the text + * @param base_dir base dir of the text + * @param pos_conv_out an `uint16_t` array to store the related logical position of the character. + * Can be `NULL` is unused + * @param pos_conv_len length of `pos_conv_out` in element count + */ +void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_base_dir_t base_dir, + uint16_t * pos_conv_out, uint16_t pos_conv_len); + +/** + * Get the real text alignment from the a text alignment, base direction and a text. + * @param align LV_TEXT_ALIGN_..., write back the calculated align here (LV_TEXT_ALIGN_LEFT/RIGHT/CENTER) + * @param base_dir LV_BASE_DIR_..., write the calculated base dir here (LV_BASE_DIR_LTR/RTL) + * @param txt a text, used with LV_BASE_DIR_AUTO to determine the base direction + */ +void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt); + + +/********************** + * MACROS + **********************/ + +#else /*LV_USE_BIDI*/ +/** + * For compatibility if LV_USE_BIDI = 0 + * Get the real text alignment from the a text alignment, base direction and a text. + * @param align For LV_TEXT_ALIGN_AUTO give LV_TEXT_ALIGN_LEFT else leave unchanged, write back the calculated align here + * @param base_dir Unused + * @param txt Unused + */ +static inline void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt) +{ + LV_UNUSED(txt); + LV_UNUSED(base_dir); + if(*align == LV_TEXT_ALIGN_AUTO) * align = LV_TEXT_ALIGN_LEFT; +} +#endif /*LV_USE_BIDI*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_BIDI_H*/ diff --git a/include/liblvgl/misc/lv_color.h b/include/liblvgl/misc/lv_color.h new file mode 100644 index 00000000..8e80a616 --- /dev/null +++ b/include/liblvgl/misc/lv_color.h @@ -0,0 +1,708 @@ +/** + * @file lv_color.h + * + */ + +#ifndef LV_COLOR_H +#define LV_COLOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "lv_assert.h" +#include "lv_math.h" +#include "lv_types.h" + +/*Error checking*/ +#if LV_COLOR_DEPTH == 24 +#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)" +#endif + +#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0 +#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h" +#endif + +#include + +/********************* + * DEFINES + *********************/ +LV_EXPORT_CONST_INT(LV_COLOR_DEPTH); +LV_EXPORT_CONST_INT(LV_COLOR_16_SWAP); + +/** + * Opacity percentages. + */ +enum { + LV_OPA_TRANSP = 0, + LV_OPA_0 = 0, + LV_OPA_10 = 25, + LV_OPA_20 = 51, + LV_OPA_30 = 76, + LV_OPA_40 = 102, + LV_OPA_50 = 127, + LV_OPA_60 = 153, + LV_OPA_70 = 178, + LV_OPA_80 = 204, + LV_OPA_90 = 229, + LV_OPA_100 = 255, + LV_OPA_COVER = 255, +}; + +#define LV_OPA_MIN 2 /*Opacities below this will be transparent*/ +#define LV_OPA_MAX 253 /*Opacities above this will fully cover*/ + +#if LV_COLOR_DEPTH == 1 +#define LV_COLOR_SIZE 8 +#elif LV_COLOR_DEPTH == 8 +#define LV_COLOR_SIZE 8 +#elif LV_COLOR_DEPTH == 16 +#define LV_COLOR_SIZE 16 +#elif LV_COLOR_DEPTH == 32 +#define LV_COLOR_SIZE 32 +#else +#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!" +#endif + +#if defined(__cplusplus) && !defined(_LV_COLOR_HAS_MODERN_CPP) +/** +* MSVC compiler's definition of the __cplusplus indicating 199711L regardless to C++ standard version +* see https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-cplusplus +* so we use _MSC_VER macro instead of __cplusplus +*/ +#ifdef _MSC_VER +#if _MSC_VER >= 1900 /*Visual Studio 2015*/ +#define _LV_COLOR_HAS_MODERN_CPP 1 +#endif +#else +#if __cplusplus >= 201103L +#define _LV_COLOR_HAS_MODERN_CPP 1 +#endif +#endif +#endif /*__cplusplus*/ + +#ifndef _LV_COLOR_HAS_MODERN_CPP +#define _LV_COLOR_HAS_MODERN_CPP 0 +#endif + +#if _LV_COLOR_HAS_MODERN_CPP +/*Fix msvc compiler error C4576 inside C++ code*/ +#define _LV_COLOR_MAKE_TYPE_HELPER lv_color_t +#else +#define _LV_COLOR_MAKE_TYPE_HELPER (lv_color_t) +#endif + +/*--------------------------------------- + * Macros for all existing color depths + * to set/get values of the color channels + *------------------------------------------*/ +# define LV_COLOR_SET_R1(c, v) (c).ch.red = (uint8_t)((v) & 0x1) +# define LV_COLOR_SET_G1(c, v) (c).ch.green = (uint8_t)((v) & 0x1) +# define LV_COLOR_SET_B1(c, v) (c).ch.blue = (uint8_t)((v) & 0x1) +# define LV_COLOR_SET_A1(c, v) do {} while(0) + +# define LV_COLOR_GET_R1(c) (c).ch.red +# define LV_COLOR_GET_G1(c) (c).ch.green +# define LV_COLOR_GET_B1(c) (c).ch.blue +# define LV_COLOR_GET_A1(c) 0xFF + +# define _LV_COLOR_ZERO_INITIALIZER1 {0x00} +# define LV_COLOR_MAKE1(r8, g8, b8) {(uint8_t)((b8 >> 7) | (g8 >> 7) | (r8 >> 7))} + +# define LV_COLOR_SET_R8(c, v) (c).ch.red = (uint8_t)((v) & 0x7U) +# define LV_COLOR_SET_G8(c, v) (c).ch.green = (uint8_t)((v) & 0x7U) +# define LV_COLOR_SET_B8(c, v) (c).ch.blue = (uint8_t)((v) & 0x3U) +# define LV_COLOR_SET_A8(c, v) do {} while(0) + +# define LV_COLOR_GET_R8(c) (c).ch.red +# define LV_COLOR_GET_G8(c) (c).ch.green +# define LV_COLOR_GET_B8(c) (c).ch.blue +# define LV_COLOR_GET_A8(c) 0xFF + +# define _LV_COLOR_ZERO_INITIALIZER8 {{0x00, 0x00, 0x00}} +# define LV_COLOR_MAKE8(r8, g8, b8) {{(uint8_t)((b8 >> 6) & 0x3U), (uint8_t)((g8 >> 5) & 0x7U), (uint8_t)((r8 >> 5) & 0x7U)}} + +# define LV_COLOR_SET_R16(c, v) (c).ch.red = (uint8_t)((v) & 0x1FU) +#if LV_COLOR_16_SWAP == 0 +# define LV_COLOR_SET_G16(c, v) (c).ch.green = (uint8_t)((v) & 0x3FU) +#else +# define LV_COLOR_SET_G16(c, v) {(c).ch.green_h = (uint8_t)(((v) >> 3) & 0x7); (c).ch.green_l = (uint8_t)((v) & 0x7);} +#endif +# define LV_COLOR_SET_B16(c, v) (c).ch.blue = (uint8_t)((v) & 0x1FU) +# define LV_COLOR_SET_A16(c, v) do {} while(0) + +# define LV_COLOR_GET_R16(c) (c).ch.red +#if LV_COLOR_16_SWAP == 0 +# define LV_COLOR_GET_G16(c) (c).ch.green +#else +# define LV_COLOR_GET_G16(c) (((c).ch.green_h << 3) + (c).ch.green_l) +#endif +# define LV_COLOR_GET_B16(c) (c).ch.blue +# define LV_COLOR_GET_A16(c) 0xFF + +#if LV_COLOR_16_SWAP == 0 +# define _LV_COLOR_ZERO_INITIALIZER16 {{0x00, 0x00, 0x00}} +# define LV_COLOR_MAKE16(r8, g8, b8) {{(uint8_t)((b8 >> 3) & 0x1FU), (uint8_t)((g8 >> 2) & 0x3FU), (uint8_t)((r8 >> 3) & 0x1FU)}} +#else +# define _LV_COLOR_ZERO_INITIALIZER16 {{0x00, 0x00, 0x00, 0x00}} +# define LV_COLOR_MAKE16(r8, g8, b8) {{(uint8_t)((g8 >> 5) & 0x7U), (uint8_t)((r8 >> 3) & 0x1FU), (uint8_t)((b8 >> 3) & 0x1FU), (uint8_t)((g8 >> 2) & 0x7U)}} +#endif + +# define LV_COLOR_SET_R32(c, v) (c).ch.red = (uint8_t)((v) & 0xFF) +# define LV_COLOR_SET_G32(c, v) (c).ch.green = (uint8_t)((v) & 0xFF) +# define LV_COLOR_SET_B32(c, v) (c).ch.blue = (uint8_t)((v) & 0xFF) +# define LV_COLOR_SET_A32(c, v) (c).ch.alpha = (uint8_t)((v) & 0xFF) + +# define LV_COLOR_GET_R32(c) (c).ch.red +# define LV_COLOR_GET_G32(c) (c).ch.green +# define LV_COLOR_GET_B32(c) (c).ch.blue +# define LV_COLOR_GET_A32(c) (c).ch.alpha + +# define _LV_COLOR_ZERO_INITIALIZER32 {{0x00, 0x00, 0x00, 0x00}} +# define LV_COLOR_MAKE32(r8, g8, b8) {{b8, g8, r8, 0xff}} /*Fix 0xff alpha*/ + +/*--------------------------------------- + * Macros for the current color depth + * to set/get values of the color channels + *------------------------------------------*/ +#define LV_COLOR_SET_R(c, v) LV_CONCAT(LV_COLOR_SET_R, LV_COLOR_DEPTH)(c, v) +#define LV_COLOR_SET_G(c, v) LV_CONCAT(LV_COLOR_SET_G, LV_COLOR_DEPTH)(c, v) +#define LV_COLOR_SET_B(c, v) LV_CONCAT(LV_COLOR_SET_B, LV_COLOR_DEPTH)(c, v) +#define LV_COLOR_SET_A(c, v) LV_CONCAT(LV_COLOR_SET_A, LV_COLOR_DEPTH)(c, v) + +#define LV_COLOR_GET_R(c) LV_CONCAT(LV_COLOR_GET_R, LV_COLOR_DEPTH)(c) +#define LV_COLOR_GET_G(c) LV_CONCAT(LV_COLOR_GET_G, LV_COLOR_DEPTH)(c) +#define LV_COLOR_GET_B(c) LV_CONCAT(LV_COLOR_GET_B, LV_COLOR_DEPTH)(c) +#define LV_COLOR_GET_A(c) LV_CONCAT(LV_COLOR_GET_A, LV_COLOR_DEPTH)(c) + +#define _LV_COLOR_ZERO_INITIALIZER LV_CONCAT(_LV_COLOR_ZERO_INITIALIZER, LV_COLOR_DEPTH) +#define LV_COLOR_MAKE(r8, g8, b8) LV_CONCAT(LV_COLOR_MAKE, LV_COLOR_DEPTH)(r8, g8, b8) + +/********************** + * TYPEDEFS + **********************/ + +typedef union { + uint8_t full; /*must be declared first to set all bits of byte via initializer list*/ + union { + uint8_t blue : 1; + uint8_t green : 1; + uint8_t red : 1; + } ch; +} lv_color1_t; + +typedef union { + struct { + uint8_t blue : 2; + uint8_t green : 3; + uint8_t red : 3; + } ch; + uint8_t full; +} lv_color8_t; + +typedef union { + struct { +#if LV_COLOR_16_SWAP == 0 + uint16_t blue : 5; + uint16_t green : 6; + uint16_t red : 5; +#else + uint16_t green_h : 3; + uint16_t red : 5; + uint16_t blue : 5; + uint16_t green_l : 3; +#endif + } ch; + uint16_t full; +} lv_color16_t; + +typedef union { + struct { + uint8_t blue; + uint8_t green; + uint8_t red; + uint8_t alpha; + } ch; + uint32_t full; +} lv_color32_t; + +typedef LV_CONCAT3(uint, LV_COLOR_SIZE, _t) lv_color_int_t; +typedef LV_CONCAT3(lv_color, LV_COLOR_DEPTH, _t) lv_color_t; + +typedef struct { + uint16_t h; + uint8_t s; + uint8_t v; +} lv_color_hsv_t; + +//! @cond Doxygen_Suppress +/*No idea where the guard is required but else throws warnings in the docs*/ +typedef uint8_t lv_opa_t; +//! @endcond + +struct _lv_color_filter_dsc_t; + +typedef lv_color_t (*lv_color_filter_cb_t)(const struct _lv_color_filter_dsc_t *, lv_color_t, lv_opa_t); + +typedef struct _lv_color_filter_dsc_t { + lv_color_filter_cb_t filter_cb; + void * user_data; +} lv_color_filter_dsc_t; + + +typedef enum { + LV_PALETTE_RED, + LV_PALETTE_PINK, + LV_PALETTE_PURPLE, + LV_PALETTE_DEEP_PURPLE, + LV_PALETTE_INDIGO, + LV_PALETTE_BLUE, + LV_PALETTE_LIGHT_BLUE, + LV_PALETTE_CYAN, + LV_PALETTE_TEAL, + LV_PALETTE_GREEN, + LV_PALETTE_LIGHT_GREEN, + LV_PALETTE_LIME, + LV_PALETTE_YELLOW, + LV_PALETTE_AMBER, + LV_PALETTE_ORANGE, + LV_PALETTE_DEEP_ORANGE, + LV_PALETTE_BROWN, + LV_PALETTE_BLUE_GREY, + LV_PALETTE_GREY, + _LV_PALETTE_LAST, + LV_PALETTE_NONE = 0xff, +} lv_palette_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/*In color conversations: + * - When converting to bigger color type the LSB weight of 1 LSB is calculated + * E.g. 16 bit Red has 5 bits + * 8 bit Red has 3 bits + * ---------------------- + * 8 bit red LSB = (2^5 - 1) / (2^3 - 1) = 31 / 7 = 4 + * + * - When calculating to smaller color type simply shift out the LSBs + * E.g. 8 bit Red has 3 bits + * 16 bit Red has 5 bits + * ---------------------- + * Shift right with 5 - 3 = 2 + */ +static inline uint8_t lv_color_to1(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + return color.full; +#elif LV_COLOR_DEPTH == 8 + if((LV_COLOR_GET_R(color) & 0x4) || (LV_COLOR_GET_G(color) & 0x4) || (LV_COLOR_GET_B(color) & 0x2)) { + return 1; + } + else { + return 0; + } +#elif LV_COLOR_DEPTH == 16 + if((LV_COLOR_GET_R(color) & 0x10) || (LV_COLOR_GET_G(color) & 0x20) || (LV_COLOR_GET_B(color) & 0x10)) { + return 1; + } + else { + return 0; + } +#elif LV_COLOR_DEPTH == 32 + if((LV_COLOR_GET_R(color) & 0x80) || (LV_COLOR_GET_G(color) & 0x80) || (LV_COLOR_GET_B(color) & 0x80)) { + return 1; + } + else { + return 0; + } +#endif +} + +static inline uint8_t lv_color_to8(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) + return 0; + else + return 0xFF; +#elif LV_COLOR_DEPTH == 8 + return color.full; +#elif LV_COLOR_DEPTH == 16 + lv_color8_t ret; + LV_COLOR_SET_R8(ret, LV_COLOR_GET_R(color) >> 2); /*5 - 3 = 2*/ + LV_COLOR_SET_G8(ret, LV_COLOR_GET_G(color) >> 3); /*6 - 3 = 3*/ + LV_COLOR_SET_B8(ret, LV_COLOR_GET_B(color) >> 3); /*5 - 2 = 3*/ + return ret.full; +#elif LV_COLOR_DEPTH == 32 + lv_color8_t ret; + LV_COLOR_SET_R8(ret, LV_COLOR_GET_R(color) >> 5); /*8 - 3 = 5*/ + LV_COLOR_SET_G8(ret, LV_COLOR_GET_G(color) >> 5); /*8 - 3 = 5*/ + LV_COLOR_SET_B8(ret, LV_COLOR_GET_B(color) >> 6); /*8 - 2 = 6*/ + return ret.full; +#endif +} + +static inline uint16_t lv_color_to16(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) + return 0; + else + return 0xFFFF; +#elif LV_COLOR_DEPTH == 8 + lv_color16_t ret; + LV_COLOR_SET_R16(ret, LV_COLOR_GET_R(color) * 4); /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/ + LV_COLOR_SET_G16(ret, LV_COLOR_GET_G(color) * 9); /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/ + LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) * 10); /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/ + return ret.full; +#elif LV_COLOR_DEPTH == 16 + return color.full; +#elif LV_COLOR_DEPTH == 32 + lv_color16_t ret; + LV_COLOR_SET_R16(ret, LV_COLOR_GET_R(color) >> 3); /*8 - 5 = 3*/ + LV_COLOR_SET_G16(ret, LV_COLOR_GET_G(color) >> 2); /*8 - 6 = 2*/ + LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) >> 3); /*8 - 5 = 3*/ + return ret.full; +#endif +} + +static inline uint32_t lv_color_to32(lv_color_t color) +{ +#if LV_COLOR_DEPTH == 1 + if(color.full == 0) + return 0xFF000000; + else + return 0xFFFFFFFF; +#elif LV_COLOR_DEPTH == 8 + lv_color32_t ret; + LV_COLOR_SET_R32(ret, LV_COLOR_GET_R(color) * 36); /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ + LV_COLOR_SET_G32(ret, LV_COLOR_GET_G(color) * 36); /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/ + LV_COLOR_SET_B32(ret, LV_COLOR_GET_B(color) * 85); /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/ + LV_COLOR_SET_A32(ret, 0xFF); + return ret.full; +#elif LV_COLOR_DEPTH == 16 + /** + * The floating point math for conversion is: + * valueto = valuefrom * ( (2^bitsto - 1) / (float)(2^bitsfrom - 1) ) + * The faster integer math for conversion is: + * valueto = ( valuefrom * multiplier + adder ) >> divisor + * multiplier = FLOOR( ( (2^bitsto - 1) << divisor ) / (float)(2^bitsfrom - 1) ) + * + * Find the first divisor where ( adder >> divisor ) <= 0 + * + * 5-bit to 8-bit: ( 31 * multiplier + adder ) >> divisor = 255 + * divisor multiplier adder min (0) max (31) + * 0 8 7 7 255 + * 1 16 14 7 255 + * 2 32 28 7 255 + * 3 65 25 3 255 + * 4 131 19 1 255 + * 5 263 7 0 255 + * + * 6-bit to 8-bit: 255 = ( 63 * multiplier + adder ) >> divisor + * divisor multiplier adder min (0) max (63) + * 0 4 3 3 255 + * 1 8 6 3 255 + * 2 16 12 3 255 + * 3 32 24 3 255 + * 4 64 48 3 255 + * 5 129 33 1 255 + * 6 259 3 0 255 + */ + + lv_color32_t ret; + LV_COLOR_SET_R32(ret, (LV_COLOR_GET_R(color) * 263 + 7) >> 5); + LV_COLOR_SET_G32(ret, (LV_COLOR_GET_G(color) * 259 + 3) >> 6); + LV_COLOR_SET_B32(ret, (LV_COLOR_GET_B(color) * 263 + 7) >> 5); + LV_COLOR_SET_A32(ret, 0xFF); + return ret.full; +#elif LV_COLOR_DEPTH == 32 + return color.full; +#endif +} + +//! @cond Doxygen_Suppress + +/** + * Mix two colors with a given ratio. + * @param c1 the first color to mix (usually the foreground) + * @param c2 the second color to mix (usually the background) + * @param mix The ratio of the colors. 0: full `c2`, 255: full `c1`, 127: half `c1` and half`c2` + * @return the mixed color + */ +LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix) +{ + lv_color_t ret; + +#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0 && LV_COLOR_MIX_ROUND_OFS == 0 + /*Source: https://stackoverflow.com/a/50012418/1999969*/ + mix = (uint32_t)((uint32_t)mix + 4) >> 3; + uint32_t bg = (uint32_t)((uint32_t)c2.full | ((uint32_t)c2.full << 16)) & + 0x7E0F81F; /*0b00000111111000001111100000011111*/ + uint32_t fg = (uint32_t)((uint32_t)c1.full | ((uint32_t)c1.full << 16)) & 0x7E0F81F; + uint32_t result = ((((fg - bg) * mix) >> 5) + bg) & 0x7E0F81F; + ret.full = (uint16_t)((result >> 16) | result); +#elif LV_COLOR_DEPTH != 1 + /*LV_COLOR_DEPTH == 8, 16 or 32*/ + LV_COLOR_SET_R(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_R(c1) * mix + LV_COLOR_GET_R(c2) * + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_G(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_G(c1) * mix + LV_COLOR_GET_G(c2) * + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_B(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_B(c1) * mix + LV_COLOR_GET_B(c2) * + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_A(ret, 0xFF); +#else + /*LV_COLOR_DEPTH == 1*/ + ret.full = mix > LV_OPA_50 ? c1.full : c2.full; +#endif + + return ret; +} + +LV_ATTRIBUTE_FAST_MEM static inline void lv_color_premult(lv_color_t c, uint8_t mix, uint16_t * out) +{ +#if LV_COLOR_DEPTH != 1 + out[0] = (uint16_t)LV_COLOR_GET_R(c) * mix; + out[1] = (uint16_t)LV_COLOR_GET_G(c) * mix; + out[2] = (uint16_t)LV_COLOR_GET_B(c) * mix; +#else + (void) mix; + /*Pre-multiplication can't be used with 1 bpp*/ + out[0] = LV_COLOR_GET_R(c); + out[1] = LV_COLOR_GET_G(c); + out[2] = LV_COLOR_GET_B(c); +#endif + +} + +/** + * Mix two colors with a given ratio. It runs faster then `lv_color_mix` but requires some pre computation. + * @param premult_c1 The first color. Should be preprocessed with `lv_color_premult(c1)` + * @param c2 The second color. As it is no pre computation required on it + * @param mix The ratio of the colors. 0: full `c1`, 255: full `c2`, 127: half `c1` and half `c2`. + * Should be modified like mix = `255 - mix` + * @return the mixed color + * @note 255 won't give clearly `c1`. + */ +LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix_premult(uint16_t * premult_c1, lv_color_t c2, uint8_t mix) +{ + lv_color_t ret; +#if LV_COLOR_DEPTH != 1 + /*LV_COLOR_DEPTH == 8 or 32*/ + LV_COLOR_SET_R(ret, LV_UDIV255(premult_c1[0] + LV_COLOR_GET_R(c2) * mix + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_G(ret, LV_UDIV255(premult_c1[1] + LV_COLOR_GET_G(c2) * mix + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_B(ret, LV_UDIV255(premult_c1[2] + LV_COLOR_GET_B(c2) * mix + LV_COLOR_MIX_ROUND_OFS)); + LV_COLOR_SET_A(ret, 0xFF); +#else + /*LV_COLOR_DEPTH == 1*/ + /*Restore color1*/ + lv_color_t c1; + LV_COLOR_SET_R(c1, premult_c1[0]); + LV_COLOR_SET_G(c1, premult_c1[1]); + LV_COLOR_SET_B(c1, premult_c1[2]); + ret.full = mix > LV_OPA_50 ? c2.full : c1.full; +#endif + + return ret; +} + +/** + * Mix two colors. Both color can have alpha value. + * @param bg_color background color + * @param bg_opa alpha of the background color + * @param fg_color foreground color + * @param fg_opa alpha of the foreground color + * @param res_color the result color + * @param res_opa the result opacity + */ +LV_ATTRIBUTE_FAST_MEM static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa, + lv_color_t fg_color, lv_opa_t fg_opa, + lv_color_t * res_color, lv_opa_t * res_opa) +{ + /*Pick the foreground if it's fully opaque or the Background is fully transparent*/ + if(fg_opa >= LV_OPA_MAX || bg_opa <= LV_OPA_MIN) { + res_color->full = fg_color.full; + *res_opa = fg_opa; + } + /*Transparent foreground: use the Background*/ + else if(fg_opa <= LV_OPA_MIN) { + res_color->full = bg_color.full; + *res_opa = bg_opa; + } + /*Opaque background: use simple mix*/ + else if(bg_opa >= LV_OPA_MAX) { + *res_color = lv_color_mix(fg_color, bg_color, fg_opa); + *res_opa = LV_OPA_COVER; + } + /*Both colors have alpha. Expensive calculation need to be applied*/ + else { + /*Save the parameters and the result. If they will be asked again don't compute again*/ + static lv_opa_t fg_opa_save = 0; + static lv_opa_t bg_opa_save = 0; + static lv_color_t fg_color_save = _LV_COLOR_ZERO_INITIALIZER; + static lv_color_t bg_color_save = _LV_COLOR_ZERO_INITIALIZER; + static lv_color_t res_color_saved = _LV_COLOR_ZERO_INITIALIZER; + static lv_opa_t res_opa_saved = 0; + + if(fg_opa != fg_opa_save || bg_opa != bg_opa_save || fg_color.full != fg_color_save.full || + bg_color.full != bg_color_save.full) { + fg_opa_save = fg_opa; + bg_opa_save = bg_opa; + fg_color_save.full = fg_color.full; + bg_color_save.full = bg_color.full; + /*Info: + * https://en.wikipedia.org/wiki/Alpha_compositing#Analytical_derivation_of_the_over_operator*/ + res_opa_saved = 255 - ((uint16_t)((uint16_t)(255 - fg_opa) * (255 - bg_opa)) >> 8); + LV_ASSERT(res_opa_saved != 0); + lv_opa_t ratio = (uint16_t)((uint16_t)fg_opa * 255) / res_opa_saved; + res_color_saved = lv_color_mix(fg_color, bg_color, ratio); + + } + + res_color->full = res_color_saved.full; + *res_opa = res_opa_saved; + } +} + +//! @endcond + +/** + * Get the brightness of a color + * @param color a color + * @return the brightness [0..255] + */ +static inline uint8_t lv_color_brightness(lv_color_t color) +{ + lv_color32_t c32; + c32.full = lv_color_to32(color); + uint16_t bright = (uint16_t)(3u * LV_COLOR_GET_R32(c32) + LV_COLOR_GET_B32(c32) + 4u * LV_COLOR_GET_G32(c32)); + return (uint8_t)(bright >> 3); +} + +static inline lv_color_t lv_color_make(uint8_t r, uint8_t g, uint8_t b) +{ + return _LV_COLOR_MAKE_TYPE_HELPER LV_COLOR_MAKE(r, g, b); +} + +static inline lv_color_t lv_color_hex(uint32_t c) +{ +#if LV_COLOR_DEPTH == 16 + lv_color_t r; +#if LV_COLOR_16_SWAP == 0 + /* Convert a 4 bytes per pixel in format ARGB32 to R5G6B5 format + naive way (by calling lv_color_make with components): + r = ((c & 0xFF0000) >> 19) + g = ((c & 0xFF00) >> 10) + b = ((c & 0xFF) >> 3) + rgb565 = (r << 11) | (g << 5) | b + That's 3 mask, 5 bitshift and 2 or operations + + A bit better: + r = ((c & 0xF80000) >> 8) + g = ((c & 0xFC00) >> 5) + b = ((c & 0xFF) >> 3) + rgb565 = r | g | b + That's 3 mask, 3 bitshifts and 2 or operations */ + r.full = (uint16_t)(((c & 0xF80000) >> 8) | ((c & 0xFC00) >> 5) | ((c & 0xFF) >> 3)); +#else + /* We want: rrrr rrrr GGGg gggg bbbb bbbb => gggb bbbb rrrr rGGG */ + r.full = (uint16_t)(((c & 0xF80000) >> 16) | ((c & 0xFC00) >> 13) | ((c & 0x1C00) << 3) | ((c & 0xF8) << 5)); +#endif + return r; +#elif LV_COLOR_DEPTH == 32 + lv_color_t r; + r.full = c | 0xFF000000; + return r; +#else /*LV_COLOR_DEPTH == 8*/ + return lv_color_make((uint8_t)((c >> 16) & 0xFF), (uint8_t)((c >> 8) & 0xFF), (uint8_t)(c & 0xFF)); +#endif +} + +static inline lv_color_t lv_color_hex3(uint32_t c) +{ + return lv_color_make((uint8_t)(((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), (uint8_t)((c & 0xF0) | ((c & 0xF0) >> 4)), + (uint8_t)((c & 0xF) | ((c & 0xF) << 4))); +} + +static inline void lv_color_filter_dsc_init(lv_color_filter_dsc_t * dsc, lv_color_filter_cb_t cb) +{ + dsc->filter_cb = cb; +} + +//! @cond Doxygen_Suppress +//! +LV_ATTRIBUTE_FAST_MEM void lv_color_fill(lv_color_t * buf, lv_color_t color, uint32_t px_num); + +//! @endcond +lv_color_t lv_color_lighten(lv_color_t c, lv_opa_t lvl); + +lv_color_t lv_color_darken(lv_color_t c, lv_opa_t lvl); + +lv_color_t lv_color_change_lightness(lv_color_t c, lv_opa_t lvl); + +/** + * Convert a HSV color to RGB + * @param h hue [0..359] + * @param s saturation [0..100] + * @param v value [0..100] + * @return the given RGB color in RGB (with LV_COLOR_DEPTH depth) + */ +lv_color_t lv_color_hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v); + +/** + * Convert a 32-bit RGB color to HSV + * @param r8 8-bit red + * @param g8 8-bit green + * @param b8 8-bit blue + * @return the given RGB color in HSV + */ +lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8); + +/** + * Convert a color to HSV + * @param color color + * @return the given color in HSV + */ +lv_color_hsv_t lv_color_to_hsv(lv_color_t color); + +/** + * Just a wrapper around LV_COLOR_CHROMA_KEY because it might be more convenient to use a function in some cases + * @return LV_COLOR_CHROMA_KEY + */ +static inline lv_color_t lv_color_chroma_key(void) +{ + return LV_COLOR_CHROMA_KEY; +} + +/********************** + * PREDEFINED COLORS + **********************/ +/*Source: https://vuetifyjs.com/en/styles/colors/#material-colors*/ + +lv_color_t lv_palette_main(lv_palette_t p); +static inline lv_color_t lv_color_white(void) +{ + return lv_color_make(0xff, 0xff, 0xff); +} +static inline lv_color_t lv_color_black(void) +{ + return lv_color_make(0x00, 0x0, 0x00); +} +lv_color_t lv_palette_lighten(lv_palette_t p, uint8_t lvl); +lv_color_t lv_palette_darken(lv_palette_t p, uint8_t lvl); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_COLOR_H*/ diff --git a/include/liblvgl/misc/lv_fs.h b/include/liblvgl/misc/lv_fs.h new file mode 100644 index 00000000..13b2eeb5 --- /dev/null +++ b/include/liblvgl/misc/lv_fs.h @@ -0,0 +1,262 @@ +/** + * @file lv_fs.h + * + */ + +#ifndef LV_FS_H +#define LV_FS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include + +/********************* + * DEFINES + *********************/ +#define LV_FS_MAX_FN_LENGTH 64 +#define LV_FS_MAX_PATH_LENGTH 256 + +/********************** + * TYPEDEFS + **********************/ + +/** + * Errors in the file system module. + */ +enum { + LV_FS_RES_OK = 0, + LV_FS_RES_HW_ERR, /*Low level hardware error*/ + LV_FS_RES_FS_ERR, /*Error in the file system structure*/ + LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/ + LV_FS_RES_FULL, /*Disk full*/ + LV_FS_RES_LOCKED, /*The file is already opened*/ + LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/ + LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/ + LV_FS_RES_TOUT, /*Process time outed*/ + LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/ + LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/ + LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/ + LV_FS_RES_UNKNOWN, /*Other unknown error*/ +}; +typedef uint8_t lv_fs_res_t; + +/** + * File open mode. + */ +enum { + LV_FS_MODE_WR = 0x01, + LV_FS_MODE_RD = 0x02, +}; +typedef uint8_t lv_fs_mode_t; + + +/** + * Seek modes. + */ +typedef enum { + LV_FS_SEEK_SET = 0x00, /**< Set the position from absolutely (from the start of file)*/ + LV_FS_SEEK_CUR = 0x01, /**< Set the position from the current position*/ + LV_FS_SEEK_END = 0x02, /**< Set the position from the end of the file*/ +} lv_fs_whence_t; + +typedef struct _lv_fs_drv_t { + char letter; + uint16_t cache_size; + bool (*ready_cb)(struct _lv_fs_drv_t * drv); + + void * (*open_cb)(struct _lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode); + lv_fs_res_t (*close_cb)(struct _lv_fs_drv_t * drv, void * file_p); + lv_fs_res_t (*read_cb)(struct _lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br); + lv_fs_res_t (*write_cb)(struct _lv_fs_drv_t * drv, void * file_p, const void * buf, uint32_t btw, uint32_t * bw); + lv_fs_res_t (*seek_cb)(struct _lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence); + lv_fs_res_t (*tell_cb)(struct _lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p); + + void * (*dir_open_cb)(struct _lv_fs_drv_t * drv, const char * path); + lv_fs_res_t (*dir_read_cb)(struct _lv_fs_drv_t * drv, void * rddir_p, char * fn); + lv_fs_res_t (*dir_close_cb)(struct _lv_fs_drv_t * drv, void * rddir_p); + +#if LV_USE_USER_DATA + void * user_data; /**< Custom file user data*/ +#endif +} lv_fs_drv_t; + +typedef struct { + uint32_t start; + uint32_t end; + uint32_t file_position; + void * buffer; +} lv_fs_file_cache_t; + +typedef struct { + void * file_d; + lv_fs_drv_t * drv; + lv_fs_file_cache_t * cache; +} lv_fs_file_t; + +typedef struct { + void * dir_d; + lv_fs_drv_t * drv; +} lv_fs_dir_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the File system interface + */ +void _lv_fs_init(void); + +/** + * Initialize a file system driver with default values. + * It is used to surly have known values in the fields ant not memory junk. + * After it you can set the fields. + * @param drv pointer to driver variable to initialize + */ +void lv_fs_drv_init(lv_fs_drv_t * drv); + +/** + * Add a new drive + * @param drv pointer to an lv_fs_drv_t structure which is inited with the + * corresponding function pointers. Only pointer is saved, so the + * driver should be static or dynamically allocated. + */ +void lv_fs_drv_register(lv_fs_drv_t * drv); + +/** + * Give a pointer to a driver from its letter + * @param letter the driver letter + * @return pointer to a driver or NULL if not found + */ +lv_fs_drv_t * lv_fs_get_drv(char letter); + +/** + * Test if a drive is ready or not. If the `ready` function was not initialized `true` will be + * returned. + * @param letter letter of the drive + * @return true: drive is ready; false: drive is not ready + */ +bool lv_fs_is_ready(char letter); + +/** + * Open a file + * @param file_p pointer to a lv_fs_file_t variable + * @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt) + * @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode); + +/** + * Close an already opened file + * @param file_p pointer to a lv_fs_file_t variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_close(lv_fs_file_t * file_p); + +/** + * Read from a file + * @param file_p pointer to a lv_fs_file_t variable + * @param buf pointer to a buffer where the read bytes are stored + * @param btr Bytes To Read + * @param br the number of real read bytes (Bytes Read). NULL if unused. + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_read(lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br); + +/** + * Write into a file + * @param file_p pointer to a lv_fs_file_t variable + * @param buf pointer to a buffer with the bytes to write + * @param btw Bytes To Write + * @param bw the number of real written bytes (Bytes Written). NULL if unused. + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_write(lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw); + +/** + * Set the position of the 'cursor' (read write pointer) in a file + * @param file_p pointer to a lv_fs_file_t variable + * @param pos the new position expressed in bytes index (0: start of file) + * @param whence tells from where set the position. See @lv_fs_whence_t + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_seek(lv_fs_file_t * file_p, uint32_t pos, lv_fs_whence_t whence); + +/** + * Give the position of the read write pointer + * @param file_p pointer to a lv_fs_file_t variable + * @param pos_p pointer to store the position of the read write pointer + * @return LV_FS_RES_OK or any error from 'fs_res_t' + */ +lv_fs_res_t lv_fs_tell(lv_fs_file_t * file_p, uint32_t * pos); + +/** + * Initialize a 'fs_dir_t' variable for directory reading + * @param rddir_p pointer to a 'lv_fs_dir_t' variable + * @param path path to a directory + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path); + +/** + * Read the next filename form a directory. + * The name of the directories will begin with '/' + * @param rddir_p pointer to an initialized 'fs_dir_t' variable + * @param fn pointer to a buffer to store the filename + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t * rddir_p, char * fn); + +/** + * Close the directory reading + * @param rddir_p pointer to an initialized 'fs_dir_t' variable + * @return LV_FS_RES_OK or any error from lv_fs_res_t enum + */ +lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p); + +/** + * Fill a buffer with the letters of existing drivers + * @param buf buffer to store the letters ('\0' added after the last letter) + * @return the buffer + */ +char * lv_fs_get_letters(char * buf); + +/** + * Return with the extension of the filename + * @param fn string with a filename + * @return pointer to the beginning extension or empty string if no extension + */ +const char * lv_fs_get_ext(const char * fn); + +/** + * Step up one level + * @param path pointer to a file name + * @return the truncated file name + */ +char * lv_fs_up(char * path); + +/** + * Get the last element of a path (e.g. U:/folder/file -> file) + * @param path pointer to a file name + * @return pointer to the beginning of the last element in the path + */ +const char * lv_fs_get_last(const char * path); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_FS_H*/ diff --git a/include/liblvgl/misc/lv_gc.h b/include/liblvgl/misc/lv_gc.h new file mode 100644 index 00000000..7a98d107 --- /dev/null +++ b/include/liblvgl/misc/lv_gc.h @@ -0,0 +1,97 @@ +/** + * @file lv_gc.h + * + */ + +#ifndef LV_GC_H +#define LV_GC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include +#include "lv_mem.h" +#include "lv_ll.h" +#include "lv_timer.h" +#include "lv_types.h" +#include "liblvgl/draw/lv_img_cache.h" +#include "liblvgl/draw/lv_draw_mask.h" +#include "liblvgl/core/lv_obj_pos.h" + +/********************* + * DEFINES + *********************/ +#if LV_IMG_CACHE_DEF_SIZE +# define LV_IMG_CACHE_DEF 1 +#else +# define LV_IMG_CACHE_DEF 0 +#endif + +#define LV_DISPATCH(f, t, n) f(t, n) +#define LV_DISPATCH_COND(f, t, n, m, v) LV_CONCAT3(LV_DISPATCH, m, v)(f, t, n) + +#define LV_DISPATCH00(f, t, n) LV_DISPATCH(f, t, n) +#define LV_DISPATCH01(f, t, n) +#define LV_DISPATCH10(f, t, n) +#define LV_DISPATCH11(f, t, n) LV_DISPATCH(f, t, n) + +#define LV_ITERATE_ROOTS(f) \ + LV_DISPATCH(f, lv_ll_t, _lv_timer_ll) /*Linked list to store the lv_timers*/ \ + LV_DISPATCH(f, lv_ll_t, _lv_disp_ll) /*Linked list of display device*/ \ + LV_DISPATCH(f, lv_ll_t, _lv_indev_ll) /*Linked list of input device*/ \ + LV_DISPATCH(f, lv_ll_t, _lv_fsdrv_ll) \ + LV_DISPATCH(f, lv_ll_t, _lv_anim_ll) \ + LV_DISPATCH(f, lv_ll_t, _lv_group_ll) \ + LV_DISPATCH(f, lv_ll_t, _lv_img_decoder_ll) \ + LV_DISPATCH(f, lv_ll_t, _lv_obj_style_trans_ll) \ + LV_DISPATCH(f, lv_layout_dsc_t *, _lv_layout_list) \ + LV_DISPATCH_COND(f, _lv_img_cache_entry_t*, _lv_img_cache_array, LV_IMG_CACHE_DEF, 1) \ + LV_DISPATCH_COND(f, _lv_img_cache_entry_t, _lv_img_cache_single, LV_IMG_CACHE_DEF, 0) \ + LV_DISPATCH(f, lv_timer_t*, _lv_timer_act) \ + LV_DISPATCH(f, lv_mem_buf_arr_t , lv_mem_buf) \ + LV_DISPATCH_COND(f, _lv_draw_mask_radius_circle_dsc_arr_t , _lv_circle_cache, LV_DRAW_COMPLEX, 1) \ + LV_DISPATCH_COND(f, _lv_draw_mask_saved_arr_t , _lv_draw_mask_list, LV_DRAW_COMPLEX, 1) \ + LV_DISPATCH(f, void * , _lv_theme_default_styles) \ + LV_DISPATCH(f, void * , _lv_theme_basic_styles) \ + LV_DISPATCH_COND(f, uint8_t *, _lv_font_decompr_buf, LV_USE_FONT_COMPRESSED, 1) \ + LV_DISPATCH(f, uint8_t * , _lv_grad_cache_mem) \ + LV_DISPATCH(f, uint8_t * , _lv_style_custom_prop_flag_lookup_table) + +#define LV_DEFINE_ROOT(root_type, root_name) root_type root_name; +#define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT) + +#if LV_ENABLE_GC == 1 +#if LV_MEM_CUSTOM != 1 +#error "GC requires CUSTOM_MEM" +#endif /*LV_MEM_CUSTOM*/ +#include LV_GC_INCLUDE +#else /*LV_ENABLE_GC*/ +#define LV_GC_ROOT(x) x +#define LV_EXTERN_ROOT(root_type, root_name) extern root_type root_name; +LV_ITERATE_ROOTS(LV_EXTERN_ROOT) +#endif /*LV_ENABLE_GC*/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +void _lv_gc_clear_roots(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_GC_H*/ diff --git a/include/display/lv_misc/lv_ll.h b/include/liblvgl/misc/lv_ll.h similarity index 55% rename from include/display/lv_misc/lv_ll.h rename to include/liblvgl/misc/lv_ll.h index 086ba405..d38f6928 100644 --- a/include/display/lv_misc/lv_ll.h +++ b/include/liblvgl/misc/lv_ll.h @@ -1,5 +1,5 @@ /** - * @file lv_ll.c + * @file lv_ll.h * Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module. */ @@ -10,13 +10,12 @@ extern "C" { #endif - /********************* * INCLUDES *********************/ -#include "lv_mem.h" #include #include +#include /********************* * DEFINES @@ -26,15 +25,14 @@ extern "C" { * TYPEDEFS **********************/ -/*Dummy type to make handling easier*/ +/** Dummy type to make handling easier*/ typedef uint8_t lv_ll_node_t; -/*Description of a linked list*/ -typedef struct -{ +/** Description of a linked list*/ +typedef struct { uint32_t n_size; - lv_ll_node_t* head; - lv_ll_node_t* tail; + lv_ll_node_t * head; + lv_ll_node_t * tail; } lv_ll_t; /********************** @@ -43,68 +41,70 @@ typedef struct /** * Initialize linked list - * @param ll_dsc pointer to ll_dsc variable + * @param ll_p pointer to lv_ll_t variable * @param node_size the size of 1 node in bytes */ -void lv_ll_init(lv_ll_t * ll_p, uint32_t node_size); +void _lv_ll_init(lv_ll_t * ll_p, uint32_t node_size); /** * Add a new head to a linked list * @param ll_p pointer to linked list * @return pointer to the new head */ -void * lv_ll_ins_head(lv_ll_t * ll_p); +void * _lv_ll_ins_head(lv_ll_t * ll_p); /** * Insert a new node in front of the n_act node * @param ll_p pointer to linked list * @param n_act pointer a node - * @return pointer to the new head + * @return pointer to the new node */ -void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act); +void * _lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act); /** * Add a new tail to a linked list * @param ll_p pointer to linked list * @return pointer to the new tail */ -void * lv_ll_ins_tail(lv_ll_t * ll_p); +void * _lv_ll_ins_tail(lv_ll_t * ll_p); /** * Remove the node 'node_p' from 'll_p' linked list. - * It does not free the the memory of node. + * It does not free the memory of node. * @param ll_p pointer to the linked list of 'node_p' * @param node_p pointer to node in 'll_p' linked list */ -void lv_ll_rem(lv_ll_t * ll_p, void * node_p); +void _lv_ll_remove(lv_ll_t * ll_p, void * node_p); /** * Remove and free all elements from a linked list. The list remain valid but become empty. * @param ll_p pointer to linked list */ -void lv_ll_clear(lv_ll_t * ll_p); +void _lv_ll_clear(lv_ll_t * ll_p); /** * Move a node to a new linked list * @param ll_ori_p pointer to the original (old) linked list * @param ll_new_p pointer to the new linked list * @param node pointer to a node + * @param head true: be the head in the new list + * false be the tail in the new list */ -void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node); +void _lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool head); /** * Return with head node of the linked list * @param ll_p pointer to linked list * @return pointer to the head of 'll_p' */ -void * lv_ll_get_head(const lv_ll_t * ll_p); +void * _lv_ll_get_head(const lv_ll_t * ll_p); /** * Return with tail node of the linked list * @param ll_p pointer to linked list - * @return pointer to the head of 'll_p' + * @return pointer to the tail of 'll_p' */ -void * lv_ll_get_tail(const lv_ll_t * ll_p); +void * _lv_ll_get_tail(const lv_ll_t * ll_p); /** * Return with the pointer of the next node after 'n_act' @@ -112,7 +112,7 @@ void * lv_ll_get_tail(const lv_ll_t * ll_p); * @param n_act pointer a node * @return pointer to the next node */ -void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act); +void * _lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act); /** * Return with the pointer of the previous node after 'n_act' @@ -120,26 +120,48 @@ void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act); * @param n_act pointer a node * @return pointer to the previous node */ -void * lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act); +void * _lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act); + +/** + * Return the length of the linked list. + * @param ll_p pointer to linked list + * @return length of the linked list + */ +uint32_t _lv_ll_get_len(const lv_ll_t * ll_p); /** - * Move a nodw before an other node in the same linked list + * TODO + * @param ll_p + * @param n1_p + * @param n2_p +void lv_ll_swap(lv_ll_t * ll_p, void * n1_p, void * n2_p); + */ + +/** + * Move a node before an other node in the same linked list * @param ll_p pointer to a linked list * @param n_act pointer to node to move * @param n_after pointer to a node which should be after `n_act` */ -void lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after); +void _lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after); + +/** + * Check if a linked list is empty + * @param ll_p pointer to a linked list + * @return true: the linked list is empty; false: not empty + */ +bool _lv_ll_is_empty(lv_ll_t * ll_p); /********************** * MACROS **********************/ -#define LL_READ(list, i) for(i = lv_ll_get_head(&list); i != NULL; i = lv_ll_get_next(&list, i)) +#define _LV_LL_READ(list, i) for(i = _lv_ll_get_head(list); i != NULL; i = _lv_ll_get_next(list, i)) -#define LL_READ_BACK(list, i) for(i = lv_ll_get_tail(&list); i != NULL; i = lv_ll_get_prev(&list, i)) +#define _LV_LL_READ_BACK(list, i) for(i = _lv_ll_get_tail(list); i != NULL; i = _lv_ll_get_prev(list, i)) #ifdef __cplusplus -} /* extern "C" */ +} /*extern "C"*/ #endif #endif diff --git a/include/liblvgl/misc/lv_log.h b/include/liblvgl/misc/lv_log.h new file mode 100644 index 00000000..cd61905d --- /dev/null +++ b/include/liblvgl/misc/lv_log.h @@ -0,0 +1,154 @@ +/** + * @file lv_log.h + * + */ + +#ifndef LV_LOG_H +#define LV_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include + +#include "lv_types.h" + +/********************* + * DEFINES + *********************/ + +/*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/ + +#define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/ +#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/ +#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/ +#define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/ +#define LV_LOG_LEVEL_USER 4 /**< Custom logs from the user*/ +#define LV_LOG_LEVEL_NONE 5 /**< Do not log anything*/ +#define _LV_LOG_LEVEL_NUM 6 /**< Number of log levels*/ + +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_WARN); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_ERROR); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_USER); +LV_EXPORT_CONST_INT(LV_LOG_LEVEL_NONE); + +typedef int8_t lv_log_level_t; + +#if LV_USE_LOG +/********************** + * TYPEDEFS + **********************/ + +/** + * Log print function. Receives a string buffer to print". + */ +typedef void (*lv_log_print_g_cb_t)(const char * buf); + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Register custom print/write function to call when a log is added. + * It can format its "File path", "Line number" and "Description" as required + * and send the formatted log message to a console or serial port. + * @param print_cb a function pointer to print a log + */ +void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb); + +/** + * Print a log message via `printf` if enabled with `LV_LOG_PRINTF` in `lv_conf.h` + * and/or a print callback if registered with `lv_log_register_print_cb` + * @param format printf-like format string + * @param ... parameters for `format` + */ +void lv_log(const char * format, ...) LV_FORMAT_ATTRIBUTE(1, 2); + +/** + * Add a log + * @param level the level of log. (From `lv_log_level_t` enum) + * @param file name of the file when the log added + * @param line line number in the source code where the log added + * @param func name of the function when the log added + * @param format printf-like format string + * @param ... parameters for `format` + */ +void _lv_log_add(lv_log_level_t level, const char * file, int line, + const char * func, const char * format, ...) LV_FORMAT_ATTRIBUTE(5, 6); + +/********************** + * MACROS + **********************/ +#ifndef LV_LOG_TRACE +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_TRACE +# define LV_LOG_TRACE(...) _lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_TRACE(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG_INFO +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO +# define LV_LOG_INFO(...) _lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_INFO(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG_WARN +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_WARN +# define LV_LOG_WARN(...) _lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_WARN(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG_ERROR +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_ERROR +# define LV_LOG_ERROR(...) _lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_ERROR(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG_USER +# if LV_LOG_LEVEL <= LV_LOG_LEVEL_USER +# define LV_LOG_USER(...) _lv_log_add(LV_LOG_LEVEL_USER, __FILE__, __LINE__, __func__, __VA_ARGS__) +# else +# define LV_LOG_USER(...) do {}while(0) +# endif +#endif + +#ifndef LV_LOG +# if LV_LOG_LEVEL < LV_LOG_LEVEL_NONE +# define LV_LOG(...) lv_log(__VA_ARGS__) +# else +# define LV_LOG(...) do {} while(0) +# endif +#endif + +#else /*LV_USE_LOG*/ + +/*Do nothing if `LV_USE_LOG 0`*/ +#define _lv_log_add(level, file, line, ...) +#define LV_LOG_TRACE(...) do {}while(0) +#define LV_LOG_INFO(...) do {}while(0) +#define LV_LOG_WARN(...) do {}while(0) +#define LV_LOG_ERROR(...) do {}while(0) +#define LV_LOG_USER(...) do {}while(0) +#define LV_LOG(...) do {}while(0) + +#endif /*LV_USE_LOG*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LOG_H*/ diff --git a/include/liblvgl/misc/lv_lru.h b/include/liblvgl/misc/lv_lru.h new file mode 100644 index 00000000..3e9729e0 --- /dev/null +++ b/include/liblvgl/misc/lv_lru.h @@ -0,0 +1,87 @@ +/** + * @file lv_lru.h + * + */ + +#ifndef LV_LRU_H +#define LV_LRU_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "liblvgl/lv_conf_internal.h" + +#include "lv_types.h" + +#include +#include + + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef enum { + LV_LRU_OK = 0, + LV_LRU_MISSING_CACHE, + LV_LRU_MISSING_KEY, + LV_LRU_MISSING_VALUE, + LV_LRU_LOCK_ERROR, + LV_LRU_VALUE_TOO_LARGE +} lv_lru_res_t; + +typedef void (lv_lru_free_t)(void * v); +typedef struct _lv_lru_item_t lv_lru_item_t; + +typedef struct lv_lru_t { + lv_lru_item_t ** items; + uint64_t access_count; + size_t free_memory; + size_t total_memory; + size_t average_item_length; + size_t hash_table_size; + uint32_t seed; + lv_lru_free_t * value_free; + lv_lru_free_t * key_free; + lv_lru_item_t * free_items; +} lv_lru_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_lru_t * lv_lru_create(size_t cache_size, size_t average_length, lv_lru_free_t * value_free, + lv_lru_free_t * key_free); + +void lv_lru_del(lv_lru_t * cache); + +lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, void * value, size_t value_length); + +lv_lru_res_t lv_lru_get(lv_lru_t * cache, const void * key, size_t key_size, void ** value); + +lv_lru_res_t lv_lru_remove(lv_lru_t * cache, const void * key, size_t key_size); + +/** + * remove the least recently used item + * + * @todo we can optimise this by finding the n lru items, where n = required_space / average_length + */ +void lv_lru_remove_lru_item(lv_lru_t * cache); +/********************** + * MACROS + **********************/ +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LRU_H*/ diff --git a/include/liblvgl/misc/lv_math.h b/include/liblvgl/misc/lv_math.h new file mode 100644 index 00000000..24f9ea6c --- /dev/null +++ b/include/liblvgl/misc/lv_math.h @@ -0,0 +1,143 @@ +/** + * @file lv_math.h + * + */ + +#ifndef LV_MATH_H +#define LV_MATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include + +/********************* + * DEFINES + *********************/ +#define LV_TRIGO_SIN_MAX 32767 +#define LV_TRIGO_SHIFT 15 /**< >> LV_TRIGO_SHIFT to normalize*/ + +#define LV_BEZIER_VAL_MAX 1024 /**< Max time in Bezier functions (not [0..1] to use integers)*/ +#define LV_BEZIER_VAL_SHIFT 10 /**< log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + uint16_t i; + uint16_t f; +} lv_sqrt_res_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +//! @cond Doxygen_Suppress +/** + * Return with sinus of an angle + * @param angle + * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 + */ +LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_sin(int16_t angle); + +static inline LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_cos(int16_t angle) +{ + return lv_trigo_sin(angle + 90); +} + +//! @endcond + +/** + * Calculate a value of a Cubic Bezier function. + * @param t time in range of [0..LV_BEZIER_VAL_MAX] + * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] + * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] + * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] + * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] + * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] + */ +uint32_t lv_bezier3(uint32_t t, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3); + +/** + * Calculate the atan2 of a vector. + * @param x + * @param y + * @return the angle in degree calculated from the given parameters in range of [0..360] + */ +uint16_t lv_atan2(int x, int y); + +//! @cond Doxygen_Suppress + +/** + * Get the square root of a number + * @param x integer which square root should be calculated + * @param q store the result here. q->i: integer part, q->f: fractional part in 1/256 unit + * @param mask optional to skip some iterations if the magnitude of the root is known. + * Set to 0x8000 by default. + * If root < 16: mask = 0x80 + * If root < 256: mask = 0x800 + * Else: mask = 0x8000 + */ +LV_ATTRIBUTE_FAST_MEM void lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask); + +//! @endcond + +/** + * Calculate the integer exponents. + * @param base + * @param power + * @return base raised to the power exponent + */ +int64_t lv_pow(int64_t base, int8_t exp); + +/** + * Get the mapped of a number given an input and output range + * @param x integer which mapped value should be calculated + * @param min_in min input range + * @param max_in max input range + * @param min_out max output range + * @param max_out max output range + * @return the mapped number + */ +int32_t lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out); + +/** + * Get a pseudo random number in the given range + * @param min the minimum value + * @param max the maximum value + * @return return the random number. min <= return_value <= max + */ +uint32_t lv_rand(uint32_t min, uint32_t max); + +/********************** + * MACROS + **********************/ +#define LV_MIN(a, b) ((a) < (b) ? (a) : (b)) +#define LV_MIN3(a, b, c) (LV_MIN(LV_MIN(a,b), c)) +#define LV_MIN4(a, b, c, d) (LV_MIN(LV_MIN(a,b), LV_MIN(c,d))) + +#define LV_MAX(a, b) ((a) > (b) ? (a) : (b)) +#define LV_MAX3(a, b, c) (LV_MAX(LV_MAX(a,b), c)) +#define LV_MAX4(a, b, c, d) (LV_MAX(LV_MAX(a,b), LV_MAX(c,d))) + +#define LV_CLAMP(min, val, max) (LV_MAX(min, (LV_MIN(val, max)))) + +#define LV_ABS(x) ((x) > 0 ? (x) : (-(x))) +#define LV_UDIV255(x) (((x) * 0x8081U) >> 0x17) + +#define LV_IS_SIGNED(t) (((t)(-1)) < ((t)0)) +#define LV_UMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0xFULL << ((sizeof(t) * 8ULL) - 4ULL))) +#define LV_SMAX_OF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | (0x7ULL << ((sizeof(t) * 8ULL) - 4ULL))) +#define LV_MAX_OF(t) ((unsigned long)(LV_IS_SIGNED(t) ? LV_SMAX_OF(t) : LV_UMAX_OF(t))) + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/liblvgl/misc/lv_mem.h b/include/liblvgl/misc/lv_mem.h new file mode 100644 index 00000000..fd202aba --- /dev/null +++ b/include/liblvgl/misc/lv_mem.h @@ -0,0 +1,243 @@ +/** + * @file lv_mem.h + * + */ + +#ifndef LV_MEM_H +#define LV_MEM_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include + +#include "lv_types.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Heap information structure. + */ +typedef struct { + uint32_t total_size; /**< Total heap size*/ + uint32_t free_cnt; + uint32_t free_size; /**< Size of available memory*/ + uint32_t free_biggest_size; + uint32_t used_cnt; + uint32_t max_used; /**< Max size of Heap memory used*/ + uint8_t used_pct; /**< Percentage used*/ + uint8_t frag_pct; /**< Amount of fragmentation*/ +} lv_mem_monitor_t; + +typedef struct { + void * p; + uint16_t size; + uint8_t used : 1; +} lv_mem_buf_t; + +typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM]; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Initialize the dyn_mem module (work memory and other variables) + */ +void lv_mem_init(void); + +/** + * Clean up the memory buffer which frees all the allocated memories. + * @note It work only if `LV_MEM_CUSTOM == 0` + */ +void lv_mem_deinit(void); + +/** + * Allocate a memory dynamically + * @param size size of the memory to allocate in bytes + * @return pointer to the allocated memory + */ +void * lv_mem_alloc(size_t size); + +/** + * Free an allocated data + * @param data pointer to an allocated memory + */ +void lv_mem_free(void * data); + +/** + * Reallocate a memory with a new size. The old content will be kept. + * @param data pointer to an allocated memory. + * Its content will be copied to the new memory block and freed + * @param new_size the desired new size in byte + * @return pointer to the new memory, NULL on failure + */ +void * lv_mem_realloc(void * data_p, size_t new_size); + +/** + * + * @return + */ +lv_res_t lv_mem_test(void); + +/** + * Give information about the work memory of dynamic allocation + * @param mon_p pointer to a lv_mem_monitor_t variable, + * the result of the analysis will be stored here + */ +void lv_mem_monitor(lv_mem_monitor_t * mon_p); + + +/** + * Get a temporal buffer with the given size. + * @param size the required size + */ +void * lv_mem_buf_get(uint32_t size); + +/** + * Release a memory buffer + * @param p buffer to release + */ +void lv_mem_buf_release(void * p); + +/** + * Free all memory buffers + */ +void lv_mem_buf_free_all(void); + +//! @cond Doxygen_Suppress + +#if LV_MEMCPY_MEMSET_STD + +/** + * Wrapper for the standard memcpy + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +static inline void * lv_memcpy(void * dst, const void * src, size_t len) +{ + return memcpy(dst, src, len); +} + +/** + * Wrapper for the standard memcpy + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +static inline void * lv_memcpy_small(void * dst, const void * src, size_t len) +{ + return memcpy(dst, src, len); +} + +/** + * Wrapper for the standard memset + * @param dst pointer to the destination buffer + * @param v value to set [0..255] + * @param len number of byte to set + */ +static inline void lv_memset(void * dst, uint8_t v, size_t len) +{ + memset(dst, v, len); +} + +/** + * Wrapper for the standard memset with fixed 0x00 value + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +static inline void lv_memset_00(void * dst, size_t len) +{ + memset(dst, 0x00, len); +} + +/** + * Wrapper for the standard memset with fixed 0xFF value + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +static inline void lv_memset_ff(void * dst, size_t len) +{ + memset(dst, 0xFF, len); +} + +#else +/** + * Same as `memcpy` but optimized for 4 byte operation. + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +LV_ATTRIBUTE_FAST_MEM void * lv_memcpy(void * dst, const void * src, size_t len); + +/** + * Same as `memcpy` but optimized to copy only a few bytes. + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +LV_ATTRIBUTE_FAST_MEM static inline void * lv_memcpy_small(void * dst, const void * src, size_t len) +{ + uint8_t * d8 = (uint8_t *)dst; + const uint8_t * s8 = (const uint8_t *)src; + + while(len) { + *d8 = *s8; + d8++; + s8++; + len--; + } + + return dst; +} + +/** + * Same as `memset` but optimized for 4 byte operation. + * @param dst pointer to the destination buffer + * @param v value to set [0..255] + * @param len number of byte to set + */ +LV_ATTRIBUTE_FAST_MEM void lv_memset(void * dst, uint8_t v, size_t len); + +/** + * Same as `memset(dst, 0x00, len)` but optimized for 4 byte operation. + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +LV_ATTRIBUTE_FAST_MEM void lv_memset_00(void * dst, size_t len); + +/** + * Same as `memset(dst, 0xFF, len)` but optimized for 4 byte operation. + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +LV_ATTRIBUTE_FAST_MEM void lv_memset_ff(void * dst, size_t len); + +//! @endcond + +#endif + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_MEM_H*/ diff --git a/include/liblvgl/misc/lv_printf.h b/include/liblvgl/misc/lv_printf.h new file mode 100644 index 00000000..4cbbd84c --- /dev/null +++ b/include/liblvgl/misc/lv_printf.h @@ -0,0 +1,92 @@ +/////////////////////////////////////////////////////////////////////////////// +// \author (c) Marco Paland (info@paland.com) +// 2014-2019, PALANDesign Hannover, Germany +// +// \license The MIT License (MIT) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on +// embedded systems with a very limited resources. +// Use this instead of bloated standard/newlib printf. +// These routines are thread safe and reentrant. +// +/////////////////////////////////////////////////////////////////////////////// + +/*Original repository: https://github.com/mpaland/printf*/ + +#ifndef _LV_PRINTF_H_ +#define _LV_PRINTF_H_ + +#if defined(__has_include) + #if __has_include() + #include + /* platform-specific printf format for int32_t, usually "d" or "ld" */ + #define LV_PRId32 PRId32 + #define LV_PRIu32 PRIu32 + #else + #define LV_PRId32 "d" + #define LV_PRIu32 "u" + #endif +#else + /* hope this is correct for ports without __has_include or without inttypes.h */ + #define LV_PRId32 "d" + #define LV_PRIu32 "u" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../lv_conf_internal.h" + +#if LV_SPRINTF_CUSTOM == 0 + +#include +#include + +#include "lv_types.h" + +typedef struct { + const char * fmt; + va_list * va; +} lv_vaformat_t; + +/** + * Tiny snprintf/vsnprintf implementation + * \param buffer A pointer to the buffer where to store the formatted string + * \param count The maximum number of characters to store in the buffer, including a terminating null character + * \param format A string that specifies the format of the output + * \param va A value identifying a variable arguments list + * \return The number of characters that COULD have been written into the buffer, not counting the terminating + * null character. A value equal or larger than count indicates truncation. Only when the returned value + * is non-negative and less than count, the string has been completely written. + */ +int lv_snprintf(char * buffer, size_t count, const char * format, ...) LV_FORMAT_ATTRIBUTE(3, 4); +int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va) LV_FORMAT_ATTRIBUTE(3, 0); + +#else +#include LV_SPRINTF_INCLUDE +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif // _LV_PRINTF_H_ diff --git a/include/liblvgl/misc/lv_style.h b/include/liblvgl/misc/lv_style.h new file mode 100644 index 00000000..44a542dc --- /dev/null +++ b/include/liblvgl/misc/lv_style.h @@ -0,0 +1,592 @@ +/** + * @file lv_style.h + * + */ + +#ifndef LV_STYLE_H +#define LV_STYLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include +#include "liblvgl/font/lv_font.h" +#include "lv_color.h" +#include "lv_area.h" +#include "lv_anim.h" +#include "lv_txt.h" +#include "lv_types.h" +#include "lv_assert.h" +#include "lv_bidi.h" + +/********************* + * DEFINES + *********************/ + +#define LV_STYLE_SENTINEL_VALUE 0xAABBCCDD + +/** + * Flags for style behavior + * + * The rest of the flags will have _FLAG added to their name in v9. + */ +#define LV_STYLE_PROP_FLAG_NONE (0) +#define LV_STYLE_PROP_INHERIT (1 << 0) /*Inherited*/ +#define LV_STYLE_PROP_EXT_DRAW (1 << 1) /*Requires ext. draw size update when changed*/ +#define LV_STYLE_PROP_LAYOUT_REFR (1 << 2) /*Requires layout update when changed*/ +#define LV_STYLE_PROP_PARENT_LAYOUT_REFR (1 << 3) /*Requires layout update on parent when changed*/ +#define LV_STYLE_PROP_LAYER_REFR (1 << 4) /*Affects layer handling*/ +#define LV_STYLE_PROP_ALL (0x1F) /*Indicating all flags*/ + +/** + * Other constants + */ +#define LV_IMG_ZOOM_NONE 256 /*Value for not zooming the image*/ +LV_EXPORT_CONST_INT(LV_IMG_ZOOM_NONE); + +// *INDENT-OFF* +#if LV_USE_ASSERT_STYLE +#define LV_STYLE_CONST_INIT(var_name, prop_array) \ + const lv_style_t var_name = { \ + .sentinel = LV_STYLE_SENTINEL_VALUE, \ + .v_p = { .const_props = prop_array }, \ + .has_group = 0xFF, \ + .prop1 = LV_STYLE_PROP_ANY, \ + .prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \ + } +#else +#define LV_STYLE_CONST_INIT(var_name, prop_array) \ + const lv_style_t var_name = { \ + .v_p = { .const_props = prop_array }, \ + .has_group = 0xFF, \ + .prop1 = LV_STYLE_PROP_ANY, \ + .prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \ + } +#endif +// *INDENT-ON* + +#define LV_STYLE_PROP_META_INHERIT 0x8000 +#define LV_STYLE_PROP_META_INITIAL 0x4000 +#define LV_STYLE_PROP_META_MASK (LV_STYLE_PROP_META_INHERIT | LV_STYLE_PROP_META_INITIAL) + +#define LV_STYLE_PROP_ID_MASK(prop) ((lv_style_prop_t)((prop) & ~LV_STYLE_PROP_META_MASK)) + +/********************** + * TYPEDEFS + **********************/ + +/** + * Possible options how to blend opaque drawings + */ +enum { + LV_BLEND_MODE_NORMAL, /**< Simply mix according to the opacity value*/ + LV_BLEND_MODE_ADDITIVE, /**< Add the respective color channels*/ + LV_BLEND_MODE_SUBTRACTIVE,/**< Subtract the foreground from the background*/ + LV_BLEND_MODE_MULTIPLY, /**< Multiply the foreground and background*/ + LV_BLEND_MODE_REPLACE, /**< Replace background with foreground in the area*/ +}; + +typedef uint8_t lv_blend_mode_t; + +/** + * Some options to apply decorations on texts. + * 'OR'ed values can be used. + */ +enum { + LV_TEXT_DECOR_NONE = 0x00, + LV_TEXT_DECOR_UNDERLINE = 0x01, + LV_TEXT_DECOR_STRIKETHROUGH = 0x02, +}; + +typedef uint8_t lv_text_decor_t; + +/** + * Selects on which sides border should be drawn + * 'OR'ed values can be used. + */ +enum { + LV_BORDER_SIDE_NONE = 0x00, + LV_BORDER_SIDE_BOTTOM = 0x01, + LV_BORDER_SIDE_TOP = 0x02, + LV_BORDER_SIDE_LEFT = 0x04, + LV_BORDER_SIDE_RIGHT = 0x08, + LV_BORDER_SIDE_FULL = 0x0F, + LV_BORDER_SIDE_INTERNAL = 0x10, /**< FOR matrix-like objects (e.g. Button matrix)*/ +}; +typedef uint8_t lv_border_side_t; + +/** + * The direction of the gradient. + */ +enum { + LV_GRAD_DIR_NONE, /**< No gradient (the `grad_color` property is ignored)*/ + LV_GRAD_DIR_VER, /**< Vertical (top to bottom) gradient*/ + LV_GRAD_DIR_HOR, /**< Horizontal (left to right) gradient*/ +}; + +typedef uint8_t lv_grad_dir_t; + +/** + * The dithering algorithm for the gradient + * Depends on LV_DITHER_GRADIENT + */ +enum { + LV_DITHER_NONE, /**< No dithering, colors are just quantized to the output resolution*/ + LV_DITHER_ORDERED, /**< Ordered dithering. Faster to compute and use less memory but lower quality*/ + LV_DITHER_ERR_DIFF, /**< Error diffusion mode. Slower to compute and use more memory but give highest dither quality*/ +}; + +typedef uint8_t lv_dither_mode_t; + +/** A gradient stop definition. + * This matches a color and a position in a virtual 0-255 scale. + */ +typedef struct { + lv_color_t color; /**< The stop color */ + uint8_t frac; /**< The stop position in 1/255 unit */ +} lv_gradient_stop_t; + +/** A descriptor of a gradient. */ +typedef struct { + lv_gradient_stop_t stops[LV_GRADIENT_MAX_STOPS]; /**< A gradient stop array */ + uint8_t stops_count; /**< The number of used stops in the array */ + lv_grad_dir_t dir : 3; /**< The gradient direction. + * Any of LV_GRAD_DIR_HOR, LV_GRAD_DIR_VER, LV_GRAD_DIR_NONE */ + lv_dither_mode_t dither : 3; /**< Whether to dither the gradient or not. + * Any of LV_DITHER_NONE, LV_DITHER_ORDERED, LV_DITHER_ERR_DIFF */ +} lv_grad_dsc_t; + +/** + * A common type to handle all the property types in the same way. + */ +typedef union { + int32_t num; /**< Number integer number (opacity, enums, booleans or "normal" numbers)*/ + const void * ptr; /**< Constant pointers (font, cone text, etc)*/ + lv_color_t color; /**< Colors*/ +} lv_style_value_t; + +/** + * Enumeration of all built in style properties + * + * Props are split into groups of 16. When adding a new prop to a group, ensure it does not overflow into the next one. + */ +typedef enum { + LV_STYLE_PROP_INV = 0, + + /*Group 0*/ + LV_STYLE_WIDTH = 1, + LV_STYLE_MIN_WIDTH = 2, + LV_STYLE_MAX_WIDTH = 3, + LV_STYLE_HEIGHT = 4, + LV_STYLE_MIN_HEIGHT = 5, + LV_STYLE_MAX_HEIGHT = 6, + LV_STYLE_X = 7, + LV_STYLE_Y = 8, + LV_STYLE_ALIGN = 9, + LV_STYLE_LAYOUT = 10, + LV_STYLE_RADIUS = 11, + + /*Group 1*/ + LV_STYLE_PAD_TOP = 16, + LV_STYLE_PAD_BOTTOM = 17, + LV_STYLE_PAD_LEFT = 18, + LV_STYLE_PAD_RIGHT = 19, + LV_STYLE_PAD_ROW = 20, + LV_STYLE_PAD_COLUMN = 21, + LV_STYLE_BASE_DIR = 22, + LV_STYLE_CLIP_CORNER = 23, + + /*Group 2*/ + LV_STYLE_BG_COLOR = 32, + LV_STYLE_BG_OPA = 33, + LV_STYLE_BG_GRAD_COLOR = 34, + LV_STYLE_BG_GRAD_DIR = 35, + LV_STYLE_BG_MAIN_STOP = 36, + LV_STYLE_BG_GRAD_STOP = 37, + LV_STYLE_BG_GRAD = 38, + LV_STYLE_BG_DITHER_MODE = 39, + LV_STYLE_BG_IMG_SRC = 40, + LV_STYLE_BG_IMG_OPA = 41, + LV_STYLE_BG_IMG_RECOLOR = 42, + LV_STYLE_BG_IMG_RECOLOR_OPA = 43, + LV_STYLE_BG_IMG_TILED = 44, + + /*Group 3*/ + LV_STYLE_BORDER_COLOR = 48, + LV_STYLE_BORDER_OPA = 49, + LV_STYLE_BORDER_WIDTH = 50, + LV_STYLE_BORDER_SIDE = 51, + LV_STYLE_BORDER_POST = 52, + LV_STYLE_OUTLINE_WIDTH = 53, + LV_STYLE_OUTLINE_COLOR = 54, + LV_STYLE_OUTLINE_OPA = 55, + LV_STYLE_OUTLINE_PAD = 56, + + /*Group 4*/ + LV_STYLE_SHADOW_WIDTH = 64, + LV_STYLE_SHADOW_OFS_X = 65, + LV_STYLE_SHADOW_OFS_Y = 66, + LV_STYLE_SHADOW_SPREAD = 67, + LV_STYLE_SHADOW_COLOR = 68, + LV_STYLE_SHADOW_OPA = 69, + LV_STYLE_IMG_OPA = 70, + LV_STYLE_IMG_RECOLOR = 71, + LV_STYLE_IMG_RECOLOR_OPA = 72, + LV_STYLE_LINE_WIDTH = 73, + LV_STYLE_LINE_DASH_WIDTH = 74, + LV_STYLE_LINE_DASH_GAP = 75, + LV_STYLE_LINE_ROUNDED = 76, + LV_STYLE_LINE_COLOR = 77, + LV_STYLE_LINE_OPA = 78, + + /*Group 5*/ + LV_STYLE_ARC_WIDTH = 80, + LV_STYLE_ARC_ROUNDED = 81, + LV_STYLE_ARC_COLOR = 82, + LV_STYLE_ARC_OPA = 83, + LV_STYLE_ARC_IMG_SRC = 84, + LV_STYLE_TEXT_COLOR = 85, + LV_STYLE_TEXT_OPA = 86, + LV_STYLE_TEXT_FONT = 87, + LV_STYLE_TEXT_LETTER_SPACE = 88, + LV_STYLE_TEXT_LINE_SPACE = 89, + LV_STYLE_TEXT_DECOR = 90, + LV_STYLE_TEXT_ALIGN = 91, + + /*Group 6*/ + LV_STYLE_OPA = 96, + LV_STYLE_COLOR_FILTER_DSC = 97, + LV_STYLE_COLOR_FILTER_OPA = 98, + LV_STYLE_ANIM = 99, + LV_STYLE_ANIM_TIME = 100, + LV_STYLE_ANIM_SPEED = 101, + LV_STYLE_TRANSITION = 102, + LV_STYLE_BLEND_MODE = 103, + LV_STYLE_TRANSFORM_WIDTH = 104, + LV_STYLE_TRANSFORM_HEIGHT = 105, + LV_STYLE_TRANSLATE_X = 106, + LV_STYLE_TRANSLATE_Y = 107, + LV_STYLE_TRANSFORM_ZOOM = 108, + LV_STYLE_TRANSFORM_ANGLE = 109, + LV_STYLE_TRANSFORM_PIVOT_X = 110, + LV_STYLE_TRANSFORM_PIVOT_Y = 111, + + _LV_STYLE_LAST_BUILT_IN_PROP = 111, + _LV_STYLE_NUM_BUILT_IN_PROPS = _LV_STYLE_LAST_BUILT_IN_PROP + 1, + + LV_STYLE_PROP_ANY = 0xFFFF, + _LV_STYLE_PROP_CONST = 0xFFFF /* magic value for const styles */ +} lv_style_prop_t; + +enum { + LV_STYLE_RES_NOT_FOUND, + LV_STYLE_RES_FOUND, + LV_STYLE_RES_INHERIT +}; + +typedef uint8_t lv_style_res_t; + +/** + * Descriptor for style transitions + */ +typedef struct { + const lv_style_prop_t * props; /**< An array with the properties to animate.*/ +#if LV_USE_USER_DATA + void * user_data; /**< A custom user data that will be passed to the animation's user_data */ +#endif + lv_anim_path_cb_t path_xcb; /**< A path for the animation.*/ + uint32_t time; /**< Duration of the transition in [ms]*/ + uint32_t delay; /**< Delay before the transition in [ms]*/ +} lv_style_transition_dsc_t; + +/** + * Descriptor of a constant style property. + */ +typedef struct { + lv_style_prop_t prop; + lv_style_value_t value; +} lv_style_const_prop_t; + +/** + * Descriptor of a style (a collection of properties and values). + */ +typedef struct { + +#if LV_USE_ASSERT_STYLE + uint32_t sentinel; +#endif + + /*If there is only one property store it directly. + *For more properties allocate an array*/ + union { + lv_style_value_t value1; + uint8_t * values_and_props; + const lv_style_const_prop_t * const_props; + } v_p; + + uint16_t prop1; + uint8_t has_group; + uint8_t prop_cnt; +} lv_style_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + + +/** + * Initialize a style + * @param style pointer to a style to initialize + * @note Do not call `lv_style_init` on styles that already have some properties + * because this function won't free the used memory, just sets a default state for the style. + * In other words be sure to initialize styles only once! + */ +void lv_style_init(lv_style_t * style); + +/** + * Clear all properties from a style and free all allocated memories. + * @param style pointer to a style + */ +void lv_style_reset(lv_style_t * style); + +/** + * Register a new style property for custom usage + * @return a new property ID, or LV_STYLE_PROP_INV if there are no more available. + * @example + * lv_style_prop_t MY_PROP; + * static inline void lv_style_set_my_prop(lv_style_t * style, lv_color_t value) { + * lv_style_value_t v = {.color = value}; lv_style_set_prop(style, MY_PROP, v); } + * + * ... + * MY_PROP = lv_style_register_prop(); + * ... + * lv_style_set_my_prop(&style1, lv_palette_main(LV_PALETTE_RED)); + */ +lv_style_prop_t lv_style_register_prop(uint8_t flag); + +/** + * Get the number of custom properties that have been registered thus far. + */ +lv_style_prop_t lv_style_get_num_custom_props(void); + +/** + * Remove a property from a style + * @param style pointer to a style + * @param prop a style property ORed with a state. + * @return true: the property was found and removed; false: the property wasn't found + */ +bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop); + +/** + * Set the value of property in a style. + * This function shouldn't be used directly by the user. + * Instead use `lv_style_set_()`. E.g. `lv_style_set_bg_color()` + * @param style pointer to style + * @param prop the ID of a property (e.g. `LV_STYLE_BG_COLOR`) + * @param value `lv_style_value_t` variable in which a field is set according to the type of `prop` + */ +void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value); + +/** + * Set a special meta state for a property in a style. + * This function shouldn't be used directly by the user. + * @param style pointer to style + * @param prop the ID of a property (e.g. `LV_STYLE_BG_COLOR`) + * @param meta the meta value to attach to the property in the style + */ +void lv_style_set_prop_meta(lv_style_t * style, lv_style_prop_t prop, uint16_t meta); + +/** + * Get the value of a property + * @param style pointer to a style + * @param prop the ID of a property + * @param value pointer to a `lv_style_value_t` variable to store the value + * @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged) + * LV_RES_OK: the property was fond, and `value` is set accordingly + * @note For performance reasons there are no sanity check on `style` + */ +lv_style_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value); + +/** + * Initialize a transition descriptor. + * @param tr pointer to a transition descriptor to initialize + * @param props an array with the properties to transition. The last element must be zero. + * @param path_cb an animation path (ease) callback. If `NULL` liner path will be used. + * @param time duration of the transition in [ms] + * @param delay delay before the transition in [ms] + * @param user_data any custom data that will be saved in the transition animation and will be available when `path_cb` is called + * @example + * const static lv_style_prop_t trans_props[] = { LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, 0 }; + * static lv_style_transition_dsc_t trans1; + * lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0, NULL); + */ +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], + lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data); + +/** + * Get the default value of a property + * @param prop the ID of a property + * @return the default value + */ +lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop); + +/** + * Get the value of a property + * @param style pointer to a style + * @param prop the ID of a property + * @param value pointer to a `lv_style_value_t` variable to store the value + * @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged) + * LV_RES_OK: the property was fond, and `value` is set accordingly + * @note For performance reasons there are no sanity check on `style` + * @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places + */ +static inline lv_style_res_t lv_style_get_prop_inlined(const lv_style_t * style, lv_style_prop_t prop, + lv_style_value_t * value) +{ + if(style->prop1 == LV_STYLE_PROP_ANY) { + const lv_style_const_prop_t * const_prop; + uint32_t i; + for(i = 0; i < style->prop_cnt; i++) { + const_prop = style->v_p.const_props + i; + lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(const_prop->prop); + if(prop_id == prop) { + if(const_prop->prop & LV_STYLE_PROP_META_INHERIT) + return LV_STYLE_RES_INHERIT; + *value = (const_prop->prop & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(prop_id) : const_prop->value; + return LV_STYLE_RES_FOUND; + } + } + return LV_STYLE_RES_NOT_FOUND; + } + + if(style->prop_cnt == 0) return LV_STYLE_RES_NOT_FOUND; + + if(style->prop_cnt > 1) { + uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t); + uint16_t * props = (uint16_t *)tmp; + uint32_t i; + for(i = 0; i < style->prop_cnt; i++) { + lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(props[i]); + if(prop_id == prop) { + if(props[i] & LV_STYLE_PROP_META_INHERIT) + return LV_STYLE_RES_INHERIT; + if(props[i] & LV_STYLE_PROP_META_INITIAL) + *value = lv_style_prop_get_default(prop_id); + else { + lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props; + *value = values[i]; + } + return LV_STYLE_RES_FOUND; + } + } + } + else if(LV_STYLE_PROP_ID_MASK(style->prop1) == prop) { + if(style->prop1 & LV_STYLE_PROP_META_INHERIT) + return LV_STYLE_RES_INHERIT; + *value = (style->prop1 & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(LV_STYLE_PROP_ID_MASK( + style->prop1)) : style->v_p.value1; + return LV_STYLE_RES_FOUND; + } + return LV_STYLE_RES_NOT_FOUND; +} + +/** + * Checks if a style is empty (has no properties) + * @param style pointer to a style + * @return true if the style is empty + */ +bool lv_style_is_empty(const lv_style_t * style); + +/** + * Tell the group of a property. If the a property from a group is set in a style the (1 << group) bit of style->has_group is set. + * It allows early skipping the style if the property is not exists in the style at all. + * @param prop a style property + * @return the group [0..7] 7 means all the custom properties with index > 112 + */ +uint8_t _lv_style_get_prop_group(lv_style_prop_t prop); + +/** + * Get the flags of a built-in or custom property. + * + * @param prop a style property + * @return the flags of the property + */ +uint8_t _lv_style_prop_lookup_flags(lv_style_prop_t prop); + +#include "lv_style_gen.h" + +static inline void lv_style_set_size(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_width(style, value); + lv_style_set_height(style, value); +} + +static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_pad_left(style, value); + lv_style_set_pad_right(style, value); + lv_style_set_pad_top(style, value); + lv_style_set_pad_bottom(style, value); +} + +static inline void lv_style_set_pad_hor(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_pad_left(style, value); + lv_style_set_pad_right(style, value); +} + +static inline void lv_style_set_pad_ver(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_pad_top(style, value); + lv_style_set_pad_bottom(style, value); +} + +static inline void lv_style_set_pad_gap(lv_style_t * style, lv_coord_t value) +{ + lv_style_set_pad_row(style, value); + lv_style_set_pad_column(style, value); +} + +/** + * @brief Check if the style property has a specified behavioral flag. + * + * Do not pass multiple flags to this function as backwards-compatibility is not guaranteed + * for that. + * + * @param prop Property ID + * @param flag Flag + * @return true if the flag is set for this property + */ +static inline bool lv_style_prop_has_flag(lv_style_prop_t prop, uint8_t flag) +{ + return _lv_style_prop_lookup_flags(prop) & flag; +} + +/************************* + * GLOBAL VARIABLES + *************************/ + +/********************** + * MACROS + **********************/ + +#if LV_USE_ASSERT_STYLE +# define LV_ASSERT_STYLE(style_p) \ + do { \ + LV_ASSERT_MSG(style_p != NULL, "The style is NULL"); \ + LV_ASSERT_MSG(style_p->sentinel == LV_STYLE_SENTINEL_VALUE, "Style is not initialized or corrupted"); \ + } while(0) +#else +# define LV_ASSERT_STYLE(p) do{}while(0) +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_STYLE_H*/ diff --git a/include/liblvgl/misc/lv_style_gen.h b/include/liblvgl/misc/lv_style_gen.h new file mode 100644 index 00000000..8bf3b68f --- /dev/null +++ b/include/liblvgl/misc/lv_style_gen.h @@ -0,0 +1,504 @@ +void lv_style_set_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_min_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_max_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_height(lv_style_t * style, lv_coord_t value); +void lv_style_set_min_height(lv_style_t * style, lv_coord_t value); +void lv_style_set_max_height(lv_style_t * style, lv_coord_t value); +void lv_style_set_x(lv_style_t * style, lv_coord_t value); +void lv_style_set_y(lv_style_t * style, lv_coord_t value); +void lv_style_set_align(lv_style_t * style, lv_align_t value); +void lv_style_set_transform_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_height(lv_style_t * style, lv_coord_t value); +void lv_style_set_translate_x(lv_style_t * style, lv_coord_t value); +void lv_style_set_translate_y(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_zoom(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_angle(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_pivot_x(lv_style_t * style, lv_coord_t value); +void lv_style_set_transform_pivot_y(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_top(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_bottom(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_left(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_right(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_row(lv_style_t * style, lv_coord_t value); +void lv_style_set_pad_column(lv_style_t * style, lv_coord_t value); +void lv_style_set_bg_color(lv_style_t * style, lv_color_t value); +void lv_style_set_bg_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_bg_grad_color(lv_style_t * style, lv_color_t value); +void lv_style_set_bg_grad_dir(lv_style_t * style, lv_grad_dir_t value); +void lv_style_set_bg_main_stop(lv_style_t * style, lv_coord_t value); +void lv_style_set_bg_grad_stop(lv_style_t * style, lv_coord_t value); +void lv_style_set_bg_grad(lv_style_t * style, const lv_grad_dsc_t * value); +void lv_style_set_bg_dither_mode(lv_style_t * style, lv_dither_mode_t value); +void lv_style_set_bg_img_src(lv_style_t * style, const void * value); +void lv_style_set_bg_img_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_bg_img_recolor(lv_style_t * style, lv_color_t value); +void lv_style_set_bg_img_recolor_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_bg_img_tiled(lv_style_t * style, bool value); +void lv_style_set_border_color(lv_style_t * style, lv_color_t value); +void lv_style_set_border_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_border_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_border_side(lv_style_t * style, lv_border_side_t value); +void lv_style_set_border_post(lv_style_t * style, bool value); +void lv_style_set_outline_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_outline_color(lv_style_t * style, lv_color_t value); +void lv_style_set_outline_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_outline_pad(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_ofs_x(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_ofs_y(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_spread(lv_style_t * style, lv_coord_t value); +void lv_style_set_shadow_color(lv_style_t * style, lv_color_t value); +void lv_style_set_shadow_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_img_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_img_recolor(lv_style_t * style, lv_color_t value); +void lv_style_set_img_recolor_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_line_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_line_dash_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_line_dash_gap(lv_style_t * style, lv_coord_t value); +void lv_style_set_line_rounded(lv_style_t * style, bool value); +void lv_style_set_line_color(lv_style_t * style, lv_color_t value); +void lv_style_set_line_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_arc_width(lv_style_t * style, lv_coord_t value); +void lv_style_set_arc_rounded(lv_style_t * style, bool value); +void lv_style_set_arc_color(lv_style_t * style, lv_color_t value); +void lv_style_set_arc_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_arc_img_src(lv_style_t * style, const void * value); +void lv_style_set_text_color(lv_style_t * style, lv_color_t value); +void lv_style_set_text_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_text_font(lv_style_t * style, const lv_font_t * value); +void lv_style_set_text_letter_space(lv_style_t * style, lv_coord_t value); +void lv_style_set_text_line_space(lv_style_t * style, lv_coord_t value); +void lv_style_set_text_decor(lv_style_t * style, lv_text_decor_t value); +void lv_style_set_text_align(lv_style_t * style, lv_text_align_t value); +void lv_style_set_radius(lv_style_t * style, lv_coord_t value); +void lv_style_set_clip_corner(lv_style_t * style, bool value); +void lv_style_set_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_color_filter_dsc(lv_style_t * style, const lv_color_filter_dsc_t * value); +void lv_style_set_color_filter_opa(lv_style_t * style, lv_opa_t value); +void lv_style_set_anim(lv_style_t * style, const lv_anim_t * value); +void lv_style_set_anim_time(lv_style_t * style, uint32_t value); +void lv_style_set_anim_speed(lv_style_t * style, uint32_t value); +void lv_style_set_transition(lv_style_t * style, const lv_style_transition_dsc_t * value); +void lv_style_set_blend_mode(lv_style_t * style, lv_blend_mode_t value); +void lv_style_set_layout(lv_style_t * style, uint16_t value); +void lv_style_set_base_dir(lv_style_t * style, lv_base_dir_t value); + +#define LV_STYLE_CONST_WIDTH(val) \ + { \ + .prop = LV_STYLE_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_MIN_WIDTH(val) \ + { \ + .prop = LV_STYLE_MIN_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_MAX_WIDTH(val) \ + { \ + .prop = LV_STYLE_MAX_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_HEIGHT(val) \ + { \ + .prop = LV_STYLE_HEIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_MIN_HEIGHT(val) \ + { \ + .prop = LV_STYLE_MIN_HEIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_MAX_HEIGHT(val) \ + { \ + .prop = LV_STYLE_MAX_HEIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_X(val) \ + { \ + .prop = LV_STYLE_X, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_Y(val) \ + { \ + .prop = LV_STYLE_Y, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ALIGN(val) \ + { \ + .prop = LV_STYLE_ALIGN, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_WIDTH(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_HEIGHT(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_HEIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSLATE_X(val) \ + { \ + .prop = LV_STYLE_TRANSLATE_X, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSLATE_Y(val) \ + { \ + .prop = LV_STYLE_TRANSLATE_Y, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_ZOOM(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_ZOOM, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_ANGLE(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_ANGLE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_PIVOT_X(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_PIVOT_X, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSFORM_PIVOT_Y(val) \ + { \ + .prop = LV_STYLE_TRANSFORM_PIVOT_Y, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_TOP(val) \ + { \ + .prop = LV_STYLE_PAD_TOP, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_BOTTOM(val) \ + { \ + .prop = LV_STYLE_PAD_BOTTOM, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_LEFT(val) \ + { \ + .prop = LV_STYLE_PAD_LEFT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_RIGHT(val) \ + { \ + .prop = LV_STYLE_PAD_RIGHT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_ROW(val) \ + { \ + .prop = LV_STYLE_PAD_ROW, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_PAD_COLUMN(val) \ + { \ + .prop = LV_STYLE_PAD_COLUMN, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_COLOR(val) \ + { \ + .prop = LV_STYLE_BG_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_BG_OPA(val) \ + { \ + .prop = LV_STYLE_BG_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_GRAD_COLOR(val) \ + { \ + .prop = LV_STYLE_BG_GRAD_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_BG_GRAD_DIR(val) \ + { \ + .prop = LV_STYLE_BG_GRAD_DIR, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_MAIN_STOP(val) \ + { \ + .prop = LV_STYLE_BG_MAIN_STOP, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_GRAD_STOP(val) \ + { \ + .prop = LV_STYLE_BG_GRAD_STOP, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_GRAD(val) \ + { \ + .prop = LV_STYLE_BG_GRAD, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_BG_DITHER_MODE(val) \ + { \ + .prop = LV_STYLE_BG_DITHER_MODE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_IMG_SRC(val) \ + { \ + .prop = LV_STYLE_BG_IMG_SRC, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_BG_IMG_OPA(val) \ + { \ + .prop = LV_STYLE_BG_IMG_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_IMG_RECOLOR(val) \ + { \ + .prop = LV_STYLE_BG_IMG_RECOLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_BG_IMG_RECOLOR_OPA(val) \ + { \ + .prop = LV_STYLE_BG_IMG_RECOLOR_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BG_IMG_TILED(val) \ + { \ + .prop = LV_STYLE_BG_IMG_TILED, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BORDER_COLOR(val) \ + { \ + .prop = LV_STYLE_BORDER_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_BORDER_OPA(val) \ + { \ + .prop = LV_STYLE_BORDER_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BORDER_WIDTH(val) \ + { \ + .prop = LV_STYLE_BORDER_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BORDER_SIDE(val) \ + { \ + .prop = LV_STYLE_BORDER_SIDE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BORDER_POST(val) \ + { \ + .prop = LV_STYLE_BORDER_POST, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_OUTLINE_WIDTH(val) \ + { \ + .prop = LV_STYLE_OUTLINE_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_OUTLINE_COLOR(val) \ + { \ + .prop = LV_STYLE_OUTLINE_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_OUTLINE_OPA(val) \ + { \ + .prop = LV_STYLE_OUTLINE_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_OUTLINE_PAD(val) \ + { \ + .prop = LV_STYLE_OUTLINE_PAD, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_WIDTH(val) \ + { \ + .prop = LV_STYLE_SHADOW_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_OFS_X(val) \ + { \ + .prop = LV_STYLE_SHADOW_OFS_X, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_OFS_Y(val) \ + { \ + .prop = LV_STYLE_SHADOW_OFS_Y, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_SPREAD(val) \ + { \ + .prop = LV_STYLE_SHADOW_SPREAD, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_SHADOW_COLOR(val) \ + { \ + .prop = LV_STYLE_SHADOW_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_SHADOW_OPA(val) \ + { \ + .prop = LV_STYLE_SHADOW_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_IMG_OPA(val) \ + { \ + .prop = LV_STYLE_IMG_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_IMG_RECOLOR(val) \ + { \ + .prop = LV_STYLE_IMG_RECOLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_IMG_RECOLOR_OPA(val) \ + { \ + .prop = LV_STYLE_IMG_RECOLOR_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_WIDTH(val) \ + { \ + .prop = LV_STYLE_LINE_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_DASH_WIDTH(val) \ + { \ + .prop = LV_STYLE_LINE_DASH_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_DASH_GAP(val) \ + { \ + .prop = LV_STYLE_LINE_DASH_GAP, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_ROUNDED(val) \ + { \ + .prop = LV_STYLE_LINE_ROUNDED, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LINE_COLOR(val) \ + { \ + .prop = LV_STYLE_LINE_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_LINE_OPA(val) \ + { \ + .prop = LV_STYLE_LINE_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ARC_WIDTH(val) \ + { \ + .prop = LV_STYLE_ARC_WIDTH, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ARC_ROUNDED(val) \ + { \ + .prop = LV_STYLE_ARC_ROUNDED, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ARC_COLOR(val) \ + { \ + .prop = LV_STYLE_ARC_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_ARC_OPA(val) \ + { \ + .prop = LV_STYLE_ARC_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ARC_IMG_SRC(val) \ + { \ + .prop = LV_STYLE_ARC_IMG_SRC, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_TEXT_COLOR(val) \ + { \ + .prop = LV_STYLE_TEXT_COLOR, .value = { .color = val } \ + } + +#define LV_STYLE_CONST_TEXT_OPA(val) \ + { \ + .prop = LV_STYLE_TEXT_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TEXT_FONT(val) \ + { \ + .prop = LV_STYLE_TEXT_FONT, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_TEXT_LETTER_SPACE(val) \ + { \ + .prop = LV_STYLE_TEXT_LETTER_SPACE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TEXT_LINE_SPACE(val) \ + { \ + .prop = LV_STYLE_TEXT_LINE_SPACE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TEXT_DECOR(val) \ + { \ + .prop = LV_STYLE_TEXT_DECOR, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TEXT_ALIGN(val) \ + { \ + .prop = LV_STYLE_TEXT_ALIGN, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_RADIUS(val) \ + { \ + .prop = LV_STYLE_RADIUS, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_CLIP_CORNER(val) \ + { \ + .prop = LV_STYLE_CLIP_CORNER, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_OPA(val) \ + { \ + .prop = LV_STYLE_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_COLOR_FILTER_DSC(val) \ + { \ + .prop = LV_STYLE_COLOR_FILTER_DSC, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_COLOR_FILTER_OPA(val) \ + { \ + .prop = LV_STYLE_COLOR_FILTER_OPA, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ANIM(val) \ + { \ + .prop = LV_STYLE_ANIM, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_ANIM_TIME(val) \ + { \ + .prop = LV_STYLE_ANIM_TIME, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_ANIM_SPEED(val) \ + { \ + .prop = LV_STYLE_ANIM_SPEED, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_TRANSITION(val) \ + { \ + .prop = LV_STYLE_TRANSITION, .value = { .ptr = val } \ + } + +#define LV_STYLE_CONST_BLEND_MODE(val) \ + { \ + .prop = LV_STYLE_BLEND_MODE, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_LAYOUT(val) \ + { \ + .prop = LV_STYLE_LAYOUT, .value = { .num = (int32_t)val } \ + } + +#define LV_STYLE_CONST_BASE_DIR(val) \ + { \ + .prop = LV_STYLE_BASE_DIR, .value = { .num = (int32_t)val } \ + } diff --git a/include/display/lv_misc/lv_templ.h b/include/liblvgl/misc/lv_templ.h similarity index 96% rename from include/display/lv_misc/lv_templ.h rename to include/liblvgl/misc/lv_templ.h index a5459e8d..f7e3c268 100644 --- a/include/display/lv_misc/lv_templ.h +++ b/include/liblvgl/misc/lv_templ.h @@ -30,9 +30,8 @@ extern "C" { * MACROS **********************/ - #ifdef __cplusplus -} /* extern "C" */ +} /*extern "C"*/ #endif #endif /*LV_TEMPL_H*/ diff --git a/include/liblvgl/misc/lv_timer.h b/include/liblvgl/misc/lv_timer.h new file mode 100644 index 00000000..16572d3d --- /dev/null +++ b/include/liblvgl/misc/lv_timer.h @@ -0,0 +1,183 @@ +/** + * @file lv_timer.h + */ + +#ifndef LV_TIMER_H +#define LV_TIMER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/hal/lv_hal_tick.h" + +#include +#include + +/********************* + * DEFINES + *********************/ +#ifndef LV_ATTRIBUTE_TIMER_HANDLER +#define LV_ATTRIBUTE_TIMER_HANDLER +#endif + +#define LV_NO_TIMER_READY 0xFFFFFFFF + +/********************** + * TYPEDEFS + **********************/ + +struct _lv_timer_t; + +/** + * Timers execute this type of functions. + */ +typedef void (*lv_timer_cb_t)(struct _lv_timer_t *); + +/** + * Descriptor of a lv_timer + */ +typedef struct _lv_timer_t { + uint32_t period; /**< How often the timer should run*/ + uint32_t last_run; /**< Last time the timer ran*/ + lv_timer_cb_t timer_cb; /**< Timer function*/ + void * user_data; /**< Custom user data*/ + int32_t repeat_count; /**< 1: One time; -1 : infinity; n>0: residual times*/ + uint32_t paused : 1; +} lv_timer_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Init the lv_timer module + */ +void _lv_timer_core_init(void); + +//! @cond Doxygen_Suppress + +/** + * Call it periodically to handle lv_timers. + * @return time till it needs to be run next (in ms) + */ +LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void); + +//! @endcond + +/** + * Call it in the super-loop of main() or threads. It will run lv_timer_handler() + * with a given period in ms. You can use it with sleep or delay in OS environment. + * This function is used to simplify the porting. + * @param __ms the period for running lv_timer_handler() + */ +static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler_run_in_period(uint32_t ms) +{ + static uint32_t last_tick = 0; + uint32_t curr_tick = lv_tick_get(); + + if((curr_tick - last_tick) >= (ms)) { + last_tick = curr_tick; + return lv_timer_handler(); + } + return 1; +} + +/** + * Create an "empty" timer. It needs to initialized with at least + * `lv_timer_set_cb` and `lv_timer_set_period` + * @return pointer to the created timer + */ +lv_timer_t * lv_timer_create_basic(void); + +/** + * Create a new lv_timer + * @param timer_xcb a callback to call periodically. + * (the 'x' in the argument name indicates that it's not a fully generic function because it not follows + * the `func_name(object, callback, ...)` convention) + * @param period call period in ms unit + * @param user_data custom parameter + * @return pointer to the new timer + */ +lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * user_data); + +/** + * Delete a lv_timer + * @param timer pointer to an lv_timer + */ +void lv_timer_del(lv_timer_t * timer); + +/** + * Pause/resume a timer. + * @param timer pointer to an lv_timer + */ +void lv_timer_pause(lv_timer_t * timer); + +void lv_timer_resume(lv_timer_t * timer); + +/** + * Set the callback the timer (the function to call periodically) + * @param timer pointer to a timer + * @param timer_cb the function to call periodically + */ +void lv_timer_set_cb(lv_timer_t * timer, lv_timer_cb_t timer_cb); + +/** + * Set new period for a lv_timer + * @param timer pointer to a lv_timer + * @param period the new period + */ +void lv_timer_set_period(lv_timer_t * timer, uint32_t period); + +/** + * Make a lv_timer ready. It will not wait its period. + * @param timer pointer to a lv_timer. + */ +void lv_timer_ready(lv_timer_t * timer); + +/** + * Set the number of times a timer will repeat. + * @param timer pointer to a lv_timer. + * @param repeat_count -1 : infinity; 0 : stop ; n>0: residual times + */ +void lv_timer_set_repeat_count(lv_timer_t * timer, int32_t repeat_count); + +/** + * Reset a lv_timer. + * It will be called the previously set period milliseconds later. + * @param timer pointer to a lv_timer. + */ +void lv_timer_reset(lv_timer_t * timer); + +/** + * Enable or disable the whole lv_timer handling + * @param en true: lv_timer handling is running, false: lv_timer handling is suspended + */ +void lv_timer_enable(bool en); + +/** + * Get idle percentage + * @return the lv_timer idle in percentage + */ +uint8_t lv_timer_get_idle(void); + +/** + * Iterate through the timers + * @param timer NULL to start iteration or the previous return value to get the next timer + * @return the next timer or NULL if there is no more timer + */ +lv_timer_t * lv_timer_get_next(lv_timer_t * timer); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/liblvgl/misc/lv_tlsf.h b/include/liblvgl/misc/lv_tlsf.h new file mode 100644 index 00000000..f12590b6 --- /dev/null +++ b/include/liblvgl/misc/lv_tlsf.h @@ -0,0 +1,95 @@ +#include "../lv_conf_internal.h" +#if LV_MEM_CUSTOM == 0 + +#ifndef LV_TLSF_H +#define LV_TLSF_H + +/* +** Two Level Segregated Fit memory allocator, version 3.1. +** Written by Matthew Conte +** http://tlsf.baisoku.org +** +** Based on the original documentation by Miguel Masmano: +** http://www.gii.upv.es/tlsf/main/docs +** +** This implementation was written to the specification +** of the document, therefore no GPL restrictions apply. +** +** Copyright (c) 2006-2016, Matthew Conte +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the copyright holder nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY +** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +/* lv_tlsf_t: a TLSF structure. Can contain 1 to N pools. */ +/* lv_pool_t: a block of memory that TLSF can manage. */ +typedef void * lv_tlsf_t; +typedef void * lv_pool_t; + +/* Create/destroy a memory pool. */ +lv_tlsf_t lv_tlsf_create(void * mem); +lv_tlsf_t lv_tlsf_create_with_pool(void * mem, size_t bytes); +void lv_tlsf_destroy(lv_tlsf_t tlsf); +lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf); + +/* Add/remove memory pools. */ +lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void * mem, size_t bytes); +void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool); + +/* malloc/memalign/realloc/free replacements. */ +void * lv_tlsf_malloc(lv_tlsf_t tlsf, size_t bytes); +void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t bytes); +void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size); +size_t lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr); + +/* Returns internal block size, not original request size */ +size_t lv_tlsf_block_size(void * ptr); + +/* Overheads/limits of internal structures. */ +size_t lv_tlsf_size(void); +size_t lv_tlsf_align_size(void); +size_t lv_tlsf_block_size_min(void); +size_t lv_tlsf_block_size_max(void); +size_t lv_tlsf_pool_overhead(void); +size_t lv_tlsf_alloc_overhead(void); + +/* Debugging. */ +typedef void (*lv_tlsf_walker)(void * ptr, size_t size, int used, void * user); +void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void * user); +/* Returns nonzero if any internal consistency check fails. */ +int lv_tlsf_check(lv_tlsf_t tlsf); +int lv_tlsf_check_pool(lv_pool_t pool); + +#if defined(__cplusplus) +}; +#endif + +#endif /*LV_TLSF_H*/ + +#endif /* LV_MEM_CUSTOM == 0 */ diff --git a/include/liblvgl/misc/lv_txt.h b/include/liblvgl/misc/lv_txt.h new file mode 100644 index 00000000..ae60e8b8 --- /dev/null +++ b/include/liblvgl/misc/lv_txt.h @@ -0,0 +1,264 @@ +/** + * @file lv_txt.h + * + */ + +#ifndef LV_TXT_H +#define LV_TXT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#include +#include +#include "lv_area.h" +#include "liblvgl/font/lv_font.h" +#include "lv_printf.h" +#include "lv_types.h" + +/********************* + * DEFINES + *********************/ +#ifndef LV_TXT_COLOR_CMD +#define LV_TXT_COLOR_CMD "#" +#endif + +#define LV_TXT_ENC_UTF8 1 +#define LV_TXT_ENC_ASCII 2 + +/********************** + * TYPEDEFS + **********************/ + +/** + * Options for text rendering. + */ +enum { + LV_TEXT_FLAG_NONE = 0x00, + LV_TEXT_FLAG_RECOLOR = 0x01, /**< Enable parsing of recolor command*/ + LV_TEXT_FLAG_EXPAND = 0x02, /**< Ignore max-width to avoid automatic word wrapping*/ + LV_TEXT_FLAG_FIT = 0x04, /**< Max-width is already equal to the longest line. (Used to skip some calculation)*/ +}; +typedef uint8_t lv_text_flag_t; + +/** + * State machine for text renderer.*/ +enum { + LV_TEXT_CMD_STATE_WAIT, /**< Waiting for command*/ + LV_TEXT_CMD_STATE_PAR, /**< Processing the parameter*/ + LV_TEXT_CMD_STATE_IN, /**< Processing the command*/ +}; +typedef uint8_t lv_text_cmd_state_t; + +/** Label align policy*/ +enum { + LV_TEXT_ALIGN_AUTO, /**< Align text auto*/ + LV_TEXT_ALIGN_LEFT, /**< Align text to left*/ + LV_TEXT_ALIGN_CENTER, /**< Align text to center*/ + LV_TEXT_ALIGN_RIGHT, /**< Align text to right*/ +}; +typedef uint8_t lv_text_align_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Get size of a text + * @param size_res pointer to a 'point_t' variable to store the result + * @param text pointer to a text + * @param font pointer to font of the text + * @param letter_space letter space of the text + * @param line_space line space of the text + * @param flags settings for the text from ::lv_text_flag_t + * @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid + * line breaks + */ +void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, lv_coord_t letter_space, + lv_coord_t line_space, lv_coord_t max_width, lv_text_flag_t flag); + +/** + * Get the next line of text. Check line length and break chars too. + * @param txt a '\0' terminated string + * @param font pointer to a font + * @param letter_space letter space + * @param max_width max width of the text (break the lines to fit this size). Set COORD_MAX to avoid + * line breaks + * @param used_width When used_width != NULL, save the width of this line if + * flag == LV_TEXT_FLAG_NONE, otherwise save -1. + * @param flags settings for the text from 'txt_flag_type' enum + * @return the index of the first char of the new line (in byte index not letter index. With UTF-8 + * they are different) + */ +uint32_t _lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coord_t letter_space, + lv_coord_t max_width, lv_coord_t * used_width, lv_text_flag_t flag); + +/** + * Give the length of a text with a given font + * @param txt a '\0' terminate string + * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in + * UTF-8) + * @param font pointer to a font + * @param letter_space letter space + * @param flags settings for the text from 'txt_flag_t' enum + * @return length of a char_num long text + */ +lv_coord_t lv_txt_get_width(const char * txt, uint32_t length, const lv_font_t * font, lv_coord_t letter_space, + lv_text_flag_t flag); + +/** + * Check next character in a string and decide if the character is part of the command or not + * @param state pointer to a txt_cmd_state_t variable which stores the current state of command + * processing + * @param c the current character + * @return true: the character is part of a command and should not be written, + * false: the character should be written + */ +bool _lv_txt_is_cmd(lv_text_cmd_state_t * state, uint32_t c); + +/** + * Insert a string into an other + * @param txt_buf the original text (must be big enough for the result text and NULL terminated) + * @param pos position to insert (0: before the original text, 1: after the first char etc.) + * @param ins_txt text to insert, must be '\0' terminated + */ +void _lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt); + +/** + * Delete a part of a string + * @param txt string to modify, must be '\0' terminated and should point to a heap or stack frame, not read-only memory. + * @param pos position where to start the deleting (0: before the first char, 1: after the first + * char etc.) + * @param len number of characters to delete + */ +void _lv_txt_cut(char * txt, uint32_t pos, uint32_t len); + +/** + * return a new formatted text. Memory will be allocated to store the text. + * @param fmt `printf`-like format + * @return pointer to the allocated text string. + */ +char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap) LV_FORMAT_ATTRIBUTE(1, 0); + +/** + * Decode two encoded character from a string. + * @param txt pointer to '\0' terminated string + * @param letter the first decoded Unicode character or 0 on invalid data code + * @param letter_next the second decoded Unicode character or 0 on invalid data code + * @param ofs start index in 'txt' where to start. + * After the call it will point to the next encoded char in 'txt'. + * NULL to use txt[0] as index + */ +void _lv_txt_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs); + +/** + * Test if char is break char or not (a text can broken here or not) + * @param letter a letter + * @return false: 'letter' is not break char + */ +static inline bool _lv_txt_is_break_char(uint32_t letter) +{ + uint8_t i; + bool ret = false; + + /* each chinese character can be break */ + if(letter >= 0x4E00 && letter <= 0x9FA5) { + return true; + } + + /*Compare the letter to TXT_BREAK_CHARS*/ + for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) { + if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) { + ret = true; /*If match then it is break char*/ + break; + } + } + + return ret; +} + +/*************************************************************** + * GLOBAL FUNCTION POINTERS FOR CHARACTER ENCODING INTERFACE + ***************************************************************/ + +/** + * Give the size of an encoded character + * @param str pointer to a character in a string + * @return length of the encoded character (1,2,3 ...). O in invalid + */ +extern uint8_t (*_lv_txt_encoded_size)(const char *); + +/** + * Convert a Unicode letter to encoded + * @param letter_uni a Unicode letter + * @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü') + */ +extern uint32_t (*_lv_txt_unicode_to_encoded)(uint32_t); + +/** + * Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format. + * @param c a wide character + * @return `c` in the encoded format + */ +extern uint32_t (*_lv_txt_encoded_conv_wc)(uint32_t c); + +/** + * Decode the next encoded character from a string. + * @param txt pointer to '\0' terminated string + * @param i start index in 'txt' where to start. + * After the call it will point to the next encoded char in 'txt'. + * NULL to use txt[0] as index + * @return the decoded Unicode character or 0 on invalid data code + */ +extern uint32_t (*_lv_txt_encoded_next)(const char *, uint32_t *); + +/** + * Get the previous encoded character form a string. + * @param txt pointer to '\0' terminated string + * @param i_start index in 'txt' where to start. After the call it will point to the previous + * encoded char in 'txt'. + * @return the decoded Unicode character or 0 on invalid data + */ +extern uint32_t (*_lv_txt_encoded_prev)(const char *, uint32_t *); + +/** + * Convert a letter index (in the encoded text) to byte index. + * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param enc_id letter index + * @return byte index of the 'enc_id'th letter + */ +extern uint32_t (*_lv_txt_encoded_get_byte_id)(const char *, uint32_t); + +/** + * Convert a byte index (in an encoded text) to character index. + * E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long + * @param txt a '\0' terminated UTF-8 string + * @param byte_id byte index + * @return character index of the letter at 'byte_id'th position + */ +extern uint32_t (*_lv_txt_encoded_get_char_id)(const char *, uint32_t); + +/** + * Get the number of characters (and NOT bytes) in a string. + * E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes) + * @param txt a '\0' terminated char string + * @return number of characters + */ +extern uint32_t (*_lv_txt_get_encoded_length)(const char *); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TXT_H*/ diff --git a/include/liblvgl/misc/lv_txt_ap.h b/include/liblvgl/misc/lv_txt_ap.h new file mode 100644 index 00000000..3519bb60 --- /dev/null +++ b/include/liblvgl/misc/lv_txt_ap.h @@ -0,0 +1,49 @@ +/** + * @file lv_txt_ap.h + * + */ + +#ifndef LV_TXT_AP_H +#define LV_TXT_AP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include +#include "lv_txt.h" +#include "liblvgl/draw/lv_draw.h" + +#if LV_USE_ARABIC_PERSIAN_CHARS == 1 + +/********************* + * DEFINES + *********************/ + +#define LV_UNDEF_ARABIC_PERSIAN_CHARS (UINT32_MAX) +#define LV_AP_ALPHABET_BASE_CODE 0x0622 +#define LV_AP_END_CHARS_LIST {0,0,0,0,0,{0,0}} +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +uint32_t _lv_txt_ap_calc_bytes_cnt(const char * txt); +void _lv_txt_ap_proc(const char * txt, char * txt_out); + +/********************** + * MACROS + **********************/ + +#endif // LV_USE_ARABIC_PERSIAN_CHARS + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TXT_AP_H*/ diff --git a/include/liblvgl/misc/lv_types.h b/include/liblvgl/misc/lv_types.h new file mode 100644 index 00000000..84aee103 --- /dev/null +++ b/include/liblvgl/misc/lv_types.h @@ -0,0 +1,94 @@ +/** + * @file lv_types.h + * + */ + +#ifndef LV_TYPES_H +#define LV_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include + +/********************* + * DEFINES + *********************/ + +// If __UINTPTR_MAX__ or UINTPTR_MAX are available, use them to determine arch size +#if defined(__UINTPTR_MAX__) && __UINTPTR_MAX__ > 0xFFFFFFFF +#define LV_ARCH_64 + +#elif defined(UINTPTR_MAX) && UINTPTR_MAX > 0xFFFFFFFF +#define LV_ARCH_64 + +// Otherwise use compiler-dependent means to determine arch size +#elif defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) || defined (__aarch64__) +#define LV_ARCH_64 + +#endif + +/********************** + * TYPEDEFS + **********************/ + +/** + * LVGL error codes. + */ +enum { + LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action + function or an operation was failed*/ + LV_RES_OK, /*The object is valid (no deleted) after the action*/ +}; +typedef uint8_t lv_res_t; + +#if defined(__cplusplus) || __STDC_VERSION__ >= 199901L +// If c99 or newer, use the definition of uintptr_t directly from +typedef uintptr_t lv_uintptr_t; + +#else + +// Otherwise, use the arch size determination +#ifdef LV_ARCH_64 +typedef uint64_t lv_uintptr_t; +#else +typedef uint32_t lv_uintptr_t; +#endif + +#endif + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#define LV_UNUSED(x) ((void)x) + +#define _LV_CONCAT(x, y) x ## y +#define LV_CONCAT(x, y) _LV_CONCAT(x, y) + +#define _LV_CONCAT3(x, y, z) x ## y ## z +#define LV_CONCAT3(x, y, z) _LV_CONCAT3(x, y, z) + +#if defined(PYCPARSER) || defined(__CC_ARM) +#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) +#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __GNUC__ > 4) +#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__((format(gnu_printf, fmtstr, vararg))) +#elif (defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)) +#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) __attribute__((format(printf, fmtstr, vararg))) +#else +#define LV_FORMAT_ATTRIBUTE(fmtstr, vararg) +#endif + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TYPES_H*/ diff --git a/include/liblvgl/misc/lv_utils.h b/include/liblvgl/misc/lv_utils.h new file mode 100644 index 00000000..84d2bb95 --- /dev/null +++ b/include/liblvgl/misc/lv_utils.h @@ -0,0 +1,58 @@ +/** + * @file lv_utils.h + * + */ + +#ifndef LV_UTILS_H +#define LV_UTILS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** Searches base[0] to base[n - 1] for an item that matches *key. + * + * @note The function cmp must return negative if it's first + * argument (the search key) is less that it's second (a table entry), + * zero if equal, and positive if greater. + * + * @note Items in the array must be in ascending order. + * + * @param key Pointer to item being searched for + * @param base Pointer to first element to search + * @param n Number of elements + * @param size Size of each element + * @param cmp Pointer to comparison function (see #unicode_list_compare as a comparison function + * example) + * + * @return a pointer to a matching item, or NULL if none exists. + */ +void * _lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size, + int32_t (*cmp)(const void * pRef, const void * pElement)); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/include/liblvgl/widgets/lv_arc.h b/include/liblvgl/widgets/lv_arc.h new file mode 100644 index 00000000..96f4629b --- /dev/null +++ b/include/liblvgl/widgets/lv_arc.h @@ -0,0 +1,256 @@ +/** + * @file lv_arc.h + * + */ + +#ifndef LV_ARC_H +#define LV_ARC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_ARC != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_ARC_MODE_NORMAL, + LV_ARC_MODE_SYMMETRICAL, + LV_ARC_MODE_REVERSE +}; +typedef uint8_t lv_arc_mode_t; + +typedef struct { + lv_obj_t obj; + uint16_t rotation; + uint16_t indic_angle_start; + uint16_t indic_angle_end; + uint16_t bg_angle_start; + uint16_t bg_angle_end; + int16_t value; /*Current value of the arc*/ + int16_t min_value; /*Minimum value of the arc*/ + int16_t max_value; /*Maximum value of the arc*/ + uint16_t dragging : 1; + uint16_t type : 2; + uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/ + uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/ + uint32_t last_tick; /*Last dragging event timestamp of the arc*/ + int16_t last_angle; /*Last dragging angle of the arc*/ +} lv_arc_t; + +extern const lv_obj_class_t lv_arc_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_arc_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_ARC_DRAW_PART_BACKGROUND, /**< The background arc*/ + LV_ARC_DRAW_PART_FOREGROUND, /**< The foreground arc*/ + LV_ARC_DRAW_PART_KNOB, /**< The knob*/ +} lv_arc_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an arc object + * @param parent pointer to an object, it will be the parent of the new arc + * @return pointer to the created arc + */ +lv_obj_t * lv_arc_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. + * @param obj pointer to an arc object + * @param start the start angle + */ +void lv_arc_set_start_angle(lv_obj_t * obj, uint16_t start); + +/** + * Set the end angle of an arc. 0 deg: right, 90 bottom, etc. + * @param obj pointer to an arc object + * @param end the end angle + */ +void lv_arc_set_end_angle(lv_obj_t * obj, uint16_t end); + +/** + * Set the start and end angles + * @param obj pointer to an arc object + * @param start the start angle + * @param end the end angle + */ +void lv_arc_set_angles(lv_obj_t * obj, uint16_t start, uint16_t end); + +/** + * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc. + * @param obj pointer to an arc object + * @param start the start angle + */ +void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint16_t start); + +/** + * Set the start angle of an arc background. 0 deg: right, 90 bottom etc. + * @param obj pointer to an arc object + * @param end the end angle + */ +void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint16_t end); + +/** + * Set the start and end angles of the arc background + * @param obj pointer to an arc object + * @param start the start angle + * @param end the end angle + */ +void lv_arc_set_bg_angles(lv_obj_t * obj, uint16_t start, uint16_t end); + +/** + * Set the rotation for the whole arc + * @param obj pointer to an arc object + * @param rotation rotation angle + */ +void lv_arc_set_rotation(lv_obj_t * obj, uint16_t rotation); + +/** + * Set the type of arc. + * @param obj pointer to arc object + * @param mode arc's mode + */ +void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type); + +/** + * Set a new value on the arc + * @param obj pointer to an arc object + * @param value new value + */ +void lv_arc_set_value(lv_obj_t * obj, int16_t value); + +/** + * Set minimum and the maximum values of an arc + * @param obj pointer to the arc object + * @param min minimum value + * @param max maximum value + */ +void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max); + +/** + * Set a change rate to limit the speed how fast the arc should reach the pressed point. + * @param obj pointer to an arc object + * @param rate the change rate + */ +void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the start angle of an arc. + * @param obj pointer to an arc object + * @return the start angle [0..360] + */ +uint16_t lv_arc_get_angle_start(lv_obj_t * obj); + +/** + * Get the end angle of an arc. + * @param obj pointer to an arc object + * @return the end angle [0..360] + */ +uint16_t lv_arc_get_angle_end(lv_obj_t * obj); + +/** + * Get the start angle of an arc background. + * @param obj pointer to an arc object + * @return the start angle [0..360] + */ +uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj); + +/** + * Get the end angle of an arc background. + * @param obj pointer to an arc object + * @return the end angle [0..360] + */ +uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj); + +/** + * Get the value of an arc + * @param obj pointer to an arc object + * @return the value of the arc + */ +int16_t lv_arc_get_value(const lv_obj_t * obj); + +/** + * Get the minimum value of an arc + * @param obj pointer to an arc object + * @return the minimum value of the arc + */ +int16_t lv_arc_get_min_value(const lv_obj_t * obj); + +/** + * Get the maximum value of an arc + * @param obj pointer to an arc object + * @return the maximum value of the arc + */ +int16_t lv_arc_get_max_value(const lv_obj_t * obj); + +/** + * Get whether the arc is type or not. + * @param obj pointer to an arc object + * @return arc's mode + */ +lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Align an object to the current position of the arc (knob) + * @param obj pointer to an arc object + * @param obj_to_align pointer to an object to align + * @param r_offset consider the radius larger with this value (< 0: for smaller radius) + */ +void lv_arc_align_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_align, lv_coord_t r_offset); + +/** + * Rotate an object to the current position of the arc (knob) + * @param obj pointer to an arc object + * @param obj_to_align pointer to an object to rotate + * @param r_offset consider the radius larger with this value (< 0: for smaller radius) + */ +void lv_arc_rotate_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_rotate, lv_coord_t r_offset); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_ARC*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ARC_H*/ diff --git a/include/liblvgl/widgets/lv_bar.h b/include/liblvgl/widgets/lv_bar.h new file mode 100644 index 00000000..55d17119 --- /dev/null +++ b/include/liblvgl/widgets/lv_bar.h @@ -0,0 +1,164 @@ +/** + * @file lv_bar.h + * + */ + +#ifndef LV_BAR_H +#define LV_BAR_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_BAR != 0 + +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/misc/lv_anim.h" +#include "lv_btn.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_BAR_MODE_NORMAL, + LV_BAR_MODE_SYMMETRICAL, + LV_BAR_MODE_RANGE +}; +typedef uint8_t lv_bar_mode_t; + +typedef struct { + lv_obj_t * bar; + int32_t anim_start; + int32_t anim_end; + int32_t anim_state; +} _lv_bar_anim_t; + +typedef struct { + lv_obj_t obj; + int32_t cur_value; /**< Current value of the bar*/ + int32_t min_value; /**< Minimum value of the bar*/ + int32_t max_value; /**< Maximum value of the bar*/ + int32_t start_value; /**< Start value of the bar*/ + lv_area_t indic_area; /**< Save the indicator area. Might be used by derived types*/ + _lv_bar_anim_t cur_value_anim; + _lv_bar_anim_t start_value_anim; + lv_bar_mode_t mode : 2; /**< Type of bar*/ +} lv_bar_t; + +extern const lv_obj_class_t lv_bar_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_bar_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_BAR_DRAW_PART_INDICATOR, /**< The indicator*/ +} lv_bar_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a bar object + * @param parent pointer to an object, it will be the parent of the new bar + * @return pointer to the created bar + */ +lv_obj_t * lv_bar_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the bar + * @param bar pointer to a bar object + * @param value new value + * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately + */ +void lv_bar_set_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim); + +/** + * Set a new start value on the bar + * @param obj pointer to a bar object + * @param value new start value + * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately + */ +void lv_bar_set_start_value(lv_obj_t * obj, int32_t start_value, lv_anim_enable_t anim); + +/** + * Set minimum and the maximum values of a bar + * @param obj pointer to the bar object + * @param min minimum value + * @param max maximum value + */ +void lv_bar_set_range(lv_obj_t * obj, int32_t min, int32_t max); + +/** + * Set the type of bar. + * @param obj pointer to bar object + * @param mode bar type from ::lv_bar_mode_t + */ +void lv_bar_set_mode(lv_obj_t * obj, lv_bar_mode_t mode); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a bar + * @param obj pointer to a bar object + * @return the value of the bar + */ +int32_t lv_bar_get_value(const lv_obj_t * obj); + +/** + * Get the start value of a bar + * @param obj pointer to a bar object + * @return the start value of the bar + */ +int32_t lv_bar_get_start_value(const lv_obj_t * obj); + +/** + * Get the minimum value of a bar + * @param obj pointer to a bar object + * @return the minimum value of the bar + */ +int32_t lv_bar_get_min_value(const lv_obj_t * obj); + +/** + * Get the maximum value of a bar + * @param obj pointer to a bar object + * @return the maximum value of the bar + */ +int32_t lv_bar_get_max_value(const lv_obj_t * obj); + +/** + * Get the type of bar. + * @param obj pointer to bar object + * @return bar type from ::lv_bar_mode_t + */ +lv_bar_mode_t lv_bar_get_mode(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_BAR*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_BAR_H*/ diff --git a/include/liblvgl/widgets/lv_btn.h b/include/liblvgl/widgets/lv_btn.h new file mode 100644 index 00000000..893e6a05 --- /dev/null +++ b/include/liblvgl/widgets/lv_btn.h @@ -0,0 +1,56 @@ +/** + * @file lv_btn.h + * + */ + +#ifndef LV_BTN_H +#define LV_BTN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_BTN != 0 +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; +} lv_btn_t; + +extern const lv_obj_class_t lv_btn_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a button object + * @param parent pointer to an object, it will be the parent of the new button + * @return pointer to the created button + */ +lv_obj_t * lv_btn_create(lv_obj_t * parent); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_BTN*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_BTN_H*/ diff --git a/include/liblvgl/widgets/lv_btnmatrix.h b/include/liblvgl/widgets/lv_btnmatrix.h new file mode 100644 index 00000000..31d62bb3 --- /dev/null +++ b/include/liblvgl/widgets/lv_btnmatrix.h @@ -0,0 +1,225 @@ +/** + * @file lv_btnmatrix.h + * + */ + +#ifndef LV_BTNMATRIX_H +#define LV_BTNMATRIX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_BTNMATRIX != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ +#define LV_BTNMATRIX_BTN_NONE 0xFFFF +LV_EXPORT_CONST_INT(LV_BTNMATRIX_BTN_NONE); + +/********************** + * TYPEDEFS + **********************/ + +/** Type to store button control bits (disabled, hidden etc.) + * The first 3 bits are used to store the width*/ +enum { + _LV_BTNMATRIX_WIDTH = 0x0007, /**< Reserved to stire the size units*/ + LV_BTNMATRIX_CTRL_HIDDEN = 0x0008, /**< Button hidden*/ + LV_BTNMATRIX_CTRL_NO_REPEAT = 0x0010, /**< Do not repeat press this button.*/ + LV_BTNMATRIX_CTRL_DISABLED = 0x0020, /**< Disable this button.*/ + LV_BTNMATRIX_CTRL_CHECKABLE = 0x0040, /**< The button can be toggled.*/ + LV_BTNMATRIX_CTRL_CHECKED = 0x0080, /**< Button is currently toggled (e.g. checked).*/ + LV_BTNMATRIX_CTRL_CLICK_TRIG = 0x0100, /**< 1: Send LV_EVENT_VALUE_CHANGE on CLICK, 0: Send LV_EVENT_VALUE_CHANGE on PRESS*/ + LV_BTNMATRIX_CTRL_POPOVER = 0x0200, /**< Show a popover when pressing this key*/ + LV_BTNMATRIX_CTRL_RECOLOR = 0x1000, /**< Enable text recoloring with `#color`*/ + _LV_BTNMATRIX_CTRL_RESERVED = 0x2000, /**< Reserved for later use*/ + LV_BTNMATRIX_CTRL_CUSTOM_1 = 0x4000, /**< Custom free to use flag*/ + LV_BTNMATRIX_CTRL_CUSTOM_2 = 0x8000, /**< Custom free to use flag*/ +}; + +typedef uint16_t lv_btnmatrix_ctrl_t; + +typedef bool (*lv_btnmatrix_btn_draw_cb_t)(lv_obj_t * btnm, uint32_t btn_id, const lv_area_t * draw_area, + const lv_area_t * clip_area); + +/*Data of button matrix*/ +typedef struct { + lv_obj_t obj; + const char ** map_p; /*Pointer to the current map*/ + lv_area_t * button_areas; /*Array of areas of buttons*/ + lv_btnmatrix_ctrl_t * ctrl_bits; /*Array of control bytes*/ + uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/ + uint16_t row_cnt; /*Number of rows in 'map_p'(Handled by the library)*/ + uint16_t btn_id_sel; /*Index of the active button (being pressed/released etc) or LV_BTNMATRIX_BTN_NONE*/ + uint8_t one_check : 1; /*Single button toggled at once*/ +} lv_btnmatrix_t; + +extern const lv_obj_class_t lv_btnmatrix_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_btnmatrix_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_BTNMATRIX_DRAW_PART_BTN, /**< The rectangle and label of buttons*/ +} lv_btnmatrix_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a button matrix object + * @param parent pointer to an object, it will be the parent of the new button matrix + * @return pointer to the created button matrix + */ +lv_obj_t * lv_btnmatrix_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new map. Buttons will be created/deleted according to the map. The + * button matrix keeps a reference to the map and so the string array must not + * be deallocated during the life of the matrix. + * @param obj pointer to a button matrix object + * @param map pointer a string array. The last string has to be: "". Use "\n" to make a line break. + */ +void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[]); + +/** + * Set the button control map (hidden, disabled etc.) for a button matrix. + * The control map array will be copied and so may be deallocated after this + * function returns. + * @param obj pointer to a button matrix object + * @param ctrl_map pointer to an array of `lv_btn_ctrl_t` control bytes. The + * length of the array and position of the elements must match + * the number and order of the individual buttons (i.e. excludes + * newline entries). + * An element of the map should look like e.g.: + * `ctrl_map[0] = width | LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_TGL_ENABLE` + */ +void lv_btnmatrix_set_ctrl_map(lv_obj_t * obj, const lv_btnmatrix_ctrl_t ctrl_map[]); + +/** + * Set the selected buttons + * @param obj pointer to button matrix object + * @param btn_id 0 based index of the button to modify. (Not counting new lines) + */ +void lv_btnmatrix_set_selected_btn(lv_obj_t * obj, uint16_t btn_id); + +/** + * Set the attributes of a button of the button matrix + * @param obj pointer to button matrix object + * @param btn_id 0 based index of the button to modify. (Not counting new lines) + * @param ctrl OR-ed attributs. E.g. `LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CHECKABLE` + */ +void lv_btnmatrix_set_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl); + +/** + * Clear the attributes of a button of the button matrix + * @param obj pointer to button matrix object + * @param btn_id 0 based index of the button to modify. (Not counting new lines) + * @param ctrl OR-ed attributs. E.g. `LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CHECKABLE` + */ +void lv_btnmatrix_clear_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl); + +/** + * Set attributes of all buttons of a button matrix + * @param obj pointer to a button matrix object + * @param ctrl attribute(s) to set from `lv_btnmatrix_ctrl_t`. Values can be ORed. + */ +void lv_btnmatrix_set_btn_ctrl_all(lv_obj_t * obj, lv_btnmatrix_ctrl_t ctrl); + +/** + * Clear the attributes of all buttons of a button matrix + * @param obj pointer to a button matrix object + * @param ctrl attribute(s) to set from `lv_btnmatrix_ctrl_t`. Values can be ORed. + * @param en true: set the attributes; false: clear the attributes + */ +void lv_btnmatrix_clear_btn_ctrl_all(lv_obj_t * obj, lv_btnmatrix_ctrl_t ctrl); + +/** + * Set a single button's relative width. + * This method will cause the matrix be regenerated and is a relatively + * expensive operation. It is recommended that initial width be specified using + * `lv_btnmatrix_set_ctrl_map` and this method only be used for dynamic changes. + * @param obj pointer to button matrix object + * @param btn_id 0 based index of the button to modify. + * @param width relative width compared to the buttons in the same row. [1..7] + */ +void lv_btnmatrix_set_btn_width(lv_obj_t * obj, uint16_t btn_id, uint8_t width); + +/** + * Make the button matrix like a selector widget (only one button may be checked at a time). + * `LV_BTNMATRIX_CTRL_CHECKABLE` must be enabled on the buttons to be selected using + * `lv_btnmatrix_set_ctrl()` or `lv_btnmatrix_set_btn_ctrl_all()`. + * @param obj pointer to a button matrix object + * @param en whether "one check" mode is enabled + */ +void lv_btnmatrix_set_one_checked(lv_obj_t * obj, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the current map of a button matrix + * @param obj pointer to a button matrix object + * @return the current map + */ +const char ** lv_btnmatrix_get_map(const lv_obj_t * obj); + +/** + * Get the index of the lastly "activated" button by the user (pressed, released, focused etc) + * Useful in the `event_cb` to get the text of the button, check if hidden etc. + * @param obj pointer to button matrix object + * @return index of the last released button (LV_BTNMATRIX_BTN_NONE: if unset) + */ +uint16_t lv_btnmatrix_get_selected_btn(const lv_obj_t * obj); + +/** + * Get the button's text + * @param obj pointer to button matrix object + * @param btn_id the index a button not counting new line characters. + * @return text of btn_index` button + */ +const char * lv_btnmatrix_get_btn_text(const lv_obj_t * obj, uint16_t btn_id); + +/** + * Get the whether a control value is enabled or disabled for button of a button matrix + * @param obj pointer to a button matrix object + * @param btn_id the index of a button not counting new line characters. + * @param ctrl control values to check (ORed value can be used) + * @return true: the control attribute is enabled false: disabled + */ +bool lv_btnmatrix_has_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl); + +/** + * Tell whether "one check" mode is enabled or not. + * @param obj Button matrix object + * @return true: "one check" mode is enabled; false: disabled + */ +bool lv_btnmatrix_get_one_checked(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_BTNMATRIX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_BTNMATRIX_H*/ diff --git a/include/liblvgl/widgets/lv_canvas.h b/include/liblvgl/widgets/lv_canvas.h new file mode 100644 index 00000000..f92a1c5c --- /dev/null +++ b/include/liblvgl/widgets/lv_canvas.h @@ -0,0 +1,280 @@ +/** + * @file lv_canvas.h + * + */ + +#ifndef LV_CANVAS_H +#define LV_CANVAS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_CANVAS != 0 + +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/widgets/lv_img.h" +#include "liblvgl/draw/lv_draw_img.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +extern const lv_obj_class_t lv_canvas_class; + +/*Data of canvas*/ +typedef struct { + lv_img_t img; + lv_img_dsc_t dsc; +} lv_canvas_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a canvas object + * @param parent pointer to an object, it will be the parent of the new canvas + * @return pointer to the created canvas + */ +lv_obj_t * lv_canvas_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a buffer for the canvas. + * @param buf a buffer where the content of the canvas will be. + * The required size is (lv_img_color_format_get_px_size(cf) * w) / 8 * h) + * It can be allocated with `lv_mem_alloc()` or + * it can be statically allocated array (e.g. static lv_color_t buf[100*50]) or + * it can be an address in RAM or external SRAM + * @param canvas pointer to a canvas object + * @param w width of the canvas + * @param h height of the canvas + * @param cf color format. `LV_IMG_CF_...` + */ +void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); + +/** + * Set the color of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param c color of the pixel + */ +void lv_canvas_set_px_color(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c); + +/** + * DEPRECATED: added only for backward compatibility + */ +static inline void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c) +{ + lv_canvas_set_px_color(canvas, x, y, c); +} + +/** + * Set the opacity of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @param opa opacity of the pixel (0..255) + */ +void lv_canvas_set_px_opa(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_opa_t opa); + + +/** + * Set the palette color of a canvas with index format. Valid only for `LV_IMG_CF_INDEXED1/2/4/8` + * @param canvas pointer to canvas object + * @param id the palette color to set: + * - for `LV_IMG_CF_INDEXED1`: 0..1 + * - for `LV_IMG_CF_INDEXED2`: 0..3 + * - for `LV_IMG_CF_INDEXED4`: 0..15 + * - for `LV_IMG_CF_INDEXED8`: 0..255 + * @param c the color to set + */ +void lv_canvas_set_palette(lv_obj_t * canvas, uint8_t id, lv_color_t c); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the color of a pixel on the canvas + * @param canvas + * @param x x coordinate of the point to set + * @param y x coordinate of the point to set + * @return color of the point + */ +lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y); + +/** + * Get the image of the canvas as a pointer to an `lv_img_dsc_t` variable. + * @param canvas pointer to a canvas object + * @return pointer to the image descriptor. + */ +lv_img_dsc_t * lv_canvas_get_img(lv_obj_t * canvas); + +/*===================== + * Other functions + *====================*/ + +/** + * Copy a buffer to the canvas + * @param canvas pointer to a canvas object + * @param to_copy buffer to copy. The color format has to match with the canvas's buffer color + * format + * @param x left side of the destination position + * @param y top side of the destination position + * @param w width of the buffer to copy + * @param h height of the buffer to copy + */ +void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, lv_coord_t y, lv_coord_t w, + lv_coord_t h); + +/** + * Transform and image and store the result on a canvas. + * @param canvas pointer to a canvas object to store the result of the transformation. + * @param img pointer to an image descriptor to transform. + * Can be the image descriptor of an other canvas too (`lv_canvas_get_img()`). + * @param angle the angle of rotation (0..3600), 0.1 deg resolution + * @param zoom zoom factor (256 no zoom); + * @param offset_x offset X to tell where to put the result data on destination canvas + * @param offset_y offset X to tell where to put the result data on destination canvas + * @param pivot_x pivot X of rotation. Relative to the source canvas + * Set to `source width / 2` to rotate around the center + * @param pivot_y pivot Y of rotation. Relative to the source canvas + * Set to `source height / 2` to rotate around the center + * @param antialias apply anti-aliasing during the transformation. Looks better but slower. + */ +void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x, + lv_coord_t offset_y, + int32_t pivot_x, int32_t pivot_y, bool antialias); + +/** + * Apply horizontal blur on the canvas + * @param canvas pointer to a canvas object + * @param area the area to blur. If `NULL` the whole canvas will be blurred. + * @param r radius of the blur + */ +void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r); + +/** + * Apply vertical blur on the canvas + * @param canvas pointer to a canvas object + * @param area the area to blur. If `NULL` the whole canvas will be blurred. + * @param r radius of the blur + */ +void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r); + +/** + * Fill the canvas with color + * @param canvas pointer to a canvas + * @param color the background color + * @param opa the desired opacity + */ +void lv_canvas_fill_bg(lv_obj_t * canvas, lv_color_t color, lv_opa_t opa); + +/** + * Draw a rectangle on the canvas + * @param canvas pointer to a canvas object + * @param x left coordinate of the rectangle + * @param y top coordinate of the rectangle + * @param w width of the rectangle + * @param h height of the rectangle + * @param draw_dsc descriptor of the rectangle + */ +void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, + const lv_draw_rect_dsc_t * draw_dsc); + +/** + * Draw a text on the canvas. + * @param canvas pointer to a canvas object + * @param x left coordinate of the text + * @param y top coordinate of the text + * @param max_w max width of the text. The text will be wrapped to fit into this size + * @param draw_dsc pointer to a valid label descriptor `lv_draw_label_dsc_t` + * @param txt text to display + */ +void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, + lv_draw_label_dsc_t * draw_dsc, const char * txt); + +/** + * Draw an image on the canvas + * @param canvas pointer to a canvas object + * @param x left coordinate of the image + * @param y top coordinate of the image + * @param src image source. Can be a pointer an `lv_img_dsc_t` variable or a path an image. + * @param draw_dsc pointer to a valid label descriptor `lv_draw_img_dsc_t` + */ +void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, + const lv_draw_img_dsc_t * draw_dsc); + +/** + * Draw a line on the canvas + * @param canvas pointer to a canvas object + * @param points point of the line + * @param point_cnt number of points + * @param draw_dsc pointer to an initialized `lv_draw_line_dsc_t` variable + */ +void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t points[], uint32_t point_cnt, + const lv_draw_line_dsc_t * draw_dsc); + +/** + * Draw a polygon on the canvas + * @param canvas pointer to a canvas object + * @param points point of the polygon + * @param point_cnt number of points + * @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable + */ +void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t points[], uint32_t point_cnt, + const lv_draw_rect_dsc_t * draw_dsc); + +/** + * Draw an arc on the canvas + * @param canvas pointer to a canvas object + * @param x origo x of the arc + * @param y origo y of the arc + * @param r radius of the arc + * @param start_angle start angle in degrees + * @param end_angle end angle in degrees + * @param draw_dsc pointer to an initialized `lv_draw_line_dsc_t` variable + */ +void lv_canvas_draw_arc(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t r, int32_t start_angle, + int32_t end_angle, const lv_draw_arc_dsc_t * draw_dsc); + +/********************** + * MACROS + **********************/ +#define LV_CANVAS_BUF_SIZE_TRUE_COLOR(w, h) LV_IMG_BUF_SIZE_TRUE_COLOR(w, h) +#define LV_CANVAS_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h) LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h) +#define LV_CANVAS_BUF_SIZE_TRUE_COLOR_ALPHA(w, h) LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h) + +/*+ 1: to be sure no fractional row*/ +#define LV_CANVAS_BUF_SIZE_ALPHA_1BIT(w, h) LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) +#define LV_CANVAS_BUF_SIZE_ALPHA_2BIT(w, h) LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h) +#define LV_CANVAS_BUF_SIZE_ALPHA_4BIT(w, h) LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h) +#define LV_CANVAS_BUF_SIZE_ALPHA_8BIT(w, h) LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h) + +/*4 * X: for palette*/ +#define LV_CANVAS_BUF_SIZE_INDEXED_1BIT(w, h) LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h) +#define LV_CANVAS_BUF_SIZE_INDEXED_2BIT(w, h) LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h) +#define LV_CANVAS_BUF_SIZE_INDEXED_4BIT(w, h) LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h) +#define LV_CANVAS_BUF_SIZE_INDEXED_8BIT(w, h) LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h) + +#endif /*LV_USE_CANVAS*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CANVAS_H*/ diff --git a/include/liblvgl/widgets/lv_checkbox.h b/include/liblvgl/widgets/lv_checkbox.h new file mode 100644 index 00000000..6b2bdc39 --- /dev/null +++ b/include/liblvgl/widgets/lv_checkbox.h @@ -0,0 +1,97 @@ +/** + * @file lv_cb.h + * + */ + +#ifndef LV_CHECKBOX_H +#define LV_CHECKBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" +#include "liblvgl/core/lv_obj.h" + +#if LV_USE_CHECKBOX != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + char * txt; + uint32_t static_txt : 1; +} lv_checkbox_t; + +extern const lv_obj_class_t lv_checkbox_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_checkbox_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_CHECKBOX_DRAW_PART_BOX, /**< The tick box*/ +} lv_checkbox_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a check box object + * @param parent pointer to an object, it will be the parent of the new button + * @return pointer to the created check box + */ +lv_obj_t * lv_checkbox_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of a check box. `txt` will be copied and may be deallocated + * after this function returns. + * @param cb pointer to a check box + * @param txt the text of the check box. NULL to refresh with the current text. + */ +void lv_checkbox_set_text(lv_obj_t * obj, const char * txt); + +/** + * Set the text of a check box. `txt` must not be deallocated during the life + * of this checkbox. + * @param cb pointer to a check box + * @param txt the text of the check box. + */ +void lv_checkbox_set_text_static(lv_obj_t * obj, const char * txt); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a check box + * @param cb pointer to check box object + * @return pointer to the text of the check box + */ +const char * lv_checkbox_get_text(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_CHECKBOX*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_CHECKBOX_H*/ diff --git a/include/liblvgl/widgets/lv_dropdown.h b/include/liblvgl/widgets/lv_dropdown.h new file mode 100644 index 00000000..9848b145 --- /dev/null +++ b/include/liblvgl/widgets/lv_dropdown.h @@ -0,0 +1,254 @@ +/** + * @file lv_dropdown.h + * + */ + +#ifndef LV_DROPDOWN_H +#define LV_DROPDOWN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_DROPDOWN != 0 + +/*Testing of dependencies*/ + +#if LV_USE_LABEL == 0 +#error "lv_dropdown: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)" +#endif + +#include "../widgets/lv_label.h" + +/********************* + * DEFINES + *********************/ +#define LV_DROPDOWN_POS_LAST 0xFFFF +LV_EXPORT_CONST_INT(LV_DROPDOWN_POS_LAST); + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + lv_obj_t * list; /**< The dropped down list*/ + const char * text; /**< Text to display on the dropdown's button*/ + const void * symbol; /**< Arrow or other icon when the drop-down list is closed*/ + char * options; /**< Options in a '\n' separated list*/ + uint16_t option_cnt; /**< Number of options*/ + uint16_t sel_opt_id; /**< Index of the currently selected option*/ + uint16_t sel_opt_id_orig; /**< Store the original index on focus*/ + uint16_t pr_opt_id; /**< Index of the currently pressed option*/ + lv_dir_t dir : 4; /**< Direction in which the list should open*/ + uint8_t static_txt : 1; /**< 1: Only a pointer is saved in `options`*/ + uint8_t selected_highlight: 1; /**< 1: Make the selected option highlighted in the list*/ +} lv_dropdown_t; + +typedef struct { + lv_obj_t obj; + lv_obj_t * dropdown; +} lv_dropdown_list_t; + +extern const lv_obj_class_t lv_dropdown_class; +extern const lv_obj_class_t lv_dropdownlist_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a drop-down list object + * @param parent pointer to an object, it will be the parent of the new drop-down list + * @return pointer to the created drop-down list + */ +lv_obj_t * lv_dropdown_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set text of the drop-down list's button. + * If set to `NULL` the selected option's text will be displayed on the button. + * If set to a specific text then that text will be shown regardless of the selected option. + * @param obj pointer to a drop-down list object + * @param txt the text as a string (Only its pointer is saved) + */ +void lv_dropdown_set_text(lv_obj_t * obj, const char * txt); + +/** + * Set the options in a drop-down list from a string. + * The options will be copied and saved in the object so the `options` can be destroyed after calling this function + * @param obj pointer to drop-down list object + * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" + */ +void lv_dropdown_set_options(lv_obj_t * obj, const char * options); + +/** + * Set the options in a drop-down list from a static string (global, static or dynamically allocated). + * Only the pointer of the option string will be saved. + * @param obj pointer to drop-down list object + * @param options a static string with '\n' separated options. E.g. "One\nTwo\nThree" + */ +void lv_dropdown_set_options_static(lv_obj_t * obj, const char * options); + +/** + * Add an options to a drop-down list from a string. Only works for non-static options. + * @param obj pointer to drop-down list object + * @param option a string without '\n'. E.g. "Four" + * @param pos the insert position, indexed from 0, LV_DROPDOWN_POS_LAST = end of string + */ +void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos); + +/** + * Clear all options in a drop-down list. Works with both static and dynamic options. + * @param obj pointer to drop-down list object + */ +void lv_dropdown_clear_options(lv_obj_t * obj); + +/** + * Set the selected option + * @param obj pointer to drop-down list object + * @param sel_opt id of the selected option (0 ... number of option - 1); + */ +void lv_dropdown_set_selected(lv_obj_t * obj, uint16_t sel_opt); + +/** + * Set the direction of the a drop-down list + * @param obj pointer to a drop-down list object + * @param dir LV_DIR_LEFT/RIGHT/TOP/BOTTOM + */ +void lv_dropdown_set_dir(lv_obj_t * obj, lv_dir_t dir); + +/** + * Set an arrow or other symbol to display when on drop-down list's button. Typically a down caret or arrow. + * @param obj pointer to drop-down list object + * @param symbol a text like `LV_SYMBOL_DOWN`, an image (pointer or path) or NULL to not draw symbol icon + * @note angle and zoom transformation can be applied if the symbol is an image. + * E.g. when drop down is checked (opened) rotate the symbol by 180 degree + */ +void lv_dropdown_set_symbol(lv_obj_t * obj, const void * symbol); + +/** + * Set whether the selected option in the list should be highlighted or not + * @param obj pointer to drop-down list object + * @param en true: highlight enabled; false: disabled + */ +void lv_dropdown_set_selected_highlight(lv_obj_t * obj, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the list of a drop-down to allow styling or other modifications + * @param obj pointer to a drop-down list object + * @return pointer to the list of the drop-down + */ +lv_obj_t * lv_dropdown_get_list(lv_obj_t * obj); + +/** + * Get text of the drop-down list's button. + * @param obj pointer to a drop-down list object + * @return the text as string, `NULL` if no text + */ +const char * lv_dropdown_get_text(lv_obj_t * obj); + +/** + * Get the options of a drop-down list + * @param obj pointer to drop-down list object + * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") + */ +const char * lv_dropdown_get_options(const lv_obj_t * obj); + +/** + * Get the index of the selected option + * @param obj pointer to drop-down list object + * @return index of the selected option (0 ... number of option - 1); + */ +uint16_t lv_dropdown_get_selected(const lv_obj_t * obj); + +/** + * Get the total number of options + * @param obj pointer to drop-down list object + * @return the total number of options in the list + */ +uint16_t lv_dropdown_get_option_cnt(const lv_obj_t * obj); + +/** + * Get the current selected option as a string + * @param obj pointer to drop-down object + * @param buf pointer to an array to store the string + * @param buf_size size of `buf` in bytes. 0: to ignore it. + */ +void lv_dropdown_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size); + +/** + * Get the index of an option. + * @param obj pointer to drop-down object + * @param option an option as string + * @return index of `option` in the list of all options. -1 if not found. + */ +int32_t lv_dropdown_get_option_index(lv_obj_t * obj, const char * option); + +/** + * Get the symbol on the drop-down list. Typically a down caret or arrow. + * @param obj pointer to drop-down list object + * @return the symbol or NULL if not enabled + */ +const char * lv_dropdown_get_symbol(lv_obj_t * obj); + +/** + * Get whether the selected option in the list should be highlighted or not + * @param obj pointer to drop-down list object + * @return true: highlight enabled; false: disabled + */ +bool lv_dropdown_get_selected_highlight(lv_obj_t * obj); + +/** + * Get the direction of the drop-down list + * @param obj pointer to a drop-down list object + * @return LV_DIR_LEF/RIGHT/TOP/BOTTOM + */ +lv_dir_t lv_dropdown_get_dir(const lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Open the drop.down list + * @param obj pointer to drop-down list object + */ +void lv_dropdown_open(lv_obj_t * dropdown_obj); + +/** + * Close (Collapse) the drop-down list + * @param obj pointer to drop-down list object + */ +void lv_dropdown_close(lv_obj_t * obj); + +/** + * Tells whether the list is opened or not + * @param obj pointer to a drop-down list object + * @return true if the list os opened + */ +bool lv_dropdown_is_open(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_DROPDOWN*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DROPDOWN_H*/ diff --git a/include/liblvgl/widgets/lv_img.h b/include/liblvgl/widgets/lv_img.h new file mode 100644 index 00000000..5513a26c --- /dev/null +++ b/include/liblvgl/widgets/lv_img.h @@ -0,0 +1,234 @@ +/** + * @file lv_img.h + * + */ + +#ifndef LV_IMG_H +#define LV_IMG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_IMG != 0 + +/*Testing of dependencies*/ +#if LV_USE_LABEL == 0 +#error "lv_img: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/misc/lv_fs.h" +#include "liblvgl/draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** + * Data of image + */ +typedef struct { + lv_obj_t obj; + const void * src; /*Image source: Pointer to an array or a file or a symbol*/ + lv_point_t offset; + lv_coord_t w; /*Width of the image (Handled by the library)*/ + lv_coord_t h; /*Height of the image (Handled by the library)*/ + uint16_t angle; /*rotation angle of the image*/ + lv_point_t pivot; /*rotation center of the image*/ + uint16_t zoom; /*256 means no zoom, 512 double size, 128 half size*/ + uint8_t src_type : 2; /*See: lv_img_src_t*/ + uint8_t cf : 5; /*Color format from `lv_img_color_format_t`*/ + uint8_t antialias : 1; /*Apply anti-aliasing in transformations (rotate, zoom)*/ + uint8_t obj_size_mode: 2; /*Image size mode when image size and object size is different.*/ +} lv_img_t; + +extern const lv_obj_class_t lv_img_class; + +/** + * Image size mode, when image size and object size is different + */ +enum { + /** Zoom doesn't affect the coordinates of the object, + * however if zoomed in the image is drawn out of the its coordinates. + * The layout's won't change on zoom */ + LV_IMG_SIZE_MODE_VIRTUAL = 0, + + /** If the object size is set to SIZE_CONTENT, then object size equals zoomed image size. + * It causes layout recalculation. + * If the object size is set explicitly, the image will be cropped when zoomed in.*/ + LV_IMG_SIZE_MODE_REAL, +}; + +typedef uint8_t lv_img_size_mode_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create an image object + * @param parent pointer to an object, it will be the parent of the new image + * @return pointer to the created image + */ +lv_obj_t * lv_img_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the image data to display on the object + * @param obj pointer to an image object + * @param src_img 1) pointer to an ::lv_img_dsc_t descriptor (converted by LVGL's image converter) (e.g. &my_img) or + * 2) path to an image file (e.g. "S:/dir/img.bin")or + * 3) a SYMBOL (e.g. LV_SYMBOL_OK) + */ +void lv_img_set_src(lv_obj_t * obj, const void * src); + +/** + * Set an offset for the source of an image so the image will be displayed from the new origin. + * @param obj pointer to an image + * @param x the new offset along x axis. + */ +void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x); + +/** + * Set an offset for the source of an image. + * so the image will be displayed from the new origin. + * @param obj pointer to an image + * @param y the new offset along y axis. + */ +void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y); + + +/** + * Set the rotation angle of the image. + * The image will be rotated around the set pivot set by `lv_img_set_pivot()` + * Note that indexed and alpha only images can't be transformed. + * @param obj pointer to an image object + * @param angle rotation angle in degree with 0.1 degree resolution (0..3600: clock wise) + */ +void lv_img_set_angle(lv_obj_t * obj, int16_t angle); + +/** + * Set the rotation center of the image. + * The image will be rotated around this point. + * @param obj pointer to an image object + * @param x rotation center x of the image + * @param y rotation center y of the image + */ +void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y); + + +/** + * Set the zoom factor of the image. + * Note that indexed and alpha only images can't be transformed. + * @param img pointer to an image object + * @param zoom the zoom factor. + * @example 256 or LV_ZOOM_IMG_NONE for no zoom + * @example <256: scale down + * @example >256 scale up + * @example 128 half size + * @example 512 double size + */ +void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom); + +/** + * Enable/disable anti-aliasing for the transformations (rotate, zoom) or not. + * The quality is better with anti-aliasing looks better but slower. + * @param obj pointer to an image object + * @param antialias true: anti-aliased; false: not anti-aliased + */ +void lv_img_set_antialias(lv_obj_t * obj, bool antialias); + +/** + * Set the image object size mode. + * + * @param obj pointer to an image object + * @param mode the new size mode. + */ +void lv_img_set_size_mode(lv_obj_t * obj, lv_img_size_mode_t mode); +/*===================== + * Getter functions + *====================*/ + +/** + * Get the source of the image + * @param obj pointer to an image object + * @return the image source (symbol, file name or ::lv-img_dsc_t for C arrays) + */ +const void * lv_img_get_src(lv_obj_t * obj); + +/** + * Get the offset's x attribute of the image object. + * @param img pointer to an image + * @return offset X value. + */ +lv_coord_t lv_img_get_offset_x(lv_obj_t * obj); + +/** + * Get the offset's y attribute of the image object. + * @param obj pointer to an image + * @return offset Y value. + */ +lv_coord_t lv_img_get_offset_y(lv_obj_t * obj); + +/** + * Get the rotation angle of the image. + * @param obj pointer to an image object + * @return rotation angle in 0.1 degrees (0..3600) + */ +uint16_t lv_img_get_angle(lv_obj_t * obj); + +/** + * Get the pivot (rotation center) of the image. + * @param img pointer to an image object + * @param pivot store the rotation center here + */ +void lv_img_get_pivot(lv_obj_t * obj, lv_point_t * pivot); + +/** + * Get the zoom factor of the image. + * @param obj pointer to an image object + * @return zoom factor (256: no zoom) + */ +uint16_t lv_img_get_zoom(lv_obj_t * obj); + +/** + * Get whether the transformations (rotate, zoom) are anti-aliased or not + * @param obj pointer to an image object + * @return true: anti-aliased; false: not anti-aliased + */ +bool lv_img_get_antialias(lv_obj_t * obj); + +/** + * Get the size mode of the image + * @param obj pointer to an image object + * @return element of @ref lv_img_size_mode_t + */ +lv_img_size_mode_t lv_img_get_size_mode(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +/** Use this macro to declare an image in a C file*/ +#define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name; + +#endif /*LV_USE_IMG*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_IMG_H*/ diff --git a/include/liblvgl/widgets/lv_label.h b/include/liblvgl/widgets/lv_label.h new file mode 100644 index 00000000..39a68db0 --- /dev/null +++ b/include/liblvgl/widgets/lv_label.h @@ -0,0 +1,246 @@ +/** + * @file lv_label.h + * + */ + +#ifndef LV_LABEL_H +#define LV_LABEL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../lv_conf_internal.h" + +#if LV_USE_LABEL != 0 + +#include +#include "liblvgl/core/lv_obj.h" +#include "liblvgl/font/lv_font.h" +#include "liblvgl/font/lv_symbol_def.h" +#include "liblvgl/misc/lv_txt.h" +#include "liblvgl/draw/lv_draw.h" + +/********************* + * DEFINES + *********************/ +#define LV_LABEL_WAIT_CHAR_COUNT 3 +#define LV_LABEL_DOT_NUM 3 +#define LV_LABEL_POS_LAST 0xFFFF +#define LV_LABEL_TEXT_SELECTION_OFF LV_DRAW_LABEL_NO_TXT_SEL + +LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM); +LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST); +LV_EXPORT_CONST_INT(LV_LABEL_TEXT_SELECTION_OFF); + +/********************** + * TYPEDEFS + **********************/ + +/** Long mode behaviors. Used in 'lv_label_ext_t'*/ +enum { + LV_LABEL_LONG_WRAP, /**< Keep the object width, wrap the too long lines and expand the object height*/ + LV_LABEL_LONG_DOT, /**< Keep the size and write dots at the end if the text is too long*/ + LV_LABEL_LONG_SCROLL, /**< Keep the size and roll the text back and forth*/ + LV_LABEL_LONG_SCROLL_CIRCULAR, /**< Keep the size and roll the text circularly*/ + LV_LABEL_LONG_CLIP, /**< Keep the size and clip the text out of it*/ +}; +typedef uint8_t lv_label_long_mode_t; + +typedef struct { + lv_obj_t obj; + char * text; + union { + char * tmp_ptr; /*Pointer to the allocated memory containing the character replaced by dots*/ + char tmp[LV_LABEL_DOT_NUM + 1]; /*Directly store the characters if <=4 characters*/ + } dot; + uint32_t dot_end; /*The real text length, used in dot mode*/ + +#if LV_LABEL_LONG_TXT_HINT + lv_draw_label_hint_t hint; +#endif + +#if LV_LABEL_TEXT_SELECTION + uint32_t sel_start; + uint32_t sel_end; +#endif + + lv_point_t offset; /*Text draw position offset*/ + lv_label_long_mode_t long_mode : 3; /*Determine what to do with the long texts*/ + uint8_t static_txt : 1; /*Flag to indicate the text is static*/ + uint8_t recolor : 1; /*Enable in-line letter re-coloring*/ + uint8_t expand : 1; /*Ignore real width (used by the library with LV_LABEL_LONG_SCROLL)*/ + uint8_t dot_tmp_alloc : 1; /*1: dot is allocated, 0: dot directly holds up to 4 chars*/ +} lv_label_t; + +extern const lv_obj_class_t lv_label_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a label object + * @param parent pointer to an object, it will be the parent of the new label. + * @return pointer to the created button + */ +lv_obj_t * lv_label_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new text for a label. Memory will be allocated to store the text by the label. + * @param obj pointer to a label object + * @param text '\0' terminated character string. NULL to refresh with the current text. + */ +void lv_label_set_text(lv_obj_t * obj, const char * text); + +/** + * Set a new formatted text for a label. Memory will be allocated to store the text by the label. + * @param obj pointer to a label object + * @param fmt `printf`-like format + * @example lv_label_set_text_fmt(label1, "%d user", user_num); + */ +void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) LV_FORMAT_ATTRIBUTE(2, 3); + +/** + * Set a static text. It will not be saved by the label so the 'text' variable + * has to be 'alive' while the label exists. + * @param obj pointer to a label object + * @param text pointer to a text. NULL to refresh with the current text. + */ +void lv_label_set_text_static(lv_obj_t * obj, const char * text); + +/** + * Set the behavior of the label with longer text then the object size + * @param obj pointer to a label object + * @param long_mode the new mode from 'lv_label_long_mode' enum. + * In LV_LONG_WRAP/DOT/SCROLL/SCROLL_CIRC the size of the label should be set AFTER this function + */ +void lv_label_set_long_mode(lv_obj_t * obj, lv_label_long_mode_t long_mode); + +/** + * Enable the recoloring by in-line commands + * @param obj pointer to a label object + * @param en true: enable recoloring, false: disable + * @example "This is a #ff0000 red# word" + */ +void lv_label_set_recolor(lv_obj_t * obj, bool en); + +/** + * Set where text selection should start + * @param obj pointer to a label object + * @param index character index from where selection should start. `LV_LABEL_TEXT_SELECTION_OFF` for no selection + */ +void lv_label_set_text_sel_start(lv_obj_t * obj, uint32_t index); + +/** + * Set where text selection should end + * @param obj pointer to a label object + * @param index character index where selection should end. `LV_LABEL_TEXT_SELECTION_OFF` for no selection + */ +void lv_label_set_text_sel_end(lv_obj_t * obj, uint32_t index); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a label + * @param obj pointer to a label object + * @return the text of the label + */ +char * lv_label_get_text(const lv_obj_t * obj); + +/** + * Get the long mode of a label + * @param obj pointer to a label object + * @return the current long mode + */ +lv_label_long_mode_t lv_label_get_long_mode(const lv_obj_t * obj); + +/** + * Get the recoloring attribute + * @param obj pointer to a label object + * @return true: recoloring is enabled, false: disable + */ +bool lv_label_get_recolor(const lv_obj_t * obj); + +/** + * Get the relative x and y coordinates of a letter + * @param obj pointer to a label object + * @param index index of the character [0 ... text length - 1]. + * Expressed in character index, not byte index (different in UTF-8) + * @param pos store the result here (E.g. index = 0 gives 0;0 coordinates if the text if aligned to the left) + */ +void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t * pos); + +/** + * Get the index of letter on a relative point of a label. + * @param obj pointer to label object + * @param pos pointer to point with coordinates on a the label + * @return The index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter if aligned to the left) + * Expressed in character index and not byte index (different in UTF-8) + */ +uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in); + +/** + * Check if a character is drawn under a point. + * @param obj pointer to a label object + * @param pos Point to check for character under + * @return whether a character is drawn under the point + */ +bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos); + +/** + * @brief Get the selection start index. + * @param obj pointer to a label object. + * @return selection start index. `LV_LABEL_TEXT_SELECTION_OFF` if nothing is selected. + */ +uint32_t lv_label_get_text_selection_start(const lv_obj_t * obj); + +/** + * @brief Get the selection end index. + * @param obj pointer to a label object. + * @return selection end index. `LV_LABEL_TXT_SEL_OFF` if nothing is selected. + */ +uint32_t lv_label_get_text_selection_end(const lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Insert a text to a label. The label text can not be static. + * @param obj pointer to a label object + * @param pos character index to insert. Expressed in character index and not byte index. + * 0: before first char. LV_LABEL_POS_LAST: after last char. + * @param txt pointer to the text to insert + */ +void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt); + +/** + * Delete characters from a label. The label text can not be static. + * @param obj pointer to a label object + * @param pos character index from where to cut. Expressed in character index and not byte index. + * 0: start in from of the first character + * @param cnt number of characters to cut + */ +void lv_label_cut_text(lv_obj_t * obj, uint32_t pos, uint32_t cnt); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_LABEL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LABEL_H*/ diff --git a/include/liblvgl/widgets/lv_line.h b/include/liblvgl/widgets/lv_line.h new file mode 100644 index 00000000..622ef810 --- /dev/null +++ b/include/liblvgl/widgets/lv_line.h @@ -0,0 +1,93 @@ +/** + * @file lv_line.h + * + */ + +#ifndef LV_LINE_H +#define LV_LINE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_LINE != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/*Data of line*/ +typedef struct { + lv_obj_t obj; + const lv_point_t * point_array; /**< Pointer to an array with the points of the line*/ + uint16_t point_num; /**< Number of points in 'point_array'*/ + uint8_t y_inv : 1; /**< 1: y == 0 will be on the bottom*/ +} lv_line_t; + +extern const lv_obj_class_t lv_line_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a line object + * @param parent pointer to an object, it will be the parent of the new line + * @return pointer to the created line + */ +lv_obj_t * lv_line_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set an array of points. The line object will connect these points. + * @param obj pointer to a line object + * @param points an array of points. Only the address is saved, so the array needs to be alive while the line exists + * @param point_num number of points in 'point_a' + */ +void lv_line_set_points(lv_obj_t * obj, const lv_point_t points[], uint16_t point_num); + +/** + * Enable (or disable) the y coordinate inversion. + * If enabled then y will be subtracted from the height of the object, + * therefore the y = 0 coordinate will be on the bottom. + * @param obj pointer to a line object + * @param en true: enable the y inversion, false:disable the y inversion + */ +void lv_line_set_y_invert(lv_obj_t * obj, bool en); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the y inversion attribute + * @param obj pointer to a line object + * @return true: y inversion is enabled, false: disabled + */ +bool lv_line_get_y_invert(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_LINE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_LINE_H*/ diff --git a/include/liblvgl/widgets/lv_objx_templ.h b/include/liblvgl/widgets/lv_objx_templ.h new file mode 100644 index 00000000..f363df4e --- /dev/null +++ b/include/liblvgl/widgets/lv_objx_templ.h @@ -0,0 +1,81 @@ +/** + * @file lv_templ.h + * + */ + +/** + * TODO Remove these instructions + * Search and replace: templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) + * + */ + +#ifndef LV_TEMPL_H +#define LV_TEMPL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_TEMPL != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of template*/ +typedef struct { + lv_ANCESTOR_t ancestor; /*The ancestor widget, e.g. lv_slider_t slider*/ + /*New data for this type*/ +} lv_templ_t; + +extern const lv_obj_class_t lv_templ_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a templ object + * @param parent pointer to an object, it will be the parent of the new templ + * @return pointer to the created bar + */ +lv_obj_t * lv_templ_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/*===================== + * Setter functions + *====================*/ + +/*===================== + * Getter functions + *====================*/ + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TEMPL*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TEMPL_H*/ diff --git a/include/liblvgl/widgets/lv_roller.h b/include/liblvgl/widgets/lv_roller.h new file mode 100644 index 00000000..4984c262 --- /dev/null +++ b/include/liblvgl/widgets/lv_roller.h @@ -0,0 +1,138 @@ +/** + * @file lv_roller.h + * + */ + +#ifndef LV_ROLLER_H +#define LV_ROLLER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_ROLLER != 0 + +/*Testing of dependencies*/ +#if LV_USE_LABEL == 0 +#error "lv_roller: lv_label is required. Enable it in lv_conf.h (LV_USE_ROLLER 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/** Roller mode.*/ +enum { + LV_ROLLER_MODE_NORMAL, /**< Normal mode (roller ends at the end of the options).*/ + LV_ROLLER_MODE_INFINITE, /**< Infinite mode (roller can be scrolled forever).*/ +}; + +typedef uint8_t lv_roller_mode_t; + +typedef struct { + lv_obj_t obj; + uint16_t option_cnt; /**< Number of options*/ + uint16_t sel_opt_id; /**< Index of the current option*/ + uint16_t sel_opt_id_ori; /**< Store the original index on focus*/ + lv_roller_mode_t mode : 1; + uint32_t moved : 1; +} lv_roller_t; + +extern const lv_obj_class_t lv_roller_class; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a roller object + * @param parent pointer to an object, it will be the parent of the new roller. + * @return pointer to the created roller + */ +lv_obj_t * lv_roller_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the options on a roller + * @param obj pointer to roller object + * @param options a string with '\n' separated options. E.g. "One\nTwo\nThree" + * @param mode `LV_ROLLER_MODE_NORMAL` or `LV_ROLLER_MODE_INFINITE` + */ +void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_t mode); + +/** + * Set the selected option + * @param obj pointer to a roller object + * @param sel_opt index of the selected option (0 ... number of option - 1); + * @param anim_en LV_ANIM_ON: set with animation; LV_ANOM_OFF set immediately + */ +void lv_roller_set_selected(lv_obj_t * obj, uint16_t sel_opt, lv_anim_enable_t anim); + +/** + * Set the height to show the given number of rows (options) + * @param obj pointer to a roller object + * @param row_cnt number of desired visible rows + */ +void lv_roller_set_visible_row_count(lv_obj_t * obj, uint8_t row_cnt); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the index of the selected option + * @param obj pointer to a roller object + * @return index of the selected option (0 ... number of option - 1); + */ +uint16_t lv_roller_get_selected(const lv_obj_t * obj); + +/** + * Get the current selected option as a string. + * @param obj pointer to ddlist object + * @param buf pointer to an array to store the string + * @param buf_size size of `buf` in bytes. 0: to ignore it. + */ +void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_size); + + +/** + * Get the options of a roller + * @param obj pointer to roller object + * @return the options separated by '\n'-s (E.g. "Option1\nOption2\nOption3") + */ +const char * lv_roller_get_options(const lv_obj_t * obj); + +/** + * Get the total number of options + * @param obj pointer to a roller object + * @return the total number of options + */ +uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_ROLLER*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_ROLLER_H*/ diff --git a/include/liblvgl/widgets/lv_slider.h b/include/liblvgl/widgets/lv_slider.h new file mode 100644 index 00000000..20c940f8 --- /dev/null +++ b/include/liblvgl/widgets/lv_slider.h @@ -0,0 +1,195 @@ +/** + * @file lv_slider.h + * + */ + +#ifndef LV_SLIDER_H +#define LV_SLIDER_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_SLIDER != 0 + +/*Testing of dependencies*/ +#if LV_USE_BAR == 0 +#error "lv_slider: lv_bar is required. Enable it in lv_conf.h (LV_USE_BAR 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "lv_bar.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_SLIDER_MODE_NORMAL = LV_BAR_MODE_NORMAL, + LV_SLIDER_MODE_SYMMETRICAL = LV_BAR_MODE_SYMMETRICAL, + LV_SLIDER_MODE_RANGE = LV_BAR_MODE_RANGE +}; +typedef uint8_t lv_slider_mode_t; + +typedef struct { + lv_bar_t bar; /*Add the ancestor's type first*/ + lv_area_t left_knob_area; + lv_area_t right_knob_area; + int32_t * value_to_set; /*Which bar value to set*/ + uint8_t dragging : 1; /*1: the slider is being dragged*/ + uint8_t left_knob_focus : 1; /*1: with encoder now the right knob can be adjusted*/ +} lv_slider_t; + +extern const lv_obj_class_t lv_slider_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_slider_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_SLIDER_DRAW_PART_KNOB, /**< The main (right) knob's rectangle*/ + LV_SLIDER_DRAW_PART_KNOB_LEFT, /**< The left knob's rectangle*/ +} lv_slider_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a slider object + * @param parent pointer to an object, it will be the parent of the new slider. + * @return pointer to the created slider + */ +lv_obj_t * lv_slider_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the slider + * @param obj pointer to a slider object + * @param value the new value + * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately + */ +static inline void lv_slider_set_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim) +{ + lv_bar_set_value(obj, value, anim); +} + +/** + * Set a new value for the left knob of a slider + * @param obj pointer to a slider object + * @param value new value + * @param anim LV_ANIM_ON: set the value with an animation; LV_ANIM_OFF: change the value immediately + */ +static inline void lv_slider_set_left_value(lv_obj_t * obj, int32_t value, lv_anim_enable_t anim) +{ + lv_bar_set_start_value(obj, value, anim); +} + +/** + * Set minimum and the maximum values of a bar + * @param obj pointer to the slider object + * @param min minimum value + * @param max maximum value + */ +static inline void lv_slider_set_range(lv_obj_t * obj, int32_t min, int32_t max) +{ + lv_bar_set_range(obj, min, max); +} + +/** + * Set the mode of slider. + * @param obj pointer to a slider object + * @param mode the mode of the slider. See ::lv_slider_mode_t + */ +static inline void lv_slider_set_mode(lv_obj_t * obj, lv_slider_mode_t mode) +{ + lv_bar_set_mode(obj, (lv_bar_mode_t)mode); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of the main knob of a slider + * @param obj pointer to a slider object + * @return the value of the main knob of the slider + */ +static inline int32_t lv_slider_get_value(const lv_obj_t * obj) +{ + return lv_bar_get_value(obj); +} + +/** + * Get the value of the left knob of a slider + * @param obj pointer to a slider object + * @return the value of the left knob of the slider + */ +static inline int32_t lv_slider_get_left_value(const lv_obj_t * obj) +{ + return lv_bar_get_start_value(obj); +} + +/** + * Get the minimum value of a slider + * @param obj pointer to a slider object + * @return the minimum value of the slider + */ +static inline int32_t lv_slider_get_min_value(const lv_obj_t * obj) +{ + return lv_bar_get_min_value(obj); +} + +/** + * Get the maximum value of a slider + * @param obj pointer to a slider object + * @return the maximum value of the slider + */ +static inline int32_t lv_slider_get_max_value(const lv_obj_t * obj) +{ + return lv_bar_get_max_value(obj); +} + +/** + * Give the slider is being dragged or not + * @param obj pointer to a slider object + * @return true: drag in progress false: not dragged + */ +bool lv_slider_is_dragged(const lv_obj_t * obj); + +/** + * Get the mode of the slider. + * @param obj pointer to a bar object + * @return see ::lv_slider_mode_t + */ +static inline lv_slider_mode_t lv_slider_get_mode(lv_obj_t * slider) +{ + lv_bar_mode_t mode = lv_bar_get_mode(slider); + if(mode == LV_BAR_MODE_SYMMETRICAL) return LV_SLIDER_MODE_SYMMETRICAL; + else if(mode == LV_BAR_MODE_RANGE) return LV_SLIDER_MODE_RANGE; + else return LV_SLIDER_MODE_NORMAL; +} + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_SLIDER*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_SLIDER_H*/ diff --git a/include/liblvgl/widgets/lv_switch.h b/include/liblvgl/widgets/lv_switch.h new file mode 100644 index 00000000..63ec4276 --- /dev/null +++ b/include/liblvgl/widgets/lv_switch.h @@ -0,0 +1,61 @@ +/** + * @file lv_switch.h + * + */ + +#ifndef LV_SWITCH_H +#define LV_SWITCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_SWITCH != 0 + +#include "liblvgl/core/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/** Switch knob extra area correction factor */ +#define _LV_SWITCH_KNOB_EXT_AREA_CORRECTION 2 + +/********************** + * TYPEDEFS + **********************/ + +typedef struct { + lv_obj_t obj; + int32_t anim_state; +} lv_switch_t; + +extern const lv_obj_class_t lv_switch_class; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a switch object + * @param parent pointer to an object, it will be the parent of the new switch + * @return pointer to the created switch + */ +lv_obj_t * lv_switch_create(lv_obj_t * parent); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_SWITCH*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_SWITCH_H*/ diff --git a/include/liblvgl/widgets/lv_table.h b/include/liblvgl/widgets/lv_table.h new file mode 100644 index 00000000..311d9149 --- /dev/null +++ b/include/liblvgl/widgets/lv_table.h @@ -0,0 +1,210 @@ +/** + * @file lv_table.h + * + */ + +#ifndef LV_TABLE_H +#define LV_TABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_TABLE != 0 + +/*Testing of dependencies*/ +#if LV_USE_LABEL == 0 +#error "lv_table: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ +#define LV_TABLE_CELL_NONE 0XFFFF +LV_EXPORT_CONST_INT(LV_TABLE_CELL_NONE); + +/********************** + * TYPEDEFS + **********************/ + +enum { + LV_TABLE_CELL_CTRL_MERGE_RIGHT = 1 << 0, + LV_TABLE_CELL_CTRL_TEXT_CROP = 1 << 1, + LV_TABLE_CELL_CTRL_CUSTOM_1 = 1 << 4, + LV_TABLE_CELL_CTRL_CUSTOM_2 = 1 << 5, + LV_TABLE_CELL_CTRL_CUSTOM_3 = 1 << 6, + LV_TABLE_CELL_CTRL_CUSTOM_4 = 1 << 7, +}; + +typedef uint8_t lv_table_cell_ctrl_t; + +/*Data of table*/ +typedef struct { + lv_obj_t obj; + uint16_t col_cnt; + uint16_t row_cnt; + char ** cell_data; + lv_coord_t * row_h; + lv_coord_t * col_w; + uint16_t col_act; + uint16_t row_act; +} lv_table_t; + +extern const lv_obj_class_t lv_table_class; + +/** + * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_table_class` + * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END` + */ +typedef enum { + LV_TABLE_DRAW_PART_CELL, /**< A cell*/ +} lv_table_draw_part_type_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a table object + * @param parent pointer to an object, it will be the parent of the new table + * @return pointer to the created table + */ +lv_obj_t * lv_table_create(lv_obj_t * parent); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the value of a cell. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param txt text to display in the cell. It will be copied and saved so this variable is not required after this function call. + * @note New roes/columns are added automatically if required + */ +void lv_table_set_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col, const char * txt); + +/** + * Set the value of a cell. Memory will be allocated to store the text by the table. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param fmt `printf`-like format + * @note New roes/columns are added automatically if required + */ +void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, const char * fmt, ...); + +/** + * Set the number of rows + * @param obj table pointer to a Table object + * @param row_cnt number of rows + */ +void lv_table_set_row_cnt(lv_obj_t * obj, uint16_t row_cnt); + +/** + * Set the number of columns + * @param obj table pointer to a Table object + * @param col_cnt number of columns. + */ +void lv_table_set_col_cnt(lv_obj_t * obj, uint16_t col_cnt); + +/** + * Set the width of a column + * @param obj table pointer to a Table object + * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] + * @param w width of the column + */ +void lv_table_set_col_width(lv_obj_t * obj, uint16_t col_id, lv_coord_t w); + +/** + * Add control bits to the cell. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param ctrl OR-ed values from ::lv_table_cell_ctrl_t + */ +void lv_table_add_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl); + + +/** + * Clear control bits of the cell. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param ctrl OR-ed values from ::lv_table_cell_ctrl_t + */ +void lv_table_clear_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a cell. + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @return text in the cell + */ +const char * lv_table_get_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col); + +/** + * Get the number of rows. + * @param obj table pointer to a Table object + * @return number of rows. + */ +uint16_t lv_table_get_row_cnt(lv_obj_t * obj); + +/** + * Get the number of columns. + * @param obj table pointer to a Table object + * @return number of columns. + */ +uint16_t lv_table_get_col_cnt(lv_obj_t * obj); + +/** + * Get the width of a column + * @param obj table pointer to a Table object + * @param col id of the column [0 .. LV_TABLE_COL_MAX -1] + * @return width of the column + */ +lv_coord_t lv_table_get_col_width(lv_obj_t * obj, uint16_t col); + +/** + * Get whether a cell has the control bits + * @param obj pointer to a Table object + * @param row id of the row [0 .. row_cnt -1] + * @param col id of the column [0 .. col_cnt -1] + * @param ctrl OR-ed values from ::lv_table_cell_ctrl_t + * @return true: all control bits are set; false: not all control bits are set + */ +bool lv_table_has_cell_ctrl(lv_obj_t * obj, uint16_t row, uint16_t col, lv_table_cell_ctrl_t ctrl); + +/** + * Get the selected cell (pressed and or focused) + * @param obj pointer to a table object + * @param row pointer to variable to store the selected row (LV_TABLE_CELL_NONE: if no cell selected) + * @param col pointer to variable to store the selected column (LV_TABLE_CELL_NONE: if no cell selected) + */ +void lv_table_get_selected_cell(lv_obj_t * obj, uint16_t * row, uint16_t * col); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TABLE*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TABLE_H*/ diff --git a/include/liblvgl/widgets/lv_textarea.h b/include/liblvgl/widgets/lv_textarea.h new file mode 100644 index 00000000..cfa47e47 --- /dev/null +++ b/include/liblvgl/widgets/lv_textarea.h @@ -0,0 +1,358 @@ +/** + * @file lv_textarea.h + * + */ + +#ifndef LV_TEXTAREA_H +#define LV_TEXTAREA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "liblvgl/lv_conf_internal.h" + +#if LV_USE_TEXTAREA != 0 + +/*Testing of dependencies*/ +#if LV_USE_LABEL == 0 +#error "lv_ta: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)" +#endif + +#include "liblvgl/core/lv_obj.h" +#include "lv_label.h" + +/********************* + * DEFINES + *********************/ +#define LV_TEXTAREA_CURSOR_LAST (0x7FFF) /*Put the cursor after the last character*/ + +LV_EXPORT_CONST_INT(LV_TEXTAREA_CURSOR_LAST); + +/********************** + * TYPEDEFS + **********************/ + +/*Data of text area*/ +typedef struct { + lv_obj_t obj; + lv_obj_t * label; /*Label of the text area*/ + char * placeholder_txt; /*Place holder label. only visible if text is an empty string*/ + char * pwd_tmp; /*Used to store the original text in password mode*/ + char * pwd_bullet; /*Replacement characters displayed in password mode*/ + const char * accepted_chars; /*Only these characters will be accepted. NULL: accept all*/ + uint32_t max_length; /*The max. number of characters. 0: no limit*/ + uint16_t pwd_show_time; /*Time to show characters in password mode before change them to '*'*/ + struct { + lv_coord_t valid_x; /*Used when stepping up/down to a shorter line. + *(Used by the library)*/ + uint32_t pos; /*The current cursor position + *(0: before 1st letter; 1: before 2nd letter ...)*/ + lv_area_t area; /*Cursor area relative to the Text Area*/ + uint32_t txt_byte_pos; /*Byte index of the letter after (on) the cursor*/ + uint8_t show : 1; /*Cursor is visible now or not (Handled by the library)*/ + uint8_t click_pos : 1; /*1: Enable positioning the cursor by clicking the text area*/ + } cursor; +#if LV_LABEL_TEXT_SELECTION + uint32_t sel_start; /*Temporary values for text selection*/ + uint32_t sel_end; + uint8_t text_sel_in_prog : 1; /*User is in process of selecting*/ + uint8_t text_sel_en : 1; /*Text can be selected on this text area*/ +#endif + uint8_t pwd_mode : 1; /*Replace characters with '*'*/ + uint8_t one_line : 1; /*One line mode (ignore line breaks)*/ +} lv_textarea_t; + +extern const lv_obj_class_t lv_textarea_class; + +enum { + LV_PART_TEXTAREA_PLACEHOLDER = LV_PART_CUSTOM_FIRST, +}; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a text area object + * @param parent pointer to an object, it will be the parent of the new text area + * @return pointer to the created text area + */ +lv_obj_t * lv_textarea_create(lv_obj_t * parent); + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Insert a character to the current cursor position. + * To add a wide char, e.g. 'Á' use `_lv_txt_encoded_conv_wc('Á')` + * @param obj pointer to a text area object + * @param c a character (e.g. 'a') + */ +void lv_textarea_add_char(lv_obj_t * obj, uint32_t c); + +/** + * Insert a text to the current cursor position + * @param obj pointer to a text area object + * @param txt a '\0' terminated string to insert + */ +void lv_textarea_add_text(lv_obj_t * obj, const char * txt); + +/** + * Delete a the left character from the current cursor position + * @param obj pointer to a text area object + */ +void lv_textarea_del_char(lv_obj_t * obj); + +/** + * Delete the right character from the current cursor position + * @param obj pointer to a text area object + */ +void lv_textarea_del_char_forward(lv_obj_t * obj); + +/*===================== + * Setter functions + *====================*/ + +/** + * Set the text of a text area + * @param obj pointer to a text area object + * @param txt pointer to the text + */ +void lv_textarea_set_text(lv_obj_t * obj, const char * txt); + +/** + * Set the placeholder text of a text area + * @param obj pointer to a text area object + * @param txt pointer to the text + */ +void lv_textarea_set_placeholder_text(lv_obj_t * obj, const char * txt); + +/** + * Set the cursor position + * @param obj pointer to a text area object + * @param pos the new cursor position in character index + * < 0 : index from the end of the text + * LV_TEXTAREA_CURSOR_LAST: go after the last character + */ +void lv_textarea_set_cursor_pos(lv_obj_t * obj, int32_t pos); + +/** + * Enable/Disable the positioning of the cursor by clicking the text on the text area. + * @param obj pointer to a text area object + * @param en true: enable click positions; false: disable + */ +void lv_textarea_set_cursor_click_pos(lv_obj_t * obj, bool en); + +/** + * Enable/Disable password mode + * @param obj pointer to a text area object + * @param en true: enable, false: disable + */ +void lv_textarea_set_password_mode(lv_obj_t * obj, bool en); + +/** + * Set the replacement characters to show in password mode + * @param obj pointer to a text area object + * @param bullet pointer to the replacement text + */ +void lv_textarea_set_password_bullet(lv_obj_t * obj, const char * bullet); + +/** + * Configure the text area to one line or back to normal + * @param obj pointer to a text area object + * @param en true: one line, false: normal + */ +void lv_textarea_set_one_line(lv_obj_t * obj, bool en); + +/** + * Set a list of characters. Only these characters will be accepted by the text area + * @param obj pointer to a text area object + * @param list list of characters. Only the pointer is saved. E.g. "+-.,0123456789" + */ +void lv_textarea_set_accepted_chars(lv_obj_t * obj, const char * list); + +/** + * Set max length of a Text Area. + * @param obj pointer to a text area object + * @param num the maximal number of characters can be added (`lv_textarea_set_text` ignores it) + */ +void lv_textarea_set_max_length(lv_obj_t * obj, uint32_t num); + +/** + * In `LV_EVENT_INSERT` the text which planned to be inserted can be replaced by an other text. + * It can be used to add automatic formatting to the text area. + * @param obj pointer to a text area object + * @param txt pointer to a new string to insert. If `""` no text will be added. + * The variable must be live after the `event_cb` exists. (Should be `global` or `static`) + */ +void lv_textarea_set_insert_replace(lv_obj_t * obj, const char * txt); + +/** + * Enable/disable selection mode. + * @param obj pointer to a text area object + * @param en true or false to enable/disable selection mode + */ +void lv_textarea_set_text_selection(lv_obj_t * obj, bool en); + +/** + * Set how long show the password before changing it to '*' + * @param obj pointer to a text area object + * @param time show time in milliseconds. 0: hide immediately. + */ +void lv_textarea_set_password_show_time(lv_obj_t * obj, uint16_t time); + +/** + * Deprecated: use the normal text_align style property instead + * Set the label's alignment. + * It sets where the label is aligned (in one line mode it can be smaller than the text area) + * and how the lines of the area align in case of multiline text area + * @param obj pointer to a text area object + * @param align the align mode from ::lv_text_align_t + */ +void lv_textarea_set_align(lv_obj_t * obj, lv_text_align_t align); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the text of a text area. In password mode it gives the real text (not '*'s). + * @param obj pointer to a text area object + * @return pointer to the text + */ +const char * lv_textarea_get_text(const lv_obj_t * obj); + +/** + * Get the placeholder text of a text area + * @param obj pointer to a text area object + * @return pointer to the text + */ +const char * lv_textarea_get_placeholder_text(lv_obj_t * obj); + +/** + * Get the label of a text area + * @param obj pointer to a text area object + * @return pointer to the label object + */ +lv_obj_t * lv_textarea_get_label(const lv_obj_t * obj); + +/** + * Get the current cursor position in character index + * @param obj pointer to a text area object + * @return the cursor position + */ +uint32_t lv_textarea_get_cursor_pos(const lv_obj_t * obj); + +/** + * Get whether the cursor click positioning is enabled or not. + * @param obj pointer to a text area object + * @return true: enable click positions; false: disable + */ +bool lv_textarea_get_cursor_click_pos(lv_obj_t * obj); + +/** + * Get the password mode attribute + * @param obj pointer to a text area object + * @return true: password mode is enabled, false: disabled + */ +bool lv_textarea_get_password_mode(const lv_obj_t * obj); + +/** + * Get the replacement characters to show in password mode + * @param obj pointer to a text area object + * @return pointer to the replacement text + */ +const char * lv_textarea_get_password_bullet(lv_obj_t * obj); + +/** + * Get the one line configuration attribute + * @param obj pointer to a text area object + * @return true: one line configuration is enabled, false: disabled + */ +bool lv_textarea_get_one_line(const lv_obj_t * obj); + +/** + * Get a list of accepted characters. + * @param obj pointer to a text area object + * @return list of accented characters. + */ +const char * lv_textarea_get_accepted_chars(lv_obj_t * obj); + +/** + * Get max length of a Text Area. + * @param obj pointer to a text area object + * @return the maximal number of characters to be add + */ +uint32_t lv_textarea_get_max_length(lv_obj_t * obj); + +/** + * Find whether text is selected or not. + * @param obj pointer to a text area object + * @return whether text is selected or not + */ +bool lv_textarea_text_is_selected(const lv_obj_t * obj); + +/** + * Find whether selection mode is enabled. + * @param obj pointer to a text area object + * @return true: selection mode is enabled, false: disabled + */ +bool lv_textarea_get_text_selection(lv_obj_t * obj); + +/** + * Set how long show the password before changing it to '*' + * @param obj pointer to a text area object + * @return show time in milliseconds. 0: hide immediately. + */ +uint16_t lv_textarea_get_password_show_time(lv_obj_t * obj); + +/*===================== + * Other functions + *====================*/ + +/** + * Clear the selection on the text area. + * @param obj pointer to a text area object + */ +void lv_textarea_clear_selection(lv_obj_t * obj); + +/** + * Move the cursor one character right + * @param obj pointer to a text area object + */ +void lv_textarea_cursor_right(lv_obj_t * obj); + +/** + * Move the cursor one character left + * @param obj pointer to a text area object + */ +void lv_textarea_cursor_left(lv_obj_t * obj); + +/** + * Move the cursor one line down + * @param obj pointer to a text area object + */ +void lv_textarea_cursor_down(lv_obj_t * obj); + +/** + * Move the cursor one line up + * @param obj pointer to a text area object + */ +void lv_textarea_cursor_up(lv_obj_t * obj); + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_TEXTAREA_H*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_TEXTAREA_H*/ diff --git a/include/main.h b/include/main.h index a57785d1..987e2f24 100644 --- a/include/main.h +++ b/include/main.h @@ -45,6 +45,8 @@ // More includes here... #include "autons.hpp" +#include "subsystems.hpp" + /** * If you find doing pros::Motor() to be tedious and you'd prefer just to do diff --git a/include/okapi/api/coreProsAPI.hpp b/include/okapi/api/coreProsAPI.hpp index ab1aa694..a5653366 100644 --- a/include/okapi/api/coreProsAPI.hpp +++ b/include/okapi/api/coreProsAPI.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef THREADS_STD #include diff --git a/include/okapi/impl/device/motor/motor.hpp b/include/okapi/impl/device/motor/motor.hpp index 78c5b3b0..dd9cf0a5 100644 --- a/include/okapi/impl/device/motor/motor.hpp +++ b/include/okapi/impl/device/motor/motor.hpp @@ -358,73 +358,6 @@ class Motor : public AbstractMotor { */ std::int32_t setVoltageLimit(std::int32_t ilimit) override; - /** - * Sets new PID constants. - * - * @param ikF the feed-forward constant - * @param ikP the proportional constant - * @param ikI the integral constant - * @param ikD the derivative constant - * @return 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. - */ - virtual std::int32_t setPosPID(double ikF, double ikP, double ikI, double ikD); - - /** - * Sets new PID constants. - * - * @param ikF the feed-forward constant - * @param ikP the proportional constant - * @param ikI the integral constant - * @param ikD the derivative constant - * @param ifilter a constant used for filtering the profile acceleration - * @param ilimit the integral limit - * @param ithreshold the threshold for determining if a position movement has reached its goal - * @param iloopSpeed the rate at which the PID computation is run (in ms) - * @return 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. - */ - virtual std::int32_t setPosPIDFull(double ikF, - double ikP, - double ikI, - double ikD, - double ifilter, - double ilimit, - double ithreshold, - double iloopSpeed); - - /** - * Sets new PID constants. - * - * @param ikF the feed-forward constant - * @param ikP the proportional constant - * @param ikI the integral constant - * @param ikD the derivative constant - * @return `1` if the operation was successful or `PROS_ERR` if the operation failed, setting - * errno. - */ - virtual std::int32_t setVelPID(double ikF, double ikP, double ikI, double ikD); - - /** - * Sets new PID constants. - * - * @param ikF the feed-forward constant - * @param ikP the proportional constant - * @param ikI the integral constant - * @param ikD the derivative constant - * @param ifilter a constant used for filtering the profile acceleration - * @param ilimit the integral limit - * @param ithreshold the threshold for determining if a position movement has reached its goal - * @param iloopSpeed the rate at which the PID computation is run (in ms) - * @return 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. - */ - virtual std::int32_t setVelPIDFull(double ikF, - double ikP, - double ikI, - double ikD, - double ifilter, - double ilimit, - double ithreshold, - double iloopSpeed); - /** * Get the encoder associated with this motor. * diff --git a/include/pros/abstract_motor.hpp b/include/pros/abstract_motor.hpp new file mode 100644 index 00000000..d2a3e31f --- /dev/null +++ b/include/pros/abstract_motor.hpp @@ -0,0 +1,1144 @@ +/** + * \file abstract_motor.hpp + * \ingroup cpp-abstract-motor + * + * Contains prototypes for AbstractMotor, the abstract base class of both + * motors and motor groups. Abstract motors cannot be directly constructed, but + * you can use motors and motor groups as abstract motors. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * All rights reserved. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _PROS_ABSTRACT_MOTORS_HPP_ +#define _PROS_ABSTRACT_MOTORS_HPP_ + +#include +#include + +#include "pros/device.hpp" +#include "pros/motors.h" +#include "rtos.hpp" + +namespace pros { +inline namespace v5 { + +/** + * \enum MotorBrake + * Indicates the current 'brake mode' of a motor. + */ +enum class MotorBrake { + coast = 0, ///< Motor coasts when stopped, traditional behavior + brake = 1, ///< Motor brakes when stopped + hold = 2, ///< Motor actively holds position when stopped + invalid = INT32_MAX ///< Invalid brake mode +}; + +/** + * \enum MotorEncoderUnits + * Indicates the units used by the motor encoders. + */ +enum class MotorEncoderUnits { + degrees = 0, ///< Position is recorded as angle in degrees as a floating point number + deg = 0, ///< Position is recorded as angle in degrees as a floating point number + rotations = 1, ///< Position is recorded as angle in rotations as a floating point number + counts = 2, ///< Position is recorded as raw encoder ticks as a whole number + invalid = INT32_MAX ///< Invalid motor encoder units +}; + +// Alias for MotorEncoderUnits +using MotorUnits = MotorEncoderUnits; + +enum class MotorGears { + ratio_36_to_1 = 0, ///< 36:1, 100 RPM, Red gear set + red = ratio_36_to_1, ///< 36:1, 100 RPM, Red gear set + rpm_100 = ratio_36_to_1, ///< 36:1, 100 RPM, Red gear set + ratio_18_to_1 = 1, ///< 18:1, 200 RPM, Green gear set + green = ratio_18_to_1, ///< 18:1, 200 RPM, Green gear set + rpm_200 = ratio_18_to_1, ///< 18:1, 200 RPM, Green gear set + ratio_6_to_1 = 2, ///< 6:1, 600 RPM, Blue gear set + blue = ratio_6_to_1, ///< 6:1, 600 RPM, Blue gear set + rpm_600 = ratio_6_to_1, ///< 6:1, 600 RPM, Blue gear set + invalid = INT32_MAX ///< Error return code +}; + + +// Provide Aliases for MotorGears +using MotorGearset = MotorGears; +using MotorCart = MotorGears; +using MotorCartridge = MotorGears; +using MotorGear = MotorGears; + +/** + * \ingroup cpp-abstract-motor + */ +class AbstractMotor { + /** + * \addtogroup cpp-abstract-motor + * @{ + */ + public: + /// \name Motor movement functions + /// These functions allow programmers to make motors move + ///@{ + + /** + * Sets the voltage for the motor from -127 to 127. + * + * This is designed to map easily to the input from the controller's analog + * stick for simple opcontrol use. The actual behavior of the motor is + * analogous to use of motor_move(), or motorSet() from the PROS 2 API. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param voltage + * The new motor voltage from -127 to 127 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move(std::int32_t voltage) const = 0; + + /** + * Sets the target absolute position for the motor to move to. + * + * This movement is relative to the position of the motor when initialized or + * the position when it was most recently reset with + * pros::Motor::set_zero_position(). + * + * \note This function simply sets the target for the motor, it does not block + * program execution until the movement finishes. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param position + * The absolute position to move to in the motor's encoder units + * \param velocity + * The maximum allowable velocity for the movement in RPM + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move_absolute(const double position, const std::int32_t velocity) const = 0; + + /** + * Sets the relative target position for the motor to move to. + * + * This movement is relative to the current position of the motor as given in + * pros::Motor::motor_get_position(). Providing 10.0 as the position parameter + * would result in the motor moving clockwise 10 units, no matter what the + * current position is. + * + * \note This function simply sets the target for the motor, it does not block + * program execution until the movement finishes. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param position + * The relative position to move to in the motor's encoder units + * \param velocity + * The maximum allowable velocity for the movement in RPM + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move_relative(const double position, const std::int32_t velocity) const = 0; + + /** + * Sets the velocity for the motor. + * + * This velocity corresponds to different actual speeds depending on the + * gearset used for the motor. This results in a range of +-100 for + * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for + * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent + * speed, as opposed to setting the motor's voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param velocity + * The new motor velocity from -+-100, +-200, or +-600 depending on the + * motor's gearset + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move_velocity(const std::int32_t velocity) const = 0; + + /** + * Sets the output voltage for the motor from -12000 to 12000 in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param port + * The V5 port number from 1-21 + * \param voltage + * The new voltage value from -12000 to 12000 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t move_voltage(const std::int32_t voltage) const = 0; + + /** + * Stops the motor using the currently configured brake mode. + * + * This function sets motor velocity to zero, which will cause it to act + * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, + * this function may behave differently than calling move_absolute(0) + * or motor_move_relative(0). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + */ + virtual std::int32_t brake(void) const = 0; + + /** + * Changes the output velocity for a profiled movement (motor_move_absolute or + * motor_move_relative). This will have no effect if the motor is not following + * a profiled movement. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param velocity + * The new motor velocity from +-100, +-200, or +-600 depending on the + * motor's gearset + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t modify_profiled_velocity(const std::int32_t velocity) const = 0; + + /** + * Gets the target position set for the motor by the user, with a parameter + * for the motor index. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The target position in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + */ + virtual double get_target_position(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the target position(s) set for the motor(s) by the user + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector containing the target position(s) in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + */ + virtual std::vector get_target_position_all(void) const = 0; + + /** + * Gets the velocity commanded to the motor by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The commanded motor velocity from +-100, +-200, or +-600, or + * PROS_ERR if the operation failed, setting errno. + */ + virtual std::int32_t get_target_velocity(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the velocity/velocities commanded to the motor(s) by the user + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the commanded motor velocity/velocities from +-100, + * +-200, or +-600, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::vector get_target_velocity_all(void) const = 0; + + ///@} + + /// \name Motor telemetry functions + /// \addtogroup cpp-motor-telemetry + /// These functions allow programmers to collect telemetry from motors + ///@{ + + /** + * Gets the actual velocity of the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual double get_actual_velocity(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the actual velocity/velocities of the motor(s) + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the motor's/motors' actual velocity/velocities in RPM or PROS_ERR_F + * if the operation failed, setting errno. + */ + virtual std::vector get_actual_velocity_all(void) const = 0; + + /** + * Gets the current drawn by the motor in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's current in mA or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::int32_t get_current_draw(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the current(s) drawn by the motor(s) in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector conatining the motor's/motors' current(s) in mA or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::vector get_current_draw_all(void) const = 0; + + /** + * Gets the direction of movement for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + */ + virtual std::int32_t get_direction(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the direction(s) of movement for the motor(s). + * + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector containing 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + */ + virtual std::vector get_direction_all(void) const = 0; + + /** + * Gets the efficiency of the motor in percent. + * + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's efficiency in percent or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual double get_efficiency(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the efficiency/efficiencies of the motor(s) in percent. + * + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector containing the motor's/motors' efficiency/efficiencies in percent or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual std::vector get_efficiency_all(void) const = 0; + + /** + * Gets the faults experienced by the motor. + * + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A bitfield containing the motor's faults. + */ + virtual std::uint32_t get_faults(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the faults experienced by the motor(s). + * + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \return A bitfield containing the motor's/motors' faults. + */ + virtual std::vector get_faults_all(void) const = 0; + /** + * Gets the flags set by the motor's operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A bitfield containing the motor's flags. + */ + virtual std::uint32_t get_flags(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the flags set by the motor's/motors' operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A bitfield containing the motor's/motors' flags. + */ + virtual std::vector get_flags_all(void) const = 0; + + /** + * Gets the absolute position of the motor in its encoder units. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + */ + virtual double get_position(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the absolute position(s) of the motor(s) in its encoder units. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + + * + * \return A vector containing the motor's/motors' absolute position(s) in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + */ + virtual std::vector get_position_all(void) const = 0; + + /** + * Gets the power drawn by the motor in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual double get_power(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector containing the power(s) drawn by the motor(s) in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the motor's/motors' power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual std::vector get_power_all(void) const = 0; + + /** + * Gets the raw encoder count of the motor at a given timestamp. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param[in] timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The raw encoder count at the given timestamp or PROS_ERR if the + * operation failed. + */ + virtual std::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the raw encoder count(s) of the motor(s) at a given timestamp. + * + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \param timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \return A vector containing the raw encoder count(s) at the given timestamp or PROS_ERR if the + * operation failed. + */ + virtual std::vector get_raw_position_all(std::uint32_t* const timestamp) const = 0; + + /** + * Gets the temperature of the motor in degrees Celsius. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + */ + virtual double get_temperature(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the temperature(s) of the motor(s) in degrees Celsius. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' temperature(s) in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + */ + virtual std::vector get_temperature_all(void) const = 0; + /** + * Gets the torque generated by the motor in Newton Meters (Nm). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + */ + virtual double get_torque(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the torque(s) generated by the motor(s) in Newton Meters (Nm). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' torque(s) in Nm or PROS_ERR_F if the operation failed, + * setting errno. + */ + virtual std::vector get_torque_all(void) const = 0; + /** + * Gets the voltage delivered to the motor in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + */ + virtual std::int32_t get_voltage(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the voltage(s) delivered to the motor(s) in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' voltage(s) in mV or PROS_ERR_F if the operation failed, + * setting errno. + */ + virtual std::vector get_voltage_all(void) const = 0; + + /** + * Checks if the motor is drawing over its current limit. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::int32_t is_over_current(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of whether each motor is drawing over its current limit. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::vector is_over_current_all(void) const = 0; + + /** + * Gets the temperature limit flag for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::int32_t is_over_temp(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the temperature limit flag(s) for the motor(s). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::vector is_over_temp_all(void) const = 0; + + ///@} + + /// \name Motor configuration functions + /// \addtogroup cpp-motor-configuration + /// These functions allow programmers to configure the behavior of motors + ///@{ + + /** + * Gets the brake mode that was set for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return One of MotorBrake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + */ + virtual MotorBrake get_brake_mode(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the brake mode(s) that was set for the motor(s). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing MotorBrake(s), according to what was set for the + * motor(s), or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + */ + virtual std::vector get_brake_mode_all(void) const = 0; + + /** + * Gets the current limit for the motor in mA. + * + * The default value is 2500 mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::int32_t get_current_limit(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the current limit(s) for the motor(s) in mA. + * + * The default value is 2500 mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' current limit(s) in mA or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::vector get_current_limit_all(void) const = 0; + + /** + * Gets the encoder units that were set for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return One of MotorUnits according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + */ + virtual MotorUnits get_encoder_units(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the encoder units that were set for the motor(s). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector of MotorUnits according to what is set for the + * motor(s) or E_MOTOR_ENCODER_INVALID if the operation failed. + */ + virtual std::vector get_encoder_units_all(void) const = 0; + + /** + * Gets the gearset that was set for the motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return One of MotorGears according to what is set for the motor, + * or pros::MotorGears::invalid if the operation failed. + */ + virtual MotorGears get_gearing(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the gearset(s) that was/were set for the motor(s). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector of MotorGears according to what is set for the motor(s), + * or pros::MotorGears::invalid if the operation failed. + */ + virtual std::vector get_gearing_all(void) const = 0; + + /** + * @brief Gets returns a vector with all the port numbers in the motor group. + * + * @return std::vector + */ + virtual std::vector get_port_all(void) const = 0; + + /** + * Gets the voltage limit set by the user. + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return The motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::int32_t get_voltage_limit(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the voltage limit(s) set by the user. + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return A vector containing the motor's/motors' voltage limit(s) in V or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::vector get_voltage_limit_all(void) const = 0; + + /** + * Gets the operation direction of the motor as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::int32_t is_reversed(const std::uint8_t index = 0) const = 0; + + /** + * Gets a vector of the operation direction(s) of the motor(s) as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + */ + virtual std::vector is_reversed_all(void) const = 0; + + /** + * Sets one of MotorBrake to the motor. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_brake_mode_all(const MotorBrake mode) const = 0; + virtual std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const = 0; + /** + * Sets the current limit for the motor in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param limit + * The new current limit in mA + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_current_limit_all(const std::int32_t limit) const = 0; + /** + * Sets one of MotorUnits for the motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param units + * The new motor encoder units + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_encoder_units_all(const MotorUnits units) const = 0; + virtual std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const = 0; + /** + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param gearset + * The new motor gearset + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_gearing_all(const MotorGears gearset) const = 0; + virtual std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const = 0; + + /** + * Sets the reverse flag for the motor. + * + * This will invert its movements and the values returned for its position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param reverse + * True reverses the motor, false is default + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0) = 0; + virtual std::int32_t set_reversed_all(const bool reverse) = 0; + + /** + * Sets the voltage limit for the motor in Volts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param limit + * The new voltage limit in Volts + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_voltage_limit_all(const std::int32_t limit) const = 0; + + /** + * Sets the position for the motor in its encoder units. + * + * This will be the future reference point for the motor's "absolute" + * position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param position + * The new reference position in its encoder units + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const = 0; + virtual std::int32_t set_zero_position_all(const double position) const = 0; + + /** + * Sets the "absolute" zero position of the motor to its current position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param index Optional parameter. + * The index of the motor to get the target position of. + * By default index is 0, and will return an error for an out of bounds index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t tare_position(const std::uint8_t index = 0) const = 0; + virtual std::int32_t tare_position_all(void) const = 0; + virtual std::int8_t get_port(const std::uint8_t index = 0) const = 0; + /** + * @brief Returns the number of objects + * + * @return std::int8_t + */ + virtual std::int8_t size(void) const = 0; + + ///@} + private: +}; + +} // namespace v5 +} // namespace pros + +///@} + +#endif diff --git a/include/pros/adi.h b/include/pros/adi.h index 8f0f556f..f1bbe373 100644 --- a/include/pros/adi.h +++ b/include/pros/adi.h @@ -1,18 +1,21 @@ /** * \file pros/adi.h + * \ingroup c-adi * * Contains prototypes for interfacing with the ADI. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-adi ADI (TriPort) C API + * \note The external ADI API can be found [here.](@ref ext-adi) + * \note Additional example code for this module can be found in its [Tutorial.](@ref adi) */ #ifndef _PROS_ADI_H_ @@ -30,6 +33,16 @@ namespace pros { #endif /** + * \ingroup c-adi + */ + +/** + * \addtogroup c-adi + * @{ + */ + +/** + * \enum adi_port_config_e * Represents the port type for an ADI port. */ typedef enum adi_port_config_e { @@ -70,6 +83,7 @@ typedef enum adi_port_config_e { } adi_port_config_e_t; /** + * \enum adi_potentiometer_type_e_t * Represents the potentiometer version type. */ typedef enum adi_potentiometer_type_e { @@ -126,11 +140,16 @@ typedef enum adi_potentiometer_type_e { namespace c { #endif -/******************************************************************************/ -/** General ADI Use Functions **/ -/** **/ -/** These functions allow for interaction with any ADI port type **/ -/******************************************************************************/ +/** @} Add to group c-adi*/ + +/** + * \ingroup c-adi + */ + +/** + * \addtogroup c-adi + * @{ + */ /** * Gets the configuration for the given ADI port. @@ -144,6 +163,17 @@ namespace c { * the configuration * * \return The ADI configuration for the given port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * // Displays the value of E_ADI_ANALOG_IN + * printf("Port Type: %d\n", adi_port_get_config(ANALOG_SENSOR_PORT)); + * } + * \endcode */ adi_port_config_e_t adi_port_get_config(uint8_t port); @@ -159,6 +189,16 @@ adi_port_config_e_t adi_port_get_config(uint8_t port); * will be returned * * \return The value stored for the given port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * printf("Port Value: %d\n", adi_get_value(ANALOG_SENSOR_PORT)); + * } + * \endcode */ int32_t adi_port_get_value(uint8_t port); @@ -176,6 +216,15 @@ int32_t adi_port_get_value(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * } + * \endcode */ int32_t adi_port_set_config(uint8_t port, adi_port_config_e_t type); @@ -197,47 +246,19 @@ int32_t adi_port_set_config(uint8_t port, adi_port_config_e_t type); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void initialize() { + * adi_port_set_config(DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT); + * adi_set_value(DIGITAL_SENSOR_PORT, HIGH); + * } + * \endcode */ int32_t adi_port_set_value(uint8_t port, int32_t value); -/******************************************************************************/ -/** PROS 2 Compatibility Functions **/ -/** **/ -/** These functions provide similar functionality to the PROS 2 API **/ -/******************************************************************************/ - -/** - * Used for adi_digital_write() to specify a logic HIGH state to output. - * - * In reality, using any non-zero expression or "true" will work to set a pin to - * HIGH. - */ -#define HIGH 1 -/** - * Used for adi_digital_write() to specify a logic LOW state to output. - * - * In reality, using a zero expression or "false" will work to set a pin to LOW. - */ -#define LOW 0 - -/** - * adi_pin_mode() state for a digital input. - */ -#define INPUT 0x00 -/** - * adi_pin_mode() state for a digital output. - */ -#define OUTPUT 0x01 -/** - * adi_pin_mode() state for an analog input. - */ -#define INPUT_ANALOG 0x02 - -/** - * adi_pin_mode() state for an analog output. - */ -#define OUTPUT_ANALOG 0x03 - /** * Calibrates the analog sensor on the specified port and returns the new * calibration value. @@ -251,6 +272,9 @@ int32_t adi_port_set_value(uint8_t port, int32_t value); * * Do not use this function when the sensor value might be unstable * (gyro rotation, accelerometer movement). + * + * \note The ADI currently returns data at 10ms intervals, in constrast to the + * calibrate function’s 1ms sample rate. * * This function uses the following values of errno when an error state is * reached: @@ -260,6 +284,17 @@ int32_t adi_port_set_value(uint8_t port, int32_t value); * The ADI port to calibrate (from 1-8, 'a'-'h', 'A'-'H') * * \return The average sensor value computed by this function + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * adi_analog_calibrate(ANALOG_SENSOR_PORT); + * printf("Calibrated Reading: %d\n", adi_analog_read_calibrated(ANALOG_SENSOR_PORT)); + * // All readings from then on will be calibrated + * } + * \endcode */ int32_t adi_analog_calibrate(uint8_t port); @@ -280,6 +315,18 @@ int32_t adi_analog_calibrate(uint8_t port); * * \return The analog sensor value, where a value of 0 reflects an input voltage * of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Reading: %d\n", adi_analog_read(ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_analog_read(uint8_t port); @@ -302,6 +349,18 @@ int32_t adi_analog_read(uint8_t port); * * \return The difference of the sensor value from its calibrated default from * -4095 to 4095 + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Reading: %d\n", adi_analog_read_calibrated(ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_analog_read_calibrated(uint8_t port); @@ -329,6 +388,19 @@ int32_t adi_analog_read_calibrated(uint8_t port); * * \return The difference of the sensor value from its calibrated default from * -16384 to 16384 + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * adi_analog_calibrate(ANALOG_SENSOR_PORT); + * printf("Sensor Reading: %d\n", adi_analog_read_calibrated_HR(ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_analog_read_calibrated_HR(uint8_t port); @@ -349,6 +421,18 @@ int32_t adi_analog_read_calibrated_HR(uint8_t port); * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') * * \return True if the pin is HIGH, or false if it is LOW + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Value: %d\n", adi_digital_read(DIGITAL_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_digital_read(uint8_t port); @@ -373,6 +457,20 @@ int32_t adi_digital_read(uint8_t port); * * \return 1 if the button is pressed and had not been pressed * the last time this function was called, 0 otherwise. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * if (adi_digital_get_new_press(DIGITAL_SENSOR_PORT)) { + * // Toggle pneumatics or other state operations + * } + * delay(5); + * } + * } + * \endcode */ int32_t adi_digital_get_new_press(uint8_t port); @@ -394,6 +492,20 @@ int32_t adi_digital_get_new_press(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT + * + * void opcontrol() { + * bool state = LOW; + * while (true) { + * state != state; + * adi_digital_write(DIGITAL_SENSOR_PORT, state); + * delay(5); // toggle the sensor value every 50ms + * } + * } + * \endcode */ int32_t adi_digital_write(uint8_t port, bool value); @@ -411,6 +523,15 @@ int32_t adi_digital_write(uint8_t port, bool value); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * adi_pin_mode(ANALOG_SENSOR_PORT, INPUT_ANALOG); + * } + * \endcode */ int32_t adi_pin_mode(uint8_t port, uint8_t mode); @@ -430,6 +551,17 @@ int32_t adi_pin_mode(uint8_t port, uint8_t mode); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * adi_motor_set(MOTOR_PORT, 127); // Go full speed forward + * delay(1000); + * adi_motor_set(MOTOR_PORT, 0); // Stop the motor + * } + * \endcode */ int32_t adi_motor_set(uint8_t port, int8_t speed); @@ -445,6 +577,18 @@ int32_t adi_motor_set(uint8_t port, int8_t speed); * The ADI port to get (from 1-8, 'a'-'h', 'A'-'H') * * \return The last set speed of the motor on the given port + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * adi_motor_set(MOTOR_PORT, 127); // Go full speed forward + * printf("Commanded Motor Power: %d\n", adi_motor_get(MOTOR_PORT)); // Will display 127 + * delay(1000); + * adi_motor_set(MOTOR_PORT, 0); // Stop the motor + * } + * \endcode */ int32_t adi_motor_get(uint8_t port); @@ -461,14 +605,25 @@ int32_t adi_motor_get(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * adi_motor_set(MOTOR_PORT, 127); // Go full speed forward + * delay(1000); + * // adi_motor_set(MOTOR_PORT, 0); // Stop the motor + * adi_motor_stop(MOTOR_PORT); // use this instead + * } + * \endcode */ int32_t adi_motor_stop(uint8_t port); /** * Reference type for an initialized encoder. * - * This merely contains the port number for the encoder, unlike its use as an - * object to store encoder data in PROS 2. + * This merely contains the port number for the encoder. */ typedef int32_t adi_encoder_t; @@ -481,13 +636,26 @@ typedef int32_t adi_encoder_t; * reached: * ENXIO - The given value is not within the range of ADI Ports * EADDRINUSE - The port is not configured as an encoder - * * \param enc * The adi_encoder_t object from adi_encoder_init() to read * * \return The signed and cumulative number of counts since the last start or * reset + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * printf("Encoder Value: %d\n", adi_encoder_get(enc)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_encoder_get(adi_encoder_t enc); @@ -510,6 +678,20 @@ int32_t adi_encoder_get(adi_encoder_t enc); * * \return An adi_encoder_t object to be stored and used for later calls to * encoder functions + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * printf("Encoder Value: %d\n", adi_encoder_get(enc)); + * delay(5); + * } + * } + * \endcode */ adi_encoder_t adi_encoder_init(uint8_t port_top, uint8_t port_bottom, bool reverse); @@ -530,6 +712,18 @@ adi_encoder_t adi_encoder_init(uint8_t port_top, uint8_t port_bottom, bool rever * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false); + * delay(1000); // Move the encoder around in this time + * adi_encoder_reset(enc); // The encoder is now zero again + * } + * \endcode */ int32_t adi_encoder_reset(adi_encoder_t enc); @@ -546,14 +740,25 @@ int32_t adi_encoder_reset(adi_encoder_t enc); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * adi_encoder_t enc = adi_encoder_init(PORT_TOP, PORT_BOTTOM, false); + * // Use the encoder + * adi_encoder_shutdown(enc); + * } + * \endcode */ int32_t adi_encoder_shutdown(adi_encoder_t enc); /** * Reference type for an initialized ultrasonic. * - * This merely contains the port number for the ultrasonic, unlike its use as an - * object to store ultrasonic data in PROS 2. + * This merely contains the port number for the ultrasonic. */ typedef int32_t adi_ultrasonic_t; @@ -574,6 +779,21 @@ typedef int32_t adi_ultrasonic_t; * * \return The distance to the nearest object in m^-4 (10000 indicates 1 meter), * measured from the sensor's mounting points. + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", adi_ultrasonic_get(ult)); + * delay(5); + * } + * } + * \endcode */ int32_t adi_ultrasonic_get(adi_ultrasonic_t ult); @@ -594,6 +814,21 @@ int32_t adi_ultrasonic_get(adi_ultrasonic_t ult); * * \return An adi_ultrasonic_t object to be stored and used for later calls to * ultrasonic functions + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", adi_ultrasonic_get(ult)); + * delay(5); + * } + * } + * \endcode */ adi_ultrasonic_t adi_ultrasonic_init(uint8_t port_ping, uint8_t port_echo); @@ -610,14 +845,29 @@ adi_ultrasonic_t adi_ultrasonic_init(uint8_t port_ping, uint8_t port_echo); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * adi_ultrasonic_t ult = adi_ultrasonic_init(PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", adi_ultrasonic_get(ult)); + * delay(5); + * } + * adi_ultrasonic_shutdown(ult); + * } + * \endcode */ int32_t adi_ultrasonic_shutdown(adi_ultrasonic_t ult); /** * Reference type for an initialized gyroscope. * - * This merely contains the port number for the gyroscope, unlike its use as an - * object to store gyro data in PROS 2. + * This merely contains the port number for the gyroscope. */ typedef int32_t adi_gyro_t; @@ -638,6 +888,21 @@ typedef int32_t adi_gyro_t; * The adi_gyro_t object for which the angle will be returned * * \return The gyro angle in degrees. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * + * void opcontrol() { + * adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", adi_gyro_get(gyro)); + * delay(5); + * } + * } + * \endcode */ double adi_gyro_get(adi_gyro_t gyro); @@ -662,6 +927,21 @@ double adi_gyro_get(adi_gyro_t gyro); * * \return An adi_gyro_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * + * void opcontrol() { + * adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", adi_gyro_get(gyro)); + * delay(5); + * } + * } + * \endcode */ adi_gyro_t adi_gyro_init(uint8_t port, double multiplier); @@ -678,6 +958,29 @@ adi_gyro_t adi_gyro_init(uint8_t port, double multiplier); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * + * void opcontrol() { + * adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER); + * uint32_t now = millis(); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", adi_gyro_get(gyro)); + * + * if (millis() - now > 2000) { + * // Reset the gyro every 2 seconds + * adi_gyro_reset(gyro); + * now = millis(); + * } + * + * delay(5); + * } + * } + * \endcode */ int32_t adi_gyro_reset(adi_gyro_t gyro); @@ -694,14 +997,36 @@ int32_t adi_gyro_reset(adi_gyro_t gyro); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * + * void opcontrol() { + * adi_gyro_t gyro = adi_gyro_init(GYRO_PORT, GYRO_MULTIPLIER); + * uint32_t now = millis(); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", adi_gyro_get(gyro)); + * + * if (millis() - now > 2000) { + * adi_gyro_shutdown(gyro); + * // Shut down the gyro after two seconds + * break; + * } + * + * delay(5); + * } + * } + * \endcode */ int32_t adi_gyro_shutdown(adi_gyro_t gyro); /** * Reference type for an initialized potentiometer. * - * This merely contains the port number for the potentiometer, unlike its use as an - * object to store potentiometer data in PROS 2. + * This merely contains the port number for the potentiometer. */ typedef int32_t adi_potentiometer_t; @@ -718,6 +1043,20 @@ typedef int32_t adi_potentiometer_t; * * \return An adi_potentiometer_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * + * void opcontrol() { + * adi_potentiometer_t potentiometer = adi_potentiometer_init(POTENTIOMETER_PORT); + * while (true) { + * // Print the potentiometer's angle + * printf("Angle: %lf\n", adi_potentiometer_get_angle(potentiometer)); + * delay(5); + * } + * } + * \endcode */ adi_potentiometer_t adi_potentiometer_init(uint8_t port); @@ -736,6 +1075,21 @@ adi_potentiometer_t adi_potentiometer_init(uint8_t port); * * \return An adi_potentiometer_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * #define POTENTIOMETER_TYPE E_ADI_POT_EDR + * + * void opcontrol() { + * adi_potentiometer_t potentiometer = adi_potentiometer_type_init(POTENTIOMETER_PORT, POTENTIOMETER_TYPE); + * while (true) { + * // Print the potentiometer's angle + * printf("Angle: %lf\n", adi_potentiometer_get_angle(potentiometer)); + * delay(5); + * } + * } + * \endcode */ adi_potentiometer_t adi_potentiometer_type_init(uint8_t port, adi_potentiometer_type_e_t potentiometer_type); @@ -754,6 +1108,20 @@ adi_potentiometer_t adi_potentiometer_type_init(uint8_t port, adi_potentiometer_ * The adi_potentiometer_t object for which the angle will be returned * * \return The potentiometer angle in degrees. + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * + * void opcontrol() { + * adi_potentiometer_t potentiometer = adi_potentiometer_t(POTENTIOMETER_PORT); + * while (true) { + * // Print the potnetiometer's angle + * printf("Angle: %lf\n", adi_potentiometer_get_angle(potentiometer)); + * delay(5); + * } + * } + * \endcode */ double adi_potentiometer_get_angle(adi_potentiometer_t potentiometer); @@ -761,7 +1129,7 @@ double adi_potentiometer_get_angle(adi_potentiometer_t potentiometer); * Reference type for an initialized addressable led. * * This merely contains the port number for the led, unlike its use as an - * object to store led data in PROS 2. + * object to store led data in the C++ API. */ typedef int32_t adi_led_t; @@ -779,6 +1147,21 @@ typedef int32_t adi_led_t; * * \return An adi_led_t object containing the given port, or PROS_ERR if the * initialization failed, setting errno + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the led to the colors in the buffer + * adi_led_set(led, buffer, 10); + * delay(5); + * } + * } + * \endcode */ adi_led_t adi_led_init(uint8_t port); @@ -795,6 +1178,25 @@ adi_led_t adi_led_init(uint8_t port); * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw * @param buffer_length length of buffer to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the led to the colors in the buffer + * adi_led_set(led, buffer, 10); + * delay(5); + * + * // Clear the led strip + * adi_led_clear(led); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_clear_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length); @@ -811,6 +1213,21 @@ int32_t adi_led_clear_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_lengt * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw * @param buffer_length length of buffer to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the led strip to the colors in the buffer + * adi_led_set(led, buffer, 10); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_set(adi_led_t led, uint32_t* buffer, uint32_t buffer_length); @@ -828,6 +1245,21 @@ int32_t adi_led_set(adi_led_t led, uint32_t* buffer, uint32_t buffer_length); * @param buffer_length length of buffer to clear * @param color color to set all the led strip value to * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the led strip to red + * adi_led_set_all(led, buffer, 10, 0xFF0000); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_set_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color); @@ -846,6 +1278,21 @@ int32_t adi_led_set_all(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, * @param color color to clear all the led strip to * @param pixel_position position of the pixel to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the first pixel to red + * adi_led_set_pixel(led, buffer, 10, 0xFF0000, 0); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_set_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, uint32_t pixel_position); @@ -863,9 +1310,70 @@ int32_t adi_led_set_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_lengt * @param buffer_length length of the input buffer * @param pixel_position position of the pixel to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example + * \code + * #define LED_PORT 1 + * + * void opcontrol() { + * adi_led_t led = adi_led_init(LED_PORT); + * uint32_t buffer[10] = {0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF, 0x000000, 0x000000, 0x000000}; + * while (true) { + * // Set the first pixel to red + * adi_led_set_pixel(led, buffer, 10, 0xFF0000, 0); + * delay(5); + * + * // Clear the first pixel + * adi_led_clear_pixel(led, buffer, 10, 0); + * delay(5); + * } + * } + * \endcode */ int32_t adi_led_clear_pixel(adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t pixel_position); +/** + * \name Ease of use macro definitions + * These functions provide ease of use definitions for the ADI functions. + * @{ + */ + +/** + * Used for adi_digital_write() to specify a logic HIGH state to output. + * + * In reality, using any non-zero expression or "true" will work to set a pin to + * HIGH. + */ +#define HIGH 1 +/** + * Used for adi_digital_write() to specify a logic LOW state to output. + * + * In reality, using a zero expression or "false" will work to set a pin to LOW. + */ +#define LOW 0 + +/** + * adi_pin_mode() state for a digital input. + */ +#define INPUT 0x00 +/** + * adi_pin_mode() state for a digital output. + */ +#define OUTPUT 0x01 +/** + * adi_pin_mode() state for an analog input. + */ +#define INPUT_ANALOG 0x02 + +/** + * adi_pin_mode() state for an analog output. + */ +#define OUTPUT_ANALOG 0x03 + +/** @} Name: Ease of use macro definitions*/ + +/** @} Add to group: c-adi*/ + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/include/pros/adi.hpp b/include/pros/adi.hpp index c2fd258d..75429c98 100644 --- a/include/pros/adi.hpp +++ b/include/pros/adi.hpp @@ -1,39 +1,55 @@ /** * \file pros/adi.hpp + * \ingroup cpp-adi * * Contains prototypes for interfacing with the ADI. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-adi ADI (TriPort) C++ API + * \note The external ADI API can be found [here.](@ref ext-adi) + * \note Additional example code for this module can be found in its [Tutorial.](@ref adi) */ #ifndef _PROS_ADI_HPP_ #define _PROS_ADI_HPP_ #include +#include #include #include -#include +#include #include "pros/adi.h" -namespace pros { +#define LEGACY_TYPEDEF(old_name, new_name) \ + using old_name [[deprecated("use " #new_name " instead")]] = new_name +namespace pros { +namespace adi { + /** type definition for the pair of smart port and adi port for the basic adi devices */ using ext_adi_port_pair_t = std::pair; /** type definition for the triplet of smart port and two adi ports for the two wire adi devices*/ using ext_adi_port_tuple_t = std::tuple; + +/** + * \ingroup cpp-adi + */ +class Port { + /** + * \addtogroup cpp-adi + * @{ + */ -class ADIPort { public: /** * Configures an ADI port to act as a given sensor type. @@ -47,8 +63,23 @@ class ADIPort { * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param type * The configuration type for the port + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * #define POTENTIOMETER_TYPE pros::E_ADI_POT_EDR + * + * void opcontrol() { + * pros::ADIPotentiometer potentiometer (POTENTIOMETER_PORT, POTENTIOMETER_TYPE); + * while (true) { + * // Get the potentiometer angle + * std::cout << "Angle: " << potnetiometer.get_angle(); + * pros::delay(10); + * } + * } + * \endcode */ - explicit ADIPort(std::uint8_t adi_port, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED); + explicit Port(std::uint8_t adi_port, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED); /** * Configures an ADI port on an adi expander to act as a given sensor type. @@ -63,13 +94,35 @@ class ADIPort { * (from 1-8, 'a'-'h', 'A'-'H') to configure * \param type * The configuration type for the port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 'a' + * #define EXT_ADI_SMART_PORT 1 + * + * void initialize() { + * pros::adi::Port sensor ({{ EXT_ADI_SMART_PORT , ANALOG_SENSOR_PORT }}, E_ADI_ANALOG_IN); + * // Displays the value of E_ADI_ANALOG_IN + * std::cout << "Port Type: " << sensor.get_config(); + * } + * \endcode */ - ADIPort(ext_adi_port_pair_t port_pair, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED); + explicit Port(ext_adi_port_pair_t port_pair, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED); /** * Gets the configuration for the given ADI port. * * \return The ADI configuration for the given port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * void initialize() { + * adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * // Displays the value of E_ADI_ANALOG_IN + * printf("Port Type: %d\n", adi_port_get_config(ANALOG_SENSOR_PORT)); + * } + * \endcode */ std::int32_t get_config() const; @@ -77,6 +130,16 @@ class ADIPort { * Gets the value for the given ADI port. * * \return The value stored for the given port + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Port sensor (ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * std::cout << "Port Value: " << sensor.get_value(); + * } + * \endcode */ std::int32_t get_value() const; @@ -88,6 +151,18 @@ class ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::Port sensor (ANALOG_SENSOR_PORT, E_ADI_DIGITAL_IN); + * // Do things as a digital sensor + * // Digital is unplugged and an analog is plugged in + * sensor.set_config(E_ADI_ANALOG_IN); + * } + * \endcode */ std::int32_t set_config(adi_port_config_e_t type) const; @@ -102,15 +177,57 @@ class ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::Port sensor (DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT); + * sensor.set_value(DIGITAL_SENSOR_PORT, HIGH); + * } + * \endcode */ std::int32_t set_value(std::int32_t value) const; + /** + * Gets the port of the sensor. + * + * \return returns a tuple of integer ports. + * + * \note The parts of the tuple are {smart port, adi port, second adi port (when applicable)}. + * + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 // 'A' + * + * void initialize() { + * pros::adi::AnalogIn sensor (DIGITAL_SENSOR_PORT); + * + * // Getting values from the tuple using std::get + * int sensorSmartPort = std::get<0>(sensor.get_port()); // First value + * int sensorAdiPort = std::get<1>(sensor.get_port()); // Second value + * + * // Prints the first and second value from the port tuple (The Adi Port. The first value is the Smart Port) + * printf("Sensor Smart Port: %d\n", sensorSmartPort); + * printf("Sensor Adi Port: %d\n", sensorAdiPort); + * } + * \endcode + */ + virtual ext_adi_port_tuple_t get_port() const; + protected: std::uint8_t _smart_port; std::uint8_t _adi_port; }; +///@} -class ADIAnalogIn : protected ADIPort { +class AnalogIn : protected Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as an Analog Input. @@ -125,25 +242,49 @@ class ADIAnalogIn : protected ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT); + * while (true) { + * // Use the sensor + * } + * } + * \endcode */ - explicit ADIAnalogIn(std::uint8_t adi_port); + explicit AnalogIn(std::uint8_t adi_port); /** - * Configures an ADI port on an adi expander to act as an Analog Input. + * Configures an ADI port to act as an Analog Input. * * This function uses the following values of errno when an error state is * reached: * ENXIO - Either the ADI port value or the smart port value is not within its * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * - * \param port_pair - * The pair of the smart port number (from 1-22) and the - * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * \param adi_port + * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define EXT_ADI_SENSOR_PORT 1 + * #define ADI_PORT 'a' + * + * void opcontrol() { + * pros::ADIAnalogIn sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); + * while (true) { + * // Use the sensor + * } + * } + * \endcode */ - ADIAnalogIn(ext_adi_port_pair_t port_pair); + explicit AnalogIn(ext_adi_port_pair_t port_pair); /** * Calibrates the analog sensor on the specified port and returns the new @@ -153,29 +294,44 @@ class ADIAnalogIn : protected ADIPort { * this time and computes an average from approximately 500 samples, 1 ms * apart, for a 0.5 s period of calibration. The average value thus calculated * is returned and stored for later calls to the - * pros::ADIAnalogIn::get_value_calibrated() and - * pros::ADIAnalogIn::get_value_calibrated_HR() functions. These functions + * pros::AnalogIn::get_value_calibrated() and + * pros::AnalogIn::get_value_calibrated_HR() functions. These functions * will return the difference between this value and the current sensor value * when called. * * Do not use this function when the sensor value might be unstable (gyro * rotation, accelerometer movement). + * + * \note The ADI currently returns data at 10ms intervals, in contrast to the + * calibrate function’s 1ms sample rate. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port is not configured as an analog input * * \return The average sensor value computed by this function + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT); + * sensor.calibrate(ANALOG_SENSOR_PORT); + * std::cout << "Calibrated Reading:" << sensor.get_value_calibrated(); + * // All readings from then on will be calibrated + * } + * \endcode */ std::int32_t calibrate() const; /** * Gets the 12 bit calibrated value of an analog input port. * - * The pros::ADIAnalogIn::calibrate() function must be run first. This + * The pros::adi::AnalogIn::calibrate() function must be run first. This * function is inappropriate for sensor values intended for integration, as * round-off error can accumulate causing drift over time. Use - * pros::ADIAnalogIn::get_value_calibrated_HR() instead. + * pros::adi::AnalogIn::get_value_calibrated_HR() instead. * * This function uses the following values of errno when an error state is * reached: @@ -183,13 +339,25 @@ class ADIAnalogIn : protected ADIPort { * * \return The difference of the sensor value from its calibrated default from * -4095 to 4095 + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT); + * sensor.calibrate(ANALOG_SENSOR_PORT); + * std::cout << "Calibrated Reading:" << sensor.get_value_calibrated(); + * // All readings from then on will be calibrated + * } + * \endcode */ std::int32_t get_value_calibrated() const; /** * Gets the 16 bit calibrated value of an analog input port. * - * The pros::ADIAnalogIn::calibrate() function must be run first. This is + * The pros::adi::AnalogIn::calibrate() function must be run first. This is * intended for integrated sensor values such as gyros and accelerometers to * reduce drift due to round-off, and should not be used on a sensor such as a * line tracker or potentiometer. @@ -205,32 +373,72 @@ class ADIAnalogIn : protected ADIPort { * * \return The difference of the sensor value from its calibrated default from * -16384 to 16384 + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT); + * sensor.calibrate(ANALOG_SENSOR_PORT); + * std::cout << "Calibrated Reading:" << sensor.get_value_calibrated(); + * // All readings from then on will be calibrated + * } + * \endcode */ std::int32_t get_value_calibrated_HR() const; /** - * Gets the 12-bit value of the specified port. - * - * The value returned is undefined if the analog pin has been switched to a - * different mode. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port is not configured as an analog input - * + * Reads an analog input channel and returns the 12-bit value. + * + * The value returned is undefined if the analog pin has been switched to a different mode. The meaning of the returned value varies depending on the sensor attached. + * + * Inherited from ADIPort::get_value. + * + * This function uses the following values of errno when an error state is reached: + * EADDRINUSE - The port is not configured as an analog input (e.g. the port has been reconfigured) + * * \return The analog sensor value, where a value of 0 reflects an input * voltage of nearly 0 V and a value of 4095 reflects an input voltage of * nearly 5 V + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT); + * std::cout << "Sensor Reading:" << sensor.get_value(); + * } + * \endcode */ - using ADIPort::get_value; + using Port::get_value; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * AnalogIn [smart_port: analog_in._smart_port, adi_port: analog_in._adi_port, + * value calibrated: (12 bit calibrated value), + * value calibrated HR: (16 bit calibrated value), value: (12 bit value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::AnalogIn& analog_in); + + using Port::get_port; }; +///@} + // using ADIPotentiometer = ADIAnalogIn; -using ADILineSensor = ADIAnalogIn; -using ADILightSensor = ADIAnalogIn; -using ADIAccelerometer = ADIAnalogIn; +using LineSensor = AnalogIn; +using LightSensor = AnalogIn; +using Accelerometer = AnalogIn; -class ADIAnalogOut : private ADIPort { +class AnalogOut : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as an Analog Output. @@ -242,8 +450,18 @@ class ADIAnalogOut : private ADIPort { * * \param adi_port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::AnalogOut sensor (ANALOG_SENSOR_PORT); + * // Use the sensor + * } + * @endcode */ - explicit ADIAnalogOut(std::uint8_t adi_port); + explicit AnalogOut(std::uint8_t adi_port); /** * Configures an ADI port on an adi_expander to act as an Analog Output. @@ -256,30 +474,64 @@ class ADIAnalogOut : private ADIPort { * \param port_pair * The pair of the smart port number (from 1-22) and the * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure - * + * + * \b Example + * \code + * #define EXT_ADI_SMART_PORT 1 + * #define ADI_PORT 'a' + * + * void opcontrol() { + * pros::AnalogOut sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); + * // Use the sensor + * } + * \endcode */ - ADIAnalogOut(ext_adi_port_pair_t port_pair); + explicit AnalogOut(ext_adi_port_pair_t port_pair); /** - * Sets the value for the given ADI port. + * Sets the output for the Analog Output from 0 (0V) to 4095 (5V). * - * This only works on ports configured as outputs, and the behavior will - * change depending on the configuration of the port. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port is not configured as an analog output + * Inherited from ADIPort::set_value. + * + * This function uses the following values of errno when an error state is reached: + * EACCES - Another resource is currently trying to access the ADI. * * \param value * The value to set the ADI port to * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::AnalogOut sensor (ANALOG_SENSOR_PORT); + * sensor.set_value(4095); // Set the port to 5V + * } + * \endcode */ - using ADIPort::set_value; + using Port::set_value; + + using Port::get_port; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * AnalogOut [smart_port: analog_out._smart_port, adi_port: analog_out._adi_port, + * value: (value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::AnalogOut& analog_out); }; +///@} -class ADIDigitalOut : private ADIPort { +class DigitalOut : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as a Digital Output. @@ -293,8 +545,23 @@ class ADIDigitalOut : private ADIPort { * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param init_state * The initial state for the port + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * bool state = LOW; + * pros::adi::DigitalOut sensor (DIGITAL_SENSOR_PORT, state); + * while (true) { + * state != state; + * sensor.set_value(state); + * pros::delay(10); // toggle the sensor value every 50ms + * } + * } + * \endcode */ - explicit ADIDigitalOut(std::uint8_t adi_port, bool init_state = LOW); + explicit DigitalOut(std::uint8_t adi_port, bool init_state = LOW); /** * Configures an ADI port on an adi_expander to act as a Digital Output. @@ -309,28 +576,74 @@ class ADIDigitalOut : private ADIPort { * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param init_state * The initial state for the port + * + * \b Example + * \code + * #define EXT_ADI_SMART_PORT 1 + * #define ADI_PORT 'a' + * + * void opcontrol() { + * bool state = LOW; + * pros::adi::DigitalOut sensor ( {{ EXT_ADI_SMART_PORT , ADI_PORT }}); + * while (true) { + * state != state; + * sensor.set_value(state); + * pros::delay(10); // toggle the sensor value every 50ms + * } + * } + * \endcode */ - ADIDigitalOut(ext_adi_port_pair_t port_pair, bool init_state = LOW); + explicit DigitalOut(ext_adi_port_pair_t port_pair, bool init_state = LOW); /** - * Sets the value for the given ADI port. - * - * This only works on ports configured as outputs, and the behavior will - * change depending on the configuration of the port. + * Sets the digital value (1 or 0) of a pin. * + * Inherited from ADIPort::set_value. + * * This function uses the following values of errno when an error state is * reached: - * ENODEV - The port is not configured as a digital output + * EADDRINUSE - The port is not configured as a digital output (e.g. the port has been reconfigured) * * \param value * The value to set the ADI port to * * \return if the operation was successful or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * bool state = LOW; + * pros::adi::DigitalOut sensor (DIGITAL_SENSOR_PORT); + * while (true) { + * state != state; + * sensor.set_value(state); + * pros::delay(10); // toggle the sensor value every 50ms + * } + * } + * \endcode */ - using ADIPort::set_value; + using Port::set_value; + + using Port::get_port; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * DigitalOut [smart_port: digital_out._smart_port, adi_port: digital_out._adi_port, + * value: (value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::DigitalOut& digital_out); }; +///@} -class ADIDigitalIn : private ADIPort { +class DigitalIn : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as a Digital Input. @@ -342,8 +655,18 @@ class ADIDigitalIn : private ADIPort { * * \param adi_port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::adi::DigitalIn sensor (ANALOG_SENSOR_PORT); + * // Use the sensor + * } + * \endcode */ - explicit ADIDigitalIn(std::uint8_t adi_port); + explicit DigitalIn(std::uint8_t adi_port); /** * Configures an ADI port on an adi_expander to act as a Digital Input. @@ -356,8 +679,19 @@ class ADIDigitalIn : private ADIPort { * \param port_pair * The pair of the smart port number (from 1-22) and the * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define EXT_ADI_SMART_PORT 1 + * #define ADI_PORT 'a' + * + * void opcontrol() { + * pros::adi::DigitalIn sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); + * // Use the sensor + * } + * \endcode */ - ADIDigitalIn(ext_adi_port_pair_t port_pair); + explicit DigitalIn(ext_adi_port_pair_t port_pair); /** * Gets a rising-edge case for a digital button press. @@ -376,24 +710,74 @@ class ADIDigitalIn : private ADIPort { * * \return 1 if the button is pressed and had not been pressed the last time * this function was called, 0 otherwise. + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::adi::DigitalIn sensor (DIGITAL_SENSOR_PORT); + * while (true) { + * if (sensor.get_new_press()) { + * // Toggle pneumatics or other state operations + * } + * pros::delay(10); + * } + * } + * \endcode */ std::int32_t get_new_press() const; /** - * Gets the value for the given ADI port. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port is not configured as a digital input + * Gets the digital value (1 or 0) of a pin. + * + * Inherited from ADIPort::get_value. + * + * This function uses the following values of errno when an error state is reached: + * + * EADDRINUSE - The port is not configured as a digital input (e.g. the port has been reconfigured) + * + * Analogous to adi_digital_read. * * \return The value stored for the given port + * + * \b Example + * \code + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * pros::adi::DigitalIn sensor (DIGITAL_SENSOR_PORT); + * while (true) { + * std::cout << "Sensor Value:" << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - using ADIPort::get_value; + using Port::get_value; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * DigitalIn [smart_port: digital_in._smart_port, adi_port: digital_in._adi_port, + * value: (value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::DigitalIn& digital_in); + + using Port::get_port; }; -using ADIButton = ADIDigitalIn; +///@} + +//Derived Class(es) from DigitalIn +using Button = DigitalIn; -class ADIMotor : private ADIPort { +class Motor : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as a Motor. @@ -405,8 +789,21 @@ class ADIMotor : private ADIPort { * * \param adi_port * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Motor motor (MOTOR_PORT); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.set_value(0); // Stop the motor + * } + * \endcode */ - explicit ADIMotor(std::uint8_t adi_port); + explicit Motor(std::uint8_t adi_port); /** * Configures an ADI port on an adi_expander to act as a Motor. @@ -419,8 +816,22 @@ class ADIMotor : private ADIPort { * \param port_pair * The pair of the smart port number (from 1-22) and the * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * + * \b Example + * \code + * #define EXT_ADI_SMART_PORT 1 + * #define ADI_MOTOR_PORT 'a' + * + * void opcontrol() { + * pros::adi::Motor motor ( {{ EXT_ADI_SMART_PORT , ADI_MOTOR_PORT}} ); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.set_value(0); // Stop the motor + * } + * \endcode */ - ADIMotor(ext_adi_port_pair_t port_pair); + explicit Motor(ext_adi_port_pair_t port_pair); /** * Stops the motor on the given port. @@ -431,6 +842,19 @@ class ADIMotor : private ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Motor motor (MOTOR_PORT); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.stop(); // Stop the motor + * } + * \endcode */ std::int32_t stop() const; @@ -447,8 +871,21 @@ class ADIMotor : private ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Motor motor (MOTOR_PORT); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.set_value(0); // Stop the motor + * } + * \endcode */ - using ADIPort::set_value; + using Port::set_value; /** * Gets the last set speed of the motor on the given port. @@ -457,12 +894,33 @@ class ADIMotor : private ADIPort { * reached: * ENODEV - The port is not configured as a motor * - * \return The last set speed of the motor on the given port + * \return The last set speed of the motor on the given + * + * \b Example + * \code + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * pros::adi::Motor motor (MOTOR_PORT); + * motor.set_value(127); // Go full speed forward + * std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 + * delay(1000); + * motor.set_value(0); // Stop the motor + * } + * \endcode */ - using ADIPort::get_value; + using Port::get_value; + + using Port::get_port; }; -class ADIEncoder : private ADIPort { +///@} + +class Encoder : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures a set of ADI ports to act as an Encoder. @@ -478,8 +936,19 @@ class ADIEncoder : private ADIPort { * The "bottom" wire from the encoder sensor * \param reverse * If "true", the sensor will count in the opposite direction + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); + * // Use the sensor + * } + * \endcode */ - ADIEncoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed = false); + explicit Encoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed = false); /** * Configures a set of ADI ports on an adi_expander to act as an Encoder. @@ -494,13 +963,22 @@ class ADIEncoder : private ADIPort { * sensor with the removable cover side up, and the "bottom" wire from * the encoder sensor * \param reverse - * If "true", the sensor will count in the opposite direction + * If "true", the sensor will count in theopposite direction + * + * \b Example + * \code + * #define PORT_TOP 'A' + * #define PORT_BOTTOM 'B' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Encoder sensor ({ SMART_PORT, PORT_TOP, PORT_BOTTOM }, false); + * // Use the sensor + * } + * \endcode */ - ADIEncoder(ext_adi_port_tuple_t port_tuple, bool reversed = false); + explicit Encoder(ext_adi_port_tuple_t port_tuple, bool reversed = false); - // Delete copy constructor to prevent a compilation error from the constructor above. - ADIEncoder(ADIEncoder &) = delete; - /** * Sets the encoder value to zero. * @@ -513,6 +991,18 @@ class ADIEncoder : private ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); + * delay(1000); // Move the encoder around in this time + * sensor.reset(); // The encoder is now zero again + * } + * \endcode */ std::int32_t reset() const; @@ -526,12 +1016,45 @@ class ADIEncoder : private ADIPort { * ENODEV - The port is not configured as a motor * * \return The signed and cumulative number of counts since the last start or - * reset + * + * \b Example + * \code + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * std::cout << "Encoder Value: " << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ std::int32_t get_value() const; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * Encoder [smart_port: encoder._smart_port, adi_port: encoder._adi_port, + * value: (value)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::Encoder& encoder); + ext_adi_port_tuple_t get_port() const override; + + private: + ext_adi_port_pair_t _port_pair; + }; -class ADIUltrasonic : private ADIPort { +///@} + +class Ultrasonic : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures a set of ADI ports to act as an Ultrasonic sensor. @@ -547,8 +1070,23 @@ class ADIUltrasonic : private ADIPort { * \param port_echo * The port connected to the yellow INPUT cable. This should be in the * next highest port following port_ping. + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * pros::adi::Ultrasonic sensor (PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * std::cout << "Distance: " << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIUltrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo); + explicit Ultrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo); /** * Configures a set of ADI ports on an adi_expander to act as an Ultrasonic sensor. @@ -563,8 +1101,24 @@ class ADIUltrasonic : private ADIPort { * OUTPUT cable (1, 3, 5, 7 or 'A', 'C', 'E', 'G'), and the port * connected to the yellow INPUT cable (the next) highest port * following port_ping). + * + * \b Example + * \code + * #define PORT_PING 'A' + * #define PORT_ECHO 'B' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Ultrasonic sensor ( {{ SMART_PORT, PORT_PING, PORT_ECHO }} ); + * while (true) { + * // Print the distance read by the ultrasonic + * std::cout << "Distance: " << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIUltrasonic(ext_adi_port_tuple_t port_tuple); + explicit Ultrasonic(ext_adi_port_tuple_t port_tuple); /** * Gets the current ultrasonic sensor value in centimeters. @@ -579,19 +1133,42 @@ class ADIUltrasonic : private ADIPort { * * \return The distance to the nearest object in m^-4 (10000 indicates 1 * meter), measured from the sensor's mounting points. + * + * \b Example + * \code + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * + * void opcontrol() { + * pros::adi::Ultrasonic sensor (PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * std::cout << "Distance: " << sensor.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ std::int32_t get_value() const; + + using Port::get_port; }; -class ADIGyro : private ADIPort { +///@} + +class Gyro : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Initializes a gyroscope on the given port. If the given port has not * previously been configured as a gyro, then this function starts a 1300ms * calibration period. * - * It is highly recommended that an ADIGyro object be created in initialize() - * when the robot is stationary to ensure proper calibration. If an ADIGyro + * It is highly recommended that an Gyro object be created in initialize() + * when the robot is stationary to ensure proper calibration. If an Gyro * object is declared at the global scope, a hardcoded 1300ms delay at the * beginning of initialize will be necessary to ensure that the gyro's * returned values are correct at the beginning of autonomous/opcontrol. @@ -605,17 +1182,31 @@ class ADIGyro : private ADIPort { * The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H') * \param multiplier * A scalar value that will be multiplied by the gyro heading value - * supplied by the ADI + * supplied by the + * + * \b Example + * \code + * #define GYRO_PORT 1 + * + * void opcontrol() { + * pros::adi::Gyro gyro (GYRO_PORT); + * while (true) { + * // Get the gyro heading + * std::cout << "Distance: " << gyro.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - explicit ADIGyro(std::uint8_t adi_port, double multiplier = 1); + explicit Gyro(std::uint8_t adi_port, double multiplier = 1); /** * Initializes a gyroscope on the given port of an adi expander. If the given * port has not previously been configured as a gyro, then this function starts * a 1300ms calibration period. * - * It is highly recommended that an ADIGyro object be created in initialize() - * when the robot is stationary to ensure proper calibration. If an ADIGyro + * It is highly recommended that an adi::Gyro object be created in initialize() + * when the robot is stationary to ensure proper calibration. If an adi::Gyro * object is declared at the global scope, a hardcoded 1300ms delay at the * beginning of initialize will be necessary to ensure that the gyro's * returned values are correct at the beginning of autonomous/opcontrol. @@ -630,10 +1221,25 @@ class ADIGyro : private ADIPort { * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param multiplier * A scalar value that will be multiplied by the gyro heading value - * supplied by the ADI + * supplied by the + * + * \b Example + * \code + * #define ADI_GYRO_PORT 'a' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Gyro gyro ({{ SMART_PORT , ADI_GYRO_PORT }}); + * while (true) { + * // Get the gyro heading + * std::cout << "Distance: " << gyro.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIGyro(ext_adi_port_pair_t port_pair, double multiplier = 1); - + explicit Gyro(ext_adi_port_pair_t port_pair, double multiplier = 1); + /** * Gets the current gyro angle in tenths of a degree. Unless a multiplier is * applied to the gyro, the return value will be a whole number representing @@ -647,6 +1253,20 @@ class ADIGyro : private ADIPort { * ENODEV - The port is not configured as a gyro * * \return The gyro angle in degrees. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * + * void opcontrol() { + * pros::adi::Gyro gyro (GYRO_PORT); + * while (true) { + * // Get the gyro heading + * std::cout << "Distance: " << gyro.get_value(); + * pros::delay(10); + * } + * } + * \endcode */ double get_value() const; @@ -659,11 +1279,41 @@ class ADIGyro : private ADIPort { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GYRO_PORT 1 + * + * void opcontrol() { + * pros::adi::Gyro gyro (GYRO_PORT); + * std::uint32_t now = pros::millis(); + * while (true) { + * // Get the gyro heading + * std::cout << "Distance: " << gyro.get_value(); + * + * if (pros::millis() - now > 2000) { + * // Reset the gyro every 2 seconds + * gyro.reset(); + * now = pros::millis(); + * } + * + * pros::delay(10); + * } + * } + * \endcode */ std::int32_t reset() const; + + using Port::get_port; }; -class ADIPotentiometer : public ADIAnalogIn { +///@} + +class Potentiometer : public AnalogIn { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as a Potentiometer. @@ -677,8 +1327,23 @@ class ADIPotentiometer : public ADIAnalogIn { * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param potentiometer_type * An adi_potentiometer_type_e_t enum value specifying the potentiometer version type + * + * \b Example + * \code + * #define POTENTIOMETER_PORT 1 + * #define POTENTIOMETER_TYPE pros::E_ADI_POT_EDR + * + * void opcontrol() { + * pros::adi::Potentiometer potentiometer (POTENTIOMETER_PORT, POTENTIOMETER_TYPE); + * while (true) { + * // Get the potentiometer angle + * std::cout << "Angle: " << potentiometer.get_angle(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIPotentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR); + explicit Potentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR); /** * Configures an ADI port on an adi_expander to act as a Potentiometer. @@ -693,8 +1358,23 @@ class ADIPotentiometer : public ADIAnalogIn { * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param potentiometer_type * An adi_potentiometer_type_e_t enum value specifying the potentiometer version type + * + * \b Example + * \code + * #define ADI_POTENTIOMETER_PORT 'a' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Potentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }}); + * while (true) { + * // Get the potentiometer angle + * std::cout << "Angle: " << potentiometer.get_angle(); + * pros::delay(10); + * } + * } + * \endcode */ - ADIPotentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR); + explicit Potentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR); /** * Gets the current potentiometer angle in tenths of a degree. @@ -706,8 +1386,23 @@ class ADIPotentiometer : public ADIAnalogIn { * reached: * ENXIO - The given value is not within the range of ADI Ports * EADDRINUSE - The port is not configured as a potentiometer - + * * \return The potentiometer angle in degrees. + * + * \b Example + * \code + * #define ADI_POTENTIOMETER_PORT 'a' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Potentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }}); + * while (true) { + * // Get the potentiometer angle + * std::cout << "Angle: " << potentiometer.get_angle(); + * pros::delay(10); + * } + * } + * \endcode */ double get_angle() const; @@ -725,7 +1420,7 @@ class ADIPotentiometer : public ADIAnalogIn { * voltage of nearly 0 V and a value of 4095 reflects an input voltage of * nearly 5 V */ - using ADIAnalogIn::get_value; + using AnalogIn::get_value; /** * Calibrates the potentiometer on the specified port and returns the new @@ -735,7 +1430,7 @@ class ADIPotentiometer : public ADIAnalogIn { * this time and computes an average from approximately 500 samples, 1 ms * apart, for a 0.5 s period of calibration. The average value thus calculated * is returned and stored for later calls to the - * pros::ADIPotentiometer::get_value_calibrated() function. This function + * pros::adi::Potentiometer::get_value_calibrated() function. This function * will return the difference between this value and the current sensor value * when called. * @@ -747,12 +1442,12 @@ class ADIPotentiometer : public ADIAnalogIn { * * \return The average potentiometer value computed by this function */ - using ADIAnalogIn::calibrate; + using AnalogIn::calibrate; /** * Gets the 12 bit calibrated value of a potentiometer port. * - * The pros::ADIPotentiometer::calibrate() function must be run first. + * The pros::adi::Potentiometer::calibrate() function must be run first. * * This function uses the following values of errno when an error state is * reached: @@ -761,10 +1456,27 @@ class ADIPotentiometer : public ADIAnalogIn { * \return The difference of the potentiometer value from its calibrated default from * -4095 to 4095 */ - using ADIAnalogIn::get_value_calibrated; + using AnalogIn::get_value_calibrated; + + /** + * This is the overload for the << operator for printing to streams + * Potentiometer [value: (value), value calibrated: (calibrated value), + * angle: (angle)] + * Prints in format(this below is all in one line with no new line): + */ + friend std::ostream& operator<<(std::ostream& os, pros::adi::Potentiometer& potentiometer); + + using Port::get_port; + }; -class ADILed : protected ADIPort { +///@} + +class Led : protected Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * @brief Configures an ADI port to act as a LED. @@ -778,8 +1490,24 @@ class ADILed : protected ADIPort { * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param length * The number of LEDs in the chain + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set entire LED strip to red + * led.set_all(0xFF0000); + * pros::delay(20); + * } + * } + * \endcode + * */ - ADILed(std::uint8_t adi_port, std::uint32_t length); + explicit Led(std::uint8_t adi_port, std::uint32_t length); /** * @brief Configures an ADI port on a adi_expander to act as a LED. @@ -794,8 +1522,24 @@ class ADILed : protected ADIPort { * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure * \param length * The number of LEDs in the chain + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define SMART_PORT 1 + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led ({{ SMART_PORT , LED_PORT }}, LED_LENGTH); + * while (true) { + * // Set entire LED strip to red + * led.set_all(0xFF0000); + * pros::delay(20); + * } + * } + * \endcode */ - ADILed(ext_adi_port_pair_t port_pair, std::uint32_t length); + explicit Led(ext_adi_port_pair_t port_pair, std::uint32_t length); /** * @brief Operator overload to access the buffer in the ADILed class, it is @@ -803,6 +1547,27 @@ class ADILed : protected ADIPort { * * @param i 0 indexed pixel of the lED * @return uint32_t& the address of the buffer at i to modify + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first 3 pixels to red, green, and blue + * led.set_pixel(0xFF0000, 0); + * led.set_pixel(0x00FF00, 1); + * led.set_pixel(0x0000FF, 2); + * pros::delay(20); + * + * // Use the [] operator to set the first pixel to black + * led.operator[](0) = 0x000000; + * led.update(); + * pros::delay(20); + * } + * } */ std::uint32_t& operator[] (size_t i); @@ -816,6 +1581,27 @@ class ADILed : protected ADIPort { * EADDRINUSE - The port is not configured for ADI output * * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first 3 pixels to red, green, and blue + * led.set_pixel(0xFF0000, 0); + * led.set_pixel(0x00FF00, 1); + * led.set_pixel(0x0000FF, 2); + * pros::delay(20); + * + * // Clear the led strip of color + * led.clear(); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t clear_all(); std::int32_t clear(); @@ -830,6 +1616,29 @@ class ADILed : protected ADIPort { * EADDRINUSE - The port is not configured for ADI output * * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first 3 pixels to red, green, and blue + * led.set_pixel(0xFF0000, 0); + * led.set_pixel(0x00FF00, 1); + * led.set_pixel(0x0000FF, 2); + * pros::delay(20); + * + * // Use the [] operator to set the first pixel to black + * led.operator[](0) = 0x000000; + * // Update the led strip with the new values + * led.update(); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t update() const; @@ -843,6 +1652,21 @@ class ADILed : protected ADIPort { * * @param color color to set all the led strip value to * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the entire led strip to blue + * led.set_all(0x0000FF); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t set_all(uint32_t color); @@ -857,6 +1681,21 @@ class ADILed : protected ADIPort { * @param color color to clear all the led strip to * @param pixel_position position of the pixel to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first pixel to blue + * led.set_pixel(0x0000FF, 0); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t set_pixel(uint32_t color, uint32_t pixel_position); @@ -870,6 +1709,25 @@ class ADILed : protected ADIPort { * * @param pixel_position position of the pixel to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Set the first pixel to blue + * led.set_pixel(0x0000FF, 0); + * pros::delay(20); + * + * // Clear the first pixel + * led.clear_pixel(0); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t clear_pixel(uint32_t pixel_position); @@ -882,15 +1740,306 @@ class ADILed : protected ADIPort { * EADDRINUSE - The port is not configured for ADI output * * @return The length (in pixels) of the LED strip + * + * \b Example: + * \code + * #define LED_PORT 'a' + * #define LED_LENGTH 3 + * + * void opcontrol() { + * pros::Led led (LED_PORT, LED_LENGTH); + * while (true) { + * // Get the length of the led strip + * int length = led.length(); + * pros::lcd::print(1, "Length: %d", length); + * pros::delay(20); + * } + * } + * \endcode */ std::int32_t length(); + using Port::get_port; + protected: std::vector _buffer; }; +///@} + +/// @brief Alias for ADILed +using LED = Led; + +class Pneumatics : public DigitalOut { + /** + * \addtogroup cpp-adi + * @{ + */ + public: + + /** + * Creates a Pneumatics object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of ADI Ports + * + * \param adi_port + * The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * \param start_extended + * If true, the pneumatic will start extended when the program starts. + * By default, the piston starts retracted when the program starts. + * \param extended_is_low + * A flag to set whether the the pneumatic is extended when the ADI + * it receives a high or a low value. When true, the extended state + * corresponds to a output low on the ADI port. This allows the user + * to reverse the behavior of the pneumatics if needed. + * + * /b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics left_piston('a', false); // Starts retracted, extends when the ADI port is high + * pros::adi::Pneumatics right_piston('b', false, true); // Starts retracted, extends when the ADI port is low + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) { + * left_piston.retract(); + * } + * + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_2)) { + * left_piston.retract(); + * } + * + * pros::delay(10); + * } + * + * \endcode + */ + explicit Pneumatics(std::uint8_t adi_port, + bool start_extended, + bool extended_is_low = false + ); + + /** + * Creates a Pneumatics object for the given port pair. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of ADI Ports + * + * \param port_pair + * The pair of the smart port number (from 1-22) and the + * ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure + * \param start_extended + * If true, the pneumatic will start extended when the program starts. + * By default, the piston starts retracted when the program starts. + * \param extended_is_low + * A flag to set whether the the pneumatic is extended when the ADI + * it receives a high or a low value. When true, the extended state + * corresponds to a output low on the ADI port. This allows the user + * to reverse the behavior of the pneumatics if needed. + * + * /b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics left_piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high + * pros::adi::Pneumatics right_piston({1, 'b'}, false, true); // Starts retracted, extends when the ADI port is low + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) { + * left_piston.retract(); + * } + * + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R2)) { + * left_piston.retract(); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + explicit Pneumatics(ext_adi_port_pair_t port_pair, + bool start_extended, + bool extended_is_low = false + ); + + /** + * Extends the piston, if not already extended. + * + * \return 1 if the piston newly extended, 0 if the piston was already + * extended, or PROS_ERR is the operation failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { + * left_piston.retract(); + * } + * if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { + * left_piston.toggle(); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + std::int32_t extend(); -// Alias for ADILed -using ADILED = ADILed; + /** + * Retracts the piston, if not already retracted. + * + * \return 1 if the piston newly retracted, 0 if the piston was already + * retracted, or PROS_ERR is the operation failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { + * left_piston.retract(); + * } + * if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { + * left_piston.toggle(); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + std::int32_t retract(); + + /** + * Puts the piston into the opposite state of its current state. + * If it is retracted, it will extend. If it is extended, it will retract. + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \return 1 if the piston successfully toggled, or PROS_ERR if the + * operation failed, setting errno. + * + *\b Example: + * \code + * void opcontrol() { + * pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high + * + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * + * while (true) { + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { + * left_piston.extend(); + * } + * if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { + * left_piston.retract(); + * } + * if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { + * left_piston.toggle(); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + std::int32_t toggle(); + + /** + * Returns whether the piston is extended or not. + * + * \return true if the piston is extended, false if it is retracted. + * + * \b Example + * \code + * #define ADI_PNEUMATICS_PORT 'a' + * + * void opcontrol() { + * pros::adi::Pneumatics pneumatics (ADI_PNEUMATICS_PORT); + * while (true) { + * // Check if the piston is extended + * if (pneumatics.is_extended()) { + * printf("The pneumatic is extended\n"); + * } + * else { + * printf("The pneumatic is not extended\n"); + * } + * + * pros::delay(10); + * } + * } + * \endcode + */ + bool is_extended() const; + +private: + bool state; // Holds the physical state of the ADI port + bool extended_is_low; // A flag that sets whether extended corresponds to + // a low signal + + +}; +///@} + +} // namespace adi + +/* +Pros4 upgrade backwards compatibility for ADI api. + +Prints a deprecated warning when user uses old pros::ADIDevice style API. +Remove when and if fully removing old API. +*/ +LEGACY_TYPEDEF(ADIPort, pros::adi::Port); +LEGACY_TYPEDEF(ADIAnalogIn, pros::adi::AnalogIn); +LEGACY_TYPEDEF(ADIAnalogOut, pros::adi::AnalogOut); +LEGACY_TYPEDEF(ADIDigitalIn, pros::adi::DigitalIn); +LEGACY_TYPEDEF(ADIDigitalOut, pros::adi::DigitalOut); +LEGACY_TYPEDEF(ADIMotor, pros::adi::Motor); +LEGACY_TYPEDEF(ADIGyro, pros::adi::Gyro); +LEGACY_TYPEDEF(ADIEncoder, pros::adi::Encoder); +LEGACY_TYPEDEF(ADIUltrasonic, pros::adi::Ultrasonic); +LEGACY_TYPEDEF(LED, pros::adi::Led); + +// Backwards Compatibility for Derived Classes +LEGACY_TYPEDEF(ADIPotentiometer,pros::adi::Potentiometer); +LEGACY_TYPEDEF(ADILineSensor,pros::adi::LineSensor); +LEGACY_TYPEDEF(ADILightSensor,pros::adi::LightSensor); +LEGACY_TYPEDEF(ADIAccelerometer,pros::adi::Accelerometer); +LEGACY_TYPEDEF(ADIButton,pros::adi::Button); +LEGACY_TYPEDEF(ADIPneumatics,pros::adi::Pneumatics); +LEGACY_TYPEDEF(ADILED, pros::adi::Led); +LEGACY_TYPEDEF(ADILed, pros::adi::Led); } // namespace pros diff --git a/include/pros/api_legacy.h b/include/pros/api_legacy.h deleted file mode 100644 index deb7d222..00000000 --- a/include/pros/api_legacy.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * \file pros/api_legacy.h - * - * PROS 2 Legacy API header - * - * Contains declarations for functions that are name-compatible with the PROS 2 - * API. Some functions from the PROS 2 API are not useful or cannot be - * implemented in PROS 3, but most common functions are available. - * - * This file should not be modified by users, since it gets replaced whenever - * a kernel upgrade occurs. - * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. - * All rights reserved. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef _PROS_API_LEGACY_H_ -#define _PROS_API_LEGACY_H_ - -#include "api.h" - -#ifdef __cplusplus -#define _NAMESPACE pros:: -#define _CNAMESPACE pros::c:: -#else -#define _NAMESPACE -#define _CNAMESPACE -#endif - -/** - * From adi.h - */ -#define analogCalibrate(port) adi_analog_calibrate(port) -#define analogRead(port) adi_analog_read(port) -#define analogReadCalibrated(port) adi_analog_read_calibrated(port) -#define analogReadCalibratedHR(port) adi_analog_read_calibrated_HR(port) -#define digitalRead(port) adi_digital_read(port) -#define digitalWrite(port, value) adi_digital_write(port, value) -#define pinMode(port, mode) adi_pin_mode(port, mode) -#define adiMotorSet(port, speed) adi_motor_set(port, speed) -#define adiMotorGet(port) adi_motor_get(port) -#define adiMotorStop(port) adi_motor_stop(port) -#define encoderGet(enc) adi_encoder_get(enc) -#define encoderInit(portTop, portBottom, reverse) adi_encoder_init(portTop, portBottom, reverse) -#define encoderShutdown(enc) adi_encoder_shutdown(enc) -#define ultrasonicGet(ult) adi_ultrasonic_get(ult) -#define ultrasonicInit(portEcho, portPing) adi_ultrasonic_init(portEcho, portPing) -#define ultrasonicShutdown(ult) adi_ultrasonic_shutdown(ult) - -typedef _CNAMESPACE adi_encoder_t Encoder; -typedef _CNAMESPACE adi_ultrasonic_t Ultrasonic; - -/** - * From llemu.h - */ -#define lcdInit lcd_initialize -#define lcdReadButtons lcd_read_buttons -#define lcdClear lcd_clear -#define lcdClearLine lcd_clear_line -#define lcdShutdown lcd_shutdown -#define lcdPrint(line, fmt, ...) lcd_print(line, fmt, __VA_ARGS__) -#define lcdSetText(line, text) lcd_set_text(line, text) - -/** - * From misc.h - */ -#define isEnabled() (!competition_is_disabled()) -#define isAutonomous competition_is_autonomous -#define isOnline competition_is_connected -#define isJoystickConnected(id) controller_is_connected(id) -#define joystickGetAnalog(id, channel) controller_get_analog(id, channel) - -/** - * From rtos.h - */ -#define taskCreate(taskCode, stackDepth, parameters, priority) \ - task_create(taskCode, parameters, priority, stackDepth, "") -#define taskDelete(task) task_delete(task) -#define taskDelay task_delay -#define taskDelayUntil(previousWakeTime, cycleTime) task_delay_until(previousWakeTime, cycleTime) -#define taskPriorityGet(task) task_get_priority(task) -#define taskPrioritySet(task, newPriority) task_priority_set(task, newPriority) -#define taskGetState(task) task_get_state(task) -#define taskSuspend(task) task_suspend(task) -#define taskResume(task) task_resume(task) -#define taskGetCount task_get_count -#define mutexCreate mutex_create -#define mutexTake(mutex, blockTime) mutex_take(mutex, blockTime) -#define mutexGive(mutex) mutex_give(mutex) - -typedef _NAMESPACE task_t TaskHandle; -typedef _NAMESPACE mutex_t Mutex; - -/** - * From motors.h - */ -#define motorSet(port, speed) motor_move(port, speed) -#define motorGet(port) motor_get_voltage(port) -#define motorStop(port) motor_move(port, 0) - -#undef _NAMESPACE -#undef _CNAMESPACE - -#endif // _PROS_API_LEGACY_H_ diff --git a/include/pros/apix.h b/include/pros/apix.h index 876a98c8..165c0541 100644 --- a/include/pros/apix.h +++ b/include/pros/apix.h @@ -1,5 +1,6 @@ /** * \file pros/apix.h + * \ingroup apix * * PROS Extended API header * @@ -7,26 +8,27 @@ * functions do not typically have as much error handling or require deeper * knowledge of real time operating systems. * - * Visit https://pros.cs.purdue.edu/v5/extended/api.html to learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup apix Extended API + * \note Also included in the Extended API is [LVGL.](https://lvgl.io/) */ #ifndef _PROS_API_EXTENDED_H_ #define _PROS_API_EXTENDED_H_ #include "api.h" +#include "pros/device.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wall" -#include "display/lvgl.h" #pragma GCC diagnostic pop #include "pros/serial.h" @@ -36,12 +38,17 @@ namespace pros::c { extern "C" { #endif -/******************************************************************************/ -/** RTOS FACILITIES **/ -/** **/ -/** **/ -/**See https://pros.cs.purdue.edu/v5/extended/multitasking.html to learn more**/ -/******************************************************************************/ +/** + * \ingroup apix + */ + +/** + * \addtogroup apix + * @{ + */ + +/// \name RTOS Facilities +///@{ typedef void* queue_t; typedef void* sem_t; @@ -50,19 +57,25 @@ typedef void* sem_t; * Unblocks a task in the Blocked state (e.g. waiting for a delay, on a * semaphore, etc.). * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#abort_delay for - * details. + * \param task + * The task to unblock + * + * \return True if the task was unblocked, false otherwise + * + * \b Example: + * \code + * task_t task = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * task_delay(1000); + * // in another task somewhere else, this will abort the task_delay bove: + * task_abort_delay(task); + * \endcode */ bool task_abort_delay(task_t task); /** * Notify a task when a target task is being deleted. * - * This function will configure the PROS kernel to call - * task_notify_ext(task_to_notify, value, action, NULL) when target_task is - * deleted. - * - * * \param target_task * The task being watched for deletion * \param task_to_notify @@ -71,6 +84,19 @@ bool task_abort_delay(task_t task); * The value to supply to task_notify_ext * \param notify_action * The action to supply to task_notify_ext + * + * \b Example: + * \code + * task_t task_to_delete = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * task_t task_to_notify = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn2"); + * + * task_notify_ext(task_to_notify, 0, NOTIFY_ACTION_INCREMENT, NULL); + * + * task_notify_when_deleting(task_to_delete, task_get_current(), 0, NOTIFY_ACTION_NONE); + * task_delete(task_to_delete); + * \endcode */ void task_notify_when_deleting(task_t target_task, task_t task_to_notify, uint32_t value, notify_action_e_t notify_action); @@ -78,64 +104,127 @@ void task_notify_when_deleting(task_t target_task, task_t task_to_notify, uint32 /** * Creates a recursive mutex which can be locked recursively by the owner. * - * See - * https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes - * for details. - * * \return A newly created recursive mutex. + * + * \b Example: + * \code + * mutex_t mutex = mutex_recursive_create(); + * + * void task_fn(void* param) { + * while(1) { + * mutex_recursive_take(mutex, 1000); + * // critical section + * mutex_recursive_give(mutex); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ mutex_t mutex_recursive_create(void); /** * Takes a recursive mutex. * - * See - * https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes - * for details. - * * \param mutex * A mutex handle created by mutex_recursive_create * \param wait_time * Amount of time to wait before timing out * * \return 1 if the mutex was obtained, 0 otherwise + * + * \b Example: + * \code + * mutex_t mutex = mutex_recursive_create(); + * + * void task_fn(void* param) { + * while(1) { + * mutex_recursive_take(mutex, 1000); + * // critical section + * mutex_recursive_give(mutex); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ bool mutex_recursive_take(mutex_t mutex, uint32_t timeout); /** * Gives a recursive mutex. * - * See - * https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes - * for details. - * * \param mutex * A mutex handle created by mutex_recursive_create * * \return 1 if the mutex was obtained, 0 otherwise + * + * \b Example: + * \code + * mutex_t mutex = mutex_recursive_create(); + * + * void task_fn(void* param) { + * while(1) { + * mutex_recursive_take(mutex, 1000); + * // critical section + * mutex_recursive_give(mutex); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ bool mutex_recursive_give(mutex_t mutex); /** * Returns a handle to the current owner of a mutex. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#extra for - * details. - * * \param mutex * A mutex handle * * \return A handle to the current task that owns the mutex, or NULL if the * mutex isn't owned. + * + * \b Example: + * \code + * mutex_t mutex = mutex_create(); + * + * void task_fn(void* param) { + * while(1) { + * mutex_take(mutex, 1000); + * // critical section + * mutex_give(mutex); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * void opcontrol(void) { +* while (1) { +* if (joystick_get_digital(1, 7, JOY_UP)) { +* task_t owner = mutex_get_owner(mutex); +* if (owner != NULL) { +* printf("Mutex is owned by task %s", task_get_name(owner)); +* } else { +* printf("Mutex is not owned"); +* } +* } +* task_delay(20); +* } +* } + * \endcode */ task_t mutex_get_owner(mutex_t mutex); /** * Creates a counting sempahore. * - * See https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores for - *details. - * * \param max_count * The maximum count value that can be reached. * \param init_count @@ -143,28 +232,86 @@ task_t mutex_get_owner(mutex_t mutex); * * \return A newly created semaphore. If an error occurred, NULL will be * returned and errno can be checked for hints as to why sem_create failed. + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * + * void task_fn(void* param) { + * while(1) { + * sem_take(sem, 1000); + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ sem_t sem_create(uint32_t max_count, uint32_t init_count); /** * Deletes a semaphore (or binary semaphore) * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#semaphores for - * details. - * * \param sem * Semaphore to delete + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * + * void task_fn(void* param) { + * while(1) { + * sem_take(sem, 1000); + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * void opcontrol(void) { + * while (1) { + * if (joystick_get_digital(1, 7, JOY_UP)) { + * // honestly this is a bad example because you should never + * // delete a semaphore like this + * sem_delete(sem); + * } + * task_delay(20); + * } + * } + * + * \endcode */ void sem_delete(sem_t sem); /** * Creates a binary semaphore. * - * See - * https://pros.cs.purdue.edu/v5/extended/multitasking#.htmlbinary_semaphores - * for details. - * * \return A newly created semaphore. + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_binary_create(); + * + * void task_fn(void* param) { + * while(1) { + * sem_take(sem, 1000); + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ sem_t sem_binary_create(void); @@ -172,9 +319,6 @@ sem_t sem_binary_create(void); * Waits for the semaphore's value to be greater than 0. If the value is already * greater than 0, this function immediately returns. * - * See https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores for - * details. - * * \param sem * Semaphore to wait on * \param timeout @@ -185,44 +329,98 @@ sem_t sem_binary_create(void); * \return True if the semaphore was successfully take, false otherwise. If * false is returned, then errno is set with a hint about why the sempahore * couldn't be taken. + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * + * void task_fn(void* param) { + * while(1) { + * if(!sem_wait(sem, 1000)) { + * printf("Failed to take semaphore"); + * task_delay(1000); + * continue; + * } + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * void opcontrol(void) { + * while (1) { + * if (sem_wait(sem, 0))) { + * printf("Semaphore is available"); + * } + * task_delay(20); + * } + * } + * \endcode */ bool sem_wait(sem_t sem, uint32_t timeout); /** * Increments a semaphore's value. * - * See https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores for - * details. - * * \param sem * Semaphore to post * * \return True if the value was incremented, false otherwise. If false is * returned, then errno is set with a hint about why the semaphore couldn't be * taken. + * + * \b Example: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * + * void task_fn(void* param) { + * while(1) { + * sem_post(sem); // increments, mimicking to "claim" + * // critical section + * sem_give(sem); + * task_delay(1000); + * } + * } + * task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "task_fn"); + * + * \endcode */ bool sem_post(sem_t sem); /** * Returns the current value of the semaphore. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#extra for - * details. - * * \param sem * A semaphore handle * * \return The current value of the semaphore (e.g. the number of resources * available) + * + * \b Example of sem_get_count: + * \code + * // Binary semaphore acts as a mutex + * sem_t sem = sem_create(1, 0); + * printf("semaphore count: %d", sem_get_count(sem)); + * // semaphore count: 0 + * sem_take(sem, 1000); + * printf("semaphore count: %d", sem_get_count(sem)); + * // semaphore count: 1 + * sem_give(sem); + * printf("semaphore count: %d", sem_get_count(sem)); + * // semaphore count: 0 + * + * \endcode */ uint32_t sem_get_count(sem_t sem); /** * Creates a queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param length * The maximum number of items that the queue can contain. * \param item_size @@ -230,6 +428,17 @@ uint32_t sem_get_count(sem_t sem); * * \return A handle to a newly created queue, or NULL if the queue cannot be * created. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue length: %d", queue_get_length(queue)); + * } + * \endcode */ queue_t queue_create(uint32_t length, uint32_t item_size); @@ -237,9 +446,6 @@ queue_t queue_create(uint32_t length, uint32_t item_size); * Posts an item to the front of a queue. The item is queued by copy, not by * reference. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle * \param item @@ -250,6 +456,16 @@ queue_t queue_create(uint32_t length, uint32_t item_size); * indefinitely. * * \return True if the item was preprended, false otherwise. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue length: %d", queue_get_length(queue)); + * } */ bool queue_prepend(queue_t queue, const void* item, uint32_t timeout); @@ -257,9 +473,6 @@ bool queue_prepend(queue_t queue, const void* item, uint32_t timeout); * Posts an item to the end of a queue. The item is queued by copy, not by * reference. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle * \param item @@ -270,15 +483,23 @@ bool queue_prepend(queue_t queue, const void* item, uint32_t timeout); * indefinitely. * * \return True if the item was preprended, false otherwise. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue length: %d", queue_get_length(queue)); + * } + * \endcode */ bool queue_append(queue_t queue, const void* item, uint32_t timeout); /** * Receive an item from a queue without removing the item from the queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle * \param buffer @@ -288,15 +509,26 @@ bool queue_append(queue_t queue, const void* item, uint32_t timeout); * the time of the call. TIMEOUT_MAX can be used to block indefinitely. * * \return True if an item was copied into the buffer, false otherwise. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * char* item = "Hello! this is a test"; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * char* recv = malloc(sizeof("Hello! this is a test")); + * queue_peek(queue, recv, 1000); + * printf("Queue: %s", recv); + * free(recv); + * } + * \endcode */ bool queue_peek(queue_t queue, void* const buffer, uint32_t timeout); /** * Receive an item from the queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle * \param buffer @@ -308,43 +540,80 @@ bool queue_peek(queue_t queue, void* const buffer, uint32_t timeout); * is zero and the queue is empty. * * \return True if an item was copied into the buffer, false otherwise. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * char* item = "Hello! this is a test"; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * char* recv = malloc(sizeof("Hello! this is a test")); + * queue_recv(queue, recv, 1000); + * printf("Queue: %s", recv); + * free(recv); + * } + * \endcode */ bool queue_recv(queue_t queue, void* const buffer, uint32_t timeout); /** * Return the number of messages stored in a queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle. * * \return The number of messages available in the queue. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue waiting: %d", queue_get_waiting(queue)); + * } + * \endcode */ uint32_t queue_get_waiting(const queue_t queue); /** * Return the number of spaces left in a queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * The queue handle. * * \return The number of spaces available in the queue. + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * printf("queue available: %d", queue_get_available(queue)); + * } + * \endcode */ uint32_t queue_get_available(const queue_t queue); /** * Delete a queue. * - * See https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues for - * details. - * * \param queue * Queue handle to delete + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * queue_delete(queue); + * } + * \endcode */ void queue_delete(queue_t queue); @@ -353,36 +622,26 @@ void queue_delete(queue_t queue); * * \param queue * Queue handle to reset + * + * \b Example: + * \code + * void opcontrol(void) { + * queue_t queue = queue_create(10, sizeof(int)); + * int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + * queue_prepend(queue, item, 1000); + * queue_append(queue, item, 1000); + * queue_reset(queue); + * } + * \endcode */ void queue_reset(queue_t queue); -/******************************************************************************/ -/** Device Registration **/ -/******************************************************************************/ +///@} -/* - * List of possible v5 devices - * - * This list contains all current V5 Devices, and mirrors V5_DeviceType from the - * api. - */ -typedef enum v5_device_e { - E_DEVICE_NONE = 0, - E_DEVICE_MOTOR = 2, - E_DEVICE_ROTATION = 4, - E_DEVICE_IMU = 6, - E_DEVICE_DISTANCE = 7, - E_DEVICE_RADIO = 8, - E_DEVICE_VISION = 11, - E_DEVICE_ADI = 12, - E_DEVICE_OPTICAL = 16, - E_DEVICE_GPS = 20, - E_DEVICE_SERIAL = 129, - E_DEVICE_GENERIC __attribute__((deprecated("use E_DEVICE_SERIAL instead"))) = E_DEVICE_SERIAL, - E_DEVICE_UNDEFINED = 255 -} v5_device_e_t; +/// \name Device Registration +///@{ -/* +/** * Registers a device in the given zero-indexed port * * Registers a device of the given type in the given port into the registry, if @@ -400,10 +659,17 @@ typedef enum v5_device_e { * The type of device to register * * \return 1 upon success, PROS_ERR upon failure + * + * \b Example: + * \code + * void opcontrol(void) { + * registry_bind_port(1, E_DEVICE_MOTOR); + * } + * \endcode */ int registry_bind_port(uint8_t port, v5_device_e_t device_type); -/* +/** * Deregisters a devices from the given zero-indexed port * * Removes the device registed in the given port, if there is one. @@ -416,10 +682,18 @@ int registry_bind_port(uint8_t port, v5_device_e_t device_type); * The port number to deregister * * \return 1 upon success, PROS_ERR upon failure + * + * \b Example: + * \code + * void opcontrol(void) { + * registry_bind_port(1, E_DEVICE_MOTOR); + * registry_unbind_port(1); + * } + * \endcode */ int registry_unbind_port(uint8_t port); -/* +/** * Returns the type of device registered to the zero-indexed port. * * This function uses the following values of errno when an error state is @@ -431,10 +705,18 @@ int registry_unbind_port(uint8_t port); * * \return The type of device that is registered into the port (NOT what is * plugged in) + * + * \b Example: + * \code + * void opcontrol(void) { + * registry_bind_port(1, E_DEVICE_MOTOR); + * printf("port 1 is registered to a motor: %d", registry_get_bound_type(1) == E_DEVICE_MOTOR); + * } + * \endcode */ v5_device_e_t registry_get_bound_type(uint8_t port); -/* +/** * Returns the type of the device plugged into the zero-indexed port. * * This function uses the following values of errno when an error state is @@ -446,12 +728,22 @@ v5_device_e_t registry_get_bound_type(uint8_t port); * * \return The type of device that is plugged into the port (NOT what is * registered) + * + * \b Example: + * \code + * void opcontrol(void) { + * registry_bind_port(1, E_DEVICE_MOTOR); + * printf("port 1 is registered to a motor: %d", registry_get_plugged_type(1) == E_DEVICE_MOTOR); + * } + * \endcode */ v5_device_e_t registry_get_plugged_type(uint8_t port); -/******************************************************************************/ -/** Filesystem **/ -/******************************************************************************/ +///@} + +/// \name Filesystem +///@{ + /** * Control settings of the serial driver. * @@ -460,10 +752,16 @@ v5_device_e_t registry_get_plugged_type(uint8_t port); * details on the different actions. * \param extra_arg * An argument to pass in based on the action + * + * \b Example: + * \code + * void opcontrol(void) { + * serctl(SERCTL_SET_BAUDRATE, (void*) 9600); + * } */ int32_t serctl(const uint32_t action, void* const extra_arg); -/** +/* * Control settings of the microSD card driver. * * \param action @@ -487,9 +785,69 @@ int32_t serctl(const uint32_t action, void* const extra_arg); * microSD card file) * \param extra_arg * An argument to pass in based on the action + * + * \b Example: + * \code + * void opcontrol(void) { + * int32_t fd = open("serial", O_RDWR); + * fdctl(fd, SERCTL_SET_BAUDRATE, (void*) 9600); + * } + * \endcode */ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); +/** + * Sets the reverse flag for the motor. + * + * This will invert its movements and the values returned for its position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor + * + * \param port + * The V5 port number from 1-21 + * \param reverse + * True reverses the motor, false is default + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_set_reversed(1, true); + * printf("Is this motor reversed? %d\n", motor_is_reversed(1)); + * } + * \endcode + */ +int32_t motor_set_reversed(int8_t port, const bool reverse); + +/** + * Gets the operation direction of the motor as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a motor + * + * \param port + * The V5 port number from 1-21 + * + * \return 1 if the motor has been reversed and 0 if the motor was not reversed, + * or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * printf("Is the motor reversed? %d\n", motor_is_reversed(1)); + * // Prints "Is the motor reversed? 0" + * } + * \endcode + */ +int32_t motor_is_reversed(int8_t port); + /** * Action macro to pass into serctl or fdctl that activates the stream * identifier. @@ -497,8 +855,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * When used with serctl, the extra argument must be the little endian * representation of the stream identifier (e.g. "sout" -> 0x74756f73) * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_ACTIVATE 10 @@ -509,8 +865,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * When used with serctl, the extra argument must be the little endian * representation of the stream identifier (e.g. "sout" -> 0x74756f73) * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_DEACTIVATE 11 @@ -520,8 +874,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * The extra argument is not used with this action, provide any value (e.g. * NULL) instead * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_BLKWRITE 12 @@ -531,8 +883,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * The extra argument is not used with this action, provide any value (e.g. * NULL) instead * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_NOBLKWRITE 13 @@ -543,8 +893,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * The extra argument is not used with this action, provide any value (e.g. * NULL) instead * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_ENABLE_COBS 14 @@ -555,8 +903,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * The extra argument is not used with this action, provide any value (e.g. * NULL) instead * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial - * to learn more. */ #define SERCTL_DISABLE_COBS 15 @@ -564,8 +910,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * Action macro to check if there is data available from the Generic Serial * Device * - * The extra argument is not used with this action, provide any value (e.g. - * NULL) instead */ #define DEVCTL_FIONREAD 16 @@ -573,8 +917,6 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); * Action macro to check if there is space available in the Generic Serial * Device's output buffer * - * The extra argument is not used with this action, provide any value (e.g. - * NULL) instead */ #define DEVCTL_FIONWRITE 18 @@ -585,6 +927,10 @@ int32_t fdctl(int file, const uint32_t action, void* const extra_arg); */ #define DEVCTL_SET_BAUDRATE 17 +///@} + +///@} + #ifdef __cplusplus } } diff --git a/include/pros/colors.h b/include/pros/colors.h index 0aa4cb35..b70a8f99 100644 --- a/include/pros/colors.h +++ b/include/pros/colors.h @@ -1,4 +1,4 @@ -/* +/** * \file pros/colors.h * * Contains macro definitions of colors (as `uint32_t`) @@ -11,6 +11,18 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License v. 2.0. If a copy of the MPL was not distributed with this * file You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-colors Colors C API + */ + +/** + * \ingroup c-colors + * \note These functions can be used for dynamic device instantiation. + */ + +/** + * \addtogroup c-colors + * @{ */ #ifndef _PROS_COLORS_H_ @@ -21,151 +33,172 @@ #define COLOR2G(COLOR) ((COLOR >> 8) & 0xff) #define COLOR2B(COLOR) (COLOR & 0xff) -#define COLOR_ALICE_BLUE 0x00F0F8FF -#define COLOR_ANTIQUE_WHITE 0x00FAEBD7 -#define COLOR_AQUA 0x0000FFFF -#define COLOR_AQUAMARINE 0x007FFFD4 -#define COLOR_AZURE 0x00F0FFFF -#define COLOR_BEIGE 0x00F5F5DC -#define COLOR_BISQUE 0x00FFE4C4 -#define COLOR_BLACK 0x00000000 -#define COLOR_BLANCHED_ALMOND 0x00FFEBCD -#define COLOR_BLUE 0x000000FF -#define COLOR_BLUE_VIOLET 0x008A2BE2 -#define COLOR_BROWN 0x00A52A2A -#define COLOR_BURLY_WOOD 0x00DEB887 -#define COLOR_CADET_BLUE 0x005F9EA0 -#define COLOR_CHARTREUSE 0x007FFF00 -#define COLOR_CHOCOLATE 0x00D2691E -#define COLOR_CORAL 0x00FF7F50 -#define COLOR_CORNFLOWER_BLUE 0x006495ED -#define COLOR_CORNSILK 0x00FFF8DC -#define COLOR_CRIMSON 0x00DC143C -#define COLOR_CYAN 0x0000FFFF -#define COLOR_DARK_BLUE 0x0000008B -#define COLOR_DARK_CYAN 0x00008B8B -#define COLOR_DARK_GOLDENROD 0x00B8860B -#define COLOR_DARK_GRAY 0x00A9A9A9 -#define COLOR_DARK_GREEN 0x00006400 -#define COLOR_DARK_KHAKI 0x00BDB76B -#define COLOR_DARK_MAGENTA 0x008B008B -#define COLOR_DARK_OLIVE_GREEN 0x00556B2F -#define COLOR_DARK_ORANGE 0x00FF8C00 -#define COLOR_DARK_ORCHID 0x009932CC -#define COLOR_DARK_RED 0x008B0000 -#define COLOR_DARK_SALMON 0x00E9967A -#define COLOR_DARK_SEA_GREEN 0x008FBC8F -#define COLOR_DARK_SLATE_GRAY 0x002F4F4F -#define COLOR_DARK_TURQUOISE 0x0000CED1 -#define COLOR_DARK_VIOLET 0x009400D3 -#define COLOR_DEEP_PINK 0x00FF1493 -#define COLOR_DEEP_SKY_BLUE 0x0000BFFF -#define COLOR_DIM_GRAY 0x00696969 -#define COLOR_DODGER_BLUE 0x001E90FF -#define COLOR_FIRE_BRICK 0x00B22222 -#define COLOR_FLORAL_WHITE 0x00FFFAF0 -#define COLOR_FOREST_GREEN 0x00228B22 -#define COLOR_FUCHSIA 0x00FF00FF -#define COLOR_GAINSBORO 0x00DCDCDC -#define COLOR_GHOST_WHITE 0x00F8F8FF -#define COLOR_GOLD 0x00FFD700 -#define COLOR_GOLDENROD 0x00DAA520 -#define COLOR_GRAY 0x00808080 -#define COLOR_GREEN 0x00008000 -#define COLOR_GREEN_YELLOW 0x00ADFF2F -#define COLOR_HONEYDEW 0x00F0FFF0 -#define COLOR_HOT_PINK 0x00FF69B4 -#define COLOR_INDIAN_RED 0x00CD5C5C -#define COLOR_INDIGO 0x004B0082 -#define COLOR_IVORY 0x00FFFFF0 -#define COLOR_KHAKI 0x00F0E68C -#define COLOR_LAVENDER 0x00E6E6FA -#define COLOR_LAVENDER_BLUSH 0x00FFF0F5 -#define COLOR_LAWN_GREEN 0x007CFC00 -#define COLOR_LEMON_CHIFFON 0x00FFFACD -#define COLOR_LIGHT_BLUE 0x00ADD8E6 -#define COLOR_LIGHT_CORAL 0x00F08080 -#define COLOR_LIGHT_CYAN 0x00E0FFFF -#define COLOR_LIGHT_GOLDENROD_YELLOW 0x00FAFAD2 -#define COLOR_LIGHT_GREEN 0x0090EE90 -#define COLOR_LIGHT_GRAY 0x00D3D3D3 -#define COLOR_LIGHT_PINK 0x00FFB6C1 -#define COLOR_LIGHT_SALMON 0x00FFA07A -#define COLOR_LIGHT_SEA_GREEN 0x0020B2AA -#define COLOR_LIGHT_SKY_BLUE 0x0087CEFA -#define COLOR_LIGHT_SLATE_GRAY 0x00778899 -#define COLOR_LIGHT_STEEL_BLUE 0x00B0C4DE -#define COLOR_LIGHT_YELLOW 0x00FFFFE0 -#define COLOR_LIME 0x0000FF00 -#define COLOR_LIME_GREEN 0x0032CD32 -#define COLOR_LINEN 0x00FAF0E6 -#define COLOR_MAGENTA 0x00FF00FF -#define COLOR_MAROON 0x00800000 -#define COLOR_MEDIUM_AQUAMARINE 0x0066CDAA -#define COLOR_MEDIUM_BLUE 0x000000CD -#define COLOR_MEDIUM_ORCHID 0x00BA55D3 -#define COLOR_MEDIUM_PURPLE 0x009370DB -#define COLOR_MEDIUM_SEA_GREEN 0x003CB371 -#define COLOR_MEDIUM_SLATE_BLUE 0x007B68EE -#define COLOR_MEDIUM_SPRING_GREEN 0x0000FA9A -#define COLOR_MEDIUM_TURQUOISE 0x0048D1CC -#define COLOR_MEDIUM_VIOLET_RED 0x00C71585 -#define COLOR_MIDNIGHT_BLUE 0x00191970 -#define COLOR_MINT_CREAM 0x00F5FFFA -#define COLOR_MISTY_ROSE 0x00FFE4E1 -#define COLOR_MOCCASIN 0x00FFE4B5 -#define COLOR_NAVAJO_WHITE 0x00FFDEAD -#define COLOR_NAVY 0x00000080 -#define COLOR_OLD_LACE 0x00FDF5E6 -#define COLOR_OLIVE 0x00808000 -#define COLOR_OLIVE_DRAB 0x006B8E23 -#define COLOR_ORANGE 0x00FFA500 -#define COLOR_ORANGE_RED 0x00FF4500 -#define COLOR_ORCHID 0x00DA70D6 -#define COLOR_PALE_GOLDENROD 0x00EEE8AA -#define COLOR_PALE_GREEN 0x0098FB98 -#define COLOR_PALE_TURQUOISE 0x00AFEEEE -#define COLOR_PALE_VIOLET_RED 0x00DB7093 -#define COLOR_PAPAY_WHIP 0x00FFEFD5 -#define COLOR_PEACH_PUFF 0x00FFDAB9 -#define COLOR_PERU 0x00CD853F -#define COLOR_PINK 0x00FFC0CB -#define COLOR_PLUM 0x00DDA0DD -#define COLOR_POWDER_BLUE 0x00B0E0E6 -#define COLOR_PURPLE 0x00800080 -#define COLOR_RED 0x00FF0000 -#define COLOR_ROSY_BROWN 0x00BC8F8F -#define COLOR_ROYAL_BLUE 0x004169E1 -#define COLOR_SADDLE_BROWN 0x008B4513 -#define COLOR_SALMON 0x00FA8072 -#define COLOR_SANDY_BROWN 0x00F4A460 -#define COLOR_SEA_GREEN 0x002E8B57 -#define COLOR_SEASHELL 0x00FFF5EE -#define COLOR_SIENNA 0x00A0522D -#define COLOR_SILVER 0x00C0C0C0 -#define COLOR_SKY_BLUE 0x0087CEEB -#define COLOR_SLATE_BLUE 0x006A5ACD -#define COLOR_SLATE_GRAY 0x00708090 -#define COLOR_SNOW 0x00FFFAFA -#define COLOR_SPRING_GREEN 0x0000FF7F -#define COLOR_STEEL_BLUE 0x004682B4 -#define COLOR_TAN 0x00D2B48C -#define COLOR_TEAL 0x00008080 -#define COLOR_THISTLE 0x00D8BFD8 -#define COLOR_TOMATO 0x00FF6347 -#define COLOR_TURQUOISE 0x0040E0D0 -#define COLOR_VIOLET 0x00EE82EE -#define COLOR_WHEAT 0x00F5DEB3 -#define COLOR_WHITE 0x00FFFFFF -#define COLOR_WHITE_SMOKE 0x00F5F5F5 -#define COLOR_YELLOW 0x00FFFF00 -#define COLOR_YELLOW_GREEN 0x009ACD32 -#define COLOR_DARK_GREY COLOR_DARK_GRAY -#define COLOR_DARK_SLATE_GREY COLOR_DARK_SLATE_GRAY -#define COLOR_DIM_GREY COLOR_DIM_GRAY -#define COLOR_GREY COLOR_GRAY -#define COLOR_LIGHT_GREY COLOR_LIGHT_GRAY -#define COLOR_LIGHT_SLATE_GREY COLOR_LIGHT_SLATE_GRAY -#define COLOR_SLATE_GREY COLOR_SLATE_GRAY +#ifdef __cplusplus +namespace pros { +namespace c { +#endif + +/** + * \enum color_e_t + * @brief + * Enum of possible colors + * + * Contains common colors, all members are self descriptive. + */ +typedef enum color_e { + COLOR_ALICE_BLUE = 0x00F0F8FF, + COLOR_ANTIQUE_WHITE = 0x00FAEBD7, + COLOR_AQUA = 0x0000FFFF, + COLOR_AQUAMARINE = 0x007FFFD4, + COLOR_AZURE = 0x00F0FFFF, + COLOR_BEIGE = 0x00F5F5DC, + COLOR_BISQUE = 0x00FFE4C4, + COLOR_BLACK = 0x00000000, + COLOR_BLANCHED_ALMOND = 0x00FFEBCD, + COLOR_BLUE = 0x000000FF, + COLOR_BLUE_VIOLET = 0x008A2BE2, + COLOR_BROWN = 0x00A52A2A, + COLOR_BURLY_WOOD = 0x00DEB887, + COLOR_CADET_BLUE = 0x005F9EA0, + COLOR_CHARTREUSE = 0x007FFF00, + COLOR_CHOCOLATE = 0x00D2691E, + COLOR_CORAL = 0x00FF7F50, + COLOR_CORNFLOWER_BLUE = 0x006495ED, + COLOR_CORNSILK = 0x00FFF8DC, + COLOR_CRIMSON = 0x00DC143C, + COLOR_CYAN = 0x0000FFFF, + COLOR_DARK_BLUE = 0x0000008B, + COLOR_DARK_CYAN = 0x00008B8B, + COLOR_DARK_GOLDENROD = 0x00B8860B, + COLOR_DARK_GRAY = 0x00A9A9A9, + COLOR_DARK_GREY = COLOR_DARK_GRAY, + COLOR_DARK_GREEN = 0x00006400, + COLOR_DARK_KHAKI = 0x00BDB76B, + COLOR_DARK_MAGENTA = 0x008B008B, + COLOR_DARK_OLIVE_GREEN = 0x00556B2F, + COLOR_DARK_ORANGE = 0x00FF8C00, + COLOR_DARK_ORCHID = 0x009932CC, + COLOR_DARK_RED = 0x008B0000, + COLOR_DARK_SALMON = 0x00E9967A, + COLOR_DARK_SEA_GREEN = 0x008FBC8F, + COLOR_DARK_SLATE_GRAY = 0x002F4F4F, + COLOR_DARK_SLATE_GREY = COLOR_DARK_SLATE_GRAY, + COLOR_DARK_TURQUOISE = 0x0000CED1, + COLOR_DARK_VIOLET = 0x009400D3, + COLOR_DEEP_PINK = 0x00FF1493, + COLOR_DEEP_SKY_BLUE = 0x0000BFFF, + COLOR_DIM_GRAY = 0x00696969, + COLOR_DIM_GREY = COLOR_DIM_GRAY, + COLOR_DODGER_BLUE = 0x001E90FF, + COLOR_FIRE_BRICK = 0x00B22222, + COLOR_FLORAL_WHITE = 0x00FFFAF0, + COLOR_FOREST_GREEN = 0x00228B22, + COLOR_FUCHSIA = 0x00FF00FF, + COLOR_GAINSBORO = 0x00DCDCDC, + COLOR_GHOST_WHITE = 0x00F8F8FF, + COLOR_GOLD = 0x00FFD700, + COLOR_GOLDENROD = 0x00DAA520, + COLOR_GRAY = 0x00808080, + COLOR_GREY = COLOR_GRAY, + COLOR_GREEN = 0x00008000, + COLOR_GREEN_YELLOW = 0x00ADFF2F, + COLOR_HONEYDEW = 0x00F0FFF0, + COLOR_HOT_PINK = 0x00FF69B4, + COLOR_INDIAN_RED = 0x00CD5C5C, + COLOR_INDIGO = 0x004B0082, + COLOR_IVORY = 0x00FFFFF0, + COLOR_KHAKI = 0x00F0E68C, + COLOR_LAVENDER = 0x00E6E6FA, + COLOR_LAVENDER_BLUSH = 0x00FFF0F5, + COLOR_LAWN_GREEN = 0x007CFC00, + COLOR_LEMON_CHIFFON = 0x00FFFACD, + COLOR_LIGHT_BLUE = 0x00ADD8E6, + COLOR_LIGHT_CORAL = 0x00F08080, + COLOR_LIGHT_CYAN = 0x00E0FFFF, + COLOR_LIGHT_GOLDENROD_YELLOW = 0x00FAFAD2, + COLOR_LIGHT_GREEN = 0x0090EE90, + COLOR_LIGHT_GRAY = 0x00D3D3D3, + COLOR_LIGHT_GREY = COLOR_LIGHT_GRAY, + COLOR_LIGHT_PINK = 0x00FFB6C1, + COLOR_LIGHT_SALMON = 0x00FFA07A, + COLOR_LIGHT_SEA_GREEN = 0x0020B2AA, + COLOR_LIGHT_SKY_BLUE = 0x0087CEFA, + COLOR_LIGHT_SLATE_GRAY = 0x00778899, + COLOR_LIGHT_SLATE_GREY = COLOR_LIGHT_SLATE_GRAY, + COLOR_LIGHT_STEEL_BLUE = 0x00B0C4DE, + COLOR_LIGHT_YELLOW = 0x00FFFFE0, + COLOR_LIME = 0x0000FF00, + COLOR_LIME_GREEN = 0x0032CD32, + COLOR_LINEN = 0x00FAF0E6, + COLOR_MAGENTA = 0x00FF00FF, + COLOR_MAROON = 0x00800000, + COLOR_MEDIUM_AQUAMARINE = 0x0066CDAA, + COLOR_MEDIUM_BLUE = 0x000000CD, + COLOR_MEDIUM_ORCHID = 0x00BA55D3, + COLOR_MEDIUM_PURPLE = 0x009370DB, + COLOR_MEDIUM_SEA_GREEN = 0x003CB371, + COLOR_MEDIUM_SLATE_BLUE = 0x007B68EE, + COLOR_MEDIUM_SPRING_GREEN = 0x0000FA9A, + COLOR_MEDIUM_TURQUOISE = 0x0048D1CC, + COLOR_MEDIUM_VIOLET_RED = 0x00C71585, + COLOR_MIDNIGHT_BLUE = 0x00191970, + COLOR_MINT_CREAM = 0x00F5FFFA, + COLOR_MISTY_ROSE = 0x00FFE4E1, + COLOR_MOCCASIN = 0x00FFE4B5, + COLOR_NAVAJO_WHITE = 0x00FFDEAD, + COLOR_NAVY = 0x00000080, + COLOR_OLD_LACE = 0x00FDF5E6, + COLOR_OLIVE = 0x00808000, + COLOR_OLIVE_DRAB = 0x006B8E23, + COLOR_ORANGE = 0x00FFA500, + COLOR_ORANGE_RED = 0x00FF4500, + COLOR_ORCHID = 0x00DA70D6, + COLOR_PALE_GOLDENROD = 0x00EEE8AA, + COLOR_PALE_GREEN = 0x0098FB98, + COLOR_PALE_TURQUOISE = 0x00AFEEEE, + COLOR_PALE_VIOLET_RED = 0x00DB7093, + COLOR_PAPAY_WHIP = 0x00FFEFD5, + COLOR_PEACH_PUFF = 0x00FFDAB9, + COLOR_PERU = 0x00CD853F, + COLOR_PINK = 0x00FFC0CB, + COLOR_PLUM = 0x00DDA0DD, + COLOR_POWDER_BLUE = 0x00B0E0E6, + COLOR_PURPLE = 0x00800080, + COLOR_RED = 0x00FF0000, + COLOR_ROSY_BROWN = 0x00BC8F8F, + COLOR_ROYAL_BLUE = 0x004169E1, + COLOR_SADDLE_BROWN = 0x008B4513, + COLOR_SALMON = 0x00FA8072, + COLOR_SANDY_BROWN = 0x00F4A460, + COLOR_SEA_GREEN = 0x002E8B57, + COLOR_SEASHELL = 0x00FFF5EE, + COLOR_SIENNA = 0x00A0522D, + COLOR_SILVER = 0x00C0C0C0, + COLOR_SKY_BLUE = 0x0087CEEB, + COLOR_SLATE_BLUE = 0x006A5ACD, + COLOR_SLATE_GRAY = 0x00708090, + COLOR_SLATE_GREY = COLOR_SLATE_GRAY, + COLOR_SNOW = 0x00FFFAFA, + COLOR_SPRING_GREEN = 0x0000FF7F, + COLOR_STEEL_BLUE = 0x004682B4, + COLOR_TAN = 0x00D2B48C, + COLOR_TEAL = 0x00008080, + COLOR_THISTLE = 0x00D8BFD8, + COLOR_TOMATO = 0x00FF6347, + COLOR_TURQUOISE = 0x0040E0D0, + COLOR_VIOLET = 0x00EE82EE, + COLOR_WHEAT = 0x00F5DEB3, + COLOR_WHITE = 0x00FFFFFF, + COLOR_WHITE_SMOKE = 0x00F5F5F5, + COLOR_YELLOW = 0x00FFFF00, + COLOR_YELLOW_GREEN = 0x009ACD32, +} color_e_t; + + ///@} + +#ifdef __cplusplus +} // namespace c +} // namespace pros +#endif #endif // _PROS_COLORS_H_ diff --git a/include/pros/colors.hpp b/include/pros/colors.hpp index e3d0ba13..970c2cfa 100644 --- a/include/pros/colors.hpp +++ b/include/pros/colors.hpp @@ -11,12 +11,30 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License v. 2.0. If a copy of the MPL was not distributed with this * file You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-colors C++ Color API */ #ifndef _PROS_COLORS_HPP_ #define _PROS_COLORS_HPP_ namespace pros{ +/** + * \ingroup cpp-colors + */ + +/** + * \addtogroup cpp-colors + * @{ + */ + +/** + * \enum Color + * @brief + * Enum class of possible colors + * + * Contains common colors, all members are self descriptive. + */ enum class Color { alice_blue = 0x00F0F8FF, antique_white = 0x00FAEBD7, @@ -167,4 +185,6 @@ enum class Color { }; } // namespace pros + ///@} + #endif //_PROS_COLORS_HPP_ diff --git a/include/pros/device.h b/include/pros/device.h new file mode 100644 index 00000000..889e0085 --- /dev/null +++ b/include/pros/device.h @@ -0,0 +1,91 @@ +/** + * \file pros/device.h + * + * Contains functions for interacting with VEX devices. + * + * + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-device VEX Generic Device C API (For Advanced Users) + */ + +#ifndef _PROS_DEVICE_H_ +#define _PROS_DEVICE_H_ + +#include + +#ifdef __cplusplus +namespace pros::c { +extern "C" { +#endif + +/** + * \ingroup c-device + * \note These functions can be used for dynamic device instantiation. + */ + +/** + * \addtogroup c-device + * @{ + */ + +/** + * \enum v5_device_e + * \brief + * List of possible v5 devices + * + * This list contains all current V5 Devices, and mirrors V5_DeviceType from the + * api. + */ +typedef enum v5_device_e { + E_DEVICE_NONE = 0, ///< No device is plugged into the port + E_DEVICE_MOTOR = 2, ///< A motor is plugged into the port + E_DEVICE_ROTATION = 4, ///< A rotation sensor is plugged into the port + E_DEVICE_IMU = 6, ///< An inertial sensor is plugged into the port + E_DEVICE_DISTANCE = 7, ///< A distance sensor is plugged into the port + E_DEVICE_RADIO = 8, ///< A radio is plugged into the port + E_DEVICE_VISION = 11, ///< A vision sensor is plugged into the port + E_DEVICE_ADI = 12, ///< This port is an ADI expander + E_DEVICE_OPTICAL = 16, ///< An optical sensor is plugged into the port + E_DEVICE_GPS = 20, ///< A GPS sensor is plugged into the port + E_DEVICE_SERIAL = 129, ///< A serial device is plugged into the port + E_DEVICE_GENERIC __attribute__((deprecated("use E_DEVICE_SERIAL instead"))) = E_DEVICE_SERIAL, + E_DEVICE_UNDEFINED = 255 ///< The device type is not defined, or is not a valid device +} v5_device_e_t; + +/** + * Gets the type of device on given port. + * + * \return The device type as an enum. + * + * \b Example + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + * while (true) { + * v5_device_e_t pt = get_plugged_type(DEVICE_PORT); + * printf("device plugged type: {plugged type: %d}\n", pt); + * delay(20); + * } + * } + * \endcode +*/ +v5_device_e_t get_plugged_type(uint8_t port); + +///@} + +#ifdef __cplusplus +} // namespace c +} // namespace pros +#endif + +#endif // _PROS_DEVICE_H_ diff --git a/include/pros/device.hpp b/include/pros/device.hpp new file mode 100644 index 00000000..5055d489 --- /dev/null +++ b/include/pros/device.hpp @@ -0,0 +1,205 @@ +/** + * \file pros/device.hpp + * + * Base class for all smart devices. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-device VEX Generic Device C++ API (For Advanced Users) + */ + +#ifndef _PROS_DEVICE_HPP_ +#define _PROS_DEVICE_HPP_ + +#include "pros/misc.hpp" +#include "pros/rtos.hpp" + +namespace pros { +inline namespace v5 { +/** + * \ingroup cpp-device + * \note These functions can be used for dynamic device instantiation. + */ + +/** + * \addtogroup cpp-device + * @{ + */ + +/** + * \enum DeviceType + * \brief + * Enum of possible v5 devices. + * + * Contains all current V5 Devices. + */ +enum class DeviceType { + none = 0, ///< No device is plugged into the port + motor = 2, ///< A motor is plugged into the port + rotation = 4, ///< A rotation sensor is plugged into the port + imu = 6, ///< An inertial sensor is plugged into the port + distance = 7, ///< A distance sensor is plugged into the port + radio = 8, ///< A radio is plugged into the port + vision = 11, ///< A vision sensor is plugged into the port + adi = 12, ///< This port is an ADI expander + optical = 16, ///< An optical sensor is plugged into the port + gps = 20, ///< A GPS sensor is plugged into the port + serial = 129, ///< A serial device is plugged into the port + undefined = 255 ///< The device type is not defined, or is not a valid device +}; + +class Device { + public: + /** + * Creates a Device object. + * + * \param port The V5 port number from 1-21 + * + * \b Example + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + * Device device(DEVICE_PORT); + * } + * \endcode + */ + explicit Device(const std::uint8_t port); + + /** + * Gets the port number of the Smart Device. + * + * \return The smart device's port number. + * + * \b Example + * \code + * void opcontrol() { + * #define DEVICE_PORT 1 + * while (true) { + * Device device(DEVICE_PORT); + * printf("device plugged type: {port: %d}\n", device.get_port()); + * delay(20); + * } + * } + * \endcode + */ + std::uint8_t get_port(void) const; + + /** + * Checks if the device is installed. + * + * \return true if the corresponding device is installed, false otherwise. + * \b Example + * + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + * Device device(DEVICE_PORT); + * while (true) { + * printf("device plugged type: {is_installed: %d}\n", device.is_installed()); + * delay(20); + * } + * } + * \endcode + */ + virtual bool is_installed(); + + /** + * Gets the type of device. + * + * This function uses the following values of errno when an error state is + * reached: + * EACCES - Mutex of port cannot be taken (access denied). + * + * \return The device type as an enum. + * + * \b Example + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + Device device(DEVICE_PORT); + * while (true) { + * DeviceType dt = device.get_plugged_type(); + * printf("device plugged type: {plugged type: %d}\n", dt); + * delay(20); + * } + * } + * \endcode + */ + pros::DeviceType get_plugged_type() const; + + + /** + * Gets the type of device on a given port. + * + * This function uses the following values of errno when an error state is + * reached: + * EACCES - Mutex of port cannot be taken (access denied). + * + * \param port The V5 port number from 1-21 + * + * \return The device type as an enum. + * + * \b Example + * \code + * #define DEVICE_PORT 1 + * + * void opcontrol() { + * while (true) { + * DeviceType dt = pros::Device::get_plugged_type(DEVICE_PORT); + * printf("device plugged type: {plugged type: %d}\n", dt); + * delay(20); + * } + * } + * \endcode + */ + static pros::DeviceType get_plugged_type(std::uint8_t port); + + /** + * Gets all devices of a given device type. + * + * \param device_type The pros::DeviceType enum that matches the type of device desired. + * + * \return A vector of Device objects for the given device type. + * + * \b Example + * \code + * void opcontrol() { + * std::vector motor_devices = pros::Device::get_all_devices(pros::DeviceType::motor); // All Device objects are motors + * } + * \endcode + */ + + static std::vector get_all_devices(pros::DeviceType device_type = pros::DeviceType::undefined); + + protected: + /** + * Creates a Device object. + * + * \param port The V5 port number from 1-21 + * + * \param deviceType The type of the constructed device + */ + Device(const std::uint8_t port, const enum DeviceType deviceType) : + _port(port), + _deviceType(deviceType) {} + + protected: + const std::uint8_t _port; + const enum DeviceType _deviceType = pros::DeviceType::none; + + ///@} +}; +} // namespace v5 +} // namespace pros + +#endif diff --git a/include/pros/distance.h b/include/pros/distance.h index 783da8fd..63bcd417 100644 --- a/include/pros/distance.h +++ b/include/pros/distance.h @@ -1,19 +1,19 @@ /** * \file pros/distance.h + * \ingroup c-distance * * Contains prototypes for functions related to the VEX Distance sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/distance.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-distance VEX Distance Sensor C API */ #ifndef _PROS_DISTANCE_H_ @@ -28,6 +28,15 @@ namespace pros { namespace c { #endif +/** + * \ingroup c-distance + */ + +/** + * \addtogroup c-distance + * @{ + */ + /** * Get the currently measured distance from the sensor in mm * @@ -36,9 +45,21 @@ namespace c { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Distance Sensor * - * \param port The V5 Distance Sensor port number from 1-21 + * \param port The V5 Distance Sensor port number from 1-21 * \return The distance value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Distance Value: %d mm\n", distance_get(DISTANCE_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t distance_get(uint8_t port); @@ -57,6 +78,18 @@ int32_t distance_get(uint8_t port); * \param port The V5 Distance Sensor port number from 1-21 * \return The confidence value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Distance Confidence Value: %d\n", distance_get_confidence(DISTANCE_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t distance_get_confidence(uint8_t port); @@ -75,6 +108,18 @@ int32_t distance_get_confidence(uint8_t port); * \param port The V5 Distance Sensor port number from 1-21 * \return The size value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Distance Object Size: %d\n", distance_get_object_size(DISTANCE_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t distance_get_object_size(uint8_t port); @@ -89,9 +134,23 @@ int32_t distance_get_object_size(uint8_t port); * \param port The V5 Distance Sensor port number from 1-21 * \return The velocity value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Distance Object Velocity: %f\n", distance_get_object_velocity(DISTANCE_PORT)); + * delay(20); + * } + * } + * \endcode */ double distance_get_object_velocity(uint8_t port); +///@} + #ifdef __cplusplus } } diff --git a/include/pros/distance.hpp b/include/pros/distance.hpp index 0007035d..ae93928b 100644 --- a/include/pros/distance.hpp +++ b/include/pros/distance.hpp @@ -1,30 +1,40 @@ /** * \file pros/distance.hpp + * \ingroup cpp-distance * * Contains prototypes for the V5 Distance Sensor-related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/distance.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-distance VEX Distance Sensor C++ API */ #ifndef _PROS_DISTANCE_HPP_ #define _PROS_DISTANCE_HPP_ #include +#include +#include "pros/device.hpp" #include "pros/distance.h" namespace pros { -class Distance { +inline namespace v5 { +/** + * \ingroup cpp-distance + */ +class Distance : public Device { + /** + * \addtogroup cpp-distance + * @{ + */ public: /** * Creates a Distance Sensor object for the given port. @@ -36,9 +46,19 @@ class Distance { * * \param port * The V5 port number from 1-21 + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + * Distance distance(DISTANCE_PORT); + * } + * \endcode */ - explicit Distance(const std::uint8_t port); + Distance(const std::uint8_t port); + Distance(const Device& device) : Distance(device.get_port()){}; /** * Get the currently measured distance from the sensor in mm * @@ -48,10 +68,65 @@ class Distance { * ENODEV - The port cannot be configured as an Distance Sensor * * \return The distance value or PROS_ERR if the operation failed, setting - * errno. + * errno. Will return 9999 if the sensor can not detect an object. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance confidence: %d\n", distance.get()); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t get(); + /** + * Get the currently measured distance from the sensor in mm. + * \note This function is identical to get(). + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \return The distance value or PROS_ERR if the operation failed, setting + * errno. Will return 9999 if the sensor can not detect an object. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance confidence: %d\n", distance.get_distance()); + * delay(20); + * } + * } + * \endcode + */ + virtual std::int32_t get_distance(); + + /** + * Gets all distance sensors. + * + * \return A vector of Distance sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector distance_all = pros::Distance::get_all_devices(); // All distance sensors that are + * connected + * } + * \endcode + */ + static std::vector get_all_devices(); + /** * Get the confidence in the distance reading * @@ -66,6 +141,19 @@ class Distance { * * \return The confidence value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance confidence: %d\n", distance.get_confidence()); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t get_confidence(); @@ -82,7 +170,20 @@ class Distance { * ENODEV - The port cannot be configured as an Distance Sensor * * \return The size value or PROS_ERR if the operation failed, setting - * errno. + * errno. Will return -1 if the sensor is not able to determine object size. + * + * \b Example + * \code + * #define DISTANCE_PORT 1 + * + * void opcontrol() { + Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance confidence: %d\n", distance.get_object_size()); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t get_object_size(); @@ -96,19 +197,51 @@ class Distance { * * \return The velocity value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * + * void opcontrol() { + * Distance distance(DISTANCE_PORT); + * while (true) { + * printf("Distance Object velocity: %f\n", distance.get_object_velocity()); + * delay(20); + * } + * } + * \endcode */ virtual double get_object_velocity(); /** - * Gets the port number of the distance sensor. + * This is the overload for the << operator for printing to streams * - * \return The distance sensor's port number. + * Prints in format(this below is all in one line with no new line): + * Distance [port: (port number), distance: (distance), confidence: (confidence), + * object size: (object size), object velocity: (object velocity)] */ - std::uint8_t get_port(); + friend std::ostream& operator<<(std::ostream& os, pros::Distance& distance); private: - const std::uint8_t _port; + ///@} }; + +namespace literals { +/** + * Constructs a Distance sensor object from a literal ending in _dist via calling the constructor + * + * \return a pros::Distance for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Distance dist = 2_dist; //Makes an dist object on port 2 + * } + * \endcode + */ +const pros::Distance operator"" _dist(const unsigned long long int d); +} // namespace literals +} // namespace v5 } // namespace pros #endif diff --git a/include/pros/error.h b/include/pros/error.h index a7e4e54e..17dd6d3d 100644 --- a/include/pros/error.h +++ b/include/pros/error.h @@ -18,12 +18,25 @@ #include "limits.h" // Different Byte Size Errors + +/// @brief +/// Return This on Byte Sized Return Error #define PROS_ERR_BYTE (INT8_MAX) + +/// @brief +/// Return This on 2 Byte Sized Return Error #define PROS_ERR_2_BYTE (INT16_MAX) + +/// @brief +/// Return This on 4 Byte Sized Return Error #define PROS_ERR (INT32_MAX) + +/// @brief +/// Return This on 8 Byte Sized Return Error #define PROS_ERR_F (INFINITY) -// Return This on Success +/// @brief +/// Return This on Success (1) #define PROS_SUCCESS (1) #endif diff --git a/include/pros/ext_adi.h b/include/pros/ext_adi.h index f75ee051..421b1938 100644 --- a/include/pros/ext_adi.h +++ b/include/pros/ext_adi.h @@ -1,18 +1,20 @@ /** * \file pros/ext_adi.h + * \ingroup ext-adi * * Contains prototypes for interfacing with the 3-Wire Expander. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/adi.html to learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup ext-adi ADI Expander C API + * \note The internal ADI API can be found [here.](@ref c-adi) */ #ifndef _PROS_EXT_ADI_H_ @@ -36,6 +38,15 @@ namespace pros { namespace c { #endif +/** + * \ingroup ext-adi + */ + +/** + * \addtogroup ext-adi + * @{ + */ + /******************************************************************************/ /** General ADI Use Functions **/ /** **/ @@ -57,6 +68,19 @@ namespace c { * the configuration * * \return The ADI configuration for the given port + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * // Displays the value of E_ADI_ANALOG_IN + * printf("Port Type: %d\n", ext_adi_port_get_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * } + * \endcode */ adi_port_config_e_t ext_adi_port_get_config(uint8_t smart_port, uint8_t adi_port); @@ -75,6 +99,18 @@ adi_port_config_e_t ext_adi_port_get_config(uint8_t smart_port, uint8_t adi_port * the configuration * * \return The value stored for the given port + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * printf("Port Value: %d\n", ext_adi_get_value(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * } + * \endcode */ int32_t ext_adi_port_get_value(uint8_t smart_port, uint8_t adi_port); @@ -95,6 +131,17 @@ int32_t ext_adi_port_get_value(uint8_t smart_port, uint8_t adi_port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * ext_adi_port_set_config(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); + * } + * \endcode */ int32_t ext_adi_port_set_config(uint8_t smart_port, uint8_t adi_port, adi_port_config_e_t type); @@ -119,6 +166,18 @@ int32_t ext_adi_port_set_config(uint8_t smart_port, uint8_t adi_port, adi_port_c * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define DIGITAL_SENSOR_PORT 1 + * + * void initialize() { + * ext_adi_port_set_config(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT); + * ext_adi_set_value(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, HIGH); + * } + * \endcode */ int32_t ext_adi_port_set_value(uint8_t smart_port, uint8_t adi_port, int32_t value); @@ -147,6 +206,20 @@ int32_t ext_adi_port_set_value(uint8_t smart_port, uint8_t adi_port, int32_t val * The ADI port to calibrate (from 1-8, 'a'-'h', 'A'-'H') * * \return The average sensor value computed by this function + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * ext_adi_analog_calibrate(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT); + * printf("Calibrated Reading: %d\n", + * ext_adi_analog_read_calibrated(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * // All readings from then on will be calibrated + * } + * \endcode */ int32_t ext_adi_analog_calibrate(uint8_t smart_port, uint8_t adi_port); @@ -170,6 +243,20 @@ int32_t ext_adi_analog_calibrate(uint8_t smart_port, uint8_t adi_port); * * \return The analog sensor value, where a value of 0 reflects an input voltage * of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Reading: %d\n", ext_adi_analog_read(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_analog_read(uint8_t smart_port, uint8_t adi_port); @@ -195,6 +282,20 @@ int32_t ext_adi_analog_read(uint8_t smart_port, uint8_t adi_port); * * \return The difference of the sensor value from its calibrated default from * -4095 to 4095 + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Sensor Reading: %d\n", ext_adi_analog_read_calibrated(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_analog_read_calibrated(uint8_t smart_port, uint8_t adi_port); @@ -225,6 +326,22 @@ int32_t ext_adi_analog_read_calibrated(uint8_t smart_port, uint8_t adi_port); * * \return The difference of the sensor value from its calibrated default from * -16384 to 16384 + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * ext_adi_analog_calibrate(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT); + * + * printf("Sensor Reading: %d\n", ext_adi_analog_read_calibrated_HR(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_analog_read_calibrated_HR(uint8_t smart_port, uint8_t adi_port); @@ -248,6 +365,21 @@ int32_t ext_adi_analog_read_calibrated_HR(uint8_t smart_port, uint8_t adi_port); * The ADI port to read (from 1-8, 'a'-'h', 'A'-'H') * * \return True if the pin is HIGH, or false if it is LOW + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf(“Sensor Value: %dn”, + * ext_adi_digital_read(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_digital_read(uint8_t smart_port, uint8_t adi_port); @@ -275,6 +407,22 @@ int32_t ext_adi_digital_read(uint8_t smart_port, uint8_t adi_port); * * \return 1 if the button is pressed and had not been pressed * the last time this function was called, 0 otherwise. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * while (true) { + * if (ext_adi_digital_get_new_press(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT)) { + * // Toggle pneumatics or other state operations + * } + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_digital_get_new_press(uint8_t smart_port, uint8_t adi_port); @@ -299,6 +447,23 @@ int32_t ext_adi_digital_get_new_press(uint8_t smart_port, uint8_t adi_port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define DIGITAL_SENSOR_PORT 1 + * + * void opcontrol() { + * bool state = LOW; + * while (true) { + * state != state; + * ext_adi_digital_write(ADI_EXPANDER_PORT, DIGITAL_SENSOR_PORT, state); + * + * delay(5); // toggle the sensor value every 50ms + * } + * } + * \endcode */ int32_t ext_adi_digital_write(uint8_t smart_port, uint8_t adi_port, bool value); @@ -319,6 +484,17 @@ int32_t ext_adi_digital_write(uint8_t smart_port, uint8_t adi_port, bool value); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define ANALOG_SENSOR_PORT 1 + * + * void initialize() { + * ext_adi_pin_mode(ADI_EXPANDER_PORT, ANALOG_SENSOR_PORT, INPUT_ANALOG); + * } + * \endcode */ int32_t ext_adi_pin_mode(uint8_t smart_port, uint8_t adi_port, uint8_t mode); @@ -341,6 +517,19 @@ int32_t ext_adi_pin_mode(uint8_t smart_port, uint8_t adi_port, uint8_t mode); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 127); // Go full speed forward + * delay(1000); + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor + * } + * \endcode */ int32_t ext_adi_motor_set(uint8_t smart_port, uint8_t adi_port, int8_t speed); @@ -359,6 +548,22 @@ int32_t ext_adi_motor_set(uint8_t smart_port, uint8_t adi_port, int8_t speed); * The ADI port to get (from 1-8, 'a'-'h', 'A'-'H') * * \return The last set speed of the motor on the given port + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 # + * define MOTOR_PORT 1 + * + * void opcontrol() { + * ext_adi_motor_set(ADI_EXPANDER_PORT, + * MOTOR_PORT, 127); // Go full speed forward + * printf(“Commanded Motor Power: %dn”, + * ext_adi_motor_get(ADI_EXPANDER_PORT, MOTOR_PORT)); // Will display 127 + * delay(1000); + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor + * } + * \endcode */ int32_t ext_adi_motor_get(uint8_t smart_port, uint8_t adi_port); @@ -378,14 +583,27 @@ int32_t ext_adi_motor_get(uint8_t smart_port, uint8_t adi_port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define MOTOR_PORT 1 + * + * void opcontrol() { + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 127); // Go full speed forward + * delay(1000); + * ext_adi_motor_set(ADI_EXPANDER_PORT, MOTOR_PORT, 0); // Stop the motor + * ext_adi_motor_stop(ADI_EXPANDER_PORT, MOTOR_PORT); // use this instead + * } + * \endcode */ int32_t ext_adi_motor_stop(uint8_t smart_port, uint8_t adi_port); /** * Reference type for an initialized encoder. * - * This merely contains the port number for the encoder, unlike its use as an - * object to store encoder data in PROS 2. + * This merely contains the port number for the encoder. */ typedef int32_t ext_adi_encoder_t; @@ -405,6 +623,23 @@ typedef int32_t ext_adi_encoder_t; * * \return The signed and cumulative number of counts since the last start or * reset + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define PORT_TOP 1 #define PORT_BOTTOM 2 + * + * void opcontrol() { + * ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, + * PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * printf(“Encoder Value: %dn”, + * ext_adi_encoder_get(enc)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_encoder_get(ext_adi_encoder_t enc); @@ -429,6 +664,22 @@ int32_t ext_adi_encoder_get(ext_adi_encoder_t enc); * * \return An adi_encoder_t object to be stored and used for later calls to * encoder functions + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false); + * while (true) { + * printf("Encoder Value: %d\n", ext_adi_encoder_get(enc)); + * delay(5); + * } + * } + * \endcode */ ext_adi_encoder_t ext_adi_encoder_init(uint8_t smart_port, uint8_t adi_port_top, uint8_t adi_port_bottom, bool reverse); @@ -449,6 +700,20 @@ ext_adi_encoder_t ext_adi_encoder_init(uint8_t smart_port, uint8_t adi_port_top, * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false); + * delay(1000); // Move the encoder around in this time + * ext_adi_encoder_reset(enc); // The encoder is now zero again + * } + * \endcode */ int32_t ext_adi_encoder_reset(ext_adi_encoder_t enc); @@ -466,14 +731,27 @@ int32_t ext_adi_encoder_reset(ext_adi_encoder_t enc); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define ADI_EXPANDER_PORT 20 + * #define PORT_TOP 1 + * #define PORT_BOTTOM 2 + * + * void opcontrol() { + * ext_adi_encoder_t enc = ext_adi_encoder_init(ADI_EXPANDER_PORT, PORT_TOP, PORT_BOTTOM, false); + * // Use the encoder + * ext_adi_encoder_shutdown(enc); + * } + * \endcode */ int32_t ext_adi_encoder_shutdown(ext_adi_encoder_t enc); /** * Reference type for an initialized ultrasonic. * - * This merely contains the port number for the ultrasonic, unlike its use as an - * object to store encoder data in PROS 2. + * This merely contains the port number for the ultrasonic. */ typedef int32_t ext_adi_ultrasonic_t; @@ -495,6 +773,23 @@ typedef int32_t ext_adi_ultrasonic_t; * * \return The distance to the nearest object in m^-4 (10000 indicates 1 meter), * measured from the sensor's mounting points. + * + * \b Example + * \code + * + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", ext_adi_ultrasonic_get(ult)); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_ultrasonic_get(ext_adi_ultrasonic_t ult); @@ -518,6 +813,23 @@ int32_t ext_adi_ultrasonic_get(ext_adi_ultrasonic_t ult); * * \return An adi_ultrasonic_t object to be stored and used for later calls to * ultrasonic functions + * + * \b Example + * \code + * + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", ext_adi_ultrasonic_get(ult)); + * delay(5); + * } + * } + * \endcode */ ext_adi_ultrasonic_t ext_adi_ultrasonic_init(uint8_t smart_port, uint8_t adi_port_ping, uint8_t adi_port_echo); @@ -535,14 +847,31 @@ ext_adi_ultrasonic_t ext_adi_ultrasonic_init(uint8_t smart_port, uint8_t adi_por * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define PORT_PING 1 + * #define PORT_ECHO 2 + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_ultrasonic_t ult = ext_adi_ultrasonic_init(ADI_EXPANDER_PORT, PORT_PING, PORT_ECHO); + * while (true) { + * // Print the distance read by the ultrasonic + * printf("Distance: %d\n", ext_adi_ultrasonic_get(ult)); + * delay(5); + * } + * ext_adi_ultrasonic_shutdown(ult); + * } + * \endcode */ int32_t ext_adi_ultrasonic_shutdown(ext_adi_ultrasonic_t ult); /** * Reference type for an initialized gyroscope. * - * This merely contains the port number for the gyroscope, unlike its use as an - * object to store gyro data in PROS 2. + * This merely contains the port number for the gyroscope. * * (Might Be useless with the wire expander.) */ @@ -566,6 +895,23 @@ typedef int32_t ext_adi_gyro_t; * The adi_gyro_t object for which the angle will be returned * * \return The gyro angle in degrees. + * + * \b Example + * \code + * + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", ext_adi_gyro_get(gyro)); + * delay(5); + * } + * } + * \endcode */ double ext_adi_gyro_get(ext_adi_gyro_t gyro); @@ -593,6 +939,23 @@ double ext_adi_gyro_get(ext_adi_gyro_t gyro); * * \return An adi_gyro_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example + * \code + * + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", ext_adi_gyro_get(gyro)); + * delay(5); + * } + * } + * \endcode */ ext_adi_gyro_t ext_adi_gyro_init(uint8_t smart_port, uint8_t adi_port, double multiplier); @@ -610,6 +973,31 @@ ext_adi_gyro_t ext_adi_gyro_init(uint8_t smart_port, uint8_t adi_port, double mu * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER); + * uint32_t now = millis(); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", ext_adi_gyro_get(gyro)); + * + * if (millis() - now > 2000) { + * // Reset the gyro every 2 seconds + * ext_adi_gyro_reset(gyro); + * now = millis(); + * } + * + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_gyro_reset(ext_adi_gyro_t gyro); @@ -627,14 +1015,38 @@ int32_t ext_adi_gyro_reset(ext_adi_gyro_t gyro); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define GYRO_PORT 1 + * #define GYRO_MULTIPLIER 1 // Standard behavior + * #define ADI_EXPANDER_PORT 20 + * + * void opcontrol() { + * ext_adi_gyro_t gyro = ext_adi_gyro_init(ADI_EXPANDER_PORT, GYRO_PORT, GYRO_MULTIPLIER); + * uint32_t now = millis(); + * while (true) { + * // Print the gyro's heading + * printf("Heading: %lf\n", ext_adi_gyro_get(gyro)); + * + * if (millis() - now > 2000) { + * ext_adi_gyro_shutdown(gyro); + * // Shut down the gyro after two seconds + * break; + * } + * + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_gyro_shutdown(ext_adi_gyro_t gyro); /** * Reference type for an initialized potentiometer. * - * This merely contains the port number for the potentiometer, unlike its use as an - * object to store gyro data in PROS 2. + * This merely contains the port number for the potentiometer. */ typedef int32_t ext_adi_potentiometer_t; @@ -645,10 +1057,8 @@ typedef int32_t ext_adi_potentiometer_t; * reached: * ENXIO - The given value is not within the range of ADI Ports * EADDRINUSE - The port is not configured as a potentiometer - * - * \param smart_port - * The smart port with the adi expander (1-21) - * \param adi_port + * + * \param port * The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H') * \param potentiometer_type * An adi_potentiometer_type_e_t enum value specifying the potentiometer version type @@ -677,7 +1087,10 @@ ext_adi_potentiometer_t ext_adi_potentiometer_init(uint8_t smart_port, uint8_t a double ext_adi_potentiometer_get_angle(ext_adi_potentiometer_t potentiometer); /** - * Reference type for an initialized addressable led, which stores its smart and adi port. + * Reference type for an initialized addressable led. + * + * This merely contains the port number for the led, unlike its use as an + * object to store led data in the C++ API. */ typedef int32_t ext_adi_led_t; @@ -697,6 +1110,25 @@ typedef int32_t ext_adi_led_t; * * \return An ext_adi_led_t object containing the given port, or PROS_ERR if the * initialization failed. + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with a single color of red + * uint32_t buffer[1] = {0xFF0000}; + * + * while (true) { + * // Set the led to colors in the buffer + * ext_adi_led_set(led, buffer, 1); + * delay(5); + * } + * } + * \endcode */ ext_adi_led_t ext_adi_led_init(uint8_t smart_port, uint8_t adi_port); @@ -713,6 +1145,29 @@ ext_adi_led_t ext_adi_led_init(uint8_t smart_port, uint8_t adi_port); * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw * @param buffer_length length of buffer to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with a single color of red + * uint32_t buffer[1] = {0xFF0000}; + * + * while (true) { + * // Set the led to colors in the buffer + * ext_adi_led_set(led, buffer, 1); + * delay(5); + * + * // Clear the led + * ext_adi_led_clear_all(led, buffer, 1); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_clear_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length); @@ -729,6 +1184,25 @@ int32_t ext_adi_led_clear_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buff * @param buffer array of colors in format 0xRRGGBB, recommended that individual RGB value not to exceed 0x80 due to current draw * @param buffer_length length of buffer to clear * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with a single color of red + * uint32_t buffer[1] = {0xFF0000}; + * + * while (true) { + * // Set the led to colors in the buffer + * ext_adi_led_set(led, buffer, 1); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_set(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length); @@ -746,6 +1220,25 @@ int32_t ext_adi_led_set(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_len * @param buffer_length length of buffer to clear * @param color color to set all the led strip value to * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with a single color of red + * uint32_t buffer[1] = {0xFF0000}; + * + * while (true) { + * // Set the entire led strip to red + * ext_adi_led_set_all(led, buffer, 1, 0xFF0000); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_set_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color); @@ -764,6 +1257,25 @@ int32_t ext_adi_led_set_all(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer * @param color color to clear all the led strip to * @param pixel_position position of the pixel to clear (0 indexed) * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with multiple colors + * uint32_t buffer[3] = {0xFF0000, 0x00FF00, 0x0000FF}; + * + * while (true) { + * // Set the first pixel to red + * ext_adi_led_set_pixel(led, buffer, 3, 0xFF0000, 0); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_set_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t color, uint32_t pixel_position); @@ -781,9 +1293,34 @@ int32_t ext_adi_led_set_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buff * @param buffer_length length of the input buffer * @param pixel_position position of the pixel to clear (0 indexed) * @return PROS_SUCCESS if successful, PROS_ERR if not + * + * \b Example: + * \code + * #define SMART_PORT 1 + * #define ADI_PORT 'A' + * + * void opcontrol() { + * // Initialize a led on smart port 1 and adi port A + * ext_adi_led_t led = ext_adi_led_init(SMART_PORT, ADI_PORT); + * // Initialize a buffer with multiple colors + * uint32_t buffer[3] = {0xFF0000, 0x00FF00, 0x0000FF}; + * + * while (true) { + * // Set the first pixel to red + * ext_adi_led_set_pixel(led, buffer, 3, 0xFF0000, 0); + * delay(5); + * + * // Clear the first pixel + * ext_adi_led_clear_pixel(led, buffer, 3, 0); + * delay(5); + * } + * } + * \endcode */ int32_t ext_adi_led_clear_pixel(ext_adi_led_t led, uint32_t* buffer, uint32_t buffer_length, uint32_t pixel_position); +///@} + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/include/pros/gps.h b/include/pros/gps.h index 917f6938..c4d4fdfe 100644 --- a/include/pros/gps.h +++ b/include/pros/gps.h @@ -1,19 +1,20 @@ /** * \file pros/gps.h + * \ingroup c-gps * * Contains prototypes for functions related to the VEX GPS. * - * Visit https://pros.cs.purdue.edu/v5/api/c/gps.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-gps VEX GPS Sensor C API + * \note For a pros-specific usage guide on the GPS, please check out our article [here.](@ref gps) */ #ifndef _PROS_GPS_H_ @@ -25,26 +26,85 @@ #ifdef __cplusplus extern "C" { namespace pros { -namespace c { -#endif +#endif +/** + * \ingroup c-gps + */ + +/** + * \addtogroup c-gps + * @{ + */ + +/** + * \struct gps_position_s_t + */ +typedef struct __attribute__((__packed__)) gps_position_s { + /// X Position (meters) + double x; + /// Y Position (meters) + double y; +} gps_position_s_t; + +/** + * \struct gps_status_s_t + */ typedef struct __attribute__((__packed__)) gps_status_s { - double x; ///< X Position (meters) - double y; ///< Y Position (meters) - double pitch; ///< Percieved Pitch based on GPS + IMU - double roll; ///< Percieved Roll based on GPS + IMU - double yaw; ///< Percieved Yaw based on GPS + IMU + /// X Position (meters) + double x; + /// Y Position (meters) + double y; + /// Perceived Pitch based on GPS + IMU + double pitch; + /// Perceived Roll based on GPS + IMU + double roll; + /// Perceived Yaw based on GPS + IMU + double yaw; } gps_status_s_t; +/** + * \struct gps_orientation_s_t + */ +typedef struct __attribute__((__packed__)) gps_orientation_s { + /// Perceived Pitch based on GPS + IMU + double pitch; + /// Perceived Roll based on GPS + IMU + double roll; + /// Perceived Yaw based on GPS + IMU + double yaw; +} gps_orientation_s_t; + + +/** + * \struct gps_raw_s + */ struct gps_raw_s { - double x; ///< Percieved Pitch based on GPS + IMU - double y; ///< Percieved Roll based on GPS + IMU - double z; ///< Percieved Yaw based on GPS + IMU + /// Perceived Pitch based on GPS + IMU + double x; + /// Perceived Roll based on GPS + IMU + double y; + /// Perceived Yaw based on GPS + IMU + double z; }; +/** + * \struct gps_accel_s_t + * + */ typedef struct gps_raw_s gps_accel_s_t; + +/** + * \struct gps_gyro_s_t + * + */ typedef struct gps_raw_s gps_gyro_s_t; +#ifdef __cplusplus +namespace c { +#endif + + /** * Set the GPS's offset relative to the center of turning in meters, * as well as its initial position. @@ -69,6 +129,20 @@ typedef struct gps_raw_s gps_gyro_s_t; * Heading with 0 being north on the field, in degrees [0,360) going clockwise * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * #define X_OFFSET .225 + * #define Y_OFFSET .223 + * #define X_INITIAL 1.54 + * #define Y_INITIAL 1.14 + * #define HEADING_INITIAL 90 + * + * void initialize() { + * gps_initialize_full(GPS_PORT, X_OFFSET, Y_OFFSET, X_INITIAL, Y_INITIAL, HEADING_INITIAL); + * } + * \endcode */ int32_t gps_initialize_full(uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset); @@ -90,11 +164,22 @@ int32_t gps_initialize_full(uint8_t port, double xInitial, double yInitial, doub * Cartesian 4-Quadrant Y offset from center of turning (meters) * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * #define X_OFFSET -.225 + * #define Y_OFFSET .225 + * + * void initialize() { + * gps_set_offset(GPS_PORT, X_OFFSET, Y_OFFSET); + * } + * \endcode */ int32_t gps_set_offset(uint8_t port, double xOffset, double yOffset); /** - * Get the GPS's location relative to the center of turning/origin in meters. + * Get the GPS's cartesian location relative to the center of turning/origin in meters. * * This function uses the following values of errno when an error state is * reached: @@ -104,14 +189,25 @@ int32_t gps_set_offset(uint8_t port, double xOffset, double yOffset); * * \param port * The V5 GPS port number from 1-21 - * \param xOffset - * Pointer to cartesian 4-Quadrant X offset from center of turning (meters) - * \param yOffset - * Pointer to cartesian 4-Quadrant Y offset from center of turning (meters) - * \return 1 if the operation was successful or PROS_ERR if the operation + * \return A struct (gps_position_s_t) containing the X and Y values if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_position_s_t pos; + * + * while (true) { + * pos = gps_get_offset(GPS_PORT); + * screen_print(TEXT_MEDIUM, 1, "X Offset: %4d, Y Offset: %4d", pos.x, pos.y); + * delay(20); + * } + * } + * \endcode */ -int32_t gps_get_offset(uint8_t port, double* xOffset, double* yOffset); +gps_position_s_t gps_get_offset(uint8_t port); /** * Sets the robot's location relative to the center of the field in meters. @@ -132,6 +228,18 @@ int32_t gps_get_offset(uint8_t port, double* xOffset, double* yOffset); * Heading with 0 being north on the field, in degrees [0,360) going clockwise * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * #define X_INITIAL -1.15 + * #define Y_INITIAL 1.45 + * #define HEADING_INITIAL 90 + * + * void initialize() { + * gps_set_position(GPS_PORT, X_INITIAL, Y_INITIAL, HEADING_INITIAL); + * } + * \endcode */ int32_t gps_set_position(uint8_t port, double xInitial, double yInitial, double headingInitial); @@ -150,6 +258,19 @@ int32_t gps_set_position(uint8_t port, double xInitial, double yInitial, double * Data rate in milliseconds (Minimum: 5 ms) * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * #define GPS_DATA_RATE 5 + * + * void initialize() { + * gps_set_data_rate(GPS_PORT, GPS_DATA_RATE); + * while (true) { + * // Do something + * } + * } + * \endcode */ int32_t gps_set_data_rate(uint8_t port, uint32_t rate); @@ -167,6 +288,17 @@ int32_t gps_set_data_rate(uint8_t port, uint32_t rate); * * \return Possible RMS (Root Mean Squared) error in meters for GPS position. * If the operation failed, returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double error; + * error = gps_get_error(GPS_PORT); + * screen_print(TEXT_MEDIUM, 1, "Error: %4d", error); + * } + * \endcode */ double gps_get_error(uint8_t port); @@ -185,8 +317,56 @@ double gps_get_error(uint8_t port); * \return A struct (gps_status_s_t) containing values mentioned above. * If the operation failed, all the structure's members are filled with * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_status_s_t status; + * + * while (true) { + * status = gps_get_position_and_orientation(GPS_PORT); + * printf("X: %f, Y: %f, Pitch: %f, Roll: %f, Yaw: %f\n", status.x, status.y, status.pitch, status.roll, status.yaw); + * delay(20); + * } + * } + * \endcode */ -gps_status_s_t gps_get_status(uint8_t port); +gps_status_s_t gps_get_position_and_orientation(uint8_t port); + +/** + * Gets the x and y position on the field of the GPS in meters. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return A struct (gps_position_s_t) containing values mentioned above. + * If the operation failed, all the structure's members are filled with + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_position_s_t position; + * + * while (true) { + * position = gps_get_position(GPS_PORT); + * printf("X: %f, Y: %f\n", position.x, position.y); + * delay(20); + * } + * } + * \endcode + */ +gps_position_s_t gps_get_position(uint8_t port); /** * Gets the X position in meters of the robot relative to the starting position. @@ -202,8 +382,23 @@ gps_status_s_t gps_get_status(uint8_t port); * * \return The X position in meters. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double pos_x; + * + * while (true) { + * pos_x = gps_get_position_x(GPS_PORT); + * printf("X: %f\n", pos_x); + * delay(20); + * } + * } + * \endcode */ -double gps_get_x_position(uint8_t port); +double gps_get_position_x(uint8_t port); /** * Gets the Y position in meters of the robot relative to the starting position. @@ -219,11 +414,26 @@ double gps_get_x_position(uint8_t port); * * \return The Y position in meters. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double pos_y; + * + * while (true) { + * pos_y = gps_get_position_y(GPS_PORT); + * printf("Y: %f\n", pos_y); + * delay(20); + * } + * } + * \endcode */ -double gps_get_y_position(uint8_t port); +double gps_get_position_y(uint8_t port); /** - * Gets the pitch of the GPS in degrees relative to the starting orientation. + * Gets the pitch, roll, and yaw of the GPS relative to the starting orientation. * * This function uses the following values of errno when an error state is * reached: @@ -233,14 +443,62 @@ double gps_get_y_position(uint8_t port); * * \param port * The V5 GPS port number from 1-21 + * + * \return A struct (gps_orientation_s_t) containing values mentioned above. + * If the operation failed, all the structure's members are filled with + * PROS_ERR_F and errno is set. * - * \return The pitch in (-90,90] degree values. If the operation failed, + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_orientation_s_t orientation; + * + * while (true) { + * orientation = gps_get_orientation(GPS_PORT); + * printf("pitch: %f, roll: %f, yaw: %f\n", orientation.pitch, orientation.roll, orientation.yaw); + * delay(20); + * } + * } + * \endcode +*/ +gps_orientation_s_t gps_get_orientation(uint8_t port); + +/** + * Gets the pitch of the robot in degrees relative to the starting oreintation. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS port number from 1-21 + * + * \return The pitch in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double pitch; + * + * while (true) { + * pitch = gps_get_pitch(GPS_PORT); + * printf("pitch: %f\n", pitch); + * delay(20); + * } + * } + * \endcode */ double gps_get_pitch(uint8_t port); /** - * Gets the roll of the GPS in degrees relative to the starting orientation. + * Gets the roll of the robot in degrees relative to the starting oreintation. * * This function uses the following values of errno when an error state is * reached: @@ -251,13 +509,28 @@ double gps_get_pitch(uint8_t port); * \param port * The V5 GPS port number from 1-21 * - * \return The roll in (-180,180] degree values. If the operation failed, + * \return The roll in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double roll; + * + * while (true) { + * roll = gps_get_roll(GPS_PORT); + * printf("roll: %f\n", roll); + * delay(20); + * } + * } + * \endcode */ double gps_get_roll(uint8_t port); /** - * Gets the yaw of the GPS in degrees relative to the starting orientation. + * Gets the yaw of the robot in degrees relative to the starting oreintation. * * This function uses the following values of errno when an error state is * reached: @@ -268,8 +541,23 @@ double gps_get_roll(uint8_t port); * \param port * The V5 GPS port number from 1-21 * - * \return The yaw in (-180,180] degree values. If the operation failed, + * \return The yaw in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double yaw; + * + * while (true) { + * yaw = gps_get_yaw(GPS_PORT); + * printf("yaw: %f\n", yaw); + * delay(20); + * } + * } + * \endcode */ double gps_get_yaw(uint8_t port); @@ -287,6 +575,21 @@ double gps_get_yaw(uint8_t port); * * \return The heading in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double heading; + * + * while (true) { + * heading = gps_get_heading(GPS_PORT); + * printf("heading: %f\n", heading); + * delay(20); + * } + * } + * \endcode */ double gps_get_heading(uint8_t port); @@ -304,11 +607,26 @@ double gps_get_heading(uint8_t port); * * \return The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation * fails, returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double heading_raw; + * + * while (true) { + * heading_raw = gps_get_heading_raw(GPS_PORT); + * printf("heading_raw: %f\n", heading_raw); + * delay(20); + * } + * } + * \endcode */ double gps_get_heading_raw(uint8_t port); /** - * Gets the GPS sensor's elapsed rotation value + * Get the GPS's raw gyroscope values * * This function uses the following values of errno when an error state is * reached: @@ -318,60 +636,119 @@ double gps_get_heading_raw(uint8_t port); * * \param port * The V5 GPS port number from 1-21 - * \return The elased heading in degrees. If the operation fails, returns - * PROS_ERR_F and errno is set. + * \return A struct (gps_gyro_s_t) containing values mentioned above. + * If the operation failed, all the + * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_gyro_s_t gyro; + * + * while (true) { + * gyro = gps_get_gyro(GPS_PORT); + * printf("Gyro: %f %f %f\n", gyro.x, gyro.y, gyro.z); + * delay(20); + * } + * } + * \endcode */ -double gps_get_rotation(uint8_t port); +gps_gyro_s_t gps_get_gyro_rate(uint8_t port); /** - * Set the GPS sensor's rotation value to target value - * + * Get the GPS's raw gyroscope value in x-axis + * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a GPS * EAGAIN - The sensor is still calibrating - * + * * \param port * The V5 GPS port number from 1-21 - * \param target - * Target rotation value to set rotation value to - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t gps_set_rotation(uint8_t port, double target); + * \return The raw gyroscope value in x-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double gyro_x; + * + * while (true) { + * gyro_x = gps_get_gyro_x(GPS_PORT); + * printf("gyro_x: %f\n", gyro_x); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_gyro_rate_x(uint8_t port); /** - * Tare the GPS sensor's rotation value - * + * Get the GPS's raw gyroscope value in y-axis + * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a GPS * EAGAIN - The sensor is still calibrating - * + * * \param port * The V5 GPS port number from 1-21 - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t gps_tare_rotation(uint8_t port); + * \return The raw gyroscope value in y-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double gyro_y; + * + * while (true) { + * gyro_y = gps_get_gyro_y(GPS_PORT); + * printf("gyro_y: %f\n", gyro_y); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_gyro_rate_y(uint8_t port); /** - * Get the GPS's raw gyroscope values - * + * Get the GPS's raw gyroscope value in z-axis + * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a GPS * EAGAIN - The sensor is still calibrating - * + * * \param port * The V5 GPS port number from 1-21 - * \return The raw gyroscope values. If the operation failed, all the - * structure's members are filled with PROS_ERR_F and errno is set. - */ -gps_gyro_s_t gps_get_gyro_rate(uint8_t port); + * \return The raw gyroscope value in z-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double gyro_z; + * + * while (true) { + * gyro_z = gps_get_gyro_z(GPS_PORT); + * printf("gyro_z: %f\n", gyro_z); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_gyro_rate_z(uint8_t port); /** * Get the GPS's raw accelerometer values @@ -384,11 +761,120 @@ gps_gyro_s_t gps_get_gyro_rate(uint8_t port); * * \param port * The V5 GPS's port number from 1-21 - * \return The raw accelerometer values. If the operation failed, all the + * \return A struct (gps_accel_s_t) containing values mentioned above. + * If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_accel_s_t accel; + * + * while (true) { + * accel = gps_get_accel(GPS_PORT); + * printf("X: %f, Y: %f, Z: %f\n", accel.x, accel.y, accel.z); + * delay(20); + * } + * } + * \endcode */ gps_accel_s_t gps_get_accel(uint8_t port); +/** + * Get the GPS's raw accelerometer value in x-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS's port number from 1-21 + * \return The raw accelerometer value in x-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double accel_x; + * + * while (true) { + * accel_x = gps_get_accel_x(GPS_PORT); + * printf("accel_x: %f\n", accel_x); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_accel_x(uint8_t port); + +/** + * Get the GPS's raw accelerometer value in y-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS's port number from 1-21 + * \return The raw accelerometer value in y-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double accel_y; + * + * while (true) { + * accel_y = gps_get_accel_y(GPS_PORT); + * printf("accel_y: %f\n", accel_y); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_accel_y(uint8_t port); + +/** + * Get the GPS's raw accelerometer value in z-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 GPS's port number from 1-21 + * \return The raw accelerometer value in z-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double accel_z; + * + * while (true) { + * accel_z = gps_get_accel_z(GPS_PORT); + * printf("accel_z: %f\n", accel_z); + * delay(20); + * } + * } + * \endcode +*/ +double gps_get_accel_z(uint8_t port); + #ifdef __cplusplus } } diff --git a/include/pros/gps.hpp b/include/pros/gps.hpp index 7a321239..332e60b0 100644 --- a/include/pros/gps.hpp +++ b/include/pros/gps.hpp @@ -1,19 +1,20 @@ /** * \file pros/gps.hpp + * \ingroup cpp-gps * * Contains prototypes for functions related to the VEX GPS. * - * Visit https://pros.cs.purdue.edu/v5/api/cpp/gps.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-gps VEX GPS Sensor C API + * \note For a pros-specific usage guide on the GPS, please check out our article [here.](@ref gps) */ #ifndef _PROS_GPS_HPP_ @@ -22,26 +23,131 @@ #include #include +#include +#include "pros/device.hpp" #include "pros/gps.h" namespace pros { -class Gps { - const std::uint8_t _port; +inline namespace v5 { +/** + * \ingroup cpp-gps + * @{ + */ +class Gps : public Device { + /** + * \addtogroup cpp-gps + * @{ + */ public: - Gps(const std::uint8_t port) : _port(port){}; + /** + * Creates a GPS object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 port number from 1-21 + * \b Example: + * \code + * pros::Gps gps(1); + * \endcode + * + */ + Gps(const std::uint8_t port) : Device(port, DeviceType::gps){}; - Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial) : _port(port) { + Gps(const Device& device) : Gps(device.get_port()){}; + + /** + * Creates a GPS object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 port number from 1-21 + * \param xInitial + * Cartesian 4-Quadrant X initial position (meters) + * \param yInitial + * Cartesian 4-Quadrant Y initial position (meters) + * \param headingInitial + * Initial heading (degrees) + * + * \b Example: + * \code + * pros::Gps gps(1, 1.30, 1.20, 90); + * \endcode + * + */ + explicit Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial) + : Device(port, DeviceType::gps) { pros::c::gps_set_position(port, xInitial, yInitial, headingInitial); }; - Gps(const std::uint8_t port, double xOffset, double yOffset) : _port(port) { + /** + * Creates a GPS object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 port number from 1-21 + * \param xOffset + * Cartesian 4-Quadrant X offset from center of turning (meters) + * \param yOffset + * Cartesian 4-Quadrant Y offset from center of turning (meters) + * + * \b Example: + * \code + * pros::Gps gps(1, 1.30, 1.20); + * \endcode + * + */ + explicit Gps(const std::uint8_t port, double xOffset, double yOffset) : Device(port, DeviceType::gps) { pros::c::gps_set_offset(port, xOffset, yOffset); }; - Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset) - : _port(port) { + /** + * Creates a GPS object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 port number from 1-21 + * \param xInitial + * Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters) + * \param yInitial + * Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters) + * \param headingInitial + * Initial Heading, with 0 being North, 90 being East, 180 being South, and 270 being West (degrees) + * \param xOffset + * Cartesian 4-Quadrant X offset from center of turning (meters) + * \param yOffset + * Cartesian 4-Quadrant Y offset from center of turning (meters) + * + * \b Example: + * \code + * pros::Gps gps(1, 1.30, 1.20, 180, 1.30, 1.20); + * \endcode + * + */ + explicit Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset, + double yOffset) + : Device(port, DeviceType::gps) { pros::c::gps_initialize_full(port, xInitial, yInitial, headingInitial, xOffset, yOffset); }; @@ -52,8 +158,8 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \param xOffset * Cartesian 4-Quadrant X offset from center of turning (meters) @@ -67,6 +173,20 @@ class Gps { * Heading with 0 being north on the field, in degrees [0,360) going clockwise * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4); + * // this is equivalent to the above line + * gps.initialize_full(1.1, 1.2, 180, .4, .4); + * while (true) { + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t initialize_full(double xInitial, double yInitial, double headingInitial, double xOffset, double yOffset) const; @@ -77,8 +197,8 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \param xOffset * Cartesian 4-Quadrant X offset from center of turning (meters) @@ -86,26 +206,68 @@ class Gps { * Cartesian 4-Quadrant Y offset from center of turning (meters) * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4); + * // this is equivalent to the above line + * gps.set_offset(.4, .4); + * while (true) { + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t set_offset(double xOffset, double yOffset) const; /** - * Get the GPS's location relative to the center of turning/origin in meters. + + * Gets all GPS sensors. + * + * \return A vector of Gps sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector gps_all = pros::Gps::get_all_devices(); // All GPS sensors that are connected + * } + * \endcode + */ + static std::vector get_all_devices(); + + /** + * Get the GPS's cartesian location relative to the center of turning/origin in meters. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \param xOffset - * Pointer to cartesian 4-Quadrant X offset from center of turning (meters) - * \param yOffset - * Pointer to cartesian 4-Quadrant Y offset from center of turning (meters) - * \return 1 if the operation was successful or PROS_ERR if the operation + * \param port + * The V5 GPS port number from 1-21 + * \return A struct (gps_position_s_t) containing the X and Y values if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_position_s_t pos; + * Gps gps(GPS_PORT); + * while (true) { + * pos = gps.get_offset(); + * screen_print(TEXT_MEDIUM, 1, "X Offset: %4d, Y Offset: %4d", pos.x, pos.y); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_offset(double* xOffset, double* yOffset) const; + virtual pros::gps_position_s_t get_offset() const; /** * Sets the robot's location relative to the center of the field in meters. @@ -113,8 +275,8 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \param xInitial * Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters) @@ -124,6 +286,21 @@ class Gps { * Heading with 0 being north on the field, in degrees [0,360) going clockwise * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps.set_position(1.3, 1.4, 180); + * while (true) { + * printf("X: %f, Y: %f, Heading: %f\n", gps.get_position().x, + * gps.get_position().y, gps.get_position().heading); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t set_position(double xInitial, double yInitial, double headingInitial) const; @@ -133,13 +310,28 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \param rate * Data rate in milliseconds (Minimum: 5 ms) * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps.set_data_rate(10); + * while (true) { + * printf("X: %f, Y: %f, Heading: %f\n", gps.get_position().x, + * gps.get_position().y, gps.get_position().heading); + * delay(10); + * } + * } + * \endcode */ virtual std::int32_t set_data_rate(std::uint32_t rate) const; @@ -149,11 +341,23 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return Possible RMS (Root Mean Squared) error in meters for GPS position. * If the operation failed, returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * double error = gps.get_error(); + * printf("Error: %f\n", error); + * pros::delay(20); + * } + * \endcode */ virtual double get_error() const; @@ -163,30 +367,89 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * * \return A struct (gps_status_s_t) containing values mentioned above. * If the operation failed, all the structure's members are filled with * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps_status_s_t status; + * while (true) { + * status = gps.get_position_and_orientation(); + * printf("X: %f, Y: %f, Roll: %f, Pitch: %f, Yaw: %f\n", + * status.x, status.y, status.roll, status.pitch, status.yaw); + * delay(20); + * } + * } + * \endcode */ - virtual pros::c::gps_status_s_t get_status() const; + virtual pros::gps_status_s_t get_position_and_orientation() const; /** - * Gets the X position in meters of the robot relative to the starting position. + * Gets the x and y position on the field of the GPS in meters. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \return A struct (gps_position_s_t) containing values mentioned above. + * If the operation failed, all the structure's members are filled with + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps_position_s_t position; + * while (true) { + * position = gps.get_position(); + * printf("X: %f, Y: %f\n", position.x, position.y); + * delay(20); + * } + * } + * \endcode + */ + virtual pros::gps_position_s_t get_position() const; + + /** + * Gets the X position in meters of the robot relative to the starting position. * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The X position in meters. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double pos_x = gps.get_position_x(); + * printf("X: %f\n", pos_x); + * pros::delay(20); + * } + * } + * \endcode */ - virtual double get_x_position() const; + virtual double get_position_x() const; /** * Gets the Y position in meters of the robot relative to the starting position. @@ -194,57 +457,140 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. - * + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The Y position in meters. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double pos_y = gps.get_position_y(); + * printf("Y: %f\n", pos_y); + * pros::delay(20); + * } + * } + * \endcode */ - virtual double get_y_position() const; + virtual double get_position_y() const; /** - * Gets the pitch of the GPS in degrees relative to the starting orientation. + * Gets the pitch, roll, and yaw of the GPS relative to the starting orientation. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating + * + * \return A struct (gps_orientation_s_t) containing values mentioned above. + * If the operation failed, all the structure's members are filled with + * PROS_ERR_F and errno is set. * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * gps_orientation_s_t orientation; + * while (true) { + * orientation = gps.get_orientation(); + * printf("pitch: %f, roll: %f, yaw: %f\n", orientation.pitch, + * orientation.roll, orientation.yaw); + * delay(20); + * } + * } + * \endcode + */ + virtual pros::gps_orientation_s_t get_orientation() const; + + /** + * Gets the pitch of the robot in degrees relative to the starting oreintation. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The pitch in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double pitch = gps.get_pitch(); + * printf("pitch: %f\n", pitch); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_pitch() const; /** - * Gets the roll of the GPS in degrees relative to the starting orientation. + * Gets the roll of the robot in degrees relative to the starting oreintation. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. - * + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The roll in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double roll = gps.get_roll(); + * printf("roll: %f\n", roll); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_roll() const; /** - * Gets the yaw of the GPS in degrees relative to the starting orientation. + * Gets the yaw of the robot in degrees relative to the starting oreintation. * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. - * + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The yaw in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double yaw = gps.get_yaw(); + * printf("yaw: %f\n", yaw); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_yaw() const; @@ -254,12 +600,26 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * * \return The heading in [0,360) degree values. If the operation failed, * returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double heading = gps.get_heading(); + * printf("Heading: %f\n", heading); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_heading() const; @@ -269,71 +629,139 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * * \return The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation * fails, returns PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double heading = gps.get_heading_raw(); + * printf("Heading: %f\n", heading); + * pros::delay(20); + * } + * } + * \endcode */ virtual double get_heading_raw() const; /** - * Gets the GPS sensor's elapsed rotation value + * Get the GPS's raw gyroscope value in z-axis * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \return The elased heading in degrees. If the operation fails, returns + * \return The raw gyroscope value in z-axis. If the operation fails, returns * PROS_ERR_F and errno is set. + * + \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double gyro_z = gps.get_gyro_z(); + * printf("gyro_z: %f\n", gyro_z); + * pros::delay(20); + * } + * } + * \endcode */ - virtual double get_rotation() const; + virtual pros::gps_gyro_s_t get_gyro_rate() const; /** - * Set the GPS sensor's rotation value to target value + * Get the GPS's raw gyroscope value in x-axis * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \param target - * Target rotation value to set rotation value to - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \return The raw gyroscope value in x-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double gyro_x = gps.get_gyro_x(); + * printf("gyro_x: %f\n", gyro_x); + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t set_rotation(double target) const; + virtual double get_gyro_rate_x() const; /** - * Tare the GPS sensor's rotation value + * Get the GPS's raw gyroscope value in y-axis * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \return The raw gyroscope value in y-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double gyro_y = gps.get_gyro_y(); + * printf("gyro_y: %f\n", gyro_y); + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t tare_rotation() const; + virtual double get_gyro_rate_y() const; /** - * Get the GPS's raw gyroscope values + * Get the GPS's raw gyroscope value in z-axis * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS. - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as a GPS + * EAGAIN - The sensor is still calibrating * - * \return The raw gyroscope values. If the operation failed, all the - * structure's members are filled with PROS_ERR_F and errno is set. - */ - virtual pros::c::gps_gyro_s_t get_gyro_rate() const; + * \return The raw gyroscope value in z-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double gyro_z = gps.get_gyro_z(); + * printf("gyro_z: %f\n", gyro_z); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_gyro_rate_z() const; /** * Get the GPS's raw accelerometer values @@ -341,19 +769,169 @@ class Gps { * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a GPS - * EAGAIN - The sensor is still calibrating. + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating * - * \param port - * The V5 GPS's port number from 1-21 * \return The raw accelerometer values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. */ - virtual pros::c::gps_accel_s_t get_accel() const; + virtual pros::gps_accel_s_t get_accel() const; + + /** + * Get the GPS's raw accelerometer value in x-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \return The raw accelerometer value in x-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double accel_x = gps.get_accel_x(); + * printf("accel_x: %f\n", accel_x); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_accel_x() const; + /** + * Get the GPS's raw accelerometer value in y-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \return The raw accelerometer value in y-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double accel_y = gps.get_accel_y(); + * printf("accel_y: %f\n", accel_y); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_accel_y() const; + + /** + * Get the GPS's raw accelerometer value in z-axis + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an GPS + * EAGAIN - The sensor is still calibrating + * + * \return The raw accelerometer value in z-axis. If the operation fails, returns + * PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * double accel_z = gps.get_accel_z(); + * printf("accel_z: %f\n", accel_z); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_accel_z() const; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format: + * Gps [port: gps._port, x: (x position), y: (y position), heading: (gps heading), rotation: (gps rotation)] + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * std::cout << gps << std::endl; + * pros::delay(20); + * } + * } + * \endcode + */ + friend std::ostream& operator<<(std::ostream& os, const pros::Gps& gps); + + /** + * Gets a gps sensor that is plugged in to the brain + * + * \note The first time this function is called it returns the gps sensor at the lowest port + * If this function is called multiple times, it will cycle through all the ports. + * For example, if you have 1 gps sensor on the robot + * this function will always return a gps sensor object for that port. + * If you have 2 gps sensors, all the odd numered calls to this function will return objects + * for the lower port number, + * all the even number calls will return gps objects for the higher port number + * + * + * This functions uses the following values of errno when an error state is + * reached: + * ENODEV - No gps sensor is plugged into the brain + * + * \return A gps object corresponding to a port that a gps sensor is connected to the brain + * If no gps sensor is plugged in, it returns a gps sensor on port PROS_ERR_BYTE + * + */ + static Gps get_gps(); + ///@} }; // Gps Class +namespace literals { +/** + * Constructs a Gps object with the given port number + * + * \b Example + * \code + * using namespace literals; + * + * void opcontrol() { + * pros::Gps gps = 1_gps; + * while (true) { + * pos = gps.get_position(); + * screen_print(TEXT_MEDIUM, 1, "X Position: %4d, Y Position: %4d", pos.x, pos.y); + * delay(20); + * } + * } + * \endcode + */ +const pros::Gps operator""_gps(const unsigned long long int g); +} // namespace literals + +/// @brief +/// Alias for Gps is GPS for user convenience. using GPS = Gps; +} // namespace v5 } // namespace pros + #endif diff --git a/include/pros/imu.h b/include/pros/imu.h index d87508c4..63cc7384 100644 --- a/include/pros/imu.h +++ b/include/pros/imu.h @@ -1,19 +1,19 @@ /** * \file pros/imu.h + * \ingroup c-imu * * Contains prototypes for functions related to the VEX Inertial sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-imu VEX Inertial Sensor C API */ #ifndef _PROS_IMU_H_ @@ -25,24 +25,44 @@ #ifdef __cplusplus extern "C" { namespace pros { -namespace c { #endif +/** + * \ingroup c-imu + * */ + +/** + * \addtogroup c-imu + * @{ + */ + +/** + * \enum imu_status_e_t + * @brief Indicates IMU status. + */ typedef enum imu_status_e { - E_IMU_STATUS_READY = 0, // IMU is connected but not currently calibrating - E_IMU_STATUS_CALIBRATING = 1, // IMU is calibrating - E_IMU_STATUS_ERROR = 0xFF, // NOTE: used for returning an error from the get_status function, not that the IMU is - // necessarily in an error state + E_IMU_STATUS_READY = 0, // IMU is connected but not currently calibrating + /** The IMU is calibrating */ + E_IMU_STATUS_CALIBRATING = 1, + /** Used to indicate that an error state was reached in the imu_get_status function,\ + not that the IMU is necessarily in an error state */ + E_IMU_STATUS_ERROR = 0xFF, } imu_status_e_t; typedef enum imu_orientation_e { - E_IMU_Z_UP = 0, // IMU has the Z axis UP (VEX Logo facing DOWN) - E_IMU_Z_DOWN = 1, // IMU has the Z axis DOWN (VEX Logo facing UP) - E_IMU_X_UP = 2, // IMU has the X axis UP - E_IMU_X_DOWN = 3, // IMU has the X axis DOWN - E_IMU_Y_UP = 4, // IMU has the Y axis UP - E_IMU_Y_DOWN = 5, // IMU has the Y axis DOWN + E_IMU_Z_UP = 0, // IMU has the Z axis UP (VEX Logo facing DOWN) + E_IMU_Z_DOWN = 1, // IMU has the Z axis DOWN (VEX Logo facing UP) + E_IMU_X_UP = 2, // IMU has the X axis UP + E_IMU_X_DOWN = 3, // IMU has the X axis DOWN + E_IMU_Y_UP = 4, // IMU has the Y axis UP + E_IMU_Y_DOWN = 5, // IMU has the Y axis DOWN + E_IMU_ORIENTATION_ERROR = 0xFF // NOTE: used for returning an error from the get_physical_orientation function, not + // that the IMU is necessarily in an error state } imu_orientation_e_t; + +/** + * \struct quaternion_s_t + */ typedef struct __attribute__((__packed__)) quaternion_s { double x; double y; @@ -50,21 +70,44 @@ typedef struct __attribute__((__packed__)) quaternion_s { double w; } quaternion_s_t; +/** + * \struct imu_raw_s + * + */ struct imu_raw_s { double x; double y; double z; }; +/** + * \struct imu_gyro_s_t + * + */ typedef struct imu_raw_s imu_gyro_s_t; + +/** + * \struct imu_accel_s_t + * + */ typedef struct imu_raw_s imu_accel_s_t; +/** + * \struct euler_s_t + * + */ typedef struct __attribute__((__packed__)) euler_s { double pitch; double roll; double yaw; } euler_s_t; +#ifdef __cplusplus +namespace c { +#endif +/** + * \def IMU_MINIMUM_DATA_RATE + */ #ifdef PROS_USE_SIMPLE_NAMES #ifdef __cplusplus #define IMU_STATUS_CALIBRATING pros::E_IMU_STATUS_CALIBRATING @@ -94,6 +137,24 @@ typedef struct __attribute__((__packed__)) euler_s { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void initialize() { + * imu_reset(IMU_PORT); + * int time = millis(); + * int iter = 0; + * while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) { + * printf("IMU calibrating... %d\n", iter); + * iter += 10; + * delay(10); + * } + * // should print about 2000 ms + * printf("IMU is done calibrating (took %d ms)\n", iter - time); + * } + * \endcode */ int32_t imu_reset(uint8_t port); @@ -118,7 +179,6 @@ int32_t imu_reset(uint8_t port); * failed (timing out or port claim failure), setting errno. */ int32_t imu_reset_blocking(uint8_t port); - /** * Set the Inertial Sensor's refresh interval in milliseconds. * @@ -142,6 +202,11 @@ int32_t imu_reset_blocking(uint8_t port); * \param rate The data refresh interval in milliseconds * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * \endcode */ int32_t imu_set_data_rate(uint8_t port, uint32_t rate); @@ -162,6 +227,18 @@ int32_t imu_set_data_rate(uint8_t port, uint32_t rate); * The V5 Inertial Sensor port number from 1-21 * \return The degree value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU get rotation: %f degrees\n", imu_get_rotation(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ double imu_get_rotation(uint8_t port); @@ -183,6 +260,18 @@ double imu_get_rotation(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return The degree value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU get heading: %f degrees\n", imu_get_heading(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ double imu_get_heading(uint8_t port); @@ -200,6 +289,19 @@ double imu_get_heading(uint8_t port); * \return The quaternion representing the sensor's orientation. If the * operation failed, all the quaternion's members are filled with PROS_ERR_F and * errno is set. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * quaternion_s_t qt = imu_get_quaternion(IMU_PORT); + * printf("IMU quaternion: {x: %f, y: %f, z: %f, w: %f}\n", qt.x, qt.y, qt.z, qt.w); + * delay(20); + * } + * } + * \endcode */ quaternion_s_t imu_get_quaternion(uint8_t port); @@ -217,11 +319,24 @@ quaternion_s_t imu_get_quaternion(uint8_t port); * \return The Euler angles representing the sensor's orientation. If the * operation failed, all the structure's members are filled with PROS_ERR_F and * errno is set. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * euler_s_t eu = imu_get_euler(IMU_PORT); + * printf("IMU euler angles: {pitch: %f, roll: %f, yaw: %f}\n", eu.pitch, eu.roll, eu.yaw); + * delay(20); + * } + * } + * \endcode */ euler_s_t imu_get_euler(uint8_t port); /** - * Get the Inertial Sensor's pitch angle bounded by (-180,180) + * Get the Inertial Sensor's raw gyroscope values * * This function uses the following values of errno when an error state is * reached: @@ -233,11 +348,23 @@ euler_s_t imu_get_euler(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return The pitch angle, or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU pitch: %f\n", imu_get_pitch(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ -double imu_get_pitch(uint8_t port); +imu_gyro_s_t imu_get_gyro_rate(uint8_t port); /** - * Get the Inertial Sensor's roll angle bounded by (-180,180) + * Get the Inertial Sensor's raw acceleroneter values * * This function uses the following values of errno when an error state is * reached: @@ -248,11 +375,23 @@ double imu_get_pitch(uint8_t port); * \param port * The V5 Inertial Sensor port number from 1-21 * \return The roll angle, or PROS_ERR_F if the operation failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU roll: %f\n", imu_get_roll(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ -double imu_get_roll(uint8_t port); +imu_accel_s_t imu_get_accel(uint8_t port); /** - * Get the Inertial Sensor's yaw angle bounded by (-180,180) + * Get the Inertial Sensor's status * * This function uses the following values of errno when an error state is * reached: @@ -263,11 +402,25 @@ double imu_get_roll(uint8_t port); * \param port * The V5 Inertial Sensor port number from 1-21 * \return The yaw angle, or PROS_ERR_F if the operation failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("IMU yaw: %f\n", imu_get_yaw(IMU_PORT)); + * delay(20); + * } + * } + * \endcode */ -double imu_get_yaw(uint8_t port); +imu_status_e_t imu_get_status(uint8_t port); +// Value set functions: /** - * Get the Inertial Sensor's raw gyroscope values + * Sets the current reading of the Inertial Sensor's euler values to + * target euler values. Will default to +/- 180 if target exceeds +/- 180. * * This function uses the following values of errno when an error state is * reached: @@ -279,11 +432,24 @@ double imu_get_yaw(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return The raw gyroscope values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * int32_t val = imu_set_euler(IMU_PORT, {45, 60, 90}); + * printf("IMU : {gyro vals: %d}\n", val); + * delay(20); + * } + * } + * \endcode */ -imu_gyro_s_t imu_get_gyro_rate(uint8_t port); +int32_t imu_set_euler(uint8_t port, euler_s_t target); /** - * Get the Inertial Sensor's raw acceleroneter values + * Get the Inertial Sensor's pitch angle bounded by (-180,180) * * This function uses the following values of errno when an error state is * reached: @@ -295,29 +461,80 @@ imu_gyro_s_t imu_get_gyro_rate(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return The raw accelerometer values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * imu_accel_s_t accel = imu_get_accel(IMU_PORT); + * printf("IMU accel values: {x: %f, y: %f, z: %f}\n", accel.x, accel.y, accel.z); + * delay(20); + * } + * } + * \endcode */ -imu_accel_s_t imu_get_accel(uint8_t port); +double imu_get_pitch(uint8_t port); /** - * Get the Inertial Sensor's status + * Get the Inertial Sensor's roll angle bounded by (-180,180) * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Inertial Sensor + * EAGAIN - The sensor is still calibrating * * \param port * The V5 Inertial Sensor port number from 1-21 * \return The Inertial Sensor's status code, or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void initialize() { + * imu_reset(IMU_PORT); + * int time = millis(); + * int iter = 0; + * while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) { + * printf("IMU calibrating... %d\n", iter); + * iter += 10; + * delay(10); + * } + * // should print about 2000 ms + * printf("IMU is done calibrating (took %d ms)\n", iter - time); + * } + * \endcode */ -imu_status_e_t imu_get_status(uint8_t port); +double imu_get_roll(uint8_t port); + +/** + * Get the Inertial Sensor's yaw angle bounded by (-180,180) + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Inertial Sensor + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 Inertial Sensor port number from 1-21 + * \return The yaw angle, or PROS_ERR_F if the operation failed, setting errno. + */ +double imu_get_yaw(uint8_t port); // NOTE: not used // void imu_set_mode(uint8_t port, uint32_t mode); // uint32_t imu_get_mode(uint8_t port); -// Value reset functions: +/** + * \name Value Reset Functions + * @{ + */ + /** * Resets the current reading of the Inertial Sensor's heading to zero * @@ -331,6 +548,20 @@ imu_status_e_t imu_get_status(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_heading(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_heading(uint8_t port); @@ -347,6 +578,20 @@ int32_t imu_tare_heading(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_rotation(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_rotation(uint8_t port); @@ -363,6 +608,18 @@ int32_t imu_tare_rotation(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_pitch(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_pitch(uint8_t port); @@ -379,6 +636,20 @@ int32_t imu_tare_pitch(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_roll(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_roll(uint8_t port); @@ -395,6 +666,20 @@ int32_t imu_tare_roll(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_yaw(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_yaw(uint8_t port); @@ -411,6 +696,20 @@ int32_t imu_tare_yaw(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare_euler(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare_euler(uint8_t port); @@ -427,10 +726,30 @@ int32_t imu_tare_euler(uint8_t port); * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_tare(IMU_PORT); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_tare(uint8_t port); -// Value set functions: +/** @} */ + +/** + * \name Value Set Functions + * @{ + */ + /** * Sets the current reading of the Inertial Sensor's euler values to * target euler values. Will default to +/- 180 if target exceeds +/- 180. @@ -447,6 +766,20 @@ int32_t imu_tare(uint8_t port); * Target euler values for the euler values to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_euler(IMU_PORT, {45,45,45}); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_euler(uint8_t port, euler_s_t target); @@ -465,6 +798,20 @@ int32_t imu_set_euler(uint8_t port, euler_s_t target); * Target value for the rotation value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_rotation(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_rotation(uint8_t port, double target); @@ -484,6 +831,20 @@ int32_t imu_set_rotation(uint8_t port, double target); * Target value for the heading value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_heading(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_heading(uint8_t port, double target); @@ -503,6 +864,20 @@ int32_t imu_set_heading(uint8_t port, double target); * Target value for the pitch value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_pitch(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_pitch(uint8_t port, double target); @@ -522,6 +897,20 @@ int32_t imu_set_pitch(uint8_t port, double target); * Target value for the roll value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_roll(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_roll(uint8_t port, double target); @@ -541,6 +930,19 @@ int32_t imu_set_roll(uint8_t port, double target); * Target value for the yaw value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define IMU_PORT 1void opcontrol() { + * + * while (true) { + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * imu_set_yaw(IMU_PORT, 45); + * } + * pros::delay(20); + * } + * } + * \endcode */ int32_t imu_set_yaw(uint8_t port, double target); @@ -559,6 +961,10 @@ int32_t imu_set_yaw(uint8_t port, double target); */ imu_orientation_e_t imu_get_physical_orientation(uint8_t port); +/** @} */ + +/** @} */ + #ifdef __cplusplus } } diff --git a/include/pros/imu.hpp b/include/pros/imu.hpp index 3f6f3933..19240220 100644 --- a/include/pros/imu.hpp +++ b/include/pros/imu.hpp @@ -1,34 +1,114 @@ /** * \file pros/imu.hpp + * \ingroup cpp-imu * * Contains prototypes for functions related to the VEX Inertial sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-imu VEX Inertial Sensor C++ API */ #ifndef _PROS_IMU_HPP_ #define _PROS_IMU_HPP_ #include +#include +#include "pros/device.hpp" #include "pros/imu.h" namespace pros { -class Imu { - const std::uint8_t _port; +/** + * \ingroup cpp-imu + * */ + +/** + * \addtogroup cpp-imu + * @{ + */ + +/** + * \enum Imu_Status + * @brief Indicates IMU status. + */ + +enum class ImuStatus { + ready = 0, + /** The IMU is calibrating */ + calibrating = 19, + /** Used to indicate that an error state was reached in the imu_get_status function,\ + not that the IMU is necessarily in an error state */ + error = 0xFF, +}; + +inline namespace v5 { +/** + * \ingroup cpp-imu + */ +class Imu : public Device { + /** + * \addtogroup cpp-imu + * ///@{ + */ public: - Imu(const std::uint8_t port) : _port(port){}; + /** + * Creates an Imu object for the given port + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * + * \param port + * The V5 Inertial Sensor port number from 1-21 + * + * \b Example + * \code + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Do something with the sensor data + * } + * } + * \endcode + */ + + + Imu(const std::uint8_t port) : Device(port, DeviceType::imu){}; + + Imu(const Device& device) : Imu(device.get_port()){}; + /** + * Gets a IMU sensor that is plugged in to the brain + * + * \note The first time this function is called it returns the IMU sensor at the lowest port + * If this function is called multiple times, it will cycle through all the ports. + * For example, if you have 1 IMU sensor on the robot + * this function will always return a IMU sensor object for that port. + * If you have 2 IMU sensors, all the odd numered calls to this function will return objects + * for the lower port number, + * all the even number calls will return IMU objects for the higher port number + * + * + * This functions uses the following values of errno when an error state is + * reached: + * ENODEV - No IMU sensor is plugged into the brain + * + * \return A IMU object corresponding to a port that a IMU sensor is connected to the brain + * If no IMU sensor is plugged in, it returns a IMU sensor on port PROS_ERR_BYTE + * + */ + static Imu get_imu(); /** * Calibrate IMU * @@ -48,6 +128,19 @@ class Imu { * Whether this function blocks during calibration. * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * imu.calibrate(); + * // Block until calibration is complete + * imu.reset(true); + * } + * \endcode */ virtual std::int32_t reset(bool blocking = false) const; /** @@ -68,12 +161,51 @@ class Imu { * ENODEV - The port cannot be configured as an Inertial Sensor * EAGAIN - The sensor is still calibrating * - * \param rate - * The data refresh interval in milliseconds + * \param rate The data refresh interval in milliseconds * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the refresh rate to 5ms + * std::int32_t status = imu.set_data_rate(5); + * delay(20); + * + * // Check if the operation was successful + * if (status == PROS_ERR) { + * // Do something with the error + * } + * + * // Do something with the sensor data + * } + * } + * \endcode */ virtual std::int32_t set_data_rate(std::uint32_t rate) const; + + + /** + * Gets all IMU sensors. + * + * \return A vector of Imu sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector imu_all = pros::Imu::get_all_devices(); // All IMU sensors that are connected + * } + * \endcode + */ + + static std::vector get_all_devices(); + /** * Get the total number of degrees the Inertial Sensor has spun about the z-axis * @@ -91,6 +223,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The degree value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the total number of degrees the sensor has spun + * printf("Total rotation: %f\n", imu.get_rotation()); + * delay(20); + * } + * } + * \endcode */ virtual double get_rotation() const; /** @@ -111,6 +259,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The degree value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's heading + * printf("Heading: %f\n", imu.get_heading()); + * delay(20); + * } + * } + * \endcode */ virtual double get_heading() const; /** @@ -127,8 +291,25 @@ class Imu { * \return The quaternion representing the sensor's orientation. If the * operation failed, all the quaternion's members are filled with PROS_ERR_F and * errno is set. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's quaternion + * pros::quaternion_s_t quat = imu.get_quaternion(); + * cout << "Quaternion: " << quat.w << ", " << quat.x << ", " << quat.y << ", " << quat.z << endl; + * delay(20); + * } + * } + * \endcode */ - virtual pros::c::quaternion_s_t get_quaternion() const; + virtual pros::quaternion_s_t get_quaternion() const; /** * Get the Euler angles representing the Inertial Sensor's orientation * @@ -143,8 +324,25 @@ class Imu { * \return The Euler angles representing the sensor's orientation. If the * operation failed, all the structure's members are filled with PROS_ERR_F and * errno is set. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's Euler angles + * pros::euler_s_t euler = imu.get_euler(); + * cout << "Euler: " << euler.roll << ", " << euler.pitch << ", " << euler.yaw << endl; + * delay(20); + * } + * } + * \endcode */ - virtual pros::c::euler_s_t get_euler() const; + virtual pros::euler_s_t get_euler() const; /** * Get the Inertial Sensor's pitch angle bounded by (-180,180) * @@ -158,6 +356,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The pitch angle, or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's pitch + * printf("Pitch: %f\n", imu.get_pitch()); + * delay(20); + * } + * } + * \endcode */ virtual double get_pitch() const; /** @@ -172,6 +386,22 @@ class Imu { * \param port * The V5 Inertial Sensor port number from 1-21 * \return The roll angle, or PROS_ERR_F if the operation failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's roll + * printf("Roll: %f\n", imu.get_roll()); + * delay(20); + * } + * } + * \endcode */ virtual double get_roll() const; /** @@ -186,6 +416,22 @@ class Imu { * \param port * The V5 Inertial Sensor port number from 1-21 * \return The yaw angle, or PROS_ERR_F if the operation failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's yaw + * printf("Yaw: %f\n", imu.get_yaw()); + * delay(20); + * } + * } + * \endcode */ virtual double get_yaw() const; /** @@ -201,8 +447,25 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The raw gyroscope values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's raw gyroscope values + * pros::imu_gyro_s_t gyro = imu.get_gyro_rate(); + * cout << "Gyro: " << gyro.x << ", " << gyro.y << ", " << gyro.z << endl; + * delay(20); + * } + * } + * \endcode */ - virtual pros::c::imu_gyro_s_t get_gyro_rate() const; + virtual pros::imu_gyro_s_t get_gyro_rate() const; /** * Resets the current reading of the Inertial Sensor's rotation to zero * @@ -216,6 +479,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's rotation value to 10 + * imu.set_rotation(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's rotation value to 0 + * imu.tare_rotation(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_rotation() const; /** @@ -231,6 +516,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's heading value to 10 + * imu.set_heading(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's heading value to 0 + * imu.tare_heading(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_heading() const; /** @@ -246,6 +553,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's pitch value to 10 + * imu.set_pitch(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's pitch value to 0 + * imu.tare_pitch(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_pitch() const; /** @@ -261,6 +590,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's yaw value to 10 + * imu.set_yaw(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's yaw value to 0 + * imu.tare_yaw(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_yaw() const; /** @@ -276,6 +627,28 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's roll value to 10 + * imu.set_roll(10); + * delay(20); + * + * // Do something with sensor + * + * // Reset the sensor's roll value to 0 + * imu.tare_roll(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_roll() const; /** @@ -291,6 +664,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Reset all values of the sensor to 0 + * imu.tare(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare() const; /** @@ -306,6 +695,22 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Reset all euler values of the sensor to 0 + * imu.tare_euler(); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t tare_euler() const; /** @@ -324,6 +729,24 @@ class Imu { * Target value for the heading value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's heading value to 10 + * imu.set_heading(10); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_heading(const double target) const; /** @@ -341,6 +764,24 @@ class Imu { * Target value for the rotation value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's rotation value to 10 + * imu.set_rotation(10); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_rotation(const double target) const; /** @@ -359,6 +800,24 @@ class Imu { * Target value for yaw value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's yaw value to 10 + * imu.set_yaw(10); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_yaw(const double target) const; /** @@ -376,6 +835,24 @@ class Imu { * Target value for the pitch value to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's pitch value to 10 + * imu.set_pitch(10); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_pitch(const double target) const; /** @@ -394,6 +871,24 @@ class Imu { * Target euler values for the euler values to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's roll value to 100 + * imu.set_roll(100); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ virtual std::int32_t set_roll(const double target) const; /** @@ -412,8 +907,26 @@ class Imu { * Target euler values for the euler values to be set to * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Set the sensor's euler values to 50 + * imu.set_euler(50); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ - virtual std::int32_t set_euler(const pros::c::euler_s_t target) const; + virtual std::int32_t set_euler(const pros::euler_s_t target) const; /** * Get the Inertial Sensor's raw accelerometer values * @@ -427,8 +940,27 @@ class Imu { * The V5 Inertial Sensor port number from 1-21 * \return The raw accelerometer values. If the operation failed, all the * structure's members are filled with PROS_ERR_F and errno is set. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's raw accelerometer values + * pros::imu_accel_s_t accel = imu.get_accel(); + * printf("x: %f, y: %f, z: %f\n", accel.x, accel.y, accel.z); + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ - virtual pros::c::imu_accel_s_t get_accel() const; + virtual pros::imu_accel_s_t get_accel() const; /** * Get the Inertial Sensor's status * @@ -436,21 +968,63 @@ class Imu { * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Inertial Sensor + * EAGAIN - The sensor is still calibrating * * \param port * The V5 Inertial Sensor port number from 1-21 * \return The Inertial Sensor's status code, or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Get the sensor's status + * pros::ImuStatus status = imu.get_status(); + * cout << "Status: " << status << endl; + * delay(20); + * + * // Do something with sensor + * } + * } + * \endcode */ - virtual pros::c::imu_status_e_t get_status() const; + virtual pros::ImuStatus get_status() const; /** * Check whether the IMU is calibrating * * \return true if the V5 Inertial Sensor is calibrating or false * false if it is not. + * + * \b Example + * \code + * + * #define IMU_PORT 1 + * + * void opcontrol() { + * pros::Imu imu(IMU_PORT); + * + * while (true) { + * // Calibrate the sensor + * imu.calibrate(); + * delay(20); + * + * // Check if the sensor is calibrating + * if (imu.is_calibrating()) { + * printf("Calibrating...\n"); + * } + * + * // Do something with sensor + * } + * } + * \endcode */ virtual bool is_calibrating() const; - /** * Returns the physical orientation of the IMU * @@ -464,11 +1038,40 @@ class Imu { * \returns The physical orientation of the Inertial Sensor or PROS_ERR if an error occured. * */ - virtual pros::c::imu_orientation_e_t get_physical_orientation() const; + virtual imu_orientation_e_t get_physical_orientation() const; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * Imu [port: imu._port, rotation: (rotation), heading: (heading), + * pitch: (pitch angle), roll: (roll angle), yaw: (yaw angle), + * gyro rate: {x,y,z}, get accel: {x,y,z}, calibrating: (calibrating boolean)] + */ + friend std::ostream& operator<<(std::ostream& os, const pros::Imu& imu); + + ///@} }; -using IMU = Imu; +namespace literals { +/** + * Constructs a Imu from a literal ending in _imu via calling the constructor + * + * \return a pros::Imu for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Imu imu = 2_imu; //Makes an IMU object on port 2 + * } + * \endcode + */ +const pros::Imu operator"" _imu(const unsigned long long int i); +} // namespace literals +using IMU = Imu; +} // namespace v5 } // namespace pros #endif diff --git a/include/pros/link.h b/include/pros/link.h index 212834cc..9cd6eead 100644 --- a/include/pros/link.h +++ b/include/pros/link.h @@ -1,19 +1,19 @@ /** * \file pros/link.h + * \ingroup c-link * * Contains prototypes for functions related to the robot to robot communications. * - * Visit https://pros.cs.purdue.edu/v5/api/c/link.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-link VEX Link C API */ #ifndef _PROS_LINK_H_ @@ -27,27 +27,42 @@ extern "C" { namespace pros { #endif +/** + * \ingroup c-link + * */ + +/** + * \addtogroup c-link + * @{ + */ + +/** + * \enum link_type_e_t + * \brief Enum for the type of link (TX or RX) + */ typedef enum link_type_e { - E_LINK_RECIEVER = 0, - E_LINK_TRANSMITTER, - E_LINK_RX = E_LINK_RECIEVER, - E_LINK_TX = E_LINK_TRANSMITTER + E_LINK_RECIEVER = 0, ///< Indicates that the radio is a reciever. + E_LINK_TRANSMITTER, ///< Indicates that the link is a transmitter. + E_LINK_RX = E_LINK_RECIEVER, ///< Alias for E_LINK_RECIEVER + E_LINK_TX = E_LINK_TRANSMITTER ///< Alias for E_LINK_TRANSMITTER } link_type_e_t; #ifdef PROS_USE_SIMPLE_NAMES #ifdef __cplusplus -#define LINK_RECIEVER pros::E_LINK_RECIEVER +#define LINK_RECEIVER pros::E_LINK_RECEIVER #define LINK_TRANSMITTER pros::E_LINK_TRANSMITTER #define LINK_RX pros::E_LINK_RX #define LINK_TX pros::E_LINK_TX #else -#define LINK_RECIEVER E_LINK_RECIEVER +#define LINK_RECEIVER E_LINK_RECEIVER #define LINK_TRANSMITTER E_LINK_TRANSMITTER #define LINK_RX E_LINK_RX #define LINK_TX E_LINK_TX #endif #endif +/// @brief +/// The maximum size of a link buffer #define LINK_BUFFER_SIZE 512 #ifdef __cplusplus @@ -59,23 +74,33 @@ namespace c { * 1 to 2 second delay from when this function is called to when the link is initializes. * PROS currently only supports the use of one radio per brain. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * - * \param port + * \param port * The port of the radio for the intended link. * \param link_id * Unique link ID in the form of a string, needs to be different from other links in * the area. * \param type - * Indicates whether the radio link on the brain is a transmitter or reciever, - * with the transmitter having double the transmitting bandwidth as the recieving + * Indicates whether the radio link on the brain is a transmitter or receiver, + * with the transmitter having double the transmitting bandwidth as the receiving * end (1040 bytes/s vs 520 bytes/s). * * \return PROS_ERR if initialization fails, 1 if the initialization succeeds. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * #define LINK_ID "ROBOT1" + * + * void initialize() { + * link_init(LINK_TRANSMITTER_PORT, LINK_ID, E_LINK_TRANSMITTER); + * } + * \endcode */ uint32_t link_init(uint8_t port, const char* link_id, link_type_e_t type); @@ -85,187 +110,308 @@ uint32_t link_init(uint8_t port, const char* link_id, link_type_e_t type); * from when this function is called to when the link is initializes. * PROS currently only supports the use of one radio per brain. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * - * \param port + * \param port * The port of the radio for the intended link. * \param link_id * Unique link ID in the form of a string, needs to be different from other links in * the area. * \param type - * Indicates whether the radio link on the brain is a transmitter or reciever, - * with the transmitter having double the transmitting bandwidth as the recieving + * Indicates whether the radio link on the brain is a transmitter or receiver, + * with the transmitter having double the transmitting bandwidth as the receiving * end (1040 bytes/s vs 520 bytes/s). * * \return PROS_ERR if initialization fails, 1 if the initialization succeeds. + * + * \b Example + * \code + * #define LINK_PORT 1 + * #define LINK_ID "ROBOT1" + * + * void initialize() { + * link_init(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER); + * link_init_override(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER); + * } + * \endcode */ uint32_t link_init_override(uint8_t port, const char* link_id, link_type_e_t type); /** * Checks if a radio link on a port is active or not. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * - * \param port + * + * \param port * The port of the radio for the intended link. * * \return If a radio is connected to a port and it's connected to a link. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * if (link_connected(LINK_TRANSMITTER_PORT)) { + * screen_print(TEXT_MEDIUM, 1, "Link connected!"); + * } + * delay(20); + * } + * } + * \endcode */ bool link_connected(uint8_t port); /** - * Returns the bytes of data available to be read - * - * This function uses the following values of errno when an error state is + * Returns the bytes of data available to be read + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * - * \param port + * + * \param port * The port of the radio for the intended link. * * \return PROS_ERR if port is not a link/radio, else the bytes available to be * read by the user. + * + * \b Example + * \code + * #define LINK_RECIVER_PORT 1 + * + * void opcontrol() { + * while (true) { + * uint32_t receiveable_size = link_raw_receivable_size(LINK_RECIVER_PORT); + * screen_print(TEXT_MEDIUM, 1, "link_raw_receiveable_size: %d", receiveable_size); + * delay(20); + * } + * } + * \endcode */ uint32_t link_raw_receivable_size(uint8_t port); /** * Returns the bytes of data available in transmission buffer. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * - * \param port + * + * \param port * The port of the radio for the intended link. * - * \return PROS_ERR if port is not a link/radio, + * \return PROS_ERR if port is not a link/radio, + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * uint32_t transmittable_size = link_raw_transmittable_size(LINK_TRANSMITTER_PORT); + * screen_print(TEXT_MEDIUM, 1, "link_raw_transmittable_size: %d", transmittable_size); + * delay(20); + * } + * } + * \endcode */ uint32_t link_raw_transmittable_size(uint8_t port); /** * Send raw serial data through vexlink. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no + * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no * room in the FIFO buffer (queue) to transmit the data. * EINVAL - The data given is NULL - * - * \param port + * + * \param port * The port of the radio for the intended link. * \param data * Buffer with data to send * \param data_size * Bytes of data to be read to the destination buffer - * - * \return PROS_ERR if port is not a link, and the successfully transmitted + * + * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* data = "Hello!"; + * link_transmit_raw(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); + * delay(20); + * } + * } + * \endcode */ uint32_t link_transmit_raw(uint8_t port, void* data, uint16_t data_size); /** * Receive raw serial data through vexlink. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer - * or destination buffer. - * - * \param port + * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer + * or destination buffer. + * + * \param port * The port of the radio for the intended link. * \param dest * Destination buffer to read data to * \param data_size * Bytes of data to be read to the destination buffer - * - * \return PROS_ERR if port is not a link, and the successfully received + * + * \return PROS_ERR if port is not a link, and the successfully received * data size if it succeeded. + * + * \b Example + * \code + * #define LINK_RECIVER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* result; + * char* expected = "Hello!"; + * link_receive_raw(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected)); + * delay(20); + * } + * } + * \endcode */ uint32_t link_receive_raw(uint8_t port, void* dest, uint16_t data_size); /** * Send packeted message through vexlink, with a checksum and start byte. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no + * EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no * room in the FIFO buffer (queue) to transmit the data. * EINVAL - The data given is NULL - * - * \param port + * + * \param port * The port of the radio for the intended link. * \param data * Buffer with data to send * \param data_size * Bytes of data to be read to the destination buffer - * - * \return PROS_ERR if port is not a link, and the successfully transmitted + * + * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* data = "Hello!"; + * link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); + * delay(20); + * } + * } + * \endcode */ uint32_t link_transmit(uint8_t port, void* data, uint16_t data_size); /** * Receive packeted message through vexlink, with a checksum and start byte. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer - * or destination buffer. + * EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer + * or destination buffer. * EBADMSG - Protocol error related to start byte, data size, or checksum. - * - * \param port + * + * \param port * The port of the radio for the intended link. * \param dest * Destination buffer to read data to * \param data_size * Bytes of data to be read to the destination buffer - * - * \return PROS_ERR if port is not a link or protocol error, and the successfully + * + * \return PROS_ERR if port is not a link or protocol error, and the successfully * transmitted data size if it succeeded. + * + * \b Example + * \code + * #define LINK_RECIVER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* result; + * char* expected = "Hello!"; + * link_receive(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected)); + * delay(20); + * } + * } + * \endcode */ uint32_t link_receive(uint8_t port, void* dest, uint16_t data_size); /** * Clear the receive buffer of the link, and discarding the data. - * - * This function uses the following values of errno when an error state is + * + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - * - * \param port + * + * \param port * The port of the radio for the intended link. - * - * \return PROS_ERR if port is not a link, and the successfully received + * + * \return PROS_ERR if port is not a link, and the successfully received * data size if it succeeded. + * + * \b Example + * \code + * #define LINK_TRANSMITTER_PORT 1 + * + * void opcontrol() { + * while (true) { + * char* data = "Hello!"; + * link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data)); + * link_clear_receive_buf(LINK_TRANSMITTER_PORT); + * delay(20); + * } + * } + * \endcode */ uint32_t link_clear_receive_buf(uint8_t port); +///@} + #ifdef __cplusplus } } diff --git a/include/pros/link.hpp b/include/pros/link.hpp index d6c18f3a..68bb5e51 100644 --- a/include/pros/link.hpp +++ b/include/pros/link.hpp @@ -1,19 +1,19 @@ /** * \file pros/link.hpp + * \ingroup cpp-link * * Contains prototypes for functions related to robot to robot communications. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/link.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * Copyright (c) 2017-2021, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-link VEX Link C++ API */ #ifndef _PROS_LINK_HPP_ #define _PROS_LINK_HPP_ @@ -22,18 +22,25 @@ #include #include "pros/link.h" +#include "pros/device.hpp" namespace pros { -class Link { +/** + * \ingroup cpp-link + */ +class Link : public Device { + /** + * \addtogroup cpp-link + * ///@{ + */ private: - std::uint8_t _port; public: /** * Initializes a link on a radio port, with an indicated type. There might be a * 1 to 2 second delay from when this function is called to when the link is initializes. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -45,33 +52,46 @@ class Link { * Unique link ID in the form of a string, needs to be different from other links in * the area. * \param type - * Indicates whether the radio link on the brain is a transmitter or reciever, - * with the transmitter having double the transmitting bandwidth as the recieving + * Indicates whether the radio link on the brain is a transmitter or receiver, + * with the transmitter having double the transmitting bandwidth as the receiving * end (1040 bytes/s vs 520 bytes/s). * \param ov - * Indicates if the radio on the given port needs vexlink to override the controller radio + * Indicates if the radio on the given port needs vexlink to override the controller radio. Defualts to True. * * \return PROS_ERR if initialization fails, 1 if the initialization succeeds. + * + * \b Example: + * \code + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * \endcode */ - Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov = false); + explicit Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov = true); /** * Checks if a radio link on a port is active or not. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * * \return If a radio is connected to a port and it's connected to a link. + * + * \b Example: + * \code + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * if (link.connected()) { + * // do something + * } + * \endcode */ bool connected(); /** * Returns the bytes of data number of without protocol available to be read * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -79,26 +99,42 @@ class Link { * * \return PROS_ERR if port is not a link/radio, else the bytes available to be * read by the user. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * printf("Bytes available to read: %d", link.receivable_size()); + * } + * \endcode */ std::uint32_t raw_receivable_size(); /** * Returns the bytes of data available in transmission buffer. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. * * \return PROS_ERR if port is not a link/radio, + * else the bytes available to be transmitted by the user. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * printf("Bytes available to transmit: %d", link.transmittable_size()); + * } */ std::uint32_t raw_transmittable_size(); /** * Send raw serial data through vexlink. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -114,13 +150,23 @@ class Link { * * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * std::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04}; + * link.transmit_raw(data, 4); + * } + * + * \endcode */ std::uint32_t transmit_raw(void* data, std::uint16_t data_size); /** * Receive raw serial data through vexlink. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -135,13 +181,22 @@ class Link { * * \return PROS_ERR if port is not a link, and the successfully received * data size if it succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * std::uint8_t data[4]; + * link.receive_raw(data, 4); + * } + * \endcode */ std::uint32_t receive_raw(void* dest, std::uint16_t data_size); /** * Send packeted message through vexlink, with a checksum and start byte. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -157,13 +212,22 @@ class Link { * * \return PROS_ERR if port is not a link, and the successfully transmitted * data size if it succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * std::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04}; + * link.transmit(data, 4); + * } + * \endcode */ std::uint32_t transmit(void* data, std::uint16_t data_size); /** * Receive packeted message through vexlink, with a checksum and start byte. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. @@ -179,21 +243,40 @@ class Link { * * \return PROS_ERR if port is not a link, and the successfully received * data size if it succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * std::uint8_t data[4]; + * link.receive(data, 4); + * } + * \endcode */ std::uint32_t receive(void* dest, std::uint16_t data_size); /** * Clear the receive buffer of the link, and discarding the data. * - * This function uses the following values of errno when an error state is + * \note This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as a radio. * ENXIO - The sensor is still calibrating, or no link is connected via the radio. - + * * \return PROS_ERR if port is not a link, 1 if the operation succeeded. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Link link(1, "my_link", pros::E_LINK_TX); + * link.clear_receive_buf(); + * } + * \endcode */ std::uint32_t clear_receive_buf(); + + ///@} }; } // namespace pros diff --git a/include/pros/llemu.h b/include/pros/llemu.h index 8a6d7570..868cd736 100644 --- a/include/pros/llemu.h +++ b/include/pros/llemu.h @@ -1,92 +1,27 @@ -/* - * \file pros/llemu.h - * - * Legacy LCD Emulator - * - * This file defines a high-level API for emulating the three-button, UART-based - * VEX LCD, containing a set of functions that facilitate the use of a software- - * emulated version of the classic VEX LCD module. - * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/llemu.html to learn - * more. - * - * This file should not be modified by users, since it gets replaced whenever - * a kernel upgrade occurs. - * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - #ifndef _PROS_LLEMU_H_ #define _PROS_LLEMU_H_ -#include -#include +// TODO:? Should there be weak symbols for the C api in here as well? -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wignored-qualifiers" -#include "display/lvgl.h" -#pragma GCC diagnostic pop +#include "stdint.h" -#ifdef __cplusplus -extern "C" { -namespace pros { +/******************************************************************************/ +/** 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 -typedef void (*lcd_btn_cb_fn_t)(void); - -#define LCD_BTN_LEFT 4 -#define LCD_BTN_CENTER 2 -#define LCD_BTN_RIGHT 1 - -typedef struct lcd_s { - lv_obj_t* frame; - lv_obj_t* screen; - lv_obj_t* lcd_text[8]; - lv_obj_t* btn_container; - lv_obj_t* btns[3]; // < 0 => left; 1 => center; 2 => right - lcd_btn_cb_fn_t callbacks[3]; // < 0 => left; 1 => center; 2 => right - volatile uint8_t touch_bits; // < 4 => left; 2 => center; 1 => right (no - // multitouch support) -} lcd_s_t; - #ifdef __cplusplus +extern "C" { +namespace pros { namespace c { -#endif - -/** - * Checks whether the emulated three-button LCD has already been initialized. - * - * \return True if the LCD has been initialized or false if not. - */ -bool lcd_is_initialized(void); - -/** - * 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. - */ -bool lcd_initialize(void); - -/** - * Turns 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 lcd_initialize. - * - * 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. - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_shutdown(void); +#endif//__cplusplus /** * Displays a formatted string on the emulated three-button LCD screen. @@ -106,150 +41,14 @@ bool lcd_shutdown(void); * \return True if the operation was successful, or false otherwise, setting * errno values as specified above. */ -bool lcd_print(int16_t line, const char* fmt, ...); - -/** - * 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. - */ -bool lcd_set_text(int16_t line, const char* text); - -/** - * Clears the contents 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] - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_clear(void); - -/** - * 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. - */ -bool lcd_clear_line(int16_t line); - -/** - * Registers 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. - * - * 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_register_btn0_cb(lcd_btn_cb_fn_t cb); - -/** - * Registers 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. - * - * 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_register_btn1_cb(lcd_btn_cb_fn_t cb); - -/** - * 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. - * - * 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t (void (*cb)(void)) - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool lcd_register_btn2_cb(lcd_btn_cb_fn_t cb); - -/** - * 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 - */ -uint8_t lcd_read_buttons(void); - -/** - * Changes the color of the LCD background to a provided color expressed in - * type lv_color_t. - * - * \param color - * A color of type lv_color_t - * - * \return void - */ -void lcd_set_background_color(lv_color_t color); - -/** - * Changes the text color of the LCD to a provided color expressed in - * type lv_color_t. - * - * \param color - * A color of type lv_color_t - * - * \return void - */ -void lcd_set_text_color(lv_color_t color); +bool __attribute__((weak)) lcd_print(int16_t line, const char* fmt, ...) { + return false; +} #ifdef __cplusplus -} // namespace c -} // namespace pros -} -#endif -#endif // _PROS_LLEMU_H_ +} // namespace c +} // namespace pros +} // extern "C" +#endif//__cplusplus + +#endif // _PROS_LLEMU_H_ diff --git a/include/pros/llemu.hpp b/include/pros/llemu.hpp index a4834e02..4f75d6c7 100644 --- a/include/pros/llemu.hpp +++ b/include/pros/llemu.hpp @@ -1,19 +1,17 @@ -/* +/** * \file pros/llemu.hpp - * + * \ingroup cpp-llemu + * * Legacy LCD Emulator * - * This file defines a high-level API for emulating the three-button, UART-based + * \details This file defines a high-level API for emulating the three-button, UART-based * VEX LCD, containing a set of functions that facilitate the use of a software- * emulated version of the classic VEX LCD module. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/llemu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -26,237 +24,115 @@ #include #include -#include "pros/llemu.h" +/******************************************************************************/ +/** 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 + +/******************************************************************************/ +/** LLEMU Weak Stubs **/ +/** **/ +/** These functions allow main.cpp to be compiled without LVGL present **/ +/******************************************************************************/ namespace pros { -namespace lcd { -/** - * Checks whether the emulated three-button LCD has already been initialized. - * - * \return True if the LCD has been initialized or false if not. - */ -bool is_initialized(void); - + /** - * 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. - */ -bool initialize(void); - -/** - * Turns 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 lcd_initialize. - * - * 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. - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool shutdown(void); - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-function" -namespace { -template -T convert_args(T arg) { - return arg; -} -const char* convert_args(const std::string& arg) { - return arg.c_str(); -} -} // namespace -#pragma GCC diagnostic pop - -/** - * 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. + * \ingroup cpp-llemu */ -template -bool print(std::int16_t line, const char* fmt, Params... args) { - return pros::c::lcd_print(line, fmt, convert_args(args)...); -} - -/** - * 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. - */ -bool set_text(std::int16_t line, std::string text); - -/** - * Clears the contents 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] - * - * \return True if the operation was successful, or false otherwise, setting - * errno values as specified above. - */ -bool clear(void); - -/** - * 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. - */ -bool clear_line(std::int16_t line); - -using lcd_btn_cb_fn_t = void (*)(void); - -/** - * Registers 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t(void (*cb)(void)) - */ -void register_btn0_cb(lcd_btn_cb_fn_t cb); - -/** - * Registers 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. - * - * \param cb - * A callback function of type lcd_btn_cb_fn_t(void (*cb)(void)) - */ -void register_btn1_cb(lcd_btn_cb_fn_t cb); - -/** - * 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)) - */ -void register_btn2_cb(lcd_btn_cb_fn_t cb); - -/** - * 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 - */ -std::uint8_t read_buttons(void); - -/** - * Changes the color of the LCD background to a provided color expressed in - * type lv_color_t. - * - * \param color - * A color of type lv_color_t - * - * \return void - */ -void set_background_color(lv_color_t color); - -/** - * Changes the color of the LCD background to a provided color expressed in RGB - * form, with three values of type uint8_t. - * - * \param r - * A value of type uint8_t, with a range of 0 to 255, representing the - * red value of a color - * - * \param g - * A value of type uint8_t, with a range of 0 to 255, representing the - * green value of a color - * - * \param b - * A value of type uint8_t, with a range of 0 to 255, representing the - * blue value of a color - * - * \return void - */ -void set_background_color(std::uint8_t r, std::uint8_t g, std::uint8_t b); - -/** - * Changes the text color of the LCD to a provided color expressed in - * type lv_color_t. - * - * \param color - * A color of type lv_color_t - * - * \return void - */ -void set_text_color(lv_color_t color); - -/** - * Changes the text color of the LCD to a provided color expressed in RGB - * form, with three values of type uint8_t. - * - * \param r - * A value of type uint8_t, with a range of 0 to 255, representing the - * red value of a color - * - * \param g - * A value of type uint8_t, with a range of 0 to 255, representing the - * green value of a color - * - * \param b - * A value of type uint8_t, with a range of 0 to 255, representing the - * blue value of a color - * - * \return void - */ -void set_text_color(std::uint8_t r, std::uint8_t g, std::uint8_t b); - -} // namespace lcd -} // namespace pros - -#endif // _PROS_LLEMU_HPP_ +namespace lcd { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-function" + namespace { + template + 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); + + /* + * These weak symbols allow the example main.cpp in to compile even when + * the liblvgl template is missing from the project. + * + * For documentation on these functions, please see the doxygen comments for + * these functions in the libvgl llemu headers. + */ + + extern __attribute__((weak)) bool set_text(std::int16_t line, std::string text); + extern __attribute__((weak)) bool clear_line(std::int16_t line); + extern __attribute__((weak)) bool initialize(void); + extern __attribute__((weak)) std::uint8_t read_buttons(void); + extern __attribute__((weak)) void register_btn1_cb(lcd_btn_cb_fn_t cb); + extern __attribute__((weak)) bool is_initialized(void); + + /** + * \addtogroup cpp-llemu + * @{ + */ + + /* + * Note: This template resides in this file since the + */ + + /** + * 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 ...args + * Optional list of arguments for the format string + * + * \return True if the operation was successful, or false otherwise, setting + * errno values as specified above. + * + * \b Example + * \code + * #include "pros/llemu.hpp" + * + * void initialize() { + * pros::lcd::initialize(); + * pros::lcd::print(0, "My formatted text: %d!", 2); + * } + * \endcode + */ + template + 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 + +#endif // _PROS_LLEMU_HPP_ diff --git a/include/pros/misc.h b/include/pros/misc.h index 16cba550..677dad81 100644 --- a/include/pros/misc.h +++ b/include/pros/misc.h @@ -1,21 +1,22 @@ /** * \file pros/misc.h + * \ingroup c-misc * * Contains prototypes for miscellaneous functions pertaining to the controller, * battery, and competition control. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/controller.html to - * learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reservered. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-misc Miscellaneous C API + * \note Additional example code for this module can be found in its [Tutorial.](@ref controller) */ #ifndef _PROS_MISC_H_ @@ -25,63 +26,203 @@ #define NUM_V5_PORTS (22) -/******************************************************************************/ -/** V5 Competition **/ -/******************************************************************************/ -#define COMPETITION_DISABLED (1 << 0) +/** + * \ingroup c-misc + */ + +/** + * \addtogroup c-misc + * @{ + */ + +/// \name V5 Competition +//@{ + +/*#define COMPETITION_DISABLED (1 << 0) #define COMPETITION_AUTONOMOUS (1 << 1) #define COMPETITION_CONNECTED (1 << 2) +#define COMPETITION_SYSTEM (1 << 3)*/ +typedef enum { + COMPETITION_DISABLED = 1 << 0, + COMPETITION_CONNECTED = 1 << 2, + COMPETITION_AUTONOMOUS = 1 << 1, + COMPETITION_SYSTEM = 1 << 3, +} competition_status; + +#ifdef __cplusplus +extern "C" { +namespace pros { +namespace c { +#endif /** + * \fn competition_get_status(void) * Get the current status of the competition control. * * \return The competition control status as a mask of bits with * COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}. + * + * \b Example + * \code + * void initialize() { + * if (competition_get_status() & COMPETITION_CONNECTED == true) { + * // Field Control is Connected + * // Run LCD Selector code or similar + * } + * } + * \endcode */ -#ifdef __cplusplus -extern "C" { -namespace pros { -namespace c { -#endif uint8_t competition_get_status(void); + +/** + * \fn competition_is_disabled() + * + * \return True if the V5 Brain is disabled, false otherwise. + * + * \b Example + * \code + * void my_task_fn(void* ignore) { + * while (!competition_is_disabled()) { + * // Run competition tasks (like Lift Control or similar) + * } + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIO_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode + */ +uint8_t competition_is_disabled(void); + +/** + * \return True if the V5 Brain is connected to competition control, false otherwise. + * + * \b Example + * \code + * void initialize() { + * if (competition_is_connected()) { + * // Field Control is Connected + * // Run LCD Selector code or similar + * } + * } + * \endcode + */ +uint8_t competition_is_connected(void); + +/** + * \return True if the V5 Brain is in autonomous mode, false otherwise. + * + * \b Example + * \code + * void my_task_fn(void* ignore) { + * while (!competition_is_autonomous()) { + * // Wait to do anything until autonomous starts + * delay(2); + * } + * while (competition_is_autonomous()) { + * // Run whatever code is desired to just execute in autonomous + * } + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIO_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode + */ +uint8_t competition_is_autonomous(void); + +/** + * \return True if the V5 Brain is connected to VEXnet Field Controller, false otherwise. + * + * \b Example + * \code + * void initialize() { + * if (competition_is_field()) { + * // connected to VEXnet Field Controller + * } + * } + * \endcode + */ +uint8_t competition_is_field(void); + +/** + * \return True if the V5 Brain is connected to VEXnet Competition Switch, false otherwise. + * + * \b Example + * \code + * void initialize() { + * if (competition_is_switch()) { + * // connected to VEXnet Competition Switch + * } + * } + */ +uint8_t competition_is_switch(void); + #ifdef __cplusplus } } } #endif -#define competition_is_disabled() ((competition_get_status() & COMPETITION_DISABLED) != 0) -#define competition_is_connected() ((competition_get_status() & COMPETITION_CONNECTED) != 0) -#define competition_is_autonomous() ((competition_get_status() & COMPETITION_AUTONOMOUS) != 0) +///@} -/******************************************************************************/ -/** V5 Controller **/ -/******************************************************************************/ +/// \name V5 Controller +///@{ #ifdef __cplusplus extern "C" { namespace pros { #endif -typedef enum { E_CONTROLLER_MASTER = 0, E_CONTROLLER_PARTNER } controller_id_e_t; +/** + * \enum + */ +typedef enum { + /// The master controller. + E_CONTROLLER_MASTER = 0, + /// The partner controller. + E_CONTROLLER_PARTNER +} controller_id_e_t; +/** + * \enum + */ typedef enum { + /// The horizontal axis of the controller’s left analog stick. E_CONTROLLER_ANALOG_LEFT_X = 0, + /// The vertical axis of the controller’s left analog stick. E_CONTROLLER_ANALOG_LEFT_Y, + /// The horizontal axis of the controller’s right analog stick. E_CONTROLLER_ANALOG_RIGHT_X, + /// The vertical axis of the controller’s right analog stick. E_CONTROLLER_ANALOG_RIGHT_Y } controller_analog_e_t; +/** + * \enum + */ typedef enum { + /// The first trigger on the left side of the controller. E_CONTROLLER_DIGITAL_L1 = 6, + /// The second trigger on the left side of the controller. E_CONTROLLER_DIGITAL_L2, + /// The first trigger on the right side of the controller. E_CONTROLLER_DIGITAL_R1, + /// The second trigger on the right side of the controller. E_CONTROLLER_DIGITAL_R2, + /// The up arrow on the left arrow pad of the controller. E_CONTROLLER_DIGITAL_UP, + /// The down arrow on the left arrow pad of the controller. E_CONTROLLER_DIGITAL_DOWN, + /// The left arrow on the left arrow pad of the controller. E_CONTROLLER_DIGITAL_LEFT, + /// The right arrow on the left arrow pad of the controller. E_CONTROLLER_DIGITAL_RIGHT, + /// The ‘X’ button on the right button pad of the controller. E_CONTROLLER_DIGITAL_X, + /// The ‘B’ button on the right button pad of the controller. E_CONTROLLER_DIGITAL_B, + /// The ‘Y’ button on the right button pad of the controller. E_CONTROLLER_DIGITAL_Y, + /// The ‘A’ button on the right button pad of the controller. E_CONTROLLER_DIGITAL_A } controller_digital_e_t; @@ -127,48 +268,28 @@ typedef enum { #endif #endif -/* -Given an id and a port, this macro sets the port -variable based on the id and allows the mutex to take that port. - -Returns error (in the function/scope it's in) if the controller -failed to connect or an invalid id is given. -*/ +/** + * \def Given an id and a port, this macro sets the port variable based on the id and allows the mutex to take that + * port. + * + * \returns error (in the function/scope it's in) if the controller failed to connect or an invalid id is given. + */ #define CONTROLLER_PORT_MUTEX_TAKE(id, port) \ - switch (id) { \ - case E_CONTROLLER_MASTER: \ - port = V5_PORT_CONTROLLER_1; \ - break; \ - case E_CONTROLLER_PARTNER: \ - port = V5_PORT_CONTROLLER_2; \ - break; \ - default: \ - errno = EINVAL; \ - return PROS_ERR; \ - } \ - if (!internal_port_mutex_take(port)) { \ - errno = EACCES; \ - return PROS_ERR; \ - } \ -/******************************************************************************/ -/** Date and Time **/ -/******************************************************************************/ - -extern const char* baked_date; -extern const char* baked_time; - -typedef struct { - uint16_t year; // Year - 1980 - uint8_t day; - uint8_t month; // 1 = January -} date_s_t; - -typedef struct { - uint8_t hour; - uint8_t min; - uint8_t sec; - uint8_t sec_hund; // hundredths of a second -} time_s_t; + switch (id) { \ + case E_CONTROLLER_MASTER: \ + port = V5_PORT_CONTROLLER_1; \ + break; \ + case E_CONTROLLER_PARTNER: \ + port = V5_PORT_CONTROLLER_2; \ + break; \ + default: \ + errno = EINVAL; \ + return PROS_ERR; \ + } \ + if (!internal_port_mutex_take(port)) { \ + errno = EACCES; \ + return PROS_ERR; \ + } #ifdef __cplusplus namespace c { @@ -188,6 +309,16 @@ namespace c { * Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER * * \return 1 if the controller is connected, 0 otherwise + * + * \b Example + * \code + * void initialize() { + * if (competition_is_connected()) { + * // Field Control is Connected + * // Run LCD Selector code or similar + * } + * } + * \endcode */ int32_t controller_is_connected(controller_id_e_t id); @@ -210,6 +341,16 @@ int32_t controller_is_connected(controller_id_e_t id); * * \return The current reading of the analog channel: [-127, 127]. * If the controller was not connected, then 0 is returned + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * delay(2); + * } + * } + * \endcode */ int32_t controller_get_analog(controller_id_e_t id, controller_analog_e_t channel); @@ -227,6 +368,13 @@ int32_t controller_get_analog(controller_id_e_t id, controller_analog_e_t channe * Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER * * \return The controller's battery capacity + * + * \b Example + * \code + * void initialize() { + * printf("Battery Capacity: %d\n", controller_get_battery_capacity(E_CONTROLLER_MASTER)); + * } + * \endcode */ int32_t controller_get_battery_capacity(controller_id_e_t id); @@ -244,6 +392,13 @@ int32_t controller_get_battery_capacity(controller_id_e_t id); * Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER * * \return The controller's battery level + * + * \b Example + * \code + * void initialize() { + * printf("Battery Level: %d\n", controller_get_battery_level(E_CONTROLLER_MASTER)); + * } + * \endcode */ int32_t controller_get_battery_level(controller_id_e_t id); @@ -265,6 +420,22 @@ int32_t controller_get_battery_level(controller_id_e_t id); * * \return 1 if the button on the controller is pressed. * If the controller was not connected, then 0 is returned + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * if (controller_get_digital(E_CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_A)) { + * motor_set(1, 100); + * } + * else { + * motor_set(1, 0); + * } + * delay(2); + * } + * } + + * \endcode */ int32_t controller_get_digital(controller_id_e_t id, controller_digital_e_t button); @@ -294,20 +465,34 @@ int32_t controller_get_digital(controller_id_e_t id, controller_digital_e_t butt * * \return 1 if the button on the controller is pressed and had not been pressed * the last time this function was called, 0 otherwise. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * if (controller_get_digital_new_press(E_CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_A)) { + * // Toggle pneumatics or other similar actions + * } + * + * delay(2); + * } + * } + * \endcode */ int32_t controller_get_digital_new_press(controller_id_e_t id, controller_digital_e_t button); /** * Sets text to the controller LCD screen. * - * \note Controller text setting is currently in beta, so continuous, fast - * updates will not work well. + * \note Controller text setting is a slow process, so updates faster than 10ms + * when on a wired connection or 50ms over Vexnet will not be applied to the controller. * * This function uses the following values of errno when an error state is * reached: * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is * given. * EACCES - Another resource is currently trying to access the controller port. + * EAGAIN - Could not send the text to the controller. * * \param id * The ID of the controller (e.g. the master or partner controller). @@ -323,20 +508,36 @@ int32_t controller_get_digital_new_press(controller_id_e_t id, controller_digita * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * while (true) { + * if (!(count % 25)) { + * // Only print every 50ms, the controller text update rate is slow + * controller_print(E_CONTROLLER_MASTER, 0, 0, "Counter: %d", count); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ int32_t controller_print(controller_id_e_t id, uint8_t line, uint8_t col, const char* fmt, ...); /** * Sets text to the controller LCD screen. * - * \note Controller text setting is currently in beta, so continuous, fast - * updates will not work well. + * \note Controller text setting is a slow process, so updates faster than 10ms + * when on a wired connection or 50ms over Vexnet will not be applied to the controller. * * This function uses the following values of errno when an error state is * reached: * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is * given. * EACCES - Another resource is currently trying to access the controller port. + * EAGAIN - Could not send the text to the controller. * * \param id * The ID of the controller (e.g. the master or partner controller). @@ -350,6 +551,21 @@ int32_t controller_print(controller_id_e_t id, uint8_t line, uint8_t col, const * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * while (true) { + * if (!(count % 25)) { + * // Only print every 50ms, the controller text update rate is slow + * controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example text"); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ int32_t controller_set_text(controller_id_e_t id, uint8_t line, uint8_t col, const char* str); @@ -373,21 +589,30 @@ int32_t controller_set_text(controller_id_e_t id, uint8_t line, uint8_t col, con * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example"); + * delay(100); + * controller_clear_line(E_CONTROLLER_MASTER, 0); + * } + * \endcode */ int32_t controller_clear_line(controller_id_e_t id, uint8_t line); /** * Clears all of the lines on the controller screen. * - * \note Controller text setting is currently in beta, so continuous, fast - * updates will not work well. On vexOS version 1.0.0 this function will block - * for 110ms. + * \note Controller text setting is a slow process, so updates faster than 10ms + * when on a wired connection or 50ms over Vexnet will not be applied to the controller. * * This function uses the following values of errno when an error state is * reached: * EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is * given. * EACCES - Another resource is currently trying to access the controller port. + * EAGAIN - Could not send the text to the controller. * * \param id * The ID of the controller (e.g. the master or partner controller). @@ -395,14 +620,23 @@ int32_t controller_clear_line(controller_id_e_t id, uint8_t line); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example"); + * delay(100); + * controller_clear(E_CONTROLLER_MASTER); + * } + * \endcode */ int32_t controller_clear(controller_id_e_t id); /** * Rumble the controller. * - * \note Controller rumble activation is currently in beta, so continuous, fast - * updates will not work well. + * \note Controller rumble activation is a slow process, so updates faster than 10ms + * when on a wired connection or 50ms over Vexnet will not be applied to the controller. * * This function uses the following values of errno when an error state is * reached: @@ -420,6 +654,21 @@ int32_t controller_clear(controller_id_e_t id); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * while (true) { + * if (!(count % 25)) { + * // Only send every 50ms, the controller update rate is slow + * controller_rumble(E_CONTROLLER_MASTER, ". - . -"); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ int32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern); @@ -431,6 +680,13 @@ int32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern); * EACCES - Another resource is currently trying to access the battery port. * * \return The current voltage of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery's Voltage: %d\n", battery_get_voltage()); + * } + * \endcode */ int32_t battery_get_voltage(void); @@ -442,6 +698,13 @@ int32_t battery_get_voltage(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current current of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery Current: %d\n", battery_get_current()); + * } + * \endcode */ int32_t battery_get_current(void); @@ -453,6 +716,13 @@ int32_t battery_get_current(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current temperature of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery's Temperature: %d\n", battery_get_temperature()); + * } + * \endcode */ double battery_get_temperature(void); @@ -464,6 +734,13 @@ double battery_get_temperature(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current capacity of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery Level: %d\n", battery_get_capacity()); + * } + * \endcode */ double battery_get_capacity(void); @@ -471,12 +748,86 @@ double battery_get_capacity(void); * Checks if the SD card is installed. * * \return 1 if the SD card is installed, 0 otherwise + * + * \b Example + * \code + * void opcontrol() { + * printf("%i", usd_is_installed()); + * } + * \endcode */ int32_t usd_is_installed(void); +/** + * Lists the files in a directory specified by the path + * Puts the list of file names (NOT DIRECTORIES) into the buffer seperated by newlines + * + * This function uses the following values of errno when an error state is + * reached: + * + * EIO - Hard error occured in the low level disk I/O layer + * EINVAL - file or directory is invalid, or length is invalid + * EBUSY - THe physical drinve cannot work + * ENOENT - cannot find the path or file + * EINVAL - the path name format is invalid + * EACCES - Access denied or directory full + * EEXIST - Access denied + * EROFS - SD card is write protected + * ENXIO - drive number is invalid or not a FAT32 drive + * ENOBUFS - drive has no work area + * ENFILE - too many open files + * + * + * + * \note use a path of "\" to list the files in the main directory NOT "/usd/" + * DO NOT PREPEND YOUR PATHS WITH "/usd/" + * + * \return 1 on success or PROS_ERR on failure setting errno + * + * \b Example + * \code + * void opcontrol() { + * char* test = (char*) malloc(128); + * pros::c::usd_list_files("/", test, 128); + * pros::delay(200); + * printf("%s\n", test); //Prints the file names in the root directory seperated by newlines + * pros::delay(100); + * pros::c::usd_list_files("/test", test, 128); + * pros::delay(200); + * printf("%s\n", test); //Prints the names of files in the folder named test seperated by newlines + * pros::delay(100); + * } + * \endcode + */ +int32_t usd_list_files(const char* path, char* buffer, int32_t len); + +/******************************************************************************/ +/** Date and Time **/ +/******************************************************************************/ + +extern const char* baked_date; +extern const char* baked_time; + +typedef struct { + uint16_t year; // Year - 1980 + uint8_t day; + uint8_t month; // 1 = January +} date_s_t; + +typedef struct { + uint8_t hour; + uint8_t min; + uint8_t sec; + uint8_t sec_hund; // hundredths of a second +} time_s_t; + +///@} + +///@} + #ifdef __cplusplus } -} +} // namespace pros } #endif diff --git a/include/pros/misc.hpp b/include/pros/misc.hpp index 7fcb4b54..efa4d1d8 100644 --- a/include/pros/misc.hpp +++ b/include/pros/misc.hpp @@ -1,33 +1,42 @@ /** * \file pros/misc.hpp + * \ingroup cpp-pros * * Contains prototypes for miscellaneous functions pertaining to the controller, * battery, and competition control. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/controller.html to - * learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reservered. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-misc Miscellaneous C++ API + * \note Additional example code for this module can be found in its [Tutorial.](@ref controller) */ #ifndef _PROS_MISC_HPP_ #define _PROS_MISC_HPP_ -#include "pros/misc.h" - #include #include +#include "pros/misc.h" + namespace pros { +inline namespace v5 { +/** + * \ingroup cpp-misc + */ class Controller { + /** + * \addtogroup cpp-misc + * ///@{ + */ public: /** * Creates a controller object for the given controller id. @@ -36,7 +45,7 @@ class Controller { * The ID of the controller (e.g. the master or partner controller). * Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER */ - Controller(controller_id_e_t id); + explicit Controller(controller_id_e_t id); /** * Checks if the controller is connected. @@ -47,6 +56,16 @@ class Controller { * port. * * \return 1 if the controller is connected, 0 otherwise + * + * \b Example + * \code + * void status_display_controller(){ + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * if(!master.is_connected()) { + * pros::lcd::print(0, "Main controller is not connected!"); + * } + * } + * \endcode */ std::int32_t is_connected(void); @@ -65,6 +84,17 @@ class Controller { * * \return The current reading of the analog channel: [-127, 127]. * If the controller was not connected, then 0 is returned + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * motor_move(1, master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * delay(2); + * } + * } + * \endcode */ std::int32_t get_analog(controller_analog_e_t channel); @@ -77,6 +107,14 @@ class Controller { * port. * * \return The controller's battery capacity + * + * \b Example + * \code + * void initialize() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * printf("Battery Capacity: %d\n", master.get_battery_capacity()); + * } + * \endcode */ std::int32_t get_battery_capacity(void); @@ -89,6 +127,14 @@ class Controller { * port. * * \return The controller's battery level + * + * \b Example + * \code + * void initialize() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * printf("Battery Level: %d\n", master.get_battery_level()); + * } + * \endcode */ std::int32_t get_battery_level(void); @@ -107,6 +153,22 @@ class Controller { * * \return 1 if the button on the controller is pressed. * If the controller was not connected, then 0 is returned + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (master.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { + * motor_set(1, 100); + * } + * else { + * motor_set(1, 0); + * } + * delay(2); + * } + * } + * \endcode */ std::int32_t get_digital(controller_digital_e_t button); @@ -132,6 +194,20 @@ class Controller { * * \return 1 if the button on the controller is pressed and had not been * pressed the last time this function was called, 0 otherwise. + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)) { + * // Toggle pneumatics or other similar actions + * } + * + * delay(2); + * } + * } + * \endcode */ std::int32_t get_digital_new_press(controller_digital_e_t button); @@ -168,6 +244,22 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (!(count % 25)) { + * // Only print every 50ms, the controller text update rate is slow + * master.print(0, 0, "Counter: %d", count); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ template std::int32_t print(std::uint8_t line, std::uint8_t col, const char* fmt, Params... args) { @@ -194,6 +286,22 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (!(count % 25)) { + * // Only print every 50ms, the controller text update rate is slow + * master.set_text(0, 0, "Example text"); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ std::int32_t set_text(std::uint8_t line, std::uint8_t col, const char* str); std::int32_t set_text(std::uint8_t line, std::uint8_t col, const std::string& str); @@ -214,6 +322,16 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * master.set_text(0, 0, "Example"); + * delay(100); + * master.clear_line(0); + * } + * \endcode */ std::int32_t clear_line(std::uint8_t line); @@ -235,6 +353,22 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * int count = 0; + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * while (true) { + * if (!(count % 25)) { + * // Only send every 50ms, the controller update rate is slow + * master.rumble(". - . -"); + * } + * count++; + * delay(2); + * } + * } + * \endcode */ std::int32_t rumble(const char* rumble_pattern); @@ -252,14 +386,30 @@ class Controller { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Controller master(pros::E_CONTROLLER_MASTER); + * master.set_text(0, 0, "Example"); + * delay(100); + * master.clear(); + * } + * \endcode */ std::int32_t clear(void); private: controller_id_e_t _id; + ///@} }; +} // namespace v5 namespace battery { +/** + * \addtogroup cpp-misc + * ///@{ + */ /** * Gets the current voltage of the battery, as reported by VEXos. * @@ -268,6 +418,13 @@ namespace battery { * EACCES - Another resource is currently trying to access the battery port. * * \return The current voltage of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery Level: %.2f\n", get_capacity()); + * } + * \endcode */ double get_capacity(void); @@ -279,6 +436,13 @@ double get_capacity(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current current of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery Current: %d\n", get_current()); + * } + * \endcode */ int32_t get_current(void); @@ -290,6 +454,13 @@ int32_t get_current(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current temperature of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery's Temperature: %.2f\n", get_temperature()); + * } + * \endcode */ double get_temperature(void); @@ -301,8 +472,16 @@ double get_temperature(void); * EACCES - Another resource is currently trying to access the battery port. * * \return The current capacity of the battery + * + * \b Example + * \code + * void initialize() { + * printf("Battery's Voltage: %d\n", get_voltage()); + * } + * \endcode */ int32_t get_voltage(void); +///@} } // namespace battery namespace competition { @@ -311,11 +490,27 @@ namespace competition { * * \return The competition control status as a mask of bits with * COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}. + * + * \b Example + * \code + * void status_display_task(){ + * if(!is_connected()) { + * pros::lcd::print(0, "V5 Brain is not connected!"); + * } + * if(is_autonomous()) { + * pros::lcd::print(0, "V5 Brain is in autonomous mode!"); + * } + * if(!is_disabled()) { + * pros::lcd::print(0, "V5 Brain is disabled!"); + * } + * \endcode */ std::uint8_t get_status(void); std::uint8_t is_autonomous(void); std::uint8_t is_connected(void); std::uint8_t is_disabled(void); +std::uint8_t is_field_control(void); +std::uint8_t is_competition_switch(void); } // namespace competition namespace usd { @@ -323,9 +518,60 @@ namespace usd { * Checks if the SD card is installed. * * \return 1 if the SD card is installed, 0 otherwise + * + * \b Example + * \code + * void opcontrol() { + * printf("%i", is_installed()); + * } + * \endcode */ std::int32_t is_installed(void); +/** + * Lists the files in a directory specified by the path + * Puts the list of file names (NOT DIRECTORIES) into the buffer seperated by newlines + * + * This function uses the following values of errno when an error state is + * reached: + * + * EIO - Hard error occured in the low level disk I/O layer + * EINVAL - file or directory is invalid, or length is invalid + * EBUSY - THe physical drinve cannot work + * ENOENT - cannot find the path or file + * EINVAL - the path name format is invalid + * EACCES - Access denied or directory full + * EEXIST - Access denied + * EROFS - SD card is write protected + * ENXIO - drive number is invalid or not a FAT32 drive + * ENOBUFS - drive has no work area + * ENFILE - too many open files + * + * + * + * \note use a path of "\" to list the files in the main directory NOT "/usd/" + * DO NOT PREPEND YOUR PATHS WITH "/usd/" + * + * \return 1 on success or PROS_ERR on failure setting errno + * + * \b Example + * \code + * void opcontrol() { + * char* test = (char*) malloc(128); + * pros::usd::list_files("/", test, 128); + * pros::delay(200); + * printf("%s\n", test); //Prints the file names in the root directory seperated by newlines + * pros::delay(100); + * pros::list_files("/test", test, 128); + * pros::delay(200); + * printf("%s\n", test); //Prints the names of files in the folder named test seperated by newlines + * pros::delay(100); + * } + * \endcode + */ + +std::int32_t list_files(const char* path, char* buffer, std::int32_t len); } // namespace usd + } // namespace pros #endif // _PROS_MISC_HPP_ diff --git a/include/pros/motor_group.hpp b/include/pros/motor_group.hpp new file mode 100644 index 00000000..33edd0f5 --- /dev/null +++ b/include/pros/motor_group.hpp @@ -0,0 +1,2378 @@ +/** + * \file pros/motor_group.hpp + * \ingroup cpp-motor-group + * + * Contains prototypes for the V5 Motor-related functions. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/motors.html to learn + * more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-motor-group Motors C++ API + * \note Additional example code for this module can be found in its [Tutorial](@ref motors). + */ + +#ifndef _PROS_MOTOR_GROUP_HPP_ +#define _PROS_MOTOR_GROUP_HPP_ + +#include +#include + +#include "pros/abstract_motor.hpp" +#include "pros/colors.hpp" +#include "pros/device.hpp" +#include "pros/motors.h" +#include "pros/motors.hpp" +#include "rtos.hpp" + +namespace pros { +inline namespace v5 { +class MotorGroup : public virtual AbstractMotor { + /** + * \addtogroup cpp-motor-group + * @{ + */ + public: + /** + * Constructs a new MotorGroup object. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports |1-21|. + * ENODEV - The port cannot be configured as a motor + * + * \param port + * A initializer list of V5 port numbers from 1 to 21, or from -21 to -1 for reversed motors. + * A reversed motor will reverse the input or output movement functions and movement related + * telemetry in order to produce consistant behavior with non-reversed motors + * + * \param gearset = pros::v5::MotorGears::invalid + * Optional parameter for the gearset for the motor. + * Does not explicitly set the motor gearset if it is invalid or not specified + * + * \param encoder_units = pros::v5::MotorUnits::invalid + * Optional parameter for the encoder units of the motor + * Does not explicitly set the motor units if it is invalid or not specified + * + * \b Example + * \code + * void opcontrol() { + * MotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2 + * MotorGroup rotations_mg({4, 5}, pros::v5::MotorGears::blue, pros::v5::MotorUnits::rotations); + * //Creates a motor group on ports 4 and 5 with blue motors using rotaions as the encoder units + * } + * \endcode + */ + MotorGroup(const std::initializer_list, + const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid); + /** + * Constructs a new MotorGroup object. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENXIO - The given value is not within the range of V5 ports |1-21|. + * + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * \param port + * A initializer list of V5 port numbers from 1 to 21, or from -21 to -1 for reversed motors. + * A reversed motor will reverse the input or output movement functions and movement related + * telemetry in order to produce consistant behavior with non-reversed motors + * + * \param gearset = pros::v5::MotorGears::invalid + * \param gearset = pros::v5::MotorGears::green + * Optional parameter for the gearset for the motor. + * Does not explicitly set the motor gearset if it is invalid or not specified + * + * \param encoder_units = pros::v5::MotorUnits::invalid + * Optional parameter for the encoder units of the motor + * Does not explicitly set the motor units if it is invalid or not specified + * + * \b Example + * \code + * void opcontrol() { + * MotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2 with + * with both motors using the green gearset and degrees as the encoder units + * MotorGroup rotations_mg({4, 5}, pros::v5::MotorGears::blue, pros::v5::MotorUnits::rotations); + * //Creates a motor group on ports 4 and 5 with blue motors using rotaions as the encoder units + * } + * \endcode + */ + MotorGroup(const std::vector& ports, const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid); + + /** + * Constructs a new MotorGroup object from an abstract motor. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENXIO - The given value is not within the range of V5 ports |1-21|. + * + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * \param abstract_motor + * THe abstract motor to turn into a motor group + * Uses abstract_motor.get_port_all() to get the vector of ports + * + * + * \b Example + * \code + * void opcontrol() { + * MotorGroup first_mg({1, -2}); //Creates a motor on port 1 and a reversed motor on port 2 with + * with both motors using the green gearset and degrees as the encoder units + * AbstractMotor abs_mtr_group = first_mg; + * MotorGroup new_mg = (MotorGroup) abs_mtr_group; + * } + * \endcode + */ + + MotorGroup(AbstractMotor& motor_group); + + /// \name Motor movement functions + /// These functions allow programmers to make motors move + ///@{ + + /** + * Sets the voltage for the motor group from -127 to 127. + * + * This is designed to map easily to the input from the controller's analog + * stick for simple opcontrol use. The actual behavior of the motor is + * analogous to use of motor_move() + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param voltage + * The new voltage from -127 to 127 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup MotorGroup ({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t move(std::int32_t voltage) const; + + /** + * Sets the target absolute position for the motor group to move to. + * + * This movement is relative to the position of the motor when initialized or + * the position when it was most recently reset with + * pros::Motor::set_zero_position(). + * + * \note This function simply sets the target for the motor, it does not block + * program execution until the movement finishes. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - the motor group has size 0 + * + * \param position + * The absolute position to move to in the motor's encoder units + * \param velocity + * The maximum allowable velocity for the movement in RPM + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg ({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * while (!((mg.get_position() < 105) && (mg.get_position() > 95))) { + * // Continue running this loop as long as the mg is not within +-5 units of its goal + * pros::delay(2); + * } + * mg.move_absolute(100, 100); // This does not cause a movement + * while (!((mg.get_position() < 105) && (mg.get_position() > 95))) { + * pros::delay(2); + * } + * mg.tare_position(); + * mg.move_absolute(100, 100); // Moves 100 units forward + * while (!((mg.get_position() < 105) && (mg.get_position() > 95))) { + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t move_absolute(const double position, const std::int32_t velocity) const; + + /** + * Sets the relative target position for the motor group to move to. + * + * This movement is relative to the current position of each motor as given in + * pros::MotorGroup::get_position(). Providing 10.0 as the position parameter + * would result in the motor moving 10 units, no matter what the + * current position is. + * + * \note This function simply sets the target for the motor, it does not block + * program execution until the movement finishes. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param position + * The relative position to move to in the motor's encoder units + * \param velocity + * The maximum allowable velocity for the movement in RPM + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_relative(100, 100); // Moves 100 units forward + * while (!((mg.get_position() < 105) && (mg.get_position() > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * pros::delay(2); + * } + * mg.move_relative(100, 100); // Also moves 100 units forward + * while (!((mg.get_position() < 205) && (mg.get_position() > 195))) { + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t move_relative(const double position, const std::int32_t velocity) const; + + /** + * Sets the velocity for the motor group. + * + * This velocity corresponds to different actual speeds depending on the + * gearset used for the motor. This results in a range of +-100 for + * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for + * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent + * speed, as opposed to setting the motor's voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param velocity + * The new velocity from +-100, +-200, or +-600 depending on the + * motor's gearset + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_velocity(100); + * pros::delay(1000); // Move at 100 RPM for 1 second + * mg.move_velocity(0); + * } + * \endcode + */ + std::int32_t move_velocity(const std::int32_t velocity) const; + + /** + * Sets the output voltage for the motor group from -12000 to 12000 in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param voltage + * The new voltage value from -12000 to 12000 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * mg.move_voltage(12000); + * pros::delay(1000); // Move at max voltage for 1 second + * mg.move_voltage(0); + * } + * \endcode + */ + std::int32_t move_voltage(const std::int32_t voltage) const; + + /** + * Stops the motor group using the currently configured brake mode. + * + * This function sets motor velocity to zero, which will cause it to act + * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, + * this function may behave differently than calling move_absolute(0) + * or motor_move_relative(0). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * Motor motor(1); + * mg.move_voltage(12000); + * pros::delay(1000); // Move at max voltage for 1 second + * motor.brake(); + * } + * \endcode + */ + std::int32_t brake(void) const; + + /** + * Changes the output velocity for a profiled movement (move_absolute or + * move_relative). This will have no effect if the motor group is not following + * a profiled movement. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param velocity + * The new motor velocity from +-100, +-200, or +-600 depending on the + * motor's gearset + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg ({1,3}); + * mg.move_absolute(100, 100); + * pros::delay(100); + * mg.modify_profiled_velocity(0); // Stop the motor group early + * } + * \endcode + */ + std::int32_t modify_profiled_velocity(const std::int32_t velocity) const; + + /** + * Gets the target position set for a motor in the motor group, with a parameter + * for the motor index. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The target position in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); + * // get the target position from motor at index 1. (port 3) + * std::cout << "Motor Target: " << mg.get_target_position(1); + * // Prints 100 + * } + * \endcode + */ + double get_target_position(const std::uint8_t index) const; + + /** + * Gets a vector of the the target positions set for the motor group + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The Motor group is empty + * + * \return The a vector of the target positions in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); + * std::cout << "Motor Target: " << mg.get_target_position_all()[0]; + * // Prints 100 + * } + * \endcode + */ + std::vector get_target_position_all(void) const; + + /** + * Gets the velocity commanded to the motor by the user at the index specified. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * EDOM - The motor group was empty + * + * \param index Optional parameter. + * The zero indexed index of the motor in the motor group + * + * \return The commanded motor velocity from +-100, +-200, or +-600, or + * PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg ({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * // get the target velocity from motor at index 1. (port 3) + * std::cout << "Motor Velocity: " << mg.get_target_velocity(1); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_target_velocity(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the velocity commanded to the motor by the user + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - THe motor group is empty + * + * \return A vector of the commanded motor velocity from +-100, +-200, or +-600, or + * PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg ({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * std::cout << "Motor Velocity: " << mg.get_target_velocity_all(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_target_velocity_all(void) const; + + ///@} + + /// \name Motor telemetry functions + /// These functions allow programmers to collect telemetry from motors + ///@{ + + /** + * Gets the actual velocity of a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - THe motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter. + * The zero indexed index of the motor in the motor group + * + * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * while (true) { + * mg = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y); + * // get the actual velocity from motor at index 1. (port 3) + * printf("Actual velocity: %lf\n", mg.get_actual_velocity(1)); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_actual_velocity(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the the actual velocity of each motor the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - THe motor group is empty + * + * \return A vector of the each motor's actual velocity in RPM or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * while (true) { + * mg = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y); + * // get the target velocity from motor at index 1. (port 3) + * printf("Actual velocity: %lf\n", mg.get_actual_velocity(1)); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_actual_velocity_all(void) const; + + /** + * Gets the current drawn by a motor in the motor group in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter. + * The zero indexed index of the motor in the motor group + * + * \return The motor's current in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * //Print the current draw for the motor at index 1. (port 3) + * std::cout << "Motor Current Draw: " << mg.get_current_draw(1); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_current_draw(const std::uint8_t index = 0) const; + /** + * Gets a vector of the current drawn each motor in the motor group in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * + * \return A vector with each motor's current in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Current Draw: " << mg.get_current_draw_all(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_current_draw_all(void) const; + + /** + * Gets the direction of movement for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * //Print the motor direction for the motor at index 1. (port 3) + * std::cout << "Motor Direction: " << mg.get_direction(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_direction(const std::uint8_t index = 0) const; + /** + * Gets a vector of the directions of movement for each motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * \return 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Direction: " << mg.get_direction_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_direction_all(void) const; + + /** + * Gets the efficiency of a motor in the motor group in percent. + * + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's efficiency in percent or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * //Prints the efficiency of the motor at index 1 (port 3) + * std::cout << "Motor Efficiency: " << mg.get_efficiency(1); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_efficiency(const std::uint8_t index = 0) const; + /** + * Gets a vector of the efficiency of each motor in percent. + * + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - THe motor group is empty + * + * \return A vector containing each motor's efficiency in percent or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Efficiency: " << mg.get_efficiency_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_efficiency_all(void) const; + + /** + * Gets the faults experienced by a motor in the motor group. + * + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return A bitfield containing the motor's faults. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << mg.get_faults(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::uint32_t get_faults(const std::uint8_t index = 0) const; + /** + * Gets a vector of the faults experienced by each motor in the motor group. + * + * Compare these bitfields to the bitmasks in pros::motor_fault_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * EDOM - The motor group is empty + * + * + * \return A vector containing the bitfields containing each motor's faults. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << mg.get_faults_all(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_faults_all(void) const; + /** + * Gets the flags set by a motor in the motor group's operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << mg.get_faults(1); + * pros::delay(2); + * } + * } + * \endcode + */ + std::uint32_t get_flags(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the flags set by each motor in the motor groups's operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << mg.get_faults_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_flags_all(void) const; + + /** + * Gets the absolute position of a motor in the motor group in its encoder units. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << mg.get_position(1); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_position(const std::uint8_t index = 0) const; + /** + * Gets a vector of the absolute position of each motor in its encoder units. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of the motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << mg.get_position_all(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_position_all(void) const; + + /** + * Gets the power drawn by a motor in the motor group in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Power: " << mg.get_power(); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_power(const std::uint8_t index = 0) const; + /** + * Gets a vector of the power drawn by each motor in the motor group in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of each motor's power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Power: " << mg.get_power_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_power_all(void) const; + /** + * Gets the raw encoder count of a motor in the motor group at a given timestamp. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * + * \param timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The raw encoder count at the given timestamp or PROS_ERR if the + * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * std::uint32_t now = pros::millis(); + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << mg.get_raw_position(&now); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const; + /** + * Gets the raw encoder count of each motor at a given timestamp. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \param timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \return A vector of each raw encoder count at the given timestamp or PROS_ERR if the + * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * std::uint32_t now = pros::millis(); + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << mg.get_raw_position_all(&now)[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_raw_position_all(std::uint32_t* const timestamp) const; + + /** + * Gets the temperature of a motor in the motor group in degrees Celsius. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Temperature: " << mg.get_temperature(); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_temperature(const std::uint8_t index = 0) const; + /** + * Gets the temperature of each motor in the motor group in degrees Celsius. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of each motor's temperature in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Temperature: " << mg.get_temperature_all()[1]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_temperature_all(void) const; + /** + * Gets the torque generated by a motor in the motor groupin Newton Meters (Nm). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Torque: " << mg.get_torque(); + * pros::delay(2); + * } + * } + * \endcode + */ + double get_torque(const std::uint8_t index = 0) const; + /** + * Gets a vector of the torque generated by each motor in Newton Meters (Nm). + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector containing each motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Torque: " << mg.get_torque(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_torque_all(void) const; + /** + * Gets the voltage delivered to a motor in the motor group in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Voltage: " << mg.get_voltage(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_voltage(const std::uint8_t index = 0) const; + /** + * Gets a vector of the voltage delivered to each motor in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of each motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Voltage: " << mg.get_voltage_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_voltage_all(void) const; + + /** + * Checks if a motor in the motor group is drawing over its current limit. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its current limit?: " << mg.is_over_current(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t is_over_current(const std::uint8_t index = 0) const; + /** + * Checks if each motor in the motor group is drawing over its current limit. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector containing the following for each motor: 1 if the motor's current limit is being exceeded and 0 if + * the current limit is not exceeded, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its current limit?: " << motor.is_over_current_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector is_over_current_all(void) const; + + /** + * Gets the temperature limit flag for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t is_over_temp(const std::uint8_t index = 0) const; + /** + * Gets a vector with the temperature limit flag for each motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector is_over_temp_all(void) const; + + ///@} + + /// \name Motor configuration functions + /// These functions allow programmers to configure the behavior of motors + ///@{ + + /** + * Gets the brake mode that was set for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return One of MotorBrake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + MotorBrake get_brake_mode(const std::uint8_t index = 0) const; + /** + * Gets a vector with the brake mode that was set for each motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector with one of MotorBrake for each motor in the motor group, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << mg.get_brake_mode_all()[0]; + * } + * \endcode + */ + std::vector get_brake_mode_all(void) const; + + /** + * Gets the current limit for a motor in the motor group in mA. + * + * The default value is 2500 mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * while (true) { + * std::cout << "Motor Current Limit: " << mg.get_current_limit(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_current_limit(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the current limit for each motor in the motor group in mA. + * + * The default value is 2500 mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector of each motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * while (true) { + * std::cout << "Motor Current Limit: " << mg.get_current_limit_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_current_limit_all(void) const; + + /** + * Gets the encoder units that were set for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return One of MotorUnits according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + MotorUnits get_encoder_units(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the encoder units that were set for each motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \return A vector with the following for each motor, One of MotorUnits according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Encoder Units: " << mg.get_encoder_units_all()[0]; + * } + * \endcode + */ + std::vector get_encoder_units_all(void) const; + + /** + * Gets the gearset that was set for a motor in the motor group. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + *\param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return One of MotorGears according to what is set for the motor, + * or pros::MotorGears::invalid if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Gearing: " << mg.get_gearing(); + * } + * \endcode + */ + MotorGears get_gearing(const std::uint8_t index = 0) const; + /** + * Gets a vector of the gearset that was set for each motor. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * + * \return A vector with one of MotorGears according to what is set for the motor, + * or pros::MotorGears::invalid if the operation failed for each motor. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg ({1,3}, E_MOTOR_GEARSET_06, false, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Gearing: " << mg.get_gearing_all()[0]; + * } + * \endcode + */ + std::vector get_gearing_all(void) const; + + /** + * Gets a vector with all the port numbers in the motor group. + * A port will be negative if the motor in the motor group is reversed + * + * @return a vector with all the port numbers for the motor group + */ + std::vector get_port_all(void) const; + + /** + * Gets the voltage limit of a motor in the motor group set by the user. + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + *\param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * std::cout << "Motor Voltage Limit: " << mg.get_voltage_limit(1); + * } + * \endcode + */ + std::int32_t get_voltage_limit(const std::uint8_t index = 0) const; + + /** + * Gets a vector of the voltage limit of each motor in the motor group + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The Motor group is empty + * + * \return The motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * std::cout << "Motor Voltage Limit: " << mg.get_voltage_limit_all()[0]; + * } + * \endcode + */ + std::vector get_voltage_limit_all(void) const; + + /** + * Gets the operation direction of a motor in the motor group as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + *\param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * std::cout << "Is the motor reversed? " << motor.is_reversed(); + * // Prints "0" + * } + * \endcode + */ + std::int32_t is_reversed(const std::uint8_t index = 0) const; + /** + * Gets a vector of the operation direction of each motor in the motor group as set by the user. + * + * This function uses the following values of errno when an error state is + * reached: + * EDOM - The motor group is empty + * + * \return A vector conatining the following for each motor: 1 if the motor has been reversed and 0 if the motor was + * not reversed, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * std::cout << "Is the motor reversed? " << motor.is_reversed_all()[0]; + * // Prints "0" + * } + * \endcode + */ + std::vector is_reversed_all(void) const; + + /** + * Sets one of MotorBrake to a motor in the motor group. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode(pros::MotorBrake::brake, 1); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + std::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const; + /** + * Sets one of MotorBrake to a motor in the motor group. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD, 1); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const; + /** + * Sets one of MotorBrake all the motors in the motor group. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param mode + * The MotorBrake to set for the motor + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode_all(pros::MotorBrake:brake); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + std::int32_t set_brake_mode_all(const MotorBrake mode) const; + /** + * Sets one of MotorBrake to a motor in the motor group. Works with the C enum + * and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param mode + * The MotorBrake to set for the motor + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << mg.get_brake_mode(); + * } + * \endcode + */ + std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const; + /** + * Sets the current limit for one motor in the motor group in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param limit + * The new current limit in mA + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * mg.set_current_limit(1000); + * while (true) { + * mg = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const; + /** + * Sets the current limit for every motor in the motor group in mA. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group was empty + * + * \param limit + * The new current limit in mA + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * mg.set_current_limit_all(1000); + * while (true) { + * mg = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t set_current_limit_all(const std::int32_t limit) const; + /** + * Sets one of MotorUnits for one motor in the motor group's motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param units + * The new motor encoder units + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_encoder_units(E_MOTOR_ENCODER_DEGREES, 1); + * std::cout << "Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const; + /** + * Sets one of MotorUnits for one motor in the motor group's motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param units + * The new motor encoder units + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_encoder_units(E_MOTOR_ENCODER_DEGREES, 1); + * std::cout << "Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const; + /** + * Sets one of MotorUnits for every motor in the motor group's motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param units + * The new motor encoder units + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + std::int32_t set_encoder_units_all(const MotorUnits units) const; + /** + * Sets one of MotorUnits for every motor in the motor group's motor encoder. Works with the C + * enum and the C++ enum class. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param units + * The new motor encoder units + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << mg.get_encoder_units(); + * } + * \endcode + */ + std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const; + + /** + * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * E2BIG - The size of the vector mismatches the number of motors in the motor group + * + * \note If there are more motors than gearsets passed in, + * only the first n motors will have their gearsets changed where n is the number of gearsets passed in. + * If there are more gearsets passed in than motors, then the only the first m gearsets will be used, + * where m is the number of motors. In either case, errno will be set to E2BIG, but the operation still occurs + * + * + * \param gearset + * The new geatset of the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing(pros::MotorGears::blue, 1); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing(std::vector gearsets) const; + /** + * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param gearset + * The new geatset of the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing(E_MOTOR_GEARSET_06, 1); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const; + + /** + * Sets the gear cartridge (red, green, blue) for each motor in the motor group by taking in a vector of the + * cartridges. Usable with the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * E2BIG - The size of the vector mismatches the number of motors in the motor group + * + * \note If there are more motors than gearsets passed in, + * only the first n motors will have their gearsets changed where n is the number of gearsets passed in. + * If there are more gearsets passed in than motors, then the only the first m gearsets will be used, + * where m is the number of motors. In either case, errno will be set to E2BIG, but the operation still occurs + * + * \param gearset + * The a vector containing the new geatsets of the motors + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing(pros::MotorGears::blue, 1); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing(std::vector gearsets) const; + + /** + * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param gearset + * The new geatset of the motor + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing(E_MOTOR_GEARSET_06, 1); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const; + /** + * Sets one of the gear cartridge (red, green, blue) for one motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param gearset + * The new geatset of the motor + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing_all(const MotorGears gearset) const; + /** + * Sets one of the gear cartridge (red, green, blue) for every motor in the motor group. Usable with + * the C++ enum class and the C enum. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param gearset + * The new geatset of the motor + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_gearing_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << mg.get_gearing(); + * } + * \endcode + */ + std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const; + + /** + * sets the reversal for a motor in the motor group. + * + * This will invert its movements and the values returned for its position. + * + * This function uses the following values of errno when an error state is + * reached: + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param reverse + * True reverses the motor, false is default + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * //reverse the motor at index 1 (port 3) + * mg.set_reversed(true, 1); + * std::cout << "Is this motor reversed? " << motor.is_reversed(1); + * pros::delay(100); + * // unreverse the motor at index 1 (port 3) + * mg.set_reversed(false, 1); + * std::cout << "Is this motor reversed? " << motor.is_reversed(1); + * } + * \endcode + */ + std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0); + /** + * Sets the reversal for all the motors in the motor group. + * + * This will invert its movements and the values returned for its position. + * + * This function uses the following values of errno when an error state is + * reached: + * EDOM - The motor group is empty + * + * \param reverse + * True reverses the motor, false is default + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::MotorGroup mg({1,3}); + * mg.set_reversed_all(true); + * std::cout << "Is this motor reversed? " << motor.is_reversed(); + * } + * \endcode + */ + std::int32_t set_reversed_all(const bool reverse); + + /** + * Sets the voltage limit for a motor in the motor group in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param limit + * The new voltage limit in Volts + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * mg.set_voltage_limit(10000, 1); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor on at index 1 (port 3) will not output more than 10 V + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const; + + /** + * Sets the voltage limit for every motor in the motor group in millivolts. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param limit + * The new voltage limit in Volts + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * mg.set_voltage_limit_all(10000); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will not output more than 10 V + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t set_voltage_limit_all(const std::int32_t limit) const; + + /** + * Sets the position for a motor in the motor group in its encoder units. + * + * This will be the future reference point for the motor's "absolute" + * position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param position + * The new reference position in its encoder units + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * mg.move_absolute(100, 100); // This does not cause a movement + * mg.set_zero_position(80); + * mg.set_zero_position(80, 1); + * mg.move_absolute(100, 100); // Moves 80 units forward + * } + * \endcode + * + */ + std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const; + /** + * Sets the position for every motor in the motor group in its encoder units. + * + * This will be the future reference point for the motor's "absolute" + * position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * + * \param position + * The new reference position in its encoder units + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * mg.move_absolute(100, 100); // This does not cause a movement + * + * mg.set_zero_position_all(80); + * mg.move_absolute(100, 100); // Moves 80 units forward + * } + * \endcode + * + */ + std::int32_t set_zero_position_all(const double position) const; + + /** + * Sets the "absolute" zero position of a motor in the motor group to its current position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * EDOM - The motor group is empty + * EOVERFLOW - The index is greater than or equal to MotorGroup::size() + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * mg.move_absolute(100, 100); // This does not cause a movement + * + * mg.tare_position(); + * mg.tare_position(1); + * + * mg.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode + */ + std::int32_t tare_position(const std::uint8_t index = 0) const; + + /** + * Sets the "absolute" zero position of every motor in the motor group to its current position. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::MotorGroup mg({1,3}); + * mg.move_absolute(100, 100); // Moves 100 units forward + * mg.move_absolute(100, 100); // This does not cause a movement + * mg.tare_position_all(); + * mg.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode + */ + std::int32_t tare_position_all(void) const; + + /** + * Returns the number of motors in the motor group + * + * \return the number of motors in the motor group + */ + std::int8_t size(void) const; + + /** + * Gets the port of a motor in the motor group via index + * + * \param index Optional parameter, 0 by default. + * The zero indexed index of the motor in the motor group + * + * \return The port of the motor at the specified index. + * The return value is negative if the corresponding motor is reversed + */ + std::int8_t get_port(const std::uint8_t index = 0) const; + + /** + * Appends all the motors in the other motor group reference to this motor group + * + * Maintains the order of the other motor group + * + */ + void operator+=(AbstractMotor&); + + /** + * Appends all the motors in the other motor group reference to this motor group + * + * Maintains the order of the other motor group + * + */ + void append(AbstractMotor&); + + /** + * Removes the all motors on the port (regardless of reversal) from the motor group + * + * \param port The port to remove from the motor group + * + */ + void erase_port(std::int8_t port); + + ///@} + private: + /** + * The ordered vector of ports used by the motor group + */ + std::vector _ports; + mutable pros::Mutex _MotorGroup_mutex; +}; +} // namespace v5 +} // namespace pros +#endif \ No newline at end of file diff --git a/include/pros/motors.h b/include/pros/motors.h index 73710924..acf61e7a 100644 --- a/include/pros/motors.h +++ b/include/pros/motors.h @@ -1,19 +1,20 @@ /** * \file pros/motors.h + * \ingroup c-motors * * Contains prototypes for the V5 Motor-related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/motors.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-motors Motors C API + * \note Additional example code for this module can be found in its [Tutorial](@ref motors). */ #ifndef _PROS_MOTORS_H_ @@ -28,33 +29,54 @@ namespace pros { namespace c { #endif -/******************************************************************************/ -/** Motor movement functions **/ -/** **/ -/** These functions allow programmers to make motors move **/ -/******************************************************************************/ +/** + * \ingroup c-motors + */ + +/** + * \addtogroup c-motors + * @{ + */ + +/// \name Motor movement functions +/// These functions allow programmers to make motors move +///@{ /** * Sets the voltage for the motor from -127 to 127. * * This is designed to map easily to the input from the controller's analog * stick for simple opcontrol use. The actual behavior of the motor is analogous - * to use of motor_move_voltage(), or motorSet() from the PROS 2 API. + * to use of motor_move_voltage(). * + * \note This function will not respect brake modes, and simply sets the voltage to the desired value. + * + * \note A negative port will negate the input voltage + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param voltage * The new motor voltage from -127 to 127 * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_move(uint8_t port, int32_t voltage); +int32_t motor_move(int8_t port, int32_t voltage); /** * Stops the motor using the currently configured brake mode. @@ -66,16 +88,25 @@ int32_t motor_move(uint8_t port, int32_t voltage); * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move(1, 127); + * delay(1000); + * motor_break(1); + * } + * \endcode */ -int32_t motor_brake(uint8_t port); +int32_t motor_brake(int8_t port); /** * Sets the target absolute position for the motor to move to. @@ -83,16 +114,18 @@ int32_t motor_brake(uint8_t port); * This movement is relative to the position of the motor when initialized or * the position when it was most recently reset with motor_set_zero_position(). * - * \note This function simply sets the target for the motor, it does not block - * program execution until the movement finishes. + * \note This function simply sets the target for the motor, it does not block program + * execution until the movement finishes. The example code shows how to block until a movement is finished. * + * \note A negative port number will negate the target position + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param position * The absolute position to move to in the motor's encoder units * \param velocity @@ -100,8 +133,29 @@ int32_t motor_brake(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * delay(2); + * } + * motor_move_absolute(1, 100, 100); // This will not cause a movement + * while(!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) { + * delay(2); + * } + * + * motor_tare_position(1); + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) { + * delay(2); + * } + * } + * \endcode */ -int32_t motor_move_absolute(uint8_t port, const double position, const int32_t velocity); +int32_t motor_move_absolute(int8_t port, double position, const int32_t velocity); /** * Sets the relative target position for the motor to move to. @@ -112,15 +166,18 @@ int32_t motor_move_absolute(uint8_t port, const double position, const int32_t v * is. * * \note This function simply sets the target for the motor, it does not block - * program execution until the movement finishes. + * program execution until the movement finishes. The example code shows how to + * block until a movement is finished. * + * \note A negative port will negate the target position + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param position * The relative position to move to in the motor's encoder units * \param velocity @@ -128,8 +185,24 @@ int32_t motor_move_absolute(uint8_t port, const double position, const int32_t v * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_relative(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) < 105) && (motor_get_position(1) > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * delay(2); + * } + * + * motor_move_relative(1, 100, 100); // Also moves 100 units forward + * while (!((motor_get_position(1) < 205) && (motor_get_position(1) > 195))) { + * delay(2); + * } + * } + * \endcode */ -int32_t motor_move_relative(uint8_t port, const double position, const int32_t velocity); +int32_t motor_move_relative(int8_t port, double position, const int32_t velocity); /** * Sets the velocity for the motor. @@ -140,146 +213,243 @@ int32_t motor_move_relative(uint8_t port, const double position, const int32_t v * is held with PID to ensure consistent speed, as opposed to setting the * motor's voltage. * + * \note A negative port will negate the velocity + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param velocity * The new motor velocity from +-100, +-200, or +-600 depending on the * motor's gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_velocity(1, 100); + * delay(1000); // Move at 100 RPM for 1 second + * motor_move_velocity(1, 0); + * } + * \endcode */ -int32_t motor_move_velocity(uint8_t port, const int32_t velocity); +int32_t motor_move_velocity(int8_t port, const int32_t velocity); /** - * Sets the output voltage for the motor from -12000 to 12000 in millivolts + * Sets the output voltage for the motor from -12000 to 12000 in millivolts. * + * \note A negative port negates the voltage + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor + * + * \note This function will not respect brake modes, and simply sets the + * voltage to the desired value. * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param voltage * The new voltage value from -12000 to 12000 * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_voltage(1, 12000); + * delay(1000); // Move at max voltage for 1 second + * motor_move_voltage(1, 0); + * } + * \endcode */ -int32_t motor_move_voltage(uint8_t port, const int32_t voltage); +int32_t motor_move_voltage(int8_t port, const int32_t voltage); /** * Changes the output velocity for a profiled movement (motor_move_absolute or * motor_move_relative). This will have no effect if the motor is not following * a profiled movement. * + * \note A negative port negates the velocity + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param velocity * The new motor velocity from +-100, +-200, or +-600 depending on the * motor's gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); + * delay(100); + * motor_modify_profiled_velocity(1, 0); // Stop the motor early + * } + * \endcode */ -int32_t motor_modify_profiled_velocity(uint8_t port, const int32_t velocity); +int32_t motor_modify_profiled_velocity(int8_t port, const int32_t velocity); /** * Gets the target position set for the motor by the user. * + * \note A negative port negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The target position in its encoder units or PROS_ERR_F if the * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); + * printf("Motor Target: %d\n", motor_get_target_position(1)); + * // Prints 100 + * } + * \endcode */ -double motor_get_target_position(uint8_t port); +double motor_get_target_position(int8_t port); /** * Gets the velocity commanded to the motor by the user. * + * \note A negative port negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The commanded motor velocity from +-100, +-200, or +-600, or PROS_ERR * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move_velocity(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Commanded Velocity: %d\n", motor_get_target_velocity(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_target_velocity(uint8_t port); +int32_t motor_get_target_velocity(int8_t port); + +///@} -/******************************************************************************/ -/** Motor telemetry functions **/ -/** **/ -/** These functions allow programmers to collect telemetry from motors **/ -/******************************************************************************/ +/// \name Motor telemetry functions +/// These functions allow programmers to collect telemetry from motors +///@{ /** * Gets the actual velocity of the motor. * + * \note A negative port negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Actual velocity: %lf\n", motor_get_actual_velocity(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_actual_velocity(uint8_t port); +double motor_get_actual_velocity(int8_t port); /** * Gets the current drawn by the motor in mA. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's current in mA or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Current Draw: %d\n", motor_get_current_draw(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_current_draw(uint8_t port); +int32_t motor_get_current_draw(int8_t port); /** * Gets the direction of movement for the motor. * + * \note A negative port number negates the return value. + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 for moving in the positive direction, -1 for moving in the * negative direction, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Direction: %d\n", motor_get_direction(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_direction(uint8_t port); +int32_t motor_get_direction(int8_t port); /** * Gets the efficiency of the motor in percent. @@ -290,90 +460,102 @@ int32_t motor_get_direction(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's efficiency in percent or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Efficiency: %d\n", motor_get_efficiency(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_efficiency(uint8_t port); +double motor_get_efficiency(int8_t port); /** * Checks if the motor is drawing over its current limit. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 if the motor's current limit is being exceeded and 0 if the current * limit is not exceeded, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Current Limit Hit?: %d\n", motor_is_over_current(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_is_over_current(uint8_t port); +int32_t motor_is_over_current(int8_t port); /** * Checks if the motor's temperature is above its limit. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 if the temperature limit is exceeded and 0 if the the temperature * is below the limit, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Temp Limit: %d\n", motor_is_over_temp(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_is_over_temp(uint8_t port); +int32_t motor_is_over_temp(int8_t port); -/** - * Checks if the motor is stopped. - * - * \note Although this function forwards data from the motor, the motor - * presently does not provide any value. This function returns PROS_ERR with - * errno set to ENOSYS. - * - * \param port - * The V5 port number from 1-21 - * - * \return 1 if the motor is not moving, 0 if the motor is moving, or PROS_ERR - * if the operation failed, setting errno - */ -int32_t motor_is_stopped(uint8_t port); -/** - * Checks if the motor is at its zero position. - * - * \note Although this function forwards data from the motor, the motor - * presently does not provide any value. This function returns PROS_ERR with - * errno set to ENOSYS. - * - * \param port - * The V5 port number from 1-21 - * - * \return 1 if the motor is at zero absolute position, 0 if the motor has - * moved from its absolute zero, or PROS_ERR if the operation failed, - * setting errno - */ -int32_t motor_get_zero_position_flag(uint8_t port); #ifdef __cplusplus } // namespace c #endif +/** + * \enum motor_fault_e_t + */ typedef enum motor_fault_e { + /// No faults E_MOTOR_FAULT_NO_FAULTS = 0x00, - E_MOTOR_FAULT_MOTOR_OVER_TEMP = 0x01, // Analogous to motor_is_over_temp() - E_MOTOR_FAULT_DRIVER_FAULT = 0x02, // Indicates a motor h-bridge fault - E_MOTOR_FAULT_OVER_CURRENT = 0x04, // Analogous to motor_is_over_current() - E_MOTOR_FAULT_DRV_OVER_CURRENT = 0x08 // Indicates an h-bridge over current + /// Analogous to motor_is_over_temp() + E_MOTOR_FAULT_MOTOR_OVER_TEMP = 0x01, + /// Indicates a motor h-bridge fault + E_MOTOR_FAULT_DRIVER_FAULT = 0x02, + /// Analogous to motor_is_over_current() + E_MOTOR_FAULT_OVER_CURRENT = 0x04, + /// Indicates an h-bridge over current + E_MOTOR_FAULT_DRV_OVER_CURRENT = 0x08 } motor_fault_e_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -410,18 +592,37 @@ namespace c { * The V5 port number from 1-21 * * \return A bitfield containing the motor's faults. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Faults: %d\n", motor_get_faults(1)); + * delay(2); + * } + * } + * \endcode */ -uint32_t motor_get_faults(uint8_t port); +uint32_t motor_get_faults(int8_t port); #ifdef __cplusplus } // namespace c #endif +/** + * \enum motor_flag_e_t + * + */ typedef enum motor_flag_e { + ///There are no flags raised E_MOTOR_FLAGS_NONE = 0x00, - E_MOTOR_FLAGS_BUSY = 0x01, // Cannot currently communicate to the motor - E_MOTOR_FLAGS_ZERO_VELOCITY = 0x02, // Analogous to motor_is_stopped() - E_MOTOR_FLAGS_ZERO_POSITION = 0x04 // Analogous to motor_get_zero_position_flag() + /// Cannot currently communicate to the motor + E_MOTOR_FLAGS_BUSY = 0x01, + /// Analogous to motor_is_stopped() + E_MOTOR_FLAGS_ZERO_VELOCITY = 0x02, + /// Analogous to motor_get_zero_position_flag() + E_MOTOR_FLAGS_ZERO_POSITION = 0x04 } motor_flag_e_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -449,26 +650,39 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Flags: %d\n", motor_get_flags(1)); + * delay(2); + * } + * } + * \endcode */ -uint32_t motor_get_flags(uint8_t port); +uint32_t motor_get_flags(int8_t port); /** * Gets the raw encoder count of the motor at a given timestamp. * + * \note A negative port value negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param[in] timestamp * A pointer to a time in milliseconds for which the encoder count * will be returned. If NULL, the timestamp at which the encoder @@ -476,72 +690,131 @@ uint32_t motor_get_flags(uint8_t port); * * \return The raw encoder count at the given timestamp or PROS_ERR if the * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * uint32_t now = millis(); + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Encoder Count: %d\n", motor_get_raw_position(1, &now)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_raw_position(uint8_t port, uint32_t* const timestamp); +int32_t motor_get_raw_position(int8_t port, uint32_t* const timestamp); /** * Gets the absolute position of the motor in its encoder units. * + * \note A negative port value negates the return value + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's absolute position in its encoder units or PROS_ERR_F * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Position: %lf\n", motor_get_position(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_position(uint8_t port); +double motor_get_position(int8_t port); /** * Gets the power drawn by the motor in Watts. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's power draw in Watts or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * uint32_t now = millis(); + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Power: %lf\n", motor_get_power(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_power(uint8_t port); +double motor_get_power(int8_t port); /** * Gets the temperature of the motor in degrees Celsius. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the * operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Temperature: %lf\n", motor_get_temperature(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_temperature(uint8_t port); +double motor_get_temperature(int8_t port); /** * Gets the torque generated by the motor in Newton Meters (Nm). * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Torque: %lf\n", motor_get_torque(1)); + * delay(2); + * } + * } + * \endcode */ -double motor_get_torque(uint8_t port); +double motor_get_torque(int8_t port); /** * Gets the voltage delivered to the motor in millivolts. @@ -552,60 +825,79 @@ double motor_get_torque(uint8_t port); * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * printf("Motor Voltage: %lf\n", motor_get_voltage(1)); + * delay(2); + * } + * } + * \endcode */ -int32_t motor_get_voltage(uint8_t port); +int32_t motor_get_voltage(int8_t port); + +///@} -/******************************************************************************/ -/** Motor configuration functions **/ -/** **/ -/** These functions allow programmers to configure the behavior of motors **/ -/******************************************************************************/ +/// \name Motor configuration functions +/// These functions allow programmers to configure the behavior of motors +///@{ #ifdef __cplusplus } // namespace c #endif /** + * \enum motor_brake_mode_e_t * Indicates the current 'brake mode' of a motor. */ typedef enum motor_brake_mode_e { - E_MOTOR_BRAKE_COAST = 0, // Motor coasts when stopped, traditional behavior - E_MOTOR_BRAKE_BRAKE = 1, // Motor brakes when stopped - E_MOTOR_BRAKE_HOLD = 2, // Motor actively holds position when stopped + /// Motor coasts when stopped, traditional behavior + E_MOTOR_BRAKE_COAST = 0, + /// Motor brakes when stopped + E_MOTOR_BRAKE_BRAKE = 1, + /// Motor actively holds position when stopped + E_MOTOR_BRAKE_HOLD = 2, + /// Invalid brake mode E_MOTOR_BRAKE_INVALID = INT32_MAX } motor_brake_mode_e_t; /** + * \enum motor_encoder_units_e_t * Indicates the units used by the motor encoders. */ typedef enum motor_encoder_units_e { - E_MOTOR_ENCODER_DEGREES = 0, // Position is recorded as angle in degrees - // as a floating point number - E_MOTOR_ENCODER_ROTATIONS = 1, // Position is recorded as angle in rotations - // as a floating point number - E_MOTOR_ENCODER_COUNTS = 2, // Position is recorded as raw encoder ticks - // as a whole number + /// Position is recorded as angle in degrees as a floating point number + E_MOTOR_ENCODER_DEGREES = 0, + /// Position is recorded as angle in rotations as a floating point number + E_MOTOR_ENCODER_ROTATIONS = 1, + /// Position is recorded as raw encoder ticks as a whole number + E_MOTOR_ENCODER_COUNTS = 2, + ///Invalid motor encoder units E_MOTOR_ENCODER_INVALID = INT32_MAX } motor_encoder_units_e_t; /** + * \enum motor_gearset_e_t * Indicates the current internal gear ratio of a motor. */ typedef enum motor_gearset_e { E_MOTOR_GEARSET_36 = 0, // 36:1, 100 RPM, Red gear set - E_MOTOR_GEAR_RED = E_MOTOR_GEARSET_36, - E_MOTOR_GEAR_100 = E_MOTOR_GEARSET_36, + E_MOTOR_GEAR_RED = E_MOTOR_GEARSET_36, // 36:1, 100 RPM, Red gear set + E_MOTOR_GEAR_100 = E_MOTOR_GEARSET_36, // 36:1, 100 RPM, Red gear set E_MOTOR_GEARSET_18 = 1, // 18:1, 200 RPM, Green gear set - E_MOTOR_GEAR_GREEN = E_MOTOR_GEARSET_18, - E_MOTOR_GEAR_200 = E_MOTOR_GEARSET_18, + E_MOTOR_GEAR_GREEN = E_MOTOR_GEARSET_18, // 18:1, 200 RPM, Green gear set + E_MOTOR_GEAR_200 = E_MOTOR_GEARSET_18, // 18:1, 200 RPM, Green gear set E_MOTOR_GEARSET_06 = 2, // 6:1, 600 RPM, Blue gear set - E_MOTOR_GEAR_BLUE = E_MOTOR_GEARSET_06, - E_MOTOR_GEAR_600 = E_MOTOR_GEARSET_06, - E_MOTOR_GEARSET_INVALID = INT32_MAX + E_MOTOR_GEAR_BLUE = E_MOTOR_GEARSET_06, // 6:1, 600 RPM, Blue gear set + E_MOTOR_GEAR_600 = E_MOTOR_GEARSET_06, // 6:1, 600 RPM, Blue gear set + E_MOTOR_GEARSET_INVALID = INT32_MAX, // Error: Invalid Gearset } motor_gearset_e_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -653,35 +945,49 @@ typedef enum motor_gearset_e { #endif /** + * \struct motor_pid_full_s_t + * * Holds the information about a Motor's position or velocity PID controls. * * These values are in 4.4 format, meaning that a value of 0x20 represents 2.0, * 0x21 represents 2.0625, 0x22 represents 2.125, etc. */ typedef struct motor_pid_full_s { - uint8_t kf; // The feedforward constant - uint8_t kp; // The proportional constant - uint8_t ki; // The integral constants - uint8_t kd; // The derivative constant - uint8_t filter; // A constant used for filtering the profile acceleration - uint16_t limit; // The integral limit - uint8_t threshold; // The threshold for determining if a position movement has - // reached its goal. This has no effect for velocity PID - // calculations. - uint8_t loopspeed; // The rate at which the PID computation is run in ms + /// The feedforward constant + uint8_t kf; + /// The proportional constant + uint8_t kp; + /// The integral constants + uint8_t ki; + /// The derivative constant + uint8_t kd; + /// A constant used for filtering the profile acceleration + uint8_t filter; + /// The integral limit + uint16_t limit; + /// The threshold for determining if a position movement hasreached its goa l. This has no effect for velocity PID calculations. + uint8_t threshold; + /// The rate at which the PID computation is run in ms + uint8_t loopspeed; } motor_pid_full_s_t; /** + * \struct motor_pid_s_t + * * Holds just the constants for a Motor's position or velocity PID controls. * * These values are in 4.4 format, meaning that a value of 0x20 represents 2.0, * 0x21 represents 2.0625, 0x22 represents 2.125, etc. */ typedef struct motor_pid_s { - uint8_t kf; // The feedforward constant - uint8_t kp; // The proportional constant - uint8_t ki; // The integral constants - uint8_t kd; // The derivative constant + /// The feedforward constant + uint8_t kf; + /// The proportional constant + uint8_t kp; + /// The integral constants + uint8_t ki; + /// The derivative constant + uint8_t kd; } motor_pid_s_t; #ifdef __cplusplus @@ -695,314 +1001,239 @@ namespace c { * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param position * The new reference position in its encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * delay(2); + * } + * motor_move_absolute(1, 100, 100); // This does not cause a movement + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * delay(2); + * } + * + * motor_set_zero_position(1, 80); + * motor_move_absolute(1, 100, 100); // Moves 80 units forward + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * delay(2); + * } + * } + * \endcode */ -int32_t motor_set_zero_position(uint8_t port, const double position); +int32_t motor_set_zero_position(int8_t port, const double position); /** * Sets the "absolute" zero position of the motor to its current position. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * delay(2); + * } + * motor_move_absolute(1, 100, 100); // This does not cause a movement + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * delay(2); + * } + * + * motor_tare_position(1); + * motor_move_absolute(1, 100, 100); // Moves 100 units forward + * while (!((motor_get_position(1) - 100 < 105) && (motor_get_position(1) - 100 > 95))) { + * delay(2); + * } + * } + * \endcode */ -int32_t motor_tare_position(uint8_t port); +int32_t motor_tare_position(int8_t port); /** * Sets one of motor_brake_mode_e_t to the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param mode * The motor_brake_mode_e_t to set for the motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * motor_set_brake_mode(1, E_MOTOR_BRAKE_HOLD); + * printf("Brake Mode: %d\n", motor_get_brake_mode(1)); + * } + * \endcode */ -int32_t motor_set_brake_mode(uint8_t port, const motor_brake_mode_e_t mode); +int32_t motor_set_brake_mode(int8_t port, const motor_brake_mode_e_t mode); /** * Sets the current limit for the motor in mA. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param limit * The new current limit in mA * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * motor_set_current_limit(1, 1000); + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * delay(2); + * } + * } + * \endcode */ -int32_t motor_set_current_limit(uint8_t port, const int32_t limit); +int32_t motor_set_current_limit(int8_t port, const int32_t limit); /** * Sets one of motor_encoder_units_e_t for the motor encoder. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param units * The new motor encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * motor_set_encoder_units(1, E_MOTOR_ENCODER_DEGREES); + * printf("Encoder Units: %d\n", motor_get_encoder_units(1)); + * } + * \endcode */ -int32_t motor_set_encoder_units(uint8_t port, const motor_encoder_units_e_t units); +int32_t motor_set_encoder_units(int8_t port, const motor_encoder_units_e_t units); /** * Sets one of motor_gearset_e_t for the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param gearset * The new motor gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * motor_set_gearing(1, E_MOTOR_GEARSET_06); + * printf("Brake Mode: %d\n", motor_get_gearing(1)); + * } + * \endcode */ -int32_t motor_set_gearing(uint8_t port, const motor_gearset_e_t gearset); - -/** - * Takes in floating point values and returns a properly formatted pid struct. - * The motor_pid_s_t struct is in 4.4 format, i.e. 0x20 is 2.0, 0x21 is 2.0625, - * etc. - * This function will convert the floating point values to the nearest 4.4 - * value. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant - * - * \return A motor_pid_s_t struct formatted properly in 4.4. - */ -motor_pid_s_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_convert_pid(double kf, double kp, double ki, double kd); - -/** - * Takes in floating point values and returns a properly formatted pid struct. - * The motor_pid_s_t struct is in 4.4 format, i.e. 0x20 is 2.0, 0x21 is 2.0625, - * etc. - * This function will convert the floating point values to the nearest 4.4 - * value. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant - * \param filter - * A constant used for filtering the profile acceleration - * \param limit - * The integral limit - * \param threshold - * The threshold for determining if a position movement has reached its - * goal. This has no effect for velocity PID calculations. - * \param loopspeed - * The rate at which the PID computation is run in ms - * - * \return A motor_pid_s_t struct formatted properly in 4.4. - */ -motor_pid_full_s_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_convert_pid_full(double kf, double kp, double ki, double kd, double filter, double limit, - double threshold, double loopspeed); - -/** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. - * - * Only non-zero values of the struct will change the existing motor constants. - * - * \note This feature is in beta, it is advised to use caution when modifying - * the PID values. The motor could be damaged by particularly large constants. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param pid - * The new motor PID constants - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_set_pos_pid(uint8_t port, const motor_pid_s_t pid); - -/** - * Sets one of motor_pid_full_s_t for the motor. - * - * Only non-zero values of the struct will change the existing motor constants. - * - * \note This feature is in beta, it is advised to use caution when modifying - * the PID values. The motor could be damaged by particularly large constants. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param pid - * The new motor PID constants - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_set_pos_pid_full(uint8_t port, const motor_pid_full_s_t pid); - -/** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. - * - * Only non-zero values of the struct will change the existing motor constants. - * - * \note This feature is in beta, it is advised to use caution when modifying - * the PID values. The motor could be damaged by particularly large constants. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param pid - * The new motor PID constants - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_set_vel_pid(uint8_t port, const motor_pid_s_t pid); - -/** - * Sets one of motor_pid_full_s_t for the motor. - * - * Only non-zero values of the struct will change the existing motor constants. - * - * \note This feature is in beta, it is advised to use caution when modifying - * the PID values. The motor could be damaged by particularly large constants. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param pid - * The new motor PID constants - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_set_vel_pid_full(uint8_t port, const motor_pid_full_s_t pid); - -/** - * Sets the reverse flag for the motor. - * - * This will invert its movements and the values returned for its position. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * \param reverse - * True reverses the motor, false is default - * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ -int32_t motor_set_reversed(uint8_t port, const bool reverse); +int32_t motor_set_gearing(int8_t port, const motor_gearset_e_t gearset); /** * Sets the voltage limit for the motor in Volts. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * \param limit * The new voltage limit in Volts * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor_set_voltage_limit(1, 10000); + * while (true) { + * motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); + * // The motor will not output more than 10 V + * delay(2); + * } + * } + * \endcode */ -int32_t motor_set_voltage_limit(uint8_t port, const int32_t limit); +int32_t motor_set_voltage_limit(int8_t port, const int32_t limit); /** * Gets the brake mode that was set for the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return One of motor_brake_mode_e_t, according to what was set for the motor, * or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * motor_set_brake_mode(1, E_MOTOR_BRAKE_HOLD); + * printf("Brake Mode: %d\n", motor_get_brake_mode(1)); + * } + * \endcode */ -motor_brake_mode_e_t motor_get_brake_mode(uint8_t port); +motor_brake_mode_e_t motor_get_brake_mode(int8_t port); /** * Gets the current limit for the motor in mA. @@ -1011,106 +1242,64 @@ motor_brake_mode_e_t motor_get_brake_mode(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's current limit in mA or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void initialize() { + * printf("Motor Current Limit: %d\n", motor_get_current_limit(1)); + * // Prints "Motor Current Limit: 2500" + * } + * \endcode */ -int32_t motor_get_current_limit(uint8_t port); +int32_t motor_get_current_limit(int8_t port); /** * Gets the encoder units that were set for the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return One of motor_encoder_units_e_t according to what is set for the motor * or E_MOTOR_ENCODER_INVALID if the operation failed. */ -motor_encoder_units_e_t motor_get_encoder_units(uint8_t port); +motor_encoder_units_e_t motor_get_encoder_units(int8_t port); /** * Gets the gearset that was set for the motor. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return One of motor_gearset_e_t according to what is set for the motor, * or E_GEARSET_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * printf("Motor Encoder Units: %d\n", motor_get_encoder_units(1)); + * // Prints E_MOTOR_ENCODER_DEGREES by default + * } + * \endcode */ -motor_gearset_e_t motor_get_gearing(uint8_t port); - -/** - * Gets the position PID that was set for the motor. This function will return - * zero for all of the parameters if the motor_set_pos_pid() or - * motor_set_pos_pid_full() functions have not been used. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. - * - * \param port - * The V5 port number from 1-21 - * - * \return A motor_pid_full_s_t containing the position PID constants last set - * to the given motor - */ -motor_pid_full_s_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_get_pos_pid(uint8_t port); - -/** - * Gets the velocity PID that was set for the motor. This function will return - * zero for all of the parameters if the motor_set_vel_pid() or - * motor_set_vel_pid_full() functions have not been used. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. - * - * \param port - * The V5 port number from 1-21 - * - * \return A motor_pid_full_s_t containing the velocity PID constants last set - * to the given motor - */ -motor_pid_full_s_t __attribute__((deprecated("Changing these values is not supported by VEX and may lead to permanent motor damage."))) motor_get_vel_pid(uint8_t port); - -/** - * Gets the operation direction of the motor as set by the user. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as a motor - * - * \param port - * The V5 port number from 1-21 - * - * \return 1 if the motor has been reversed and 0 if the motor was not reversed, - * or PROS_ERR if the operation failed, setting errno. - */ -int32_t motor_is_reversed(uint8_t port); +motor_gearset_e_t motor_get_gearing(int8_t port); /** * Gets the voltage limit set by the user. @@ -1120,16 +1309,28 @@ int32_t motor_is_reversed(uint8_t port); * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors * * \return The motor's voltage limit in V or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void initialize() { + * printf("Motor Voltage Limit: %d\n", motor_get_voltage_limit(1)); + * // Prints 0 by default, indicating no limit + * } + * \endcode */ -int32_t motor_get_voltage_limit(uint8_t port); +int32_t motor_get_voltage_limit(int8_t port); + +///@} + +///@} #ifdef __cplusplus } // namespace c diff --git a/include/pros/motors.hpp b/include/pros/motors.hpp index 10925990..b6469116 100644 --- a/include/pros/motors.hpp +++ b/include/pros/motors.hpp @@ -1,92 +1,91 @@ /** * \file pros/motors.hpp + * \ingroup cpp-motors * * Contains prototypes for the V5 Motor-related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/motors.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-motors Motors C++ API + * \note Additional example code for this module can be found in its [Tutorial](@ref motors). */ #ifndef _PROS_MOTORS_HPP_ #define _PROS_MOTORS_HPP_ #include -#include -#include +#include +#include "pros/abstract_motor.hpp" +#include "pros/device.hpp" #include "pros/motors.h" -#include "pros/rtos.hpp" +#include "rtos.hpp" namespace pros { -class Motor { +inline namespace v5 { + +class Motor : public AbstractMotor, public Device { public: /** - * Creates a Motor object for the given port and specifications. + * \addtogroup cpp-motors + * @{ + */ + + /** + * Constructs a new Motor object. * * This function uses the following values of errno when an error state is * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENXIO - The given value is not within the range of V5 ports |1-21|. * ENODEV - The port cannot be configured as a motor * * \param port - * The V5 port number from 1-21 - * \param gearset - * The motor's gearset - * \param reverse - * True reverses the motor, false is default - * \param encoder_units - * The motor's encoder units - */ - explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset, const bool reverse, - const motor_encoder_units_e_t encoder_units); - - explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset, const bool reverse); - - explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset); - - explicit Motor(const std::int8_t port, const bool reverse); - - explicit Motor(const std::int8_t port); - - /****************************************************************************/ - /** Motor movement functions **/ - /** **/ - /** These functions allow programmers to make motors move **/ - /****************************************************************************/ - /** - * Sets the voltage for the motor from -128 to 127. + * The V5 port number from 1 to 21, or from -21 to -1 for reversed motors. + * A reversed motor will reverse the input or output movement functions and movement related + * telemetry in order to produce consistant behavior with non-reversed motors * - * This is designed to map easily to the input from the controller's analog - * stick for simple opcontrol use. The actual behavior of the motor is - * analogous to use of pros::Motor::move(), or motorSet from the PROS 2 API. + * \param gearset = pros::v5::MotorGears::green + * Optional parameter for the gearset for the motor. + * Does not explicitly set the gearset if not specified or if the gearset is invalid * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor + * \param encoder_units = pros::v5::MotorUnits::degrees + * Optional parameter for the encoder units of the motor + * Does not explicitly set the gearset if not specified or if the gearset is invalid * - * \param voltage - * The new motor voltage from -127 to 127 + * \b Example + * \code + * void opcontrol() { + * Motor first_motor(1); //Creates a motor on port 1 without altering gearset or encoder units + * Motor reversed_motor(-2); //Creates a reversed motor on port 1 port 1 without altering gearset or encoder units + * Motor blue_motor(3, pros::v5::MotorGears::blue); //Creates a motor on port 3 with blue gear set + * Motor rotations_motor(4, pros::v5::MotorGears::green, pros::v5::MotorUnits::rotations); //port 4 w/ rotations + * + * } + * \endcode * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. */ - virtual std::int32_t operator=(std::int32_t voltage) const; + Motor(const std::int8_t port, const pros::v5::MotorGears gearset = pros::v5::MotorGears::invalid, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::invalid); + + Motor(const Device& device) : Motor(device.get_port()){}; + + /// \name Motor movement functions + /// These functions allow programmers to make motors move + ///@{ /** * Sets the voltage for the motor from -127 to 127. * * This is designed to map easily to the input from the controller's analog * stick for simple opcontrol use. The actual behavior of the motor is - * analogous to use of motor_move(), or motorSet() from the PROS 2 API. + * analogous to use of motor_move(). * * This function uses the following values of errno when an error state is * reached: @@ -97,8 +96,20 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor Motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t move(std::int32_t voltage) const; + std::int32_t move(std::int32_t voltage) const; /** * Sets the target absolute position for the motor to move to. @@ -110,6 +121,7 @@ class Motor { * \note This function simply sets the target for the motor, it does not block * program execution until the movement finishes. * + * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor @@ -121,16 +133,37 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * pros::delay(2); + * } + * motor.move_absolute(100, 100); // This does not cause a movement + * while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { + * pros::delay(2); + * } + * motor.tare_position(); + * motor.move_absolute(100, 100); // Moves 100 units forward + * while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t move_absolute(const double position, const std::int32_t velocity) const; + std::int32_t move_absolute(const double position, const std::int32_t velocity) const; /** * Sets the relative target position for the motor to move to. * * This movement is relative to the current position of the motor as given in * pros::Motor::motor_get_position(). Providing 10.0 as the position parameter - * would result in the motor moving clockwise 10 units, no matter what the - * current position is. + * would result in the motor moving clockwise 10 units (counter clockwise if reversed), + * no matter what the current position is. * * \note This function simply sets the target for the motor, it does not block * program execution until the movement finishes. @@ -146,8 +179,24 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_relative(100, 100); // Moves 100 units forward + * while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { + * // Continue running this loop as long as the motor is not within +-5 units of its goal + * pros::delay(2); + * } + * motor.move_relative(100, 100); // Also moves 100 units forward + * while (!((motor.get_position() < 205) && (motor.get_position() > 195))) { + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t move_relative(const double position, const std::int32_t velocity) const; + std::int32_t move_relative(const double position, const std::int32_t velocity) const; /** * Sets the velocity for the motor. @@ -168,8 +217,18 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_velocity(100); + * pros::delay(1000); // Move at 100 RPM for 1 second + * motor.move_velocity(0); + * } + * \endcode */ - virtual std::int32_t move_velocity(const std::int32_t velocity) const; + std::int32_t move_velocity(const std::int32_t velocity) const; /** * Sets the output voltage for the motor from -12000 to 12000 in millivolts. @@ -178,13 +237,24 @@ class Motor { * reached: * ENODEV - The port cannot be configured as a motor * + * \param port + * The V5 port number from 1-21 * \param voltage * The new voltage value from -12000 to 12000 * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * motor.move_voltage(12000); + * pros::delay(1000); // Move at max voltage for 1 second + * motor.move_voltage(0); + * } + * \endcode */ - virtual std::int32_t move_voltage(const std::int32_t voltage) const; + std::int32_t move_voltage(const std::int32_t voltage) const; /** * Stops the motor using the currently configured brake mode. @@ -192,7 +262,7 @@ class Motor { * This function sets motor velocity to zero, which will cause it to act * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, * this function may behave differently than calling move_absolute(0) - * or move_relative(0). + * or motor_move_relative(0). * * This function uses the following values of errno when an error state is * reached: @@ -200,13 +270,23 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * Motor motor(1); + * motor.move_voltage(12000); + * pros::delay(1000); // Move at max voltage for 1 second + * motor.brake(); + * } + * \endcode */ - virtual std::int32_t brake(void) const; + std::int32_t brake(void) const; /** - * Changes the output velocity for a profiled movement (motor_move_absolute() - * or motor_move_relative()). This will have no effect if the motor is not - * following a profiled movement. + * Changes the output velocity for a profiled movement (motor_move_absolute or + * motor_move_relative). This will have no effect if the motor is not following + * a profiled movement. * * This function uses the following values of errno when an error state is * reached: @@ -218,74 +298,195 @@ class Motor { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); + * pros::delay(100); + * motor.modify_profiled_velocity(0); // Stop the motor early + * } + * \endcode */ - virtual std::int32_t modify_profiled_velocity(const std::int32_t velocity) const; + std::int32_t modify_profiled_velocity(const std::int32_t velocity) const; + + ///@} + + /// \name Motor telemetry functions + /// These functions allow programmers to collect telemetry from motors + ///@{ /** - * Gets the target position set for the motor by the user. + * Gets the target position set for the motor by the user + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return The target position in its encoder units or PROS_ERR_F if the * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); + * std::cout << "Motor Target: " << motor.get_target_position(); + * // Prints 100 + * } + * \endcode */ - virtual double get_target_position(void) const; + double get_target_position(const std::uint8_t index = 0) const; /** - * Gets the velocity commanded to the motor by the user. + * Gets the velocity commanded to the motor by the user at the index specified. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return The commanded motor velocity from +-100, +-200, or +-600, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * std::cout << "Motor Velocity: " << motor.get_target_velocity(); + * // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_target_velocity(void) const; - - /****************************************************************************/ - /** Motor telemetry functions **/ - /** **/ - /** These functions allow programmers to collect telemetry from motors **/ - /****************************************************************************/ + std::int32_t get_target_velocity(const std::uint8_t index = 0) const; /** * Gets the actual velocity of the motor. * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return The motor's actual velocity in RPM or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * while (true) { + * motor = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y); + * printf("Actual velocity: %lf\n", motor.get_actual_velocity()); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_actual_velocity(void) const; + double get_actual_velocity(const std::uint8_t index = 0) const; /** * Gets the current drawn by the motor in mA. * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * * \return The motor's current in mA or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Current Draw: " << motor.get_current_draw(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_current_draw(void) const; + std::int32_t get_current_draw(const std::uint8_t index = 0) const; /** * Gets the direction of movement for the motor. * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * * \return 1 for moving in the positive direction, -1 for moving in the * negative direction, and PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Direction: " << motor.get_direction(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_direction(void) const; + std::int32_t get_direction(const std::uint8_t index = 0) const; /** * Gets the efficiency of the motor in percent. @@ -294,1191 +495,1932 @@ class Motor { * drawing no electrical power, and an efficiency of 0% means that the motor * is drawing power but not moving. * + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * * \return The motor's efficiency in percent or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Efficiency: " << motor.get_efficiency(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_efficiency(void) const; + double get_efficiency(const std::uint8_t index = 0) const; /** - * Checks if the motor is drawing over its current limit. + * Gets the faults experienced by the motor. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. * - * \return 1 if the motor's current limit is being exceeded and 0 if the - * current limit is not exceeded, or PROS_ERR if the operation failed, setting - * errno. - */ - virtual std::int32_t is_over_current(void) const; - - /** - * Checks if the motor is stopped. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \note Although this function forwards data from the motor, the motor - * presently does not provide any value. This function returns PROS_ERR with - * errno set to ENOSYS. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * - * \return 1 if the motor is not moving, 0 if the motor is moving, or PROS_ERR - * if the operation failed, setting errno + * + * \return A bitfield containing the motor's faults. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << motor.get_faults();pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t is_stopped(void) const; + std::uint32_t get_faults(const std::uint8_t index = 0) const; /** - * Checks if the motor is at its zero position. + * Gets the flags set by the motor's operation. + * + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \note Although this function forwards data from the motor, the motor - * presently does not provide any value. This function returns PROS_ERR with - * errno set to ENOSYS. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * - * \return 1 if the motor is at zero absolute position, 0 if the motor has - * moved from its absolute zero, or PROS_ERR if the operation failed, setting - * errno + * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << motor.get_faults(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_zero_position_flag(void) const; + std::uint32_t get_flags(const std::uint8_t index = 0) const; /** - * Gets the faults experienced by the motor. + * Gets the absolute position of the motor in its encoder units. * - * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return A bitfield containing the motor's faults. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << motor.get_position(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::uint32_t get_faults(void) const; + double get_position(const std::uint8_t index = 0) const; /** - * Gets the flags set by the motor's operation. + * Gets the power drawn by the motor in Watts. * - * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return A bitfield containing the motor's flags. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Power: " << motor.get_power(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::uint32_t get_flags(void) const; + double get_power(const std::uint8_t index = 0) const; /** * Gets the raw encoder count of the motor at a given timestamp. * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups + * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param[in] timestamp + * EOVERFLOW - The index is non 0 + * + * + * \param timestamp * A pointer to a time in milliseconds for which the encoder count * will be returned. If NULL, the timestamp at which the encoder * count was read will not be supplied * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * + * * \return The raw encoder count at the given timestamp or PROS_ERR if the * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * std::uint32_t now = pros::millis(); + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << motor.get_raw_position(&now); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_raw_position(std::uint32_t* const timestamp) const; + std::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const; /** - * Gets the temperature limit flag for the motor. + * Gets the temperature of the motor in degrees Celsius. + + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return 1 if the temperature limit is exceeded and 0 if the temperature is - * below the limit, or PROS_ERR if the operation failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Temperature: " << motor.get_temperature(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t is_over_temp(void) const; + double get_temperature(const std::uint8_t index = 0) const; /** - * Gets the absolute position of the motor in its encoder units. + * Gets the torque generated by the motor in Newton Meters (Nm). + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's absolute position in its encoder units or PROS_ERR_F - * if the operation failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Torque: " << motor.get_torque(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_position(void) const; + double get_torque(const std::uint8_t index = 0) const; /** - * Gets the power drawn by the motor in Watts. + * Gets the voltage delivered to the motor in millivolts. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's power draw in Watts or PROS_ERR_F if the operation - * failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Voltage: " << motor.get_voltage(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_power(void) const; + std::int32_t get_voltage(const std::uint8_t index = 0) const; /** - * Gets the temperature of the motor in degrees Celsius. + * Checks if the motor is drawing over its current limit. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's temperature in degrees Celsius or PROS_ERR_F if the - * operation failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its current limit?: " << motor.is_over_current(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_temperature(void) const; + std::int32_t is_over_current(const std::uint8_t index = 0) const; /** - * Gets the torque generated by the motor in Newton Meters (Nm). + * Gets the temperature limit flag for the motor. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's torque in Nm or PROS_ERR_F if the operation failed, - * setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_torque(void) const; + std::int32_t is_over_temp(const std::uint8_t index = 0) const; + + ///@} + + /// \name Motor configuration functions + /// These functions allow programmers to configure the behavior of motors + ///@{ /** - * Gets the voltage delivered to the motor in millivolts. + * Gets the brake mode that was set for the motor. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's voltage in mV or PROS_ERR_F if the operation failed, - * setting errno. - * + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return One of MotorBrake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - virtual std::int32_t get_voltage(void) const; - - /****************************************************************************/ - /** Motor configuration functions **/ - /** **/ - /** These functions allow programmers to configure the behavior of motors **/ - /****************************************************************************/ + MotorBrake get_brake_mode(const std::uint8_t index = 0) const; /** - * Sets the position for the motor in its encoder units. + * Gets the current limit for the motor in mA. * - * This will be the future reference point for the motor's "absolute" - * position. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param position - * The new reference position in its encoder units + * EOVERFLOW - The index is non 0 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return The motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * while (true) { + * std::cout << "Motor Current Limit: " << motor.get_current_limit(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t set_zero_position(const double position) const; + std::int32_t get_current_limit(const std::uint8_t index = 0) const; /** - * Sets the "absolute" zero position of the motor to its current position. + * Gets the encoder units that were set for the motor. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return One of MotorUnits according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - virtual std::int32_t tare_position(void) const; + MotorUnits get_encoder_units(const std::uint8_t index = 0) const; /** - * Sets one of motor_brake_mode_e_t to the motor. + * Gets the gearset that was set for the motor. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param mode - * The motor_brake_mode_e_t to set for the motor + * EOVERFLOW - The index is non 0 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return One of MotorGears according to what is set for the motor, + * or pros::MotorGears::invalid if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Gearing: " << motor.get_gearing(); + * } + * \endcode */ - virtual std::int32_t set_brake_mode(const motor_brake_mode_e_t mode) const; + MotorGears get_gearing(const std::uint8_t index = 0) const; /** - * Sets the current limit for the motor in mA. + * Gets the voltage limit set by the user. + * + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param limit - * The new current limit in mA + * EOVERFLOW - The index is non 0 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Motor Voltage Limit: " << motor.get_voltage_limit(); + * } + * \endcode */ - virtual std::int32_t set_current_limit(const std::int32_t limit) const; + std::int32_t get_voltage_limit(const std::uint8_t index = 0) const; /** - * Sets one of motor_encoder_units_e_t for the motor encoder. + * Gets whether the motor is reversed or not + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: - * ENODEV - The port cannot be configured as a motor * - * \param units - * The new motor encoder units + * EOVERFLOW - The index is non 0 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Is the motor reversed? " << motor.is_reversed(); + * // Prints "0" + * } + * \endcode */ - virtual std::int32_t set_encoder_units(const motor_encoder_units_e_t units) const; + std::int32_t is_reversed(const std::uint8_t index = 0) const; /** - * Sets one of motor_gearset_e_t for the motor. + * Sets one of Motor_Brake to the motor. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param gearset - * The new motor gearset + * EOVERFLOW - The index is non 0 + * + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. - */ - virtual std::int32_t set_gearing(const motor_gearset_e_t gearset) const; - - /** - * Takes in floating point values and returns a properly formatted pid struct. - * The motor_pid_s_t struct is in 4.4 format, i.e. 0x20 is 2.0, 0x21 is - * 2.0625, etc. - * This function will convert the floating point values to the nearest 4.4 - * value. - * - * \param kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant - * - * \return A motor_pid_s_t struct formatted properly in 4.4. - */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] static motor_pid_s_t - convert_pid(double kf, double kp, double ki, double kd); - - /** - * Takes in floating point values and returns a properly formatted pid struct. - * The motor_pid_s_t struct is in 4.4 format, i.e. 0x20 is 2.0, 0x21 is - * 2.0625, etc. - * This function will convert the floating point values to the nearest 4.4 - * value. - * - * \param kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant - * \param filter - * A constant used for filtering the profile acceleration - * \param limit - * The integral limit - * \param threshold - * The threshold for determining if a position movement has reached its - * goal. This has no effect for velocity PID calculations. - * \param loopspeed - * The rate at which the PID computation is run in ms * - * \return A motor_pid_s_t struct formatted properly in 4.4. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor " - "damage.")]] static motor_pid_full_s_t - convert_pid_full(double kf, double kp, double ki, double kd, double filter, double limit, double threshold, - double loopspeed); - + std::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const; /** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. - * - * Only non-zero values of the struct will change the existing motor - * constants. + * Sets one of MotorBrake to the motor. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param pid - * The new motor PID constants + * EOVERFLOW - The index is non 0 + * + * + * \param mode + * The MotorBrake to set for the motor + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] virtual std::int32_t - set_pos_pid(const motor_pid_s_t pid) const; - + std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const; /** - * Sets one of motor_pid_full_s_t for the motor. + * Sets the current limit for the motor in mA. * - * Only non-zero values of the struct will change the existing motor - * constants. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param pid - * The new motor PID constants + * EOVERFLOW - The index is non 0 + * + * \param limit + * The new current limit in mA + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * motor.set_current_limit(1000); + * while (true) { + * motor = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * pros::delay(2); + * } + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] virtual std::int32_t - set_pos_pid_full(const motor_pid_full_s_t pid) const; + std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const; /** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. - * - * Only non-zero values of the struct will change the existing motor - * constants. + * Sets one of MotorUnits for the motor encoder. Works with the C + * enum and the C++ enum class. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * \param pid - * The new motor PID constants + * \param units + * The new motor encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_encoder_units(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] virtual std::int32_t - set_vel_pid(const motor_pid_s_t pid) const; - + std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const; /** - * Sets one of motor_pid_full_s_t for the motor. + * Sets one of MotorUnits for the motor encoder. Works with the C + * enum and the C++ enum class. * - * Only non-zero values of the struct will change the existing motor - * constants. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param pid - * The new motor PID constants + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * * \param units + * The new motor encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_encoder_units(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor damage.")]] virtual std::int32_t - set_vel_pid_full(const motor_pid_full_s_t pid) const; - + std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const; /** - * Sets the reverse flag for the motor. + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. * - * This will invert its movements and the values returned for its position. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param reverse - * True reverses the motor, false is default + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * \param gearset + * The new motor gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_gearing(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - virtual std::int32_t set_reversed(const bool reverse) const; + std::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const; /** - * Sets the voltage limit for the motor in Volts. + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. + + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \param limit - * The new voltage limit in Volts + * EOVERFLOW - The index is non 0 + * + * \param gearset + * The new motor gearset + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_gearing(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - virtual std::int32_t set_voltage_limit(const std::int32_t limit) const; + std::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const; /** - * Gets the brake mode that was set for the motor. + * Sets the reverse flag for the motor. + * + * This will invert its movements and the values returned for its position. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: - * ENODEV - The port cannot be configured as a motor * - * \return One of motor_brake_mode_e_t, according to what was set for the - * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. - */ - virtual motor_brake_mode_e_t get_brake_mode(void) const; - - /** - * Gets the current limit for the motor in mA. + * EOVERFLOW - The index is non 0 * - * The default value is 2500 mA. + * \param reverse + * True reverses the motor, false is default direction + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_reversed(true); + * std::cout << "Is this motor reversed? " << motor.is_reversed(); + * } + * \endcode + */ + std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0); + + /** + * Sets the voltage limit for the motor in Volts. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * \return The motor's current limit in mA or PROS_ERR if the operation failed, - * setting errno. + * \param limit + * The new voltage limit in Volts + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * motor.set_voltage_limit(10000); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will not output more than 10 V + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_current_limit(void) const; + std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const; /** - * Gets the encoder units that were set for the motor. + * Sets the position for the motor in its encoder units. + * + * This will be the future reference point for the motor's "absolute" + * position. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return One of motor_encoder_units_e_t according to what is set for the - * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * EOVERFLOW - The index is non 0 + * + * \param position + * The new reference position in its encoder units + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * motor.move_absolute(100, 100); // This does not cause a movement + * + * motor.set_zero_position(80); + * motor.move_absolute(100, 100); // Moves 80 units forward + * } + * \endcode + * */ - virtual motor_encoder_units_e_t get_encoder_units(void) const; + std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const; /** - * Gets the gearset that was set for the motor. + * Sets the "absolute" zero position of the motor to its current position. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return One of motor_gearset_e_t according to what is set for the motor, - * or E_GEARSET_INVALID if the operation failed. + * EOVERFLOW - The index is non 0 + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * motor.move_absolute(100, 100); // This does not cause a movement + * + * motor.tare_position(); + * motor.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode + */ + std::int32_t tare_position(const std::uint8_t index = 0) const; + + /** + * Gets the number of motors. + * + * \return Always returns 1 + * + */ + std::int8_t size(void) const; + + /** + * Gets all motors. + * + * \return A vector of Motor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector motor_all = pros::Motor::get_all_devices(); // All motors that are connected + * } + * \endcode + */ + static std::vector get_all_devices(); + + /** + * gets the port number of the motor + * + * \return The signed port of the motor. (negative if the motor is reversed) + * */ - virtual motor_gearset_e_t get_gearing(void) const; + std::int8_t get_port(const std::uint8_t index = 0) const; + + ///@} + /// \name Additional motor functions + /// These functions allow for motors and motor groups to be used interchangeably + ///@{ /** - * Gets the position PID that was set for the motor. This function will return - * zero for all of the parameters if the motor_set_pos_pid() or - * motor_set_pos_pid_full() functions have not been used. + * Gets a vector containing the target position set for the motor by the user * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. * - * \return A motor_pid_full_s_t containing the position PID constants last set - * to the given motor + * \return A vector containing the target position in its encoder units or PROS_ERR_F if the + * operation failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); + * std::cout << "Motor Target: " << motor.get_target_position_all()[0]; + * // Prints 100 + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor " - "damage.")]] virtual motor_pid_full_s_t - get_pos_pid(void) const; + std::vector get_target_position_all(void) const; /** - * Gets the velocity PID that was set for the motor. This function will return - * zero for all of the parameters if the motor_set_vel_pid() or - * motor_set_vel_pid_full() functions have not been used. + * Gets a vector containing the velocity commanded to the motor by the user * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. + * \return A vector containing the commanded motor velocity from +-100, + * +-200, or +-600, or PROS_ERR if the operation failed, setting errno. * - * \return A motor_pid_full_s_t containing the velocity PID constants last set - * to the given motor + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * std::cout << "Motor Velocity: " << motor.get_target_velocity_all()[0]; + * // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y + * pros::delay(2); + * } + * } + * \endcode */ - [[deprecated( - "Changing these values is not supported by VEX and may lead to permanent motor " - "damage.")]] virtual motor_pid_full_s_t - get_vel_pid(void) const; + std::vector get_target_velocity_all(void) const; /** - * Gets the operation direction of the motor as set by the user. + * Gets a vector containing the actual velocity commanded of the motor * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * \return 1 if the motor has been reversed and 0 if the motor was not - * reversed, or PROS_ERR if the operation failed, setting errno. + * \return A vector containing the motor's actual velocity in RPM or PROS_ERR_F + * if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); + * std::cout << "Motor Velocity: " << motor.get_actual_velocity_all()[0]; + * // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t is_reversed(void) const; + std::vector get_actual_velocity_all(void) const; /** - * Gets the voltage limit set by the user. - * - * Default value is 0V, which means that there is no software limitation - * imposed on the voltage. + * Gets a vector containing the current drawn by the motor in mA. * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor * - * \return The motor's voltage limit in V or PROS_ERR if the operation failed, + * + * \return A vector containing the motor's current in mA or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Current Draw: " << motor.get_current_draw_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_voltage_limit(void) const; + std::vector get_current_draw_all(void) const; /** - * Gets the port number of the motor. + * Gets a vector containing the direction of movement for the motor. + * + * + * This function uses the following values of errno when an error state is + * reached: * - * \return The motor's port number. + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vector containing 1 for moving in the positive direction, -1 for moving in the + * negative direction, and PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Direction: " << motor.get_direction_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::uint8_t get_port(void) const; - - private: - const std::uint8_t _port; -}; + std::vector get_direction_all(void) const; -class Motor_Group { - public: - Motor_Group(const std::initializer_list motors); - explicit Motor_Group(const std::vector& motors); - explicit Motor_Group(const std::initializer_list motor_ports); - explicit Motor_Group(const std::vector motor_ports); // Pass by value to preserve ABI - - /****************************************************************************/ - /** Motor Group movement functions **/ - /** **/ - /** These functions allow programmers to make motor groups move **/ - /****************************************************************************/ /** - * Sets the voltage for all the motors in the motor group from -128 to 127. + * Gets a vector containing the efficiency of the motor in percent. * - * This is designed to map easily to the input from the controller's analog - * stick for simple opcontrol use. The actual behavior of the motor is - * analogous to use of pros::Motor::move() on each motor individually + * An efficiency of 100% means that the motor is moving electrically while + * drawing no electrical power, and an efficiency of 0% means that the motor + * is drawing power but not moving. * * This function uses the following values of errno when an error state is * reached: - * ENODEV - One of the ports cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param voltage - * The new motor voltage from -127 to 127 + * ENODEV - The port cannot be configured as a motor * - * \return 1 if the operation was successful or PROS_ERR if the operation + * + * \return A vector containing The motor's efficiency in percent or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Efficiency: " << motor.get_efficiency(); + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t operator=(std::int32_t); + std::vector get_efficiency_all(void) const; /** - * Sets the voltage for the motors in the motor group from -127 to 127. + * Gets a vector of the faults experienced by the motor. * - * This is designed to map easily to the input from the controller's analog - * stick for simple opcontrol use. The actual behavior of the motor is - * analogous to use of motor_move(), or motorSet() from the - * PROS 2 API on each motor. + * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param voltage - * The new motor voltage from -127 to 127 + * \return A bitfield containing the motor's faults. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << motor.get_faults_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move(std::int32_t voltage); + std::vector get_faults_all(void) const; /** - * Sets the target absolute position for the motors to move to. + * Gets a vector of the flags set by the motor's operation. * - * This movement is relative to the position of the motors when initialized or - * the position when it was most recently reset with - * pros::Motor::set_zero_position(). + * Compare this bitfield to the bitmasks in pros::motor_flag_e_t. * - * \note This function simply sets the target for the motors, it does not block - * program execution until the movement finishes. + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A bitfield containing the motor's flags. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Faults: " << motor.get_faults_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_flags_all(void) const; + + /** + * Gets a vector containing the absolute position of the motor in its encoder units. * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * - * \param position - * The absolute position to move to in the motors' encoder units - * \param velocity - * The maximum allowable velocity for the movement in RPM + * \return A vector containing the motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. * - * \return 1 if the operation was successful or PROS_ERR if the operation + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << motor.get_position_all()[0]; + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_position_all(void) const; + + /** + * Gets a vector containing the power drawn by the motor in Watts. + * + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the motor's power draw in Watts or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Power: " << motor.get_power_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move_absolute(const double position, const std::int32_t velocity); + std::vector get_power_all(void) const; /** - * Sets the relative target position for the motor to move to. + * Gets a vector of the raw encoder count of the motor at a given timestamp. * - * This movement is relative to the current position of the motor as given in - * pros::Motor::motor_get_position(). Providing 10.0 as the position parameter - * would result in the motor moving clockwise 10 units, no matter what the - * current position is. * - * \note This function simply sets the target for the motor, it does not block - * program execution until the movement finishes. + * This function uses the following values of errno when an error state is + * reached: + * + * ENODEV - The port cannot be configured as a motor + * + * \param timestamp + * A pointer to a time in milliseconds for which the encoder count + * will be returned. If NULL, the timestamp at which the encoder + * count was read will not be supplied + * + * \return A vector containing the raw encoder count at the given timestamp or PROS_ERR if the + * operation failed. + * + * \b Example + * \code + * void opcontrol() { + * std::uint32_t now = pros::millis(); + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Position: " << motor.get_raw_position(&now); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_raw_position_all(std::uint32_t* const timestamp) const; + + /** + * Gets a vector of the temperature of the motor in degrees Celsius. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param position - * The relative position to move to in the motor's encoder units - * \param velocity - * The maximum allowable velocity for the movement in RPM + * \return A vector contaioning the motor's temperature in degrees Celsius + * or PROS_ERR_F if the operation failed, setting errno. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Temperature: " << motor.get_temperature_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move_relative(const double position, const std::int32_t velocity); + std::vector get_temperature_all(void) const; /** - * Sets the velocity for the motors. + * Gets a vector of the torque generated by the motor in Newton Meters (Nm). * - * This velocity corresponds to different actual speeds depending on the - * gearset used for the motor. This results in a range of +-100 for - * E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for - * E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent - * speed, as opposed to setting the motor's voltage. + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing the motor's torque in Nm or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Torque: " << motor.get_torque(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::vector get_torque_all(void) const; + + /** + * Gets a vector of the voltage delivered to the motor in millivolts. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param velocity - * The new motor velocity from -+-100, +-200, or +-600 depending on the - * motor's gearset * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \return A vector of the motor's voltage in mV or PROS_ERR_F if the operation failed, + * setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Motor Voltage: " << motor.get_voltage_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move_velocity(const std::int32_t velocity); + std::vector get_voltage_all(void) const; /** - * Sets the output voltage for the motors from -12000 to 12000 in millivolts. + * Checks if the motor is drawing over its current limit. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param voltage - * The new voltage value from -12000 to 12000 + * \return A vector containing 1 if the motor's current limit is being exceeded and 0 if the + * current limit is not exceeded, or PROS_ERR if the operation failed, setting + * errno. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its current limit?: " << motor.is_over_current_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t move_voltage(const std::int32_t voltage); + std::vector is_over_current_all(void) const; /** - * Stops the motor using the currently configured brake mode. - * - * This function sets motor velocity to zero, which will cause it to act - * according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, - * this function may behave differently than calling move_absolute(0) - * or move_relative(0). + * Gets the temperature limit flag for the motor. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ - std::int32_t brake(void); - - /* - * Gets the voltages delivered to the motors in millivolts. + * \return A vector containing 1 if the temperature limit is exceeded and 0 if the temperature is + * below the limit, or PROS_ERR if the operation failed, setting errno. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given - * - * \return The voltage of the motor in millivolts or PROS_ERR_F if the operation - * failed, setting errno. - * * \b Example * \code * void opcontrol() { - * pros::Motor_Group motors({1, 2}); - * std::vector voltages; + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); * while (true) { - * voltages = motors.get_voltages(); - * - * for (uint32_t i = 0; i < voltages.size(); i++) { - * printf("Voltages: %ld\n", voltages[i]); - * } - * pros::delay(20); + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp_all(); + * pros::delay(2); * } * } * \endcode - * */ - std::vector get_voltages(void); + std::vector is_over_temp_all(void) const; - /* - * Get the voltage limits of the motors set by the user. + /** + * Gets a vector containing the brake mode that was set for the motor. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given - * - * \return The voltage limit of the motor in millivolts or PROS_ERR_F if the operation - * failed, setting errno. - * + * + * \return One of Motor_Brake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. + * * \b Example * \code - * void opcontrol() { - * pros::Motor_Group motors({1, 2}); - * std::vector voltage_limits; - * while (true) { - * voltage_limits = motors.get_voltage_limits(); - * - * for (uint32_t i = 0; i < voltage_limits.size(); i++) { - * printf("Voltage Limits: %ld\n", voltage_limits[i]); - * } - * pros::delay(20); - * } + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); * } * \endcode */ - std::vector get_voltage_limits(void); + std::vector get_brake_mode_all(void) const; - /* - * Gets the raw encoder positions of a motor group at a given timestamp. + /** + * Gets a vector containing the current limit for the motor in mA. + * + * The default value is 2500 mA. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given - * - * \return A vector of the raw encoder positions of the motors in the motor group - * based on the timestamps passed in. If a timestamp is not found for a motor, the - * value at that index will be PROS_ERR. - * + * + * \return A vector containing the motor's current limit in mA or PROS_ERR if the operation failed, + * setting errno. + * * \b Example * \code * void opcontrol() { - * pros::Motor_Group motors({1, 2}); - * std::vector timestamps; - * std::vector positions; - * std::uint32_t temp = 0; - * std::uint32_t temp2 = 0; - * timestamps.push_back(&temp); - * timestamps.push_back(&temp2); - * + * pros::Motor motor (1); * while (true) { - * positions = motors.get_raw_positions(timestamps); - * - * printf("Position: %ld, Time: %ln\n", positions[0], timestamps[0]); - * printf("Position: %ld, Time: %ln\n", positions[1], timestamps[1]); - * - * pros::delay(20); + * std::cout << "Motor Current Limit: " << motor.get_current_limit_all()[0]; + * pros::delay(2); * } * } * \endcode */ - std::vector get_raw_positions(std::vector ×tamps); - /****************************************************************************/ - /** Motor configuration functions **/ - /** **/ - /** These functions let programmers configure the behavior of motor groups **/ - /****************************************************************************/ + std::vector get_current_limit_all(void) const; /** - * Indexes Motor in the Motor_Group in the same way as an array. - * + * Gets a vector containing the encoder units that were set for the motor. + * * This function uses the following values of errno when an error state is * reached: - * ENXIO - Out of bounds on indexing the motor groups. - * - * \param i - * The index value in the motor group. + * ENODEV - The port cannot be configured as a motor * - * \return the appropriate Motor reference or the erno if the operation - * failed - */ - pros::Motor& operator[](int i); - + * \return A vector containing One of Motor_Units according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Encoder Units: " << motor.get_encoder_units_all()[0]; + * } + * \endcode + */ + std::vector get_encoder_units_all(void) const; /** - * Indexes Motor in the Motor_Group. - * + * Gets a vector containing the gearset that was set for the motor. + * * This function uses the following values of errno when an error state is * reached: - * Throws an std::out_of_range error when indexing out of range - * - * \param i - * The index value in the motor group. + * ENODEV - The port cannot be configured as a motor + * + * \return A vector containing one of Motor_Gears according to what is set for the motor, + * or pros::Motor_Gears::invalid if the operation failed. * - * \return the appropriate Motor reference. - */ - pros::Motor& at(int i); + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); + * std::cout << "Motor Gearing: " << motor.get_gearing_all()[0]; + * } + * \endcode + */ + std::vector get_gearing_all(void) const; /** - * Indexes Motor in the Motor_Group in the same way as an array. - * - * \return the size of the vector containing motors - */ - std::int32_t size(); + * Gets returns a vector with all the port numbers in the motor group. + * + * \return A vector containing the signed port of the motor. (negative if the motor is reversed) + */ + std::vector get_port_all(void) const; /** - * Sets the position for the motor in its encoder units. + * Gets a vector of the voltage limit set by the user. * - * This will be the future reference point for the motors' "absolute" - * position. + * Default value is 0V, which means that there is no software limitation + * imposed on the voltage. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param position - * The new reference position in its encoder units + * \return A vector containing the motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Motor Voltage Limit: " << motor.get_voltage_limit_all()[0]; + * } + * \endcode */ - std::int32_t set_zero_position(const double position); + std::vector get_voltage_limit_all(void) const; + + /** + * Gets a vector containg whether the motor is reversed or not + * + * \return A vector containing 1 if the motor has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Is the motor reversed? " << motor.is_reversed_all()[0]; + * // Prints "0" + * } + * \endcode + */ + std::vector is_reversed_all(void) const; + /** - * Sets one of motor_brake_mode_e_t to the motor group. + * Sets one of Motor_Brake to the motor. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * * \param mode - * The motor_brake_mode_e_t to set for the motor + * The Motor_Brake to set for the motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - std::int32_t set_brake_modes(motor_brake_mode_e_t mode); + std::int32_t set_brake_mode_all(const MotorBrake mode) const; /** - * Sets the reverse flag for all the motors in the motor group. - * - * This will invert its movements and the values returned for its position. + * Sets one of Motor_Brake to the motor. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param reverse - * True reverses the motor, false is default + * \param mode + * The Motor_Brake to set for the motor * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - std::int32_t set_reversed(const bool reversed); + std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const; /** - * Sets the voltage limit for all the motors in Volts. + * Sets the current limit for the motor in mA. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * * \param limit - * The new voltage limit in Volts + * The new current limit in mA * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * motor.set_current_limit_all(1000); + * while (true) { + * motor = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will reduce its output at 1000 mA instead of the default 2500 mA + * pros::delay(2); + * } + * } + * \endcode */ - std::int32_t set_voltage_limit(const std::int32_t limit); + std::int32_t set_current_limit_all(const std::int32_t limit) const; + /** - * Sets one of motor_gearset_e_t for all the motors in the motor group. + * Sets one of Motor_Units for the motor encoder. Works with the C + * enum and the C++ enum class. + * + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: + * * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \param gearset - * The new motor gearset + * EOVERFLOW - The index is non 0 + * + * * \param units + * The new motor encoder units + * + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - std::int32_t set_gearing(const motor_gearset_e_t gearset); + std::int32_t set_encoder_units_all(const MotorUnits units) const; /** - * Sets one of motor_encoder_units_e_t for the all the motor encoders - * in the motor group. + * Sets one of Motor_Units for the motor encoder. Works with the C + * enum and the C++ enum class. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * * \param units * The new motor encoder units * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - std::int32_t set_encoder_units(const motor_encoder_units_e_t units); + std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const; /** - * Sets the "absolute" zero position of the motor group to its current position. + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * + * \param gearset + * The new motor gearset * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. - */ - std::int32_t tare_position(void); - - /****************************************************************************/ - /** Motor telemetry functions **/ - /** **/ - /** These functions let programmers to collect telemetry from motor groups **/ - /****************************************************************************/ - /** - * Gets the actual velocity of each motor. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return A vector with the each motor's actual velocity in RPM in the order - * or a vector filled with PROS_ERR_F if the operation failed, setting errno. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_gearing_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - std::vector get_actual_velocities(void); + std::int32_t set_gearing_all(const MotorGears gearset) const; /** - * Gets the velocity commanded to the motor by the user. + * Sets one of the gear cartridge (red, green, blue) for the motor. Usable with + * the C++ enum class and the C enum. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor * - * \return A vector filled with The commanded motor velocities from - * +-100, +-200, or +-600, or a vector filled with PROS_ERR if the operation - * failed, setting errno. - */ - std::vector get_target_velocities(void); - - /** - * Gets the target position set for the motor by the user. + * \param gearset + * The new motor gearset * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. * - * \return A vector filled with the target position in its encoder units - * or a vector filled with PROS_ERR_F if the operation failed, setting errno. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_gearing_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - std::vector get_target_positions(void); + std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const; /** - * Gets the absolute position of the motor in its encoder units. + * Sets the reverse flag for the motor. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor + * This will invert its movements and the values returned for its position. * - * \return The motor's absolute position in its encoder units or PROS_ERR_F - * if the operation failed, setting errno. - */ - std::vector get_positions(void); - /** - * Gets the efficiency of the motors in percent. * - * An efficiency of 100% means that the motor is moving electrically while - * drawing no electrical power, and an efficiency of 0% means that the motor - * is drawing power but not moving. + * \param reverse + * True reverses the motor, false is default direction * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \return 1 * - * \return A vector filled with the motor's efficiency in percent - * or a vector filled with PROS_ERR_F if the operation failed, setting errno. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * motor.set_reversed_all(true); + * std::cout << "Is this motor reversed? " << motor.is_reversed(); + * } + * \endcode */ - std::vector get_efficiencies(void); + std::int32_t set_reversed_all(const bool reverse); /** - * Checks if the motors are drawing over its current limit. - * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * Sets the voltage limit for the motor in Volts. * - * \return 1 if the motor's current limit is being exceeded and 0 if the - * current limit is not exceeded, or PROS_ERR if the operation failed, setting - * errno. - */ - std::vector are_over_current(void); - - /** - * Gets the temperature limit flag for the motors. + * \note This is one of many Motor functions that takes in an optional index parameter. + * This parameter can be ignored by most users but exists to give a shared base class + * for motors and motor groups * * This function uses the following values of errno when an error state is * reached: - * ENODEV - The port cannot be configured as a motor - * - * \return A vector with for each motor a 1 if the temperature limit is - * exceeded and 0 if the temperature is below the limit, - * or a vector filled with PROS_ERR if the operation failed, setting errno. - */ - std::vector are_over_temp(void); - - /** - * Gets the brake mode that was set for the motors. * - * This function uses the following values of errno when an error state is - * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return A Vector with for each motor one of motor_brake_mode_e_t, - * according to what was set for the motor, or a vector filled with - * E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. - */ - std::vector get_brake_modes(void); - - /** - * Gets the gearset that was set for the motor. + * EOVERFLOW - The index is non 0 * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \param limit + * The new voltage limit in Volts * - * \return One of motor_gearset_e_t according to what is set for the motor, - * or E_GEARSET_INVALID if the operation failed. - */ - std::vector get_gearing(void); - - /** - * Gets the current drawn by each motor in mA. + * \param index Optional parameter. + * The zero-indexed index of the motor to get the target position of. + * By default index is 0, and will return an error for a non-zero index * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); * - * \return A vector containing each motor's current in mA - * or a vector filled with PROS_ERR if the operation failed, setting errno. + * motor.set_voltage_limit_all(10000); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * // The motor will not output more than 10 V + * pros::delay(2); + * } + * } + * \endcode */ - std::vector get_current_draws(void); + std::int32_t set_voltage_limit_all(const std::int32_t limit) const; /** - * Gets the current limit for each motor in mA. + * Sets the position for the motor in its encoder units. * - * The default value is 2500 mA. + * This will be the future reference point for the motor's "absolute" + * position. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return A vector with each motor's current limit in mA or a vector filled - * with PROS_ERR if the operation failed, setting errno. - */ - std::vector get_current_limits(void); - - /** - * Gets the port number of each motor. + * \param position + * The new reference position in its encoder units * - * \return a vector with each motor's port number. - */ - std::vector get_ports(void); - /** - * Gets the direction of movement for the motors. + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * motor.move_absolute(100, 100); // This does not cause a movement + * + * motor.set_zero_position_all(80); + * motor.move_absolute(100, 100); // Moves 80 units forward + * } + * \endcode * - * \return 1 for moving in the positive direction, -1 for moving in the - * negative direction, and PROS_ERR if the operation failed, setting errno. */ - std::vector get_directions(void); + std::int32_t set_zero_position_all(const double position) const; /** - * Gets the encoder units that were set for each motor. + * Sets the "absolute" zero position of the motor to its current position. * * This function uses the following values of errno when an error state is * reached: * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given * - * \return A vector filled with one of motor_encoder_units_e_t for each motor - * according to what is set for the motor or a vector filled with - * E_MOTOR_ENCODER_INVALID if the operation failed. - */ - std::vector get_encoder_units(void); - - /** - * Gets the encoder units that were set for each motor. + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. * - * This function uses the following values of errno when an error state is - * reached: - * ENODEV - The port cannot be configured as a motor - * EACCESS - The Motor group mutex can't be taken or given + * \b Example + * \code + * void autonomous() { + * pros::Motor motor (1); + * motor.move_absolute(100, 100); // Moves 100 units forward + * motor.move_absolute(100, 100); // This does not cause a movement * - * \return The vector filled with motors' temperature in degrees Celsius or PROS_ERR_F if the - * operation failed, setting errno. + * motor.tare_position_all(); + * motor.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode */ - virtual std::vector get_temperatures(void); + std::int32_t tare_position_all(void) const; + + ///@} private: - std::vector _motors; - pros::Mutex _motor_group_mutex; - std::uint8_t _motor_count; + /** + * The port of the motor. Negative ports indicate that the motor is reversed + */ + std::int8_t _port; }; - -using MotorGroup = Motor_Group; //alias - namespace literals { +/** + * Constructs a Motor from a literal ending in _mtr + * + * \return a pros::Motor for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Motor motor = 2_mtr; //Makes an Motor object on port 2 + * } + * \endcode + */ const pros::Motor operator"" _mtr(const unsigned long long int m); +/** + * Constructs a reversed Motor from a literal ending in _rmtr + * + * \return a pros::Motor for the corresponding port that is reversed + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::motor motor = 2_rmtr; //Makes an reversed Motor object on port 2 + * } + * \endcode + */ const pros::Motor operator"" _rmtr(const unsigned long long int m); } // namespace literals +} // namespace v5 } // namespace pros #endif // _PROS_MOTORS_HPP_ diff --git a/include/pros/optical.h b/include/pros/optical.h index 9dd1c1b0..049c395b 100644 --- a/include/pros/optical.h +++ b/include/pros/optical.h @@ -1,19 +1,19 @@ /** * \file pros/optical.h + * \ingroup c-optical * * Contains prototypes for functions related to the VEX Optical sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-optical VEX Optical Sensor C API */ #ifndef _PROS_OPTICAL_H_ @@ -33,16 +33,34 @@ namespace pros { namespace c { #endif +/** + * \ingroup c-optical + */ + +/** + * \addtogroup c-optical + * @{ + */ -typedef enum optical_direction_e { - NO_GESTURE = 0, - UP = 1, - DOWN = 2, - RIGHT = 3, - LEFT = 4, +/** + * \enum optical_direction_e_t + */ +typedef enum optical_direction_e { NO_GESTURE = 0, + /// The direction indicating an upward gesture. + UP = 1, + /// The direction indicating a downward gesture. + DOWN = 2, + /// The direction indicating a rightward gesture. + RIGHT = 3, + /// The direction indicating a leftward gesture. + LEFT = 4, ERROR = PROS_ERR } optical_direction_e_t; +/** + * \struct optical_rgb_s_t + * The RGB and Brightness values for the optical sensor. + */ typedef struct optical_rgb_s { double red; double green; @@ -50,6 +68,10 @@ typedef struct optical_rgb_s { double brightness; } optical_rgb_s_t; +/** + * \struct optical_raw_s_t + * The RGB and clear values for the optical sensor. + */ typedef struct optical_raw_s { uint32_t clear; uint32_t red; @@ -57,17 +79,26 @@ typedef struct optical_raw_s { uint32_t blue; } optical_raw_s_t; +/** + * \struct optical_gesture_s_t + * This structure contains the raw gesture data. + */ typedef struct optical_gesture_s { - uint8_t udata; - uint8_t ddata; - uint8_t ldata; - uint8_t rdata; - uint8_t type; - uint8_t pad; - uint16_t count; - uint32_t time; + uint8_t udata; ///Up data + uint8_t ddata; ///Down data + uint8_t ldata; ///Left data + uint8_t rdata; ///Right data + uint8_t type; ///Type of gesture + uint8_t pad; ///Padding + uint16_t count; ///Number of gestures + uint32_t time; ///Time since gesture recognized } optical_gesture_s_t; +/** + * \name Functions + * @{ + */ + /** * Get the detected color hue * @@ -83,6 +114,18 @@ typedef struct optical_gesture_s { * The V5 Optical Sensor port number from 1-21 * \return hue value if the operation was successful or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Hue value: %lf \n", optical_get_hue(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ double optical_get_hue(uint8_t port); @@ -101,6 +144,18 @@ double optical_get_hue(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return saturation value if the operation was successful or PROS_ERR_F if * the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Saturation value: %lf \n", optical_get_saturation(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ double optical_get_saturation(uint8_t port); @@ -119,6 +174,18 @@ double optical_get_saturation(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return brightness value if the operation was successful or PROS_ERR_F if * the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Brightness value: %lf \n", optical_get_brightness(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ double optical_get_brightness(uint8_t port); @@ -137,6 +204,18 @@ double optical_get_brightness(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return poximity value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Proximity value: %d \n", optical_get_proximity(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t optical_get_proximity(uint8_t port); @@ -154,6 +233,18 @@ int32_t optical_get_proximity(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return 1 if the operation is successful or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * optical_set_led_pwm(OPTICAL_PORT, 50); + * delay(20); + * } + * } + * \endcode */ int32_t optical_set_led_pwm(uint8_t port, uint8_t value); @@ -170,6 +261,18 @@ int32_t optical_set_led_pwm(uint8_t port, uint8_t value); * The V5 Optical Sensor port number from 1-21 * \return LED pwm value that ranges from 0 to 100 if the operation was * successful or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("PWM Value: %d \n", optical_get_led_pwm(OPTICAL_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t optical_get_led_pwm(uint8_t port); @@ -185,6 +288,23 @@ int32_t optical_get_led_pwm(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return rgb value if the operation was successful or an optical_rgb_s_t with * all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * optical_rgb_s_t RGB_values; + * void opcontrol() { + * while (true) { + * RGB_values = optical_get_rgb(OPTICAL_PORT); + * printf("Red value: %lf \n", RGB_values.red); + * printf("Green value: %lf \n", RGB_values.green); + * printf("Blue value: %lf \n", RGB_values.blue); + * printf("Brightness value: %lf \n", RGB_values.brightness); + * delay(20); + * } + * } + * \endcode */ optical_rgb_s_t optical_get_rgb(uint8_t port); @@ -200,6 +320,23 @@ optical_rgb_s_t optical_get_rgb(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return raw rgb value if the operation was successful or an optical_raw_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * optical_raw_s_t raw_values; + * void opcontrol() { + * while (true) { + * raw_values = optical_get_raw(OPTICAL_PORT); + * printf("Red value: %ld \n", raw_values.red); + * printf("Green value: %ld \n", raw_values.green); + * printf("Blue value: %ld \n", raw_values.blue); + * printf("Clear value: %ld \n", raw_values.clear); + * delay(20); + * } + * } + * \endcode */ optical_raw_s_t optical_get_raw(uint8_t port); @@ -217,6 +354,20 @@ optical_raw_s_t optical_get_raw(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return gesture value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * optical_direction_e_t gesture; + * void opcontrol() { + * while (true) { + * gesture = optical_get_gesture(OPTICAL_PORT); + * printf("Gesture value: %d \n", gesture); + * delay(20); + * } + * } + * \endcode */ optical_direction_e_t optical_get_gesture(uint8_t port); @@ -232,6 +383,26 @@ optical_direction_e_t optical_get_gesture(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return gesture value if the operation was successful or an optical_gesture_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * optical_gesture_s_t raw_gesture; + * void opcontrol() { + * while (true) { + * raw_gesture = optical_get_gesture_raw(OPTICAL_PORT); + * printf("Up data: %u \n", raw_gesture.udata); + * printf("Down data: %u \n", raw_gesture.ddata); + * printf("Left data: %u \n", raw_gesture.ldata); + * printf("Right data: %u \n", raw_gesture.rdata); + * printf("Type: %u \n", raw_gesture.type); + * printf("Count: %u \n", raw_gesture.count); + * printf("Time: %lu \n", raw_gesture.time); + * delay(20); + * } + * } + * \endcode */ optical_gesture_s_t optical_get_gesture_raw(uint8_t port); @@ -247,6 +418,18 @@ optical_gesture_s_t optical_get_gesture_raw(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return 1 if the operation is successful or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * optical_enable_gesture(OPTICAL_PORT); + * delay(20); + * } + * } + * \endcode */ int32_t optical_enable_gesture(uint8_t port); @@ -262,41 +445,24 @@ int32_t optical_enable_gesture(uint8_t port); * The V5 Optical Sensor port number from 1-21 * \return 1 if the operation is successful or PROS_ERR if the operation failed, * setting errno. + * + * \b Example + * \code + * #define OPTICAL_PORT 1 + * + * void opcontrol() { + * while (true) { + * optical_disable_gesture(OPTICAL_PORT); + * delay(20); + * } + * } + * \endcode */ int32_t optical_disable_gesture(uint8_t port); -/** - * Get integration time (update rate) of the optical sensor in milliseconds, with - * minimum time being - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as an Optical Sensor - * - * \param port - * The V5 Optical Sensor port number from 1-21 - * \return Integration time in milliseconds if the operation is successful - * or PROS_ERR if the operation failed, setting errno. - */ -double optical_get_integration_time(uint8_t port); +///@} -/** - * Set integration time (update rate) of the optical sensor in milliseconds. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as an Optical Sensor - * - * \param port - * The V5 Optical Sensor port number from 1-21 - * \param time - * The desired integration time in milliseconds - * \return 1 if the operation is successful or PROS_ERR if the operation failed, - * setting errno. - */ -int32_t optical_set_integration_time(uint8_t port, double time); +///@} #ifdef __cplusplus } diff --git a/include/pros/optical.hpp b/include/pros/optical.hpp index 006108d6..463daa8a 100644 --- a/include/pros/optical.hpp +++ b/include/pros/optical.hpp @@ -1,19 +1,19 @@ /** * \file pros/optical.hpp + * \ingroup cpp-optical * * Contains prototypes for functions related to the VEX Optical sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-optical VEX Optical Sensor C++ API */ #ifndef _PROS_OPTICAL_HPP_ @@ -22,11 +22,21 @@ #include #include +#include +#include "pros/device.hpp" #include "pros/optical.h" namespace pros { -class Optical { +inline namespace v5 { +/** + * \ingroup cpp-optical + */ +class Optical : public Device { + /** + * \addtogroup cpp-optical + * @{ + */ public: /** * Creates an Optical Sensor object for the given port. @@ -38,10 +48,30 @@ class Optical { * * \param port * The V5 port number from 1-21 + * + * \b Example: + * \code{.cpp} + * pros::Optical optical(1); + * \endcode */ - explicit Optical(const std::uint8_t port); + Optical(const std::uint8_t port); + + Optical(const Device& device) : Optical(device.get_port()){}; + - explicit Optical(std::uint8_t port, double time); + /** + * Gets all optical sensors. + * + * \return A vector of Optical sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector optical_all = pros::Optical::get_all_devices(); // All optical sensors that are connected + * } + * \endcode + */ + static std::vector get_all_devices(); /** * Get the detected color hue @@ -56,6 +86,14 @@ class Optical { * * \return hue value if the operation was successful or PROS_ERR_F if the operation * failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * std::cout << "Hue: " << optical.get_hue() << std::endl; + * } + * \endcode */ virtual double get_hue(); @@ -72,6 +110,14 @@ class Optical { * * \return saturation value if the operation was successful or PROS_ERR_F if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * std::cout << "Saturation: " << optical.get_saturation() << std::endl; + * } + * \endcode */ virtual double get_saturation(); @@ -88,6 +134,14 @@ class Optical { * * \return brightness value if the operation was successful or PROS_ERR_F if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * std::cout << "Brightness: " << optical.get_brightness() << std::endl; + * } + * \endcode */ virtual double get_brightness(); @@ -102,8 +156,16 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return poximity value if the operation was successful or PROS_ERR if + * \return Proximity value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * std::cout << "Proximity: " << optical.get_proximity() << std::endl; + * } + * \endcode */ virtual std::int32_t get_proximity(); @@ -117,7 +179,15 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return The Error code encountered + * \return The Error code encountered or PROS_SUCCESS. + * + * \b Example: + * \code{.cpp} + * void initialize() { + * pros::Optical optical(1); + * optical.set_led_pwm(100); + * } + * \endcode */ virtual std::int32_t set_led_pwm(uint8_t value); @@ -133,6 +203,15 @@ class Optical { * * \return LED pwm value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * optical.set_led_pwm(100); + * std::cout << "LED PWM: " << optical.get_led_pwm() << std::endl; + * } + * \endcode */ virtual std::int32_t get_led_pwm(); @@ -144,8 +223,23 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return rgb value if the operation was successful or an optical_rgb_s_t + * \return rgb value if the operation was successful or an optical_rgb_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * pros::c::optical_rgb_s_t rgb = optical.get_rgb(); + * while(1) { + * std::cout << "Red: " << rgb.red << std::endl; + * std::cout << "Green: " << rgb.green << std::endl; + * std::cout << "Blue: " << rgb.blue << std::endl; + * std::cout << "Brightness: " << rgb.brightness << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual pros::c::optical_rgb_s_t get_rgb(); @@ -157,8 +251,23 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return raw rgb value if the operation was successful or an optical_raw_s_t + * \return raw rgb value if the operation was successful or an optical_raw_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * pros::c::optical_raw_s_t raw = optical.get_raw(); + * while (1) { + * std::cout << "Red: " << raw.red << std::endl; + * std::cout << "Green: " << raw.green << std::endl; + * std::cout << "Blue: " << raw.blue << std::endl; + * std::cout << "Clear: " << raw.clear << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual pros::c::optical_raw_s_t get_raw(); @@ -166,10 +275,12 @@ class Optical { * Get the most recent gesture data from the sensor * * Gestures will be cleared after 500mS - * 0 = no gesture - * 1 = up (towards cable) - * 2 = down - * 3 = right + * + * + * 0 = no gesture, + * 1 = up (towards cable), + * 2 = down, + * 3 = right, * 4 = left * * This function uses the following values of errno when an error state is @@ -179,6 +290,17 @@ class Optical { * * \return gesture value if the operation was successful or PROS_ERR if * the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * while(1) { + * std::cout << "Gesture: " << optical.get_gesture() << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual pros::c::optical_direction_e_t get_gesture(); @@ -190,8 +312,28 @@ class Optical { * ENXIO - The given value is not within the range of V5 ports (1-21). * ENODEV - The port cannot be configured as an Optical Sensor * - * \return gesture value if the operation was successful or an optical_gesture_s_t + * \return gesture value if the operation was successful or an optical_gesture_s_t * with all fields set to PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * optical.enable_gesture(); + * while(1) { + * pros::c::optical_gesture_s_t gesture = optical.get_gesture_raw(); + * std::cout << "Gesture raw data: " << std::endl; + * std::cout << "Up data: " << gesture.udata << std::endl; + * std::cout << "Down data: " << gesture.ddata << std::endl; + * std::cout << "Left data: " << gesture.ldata << std::endl; + * std::cout << "Right data: " << gesture.rdata << std::endl; + * std::cout << "Type: " << gesture.type << std::endl; + * std::cout << "Count: " << gesture.count << std::endl; + * std::cout << "Time: " << gesture.time << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual pros::c::optical_gesture_s_t get_gesture_raw(); @@ -204,7 +346,27 @@ class Optical { * ENODEV - The port cannot be configured as an Optical Sensor * * \return 1 if the operation is successful or PROS_ERR if the operation failed, - * setting errno. + * setting errno. + * + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * optical.enable_gesture(); + * while(1) { + * pros::c::optical_gesture_s_t gesture = optical.get_gesture_raw(); + * std::cout << "Gesture raw data: " << std::endl; + * std::cout << "Up data: " << gesture.udata << std::endl; + * std::cout << "Down data: " << gesture.ddata << std::endl; + * std::cout << "Left data: " << gesture.ldata << std::endl; + * std::cout << "Right data: " << gesture.rdata << std::endl; + * std::cout << "Type: " << gesture.type << std::endl; + * std::cout << "Count: " << gesture.count << std::endl; + * std::cout << "Time: " << gesture.time << std::endl; + * pros::delay(20); + * } + * } + * \endcode */ virtual std::int32_t enable_gesture(); @@ -217,50 +379,61 @@ class Optical { * ENODEV - The port cannot be configured as an Optical Sensor * * \return 1 if the operation is successful or PROS_ERR if the operation failed, - * setting errno. - */ - virtual std::int32_t disable_gesture(); - - /** - * Set integration time (update rate) of the optical sensor in milliseconds, with - * minimum time being 3 ms and maximum time being 712 ms. Default is 100 ms, with the - * optical sensor communciating with the V5 brain every 20 ms. - * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as an Optical Sensor - * - * \return 1 if the operation is successful or PROS_ERR_F if the operation failed, * setting errno. - */ - double get_integration_time(); - - /** - * Get integration time (update rate) of the optical sensor in milliseconds. * - * This function uses the following values of errno when an error state is - * reached: - * ENXIO - The given value is not within the range of V5 ports (1-21). - * ENODEV - The port cannot be configured as an Optical Sensor - * - * \param time - * The desired integration time in milliseconds - * \return Integration time in milliseconds if the operation is successful - * or PROS_ERR if the operation failed, setting errno. + * \b Example: + * \code{.cpp} + * void opcontrol() { + * pros::Optical optical(1); + * optical.enable_gesture(); + * while(1) { + * if(optical.get_gesture() != 0) { + * std::cout << "Gesture detected!"<< std::endl; + * optical.disable_gesture(); + * } + * pros::delay(20); + * } + * } + * \endcode */ - std::int32_t set_integration_time(double time); + virtual std::int32_t disable_gesture(); /** - * Gets the port number of the Optical Sensor. + * This is the overload for the << operator for printing to streams * - * \return The Optical Sensor's port number. + * Prints in format(this below is all in one line with no new line): + * Optical [port: (port number), hue: (hue), saturation: (saturation), + * brightness: (brightness), proximity: (proximity), rgb: {red, green, blue}] + * + * \b Example: + * \code{.cpp} + * pros::Optical optical(1); + * std::cout << optical << std::endl; + * \endcode */ - virtual std::uint8_t get_port(); + friend std::ostream& operator<<(std::ostream& os, pros::Optical& optical); private: - const std::uint8_t _port; + ///@} }; + +namespace literals { +/** + * Constructs a Optical sensor from a literal ending in _opt + * + * \return a pros::Optical for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Optical opt = 2_opt; //Makes an Optical object on port 2 + * } + * \endcode + */ +const pros::Optical operator"" _opt(const unsigned long long int o); +} // namespace literals +} // namespace v5 } // namespace pros #endif diff --git a/include/pros/rotation.h b/include/pros/rotation.h index 8daf2fd8..1c1c7317 100644 --- a/include/pros/rotation.h +++ b/include/pros/rotation.h @@ -1,19 +1,19 @@ /** * \file pros/rotation.h + * \ingroup c-rotation * * Contains prototypes for functions related to the VEX Rotation Sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/rotation.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-rotation VEX Rotation Sensor C API */ #ifndef _PROS_ROTATION_H_ @@ -28,6 +28,15 @@ namespace pros { namespace c { #endif +/** + * \ingroup c-rotation + */ + +/** + * \addtogroup c-rotation + * @{ + */ + #define ROTATION_MINIMUM_DATA_RATE 5 /** @@ -45,6 +54,21 @@ namespace c { * The V5 Rotation Sensor port number from 1-21 * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_reset(ROTATION_PORT); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_reset(uint8_t port); @@ -65,6 +89,16 @@ int32_t rotation_reset(uint8_t port); * \param rate The data refresh interval in milliseconds * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void initialize() { + * pros::Rotation rotation_sensor(ROTATION_PORT); + * rotation_set_data_rate(ROTATION_PORT, 5); + * } + * \endcode */ int32_t rotation_set_data_rate(uint8_t port, uint32_t rate); @@ -82,6 +116,21 @@ int32_t rotation_set_data_rate(uint8_t port, uint32_t rate); * The position in terms of ticks * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_set_position(ROTATION_PORT, 600); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_set_position(uint8_t port, uint32_t position); @@ -98,6 +147,21 @@ int32_t rotation_set_position(uint8_t port, uint32_t position); * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_reset_position(ROTATION_PORT); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_reset_position(uint8_t port); @@ -113,6 +177,18 @@ int32_t rotation_reset_position(uint8_t port); * The V5 Rotation Sensor port number from 1-21 * \return The position value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Position: %d centidegrees \n", rotation_get_position(ROTATION_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t rotation_get_position(uint8_t port); @@ -128,6 +204,18 @@ int32_t rotation_get_position(uint8_t port); * The V5 Rotation Sensor port number from 1-21 * \return The velocity value or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Velocity: %d centidegrees per second \n", rotation_get_velocity(ROTATION_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t rotation_get_velocity(uint8_t port); @@ -143,6 +231,18 @@ int32_t rotation_get_velocity(uint8_t port); * The V5 Rotation Sensor port number from 1-21 * \return The angle value (0-36000) or PROS_ERR_F if the operation failed, setting * errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Angle: %d centidegrees \n", rotation_get_angle(ROTATION_PORT)); + * delay(20); + * } + * } + * \endcode */ int32_t rotation_get_angle(uint8_t port); @@ -161,6 +261,22 @@ int32_t rotation_get_angle(uint8_t port); * * \return 1 if operation succeeded or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * Rotation rotation_sensor(ROTATION_PORT); + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_set_reversed(ROTATION_PORT, true); // Reverses the Rotation Sensor on ROTATION_PORT + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_set_reversed(uint8_t port, bool value); @@ -177,6 +293,22 @@ int32_t rotation_set_reversed(uint8_t port, bool value); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * Rotation rotation_sensor(ROTATION_PORT); + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_reverse(ROTATION_PORT); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_reverse(uint8_t port); @@ -195,6 +327,23 @@ int32_t rotation_reverse(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * Rotation rotation_sensor(ROTATION_PORT); + * bool reverse_flag = true; + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_init_reverse(ROTATION_PORT, reverse_flag); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_init_reverse(uint8_t port, bool reverse_flag); @@ -211,9 +360,27 @@ int32_t rotation_init_reverse(uint8_t port, bool reverse_flag); * * \return Boolean value of if the Rotation Sensor's direction is reversed or not * or PROS_ERR if the operation failed, setting errno. + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * Rotation rotation_sensor(ROTATION_PORT); + * while (true) { + * + * if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){ + * rotation_get_reversed(ROTATION_PORT); + * } + * delay(20); + * } + * } + * \endcode */ int32_t rotation_get_reversed(uint8_t port); +///@} + #ifdef __cplusplus } //namespace C } //namespace pros diff --git a/include/pros/rotation.hpp b/include/pros/rotation.hpp index a063eda2..e7743aa4 100644 --- a/include/pros/rotation.hpp +++ b/include/pros/rotation.hpp @@ -1,35 +1,62 @@ /** * \file pros/rotation.hpp + * \ingroup cpp-rotation * * Contains prototypes for functions related to the VEX Rotation Sensor. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/rotation.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-rotation VEX Rotation Sensor C++ API */ #ifndef _PROS_ROTATION_HPP_ #define _PROS_ROTATION_HPP_ #include +#include +#include "pros/device.hpp" #include "pros/rotation.h" namespace pros { -class Rotation { - const std::uint8_t _port; +inline namespace v5 { +/** + * \ingroup cpp-rotation + */ +class Rotation : public Device { + /** + * \addtogroup cpp-rotation + * @{ + */ public: - Rotation(const std::uint8_t port) : _port(port){}; + /** + * Constructs a new Rotation Sensor object + * + * ENXIO - The given value is not within the range of V5 ports |1-21|. + * ENODEV - The port cannot be configured as a Rotation Sensor + * + * \param port + * The V5 port number from 1 to 21, or from -21 to -1 for reversed Rotation Sensors. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); //Creates a Rotation Sensor on port 1 + * pros::Rotation reversed_rotation_sensor(-2); //Creates a reversed Rotation Sensor on port 2 + * } + * \endcode + */ + Rotation(const std::int8_t port); + + Rotation(const Device& device) : Rotation(device.get_port()){}; - Rotation(const std::uint8_t port, const bool reverse_flag); /** * Reset the Rotation Sensor @@ -44,6 +71,20 @@ class Rotation { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.reset(); + * } + * pros::delay(20); + * } + * } + * \endcode */ virtual std::int32_t reset(); @@ -67,6 +108,14 @@ class Rotation { * \param rate The data refresh interval in milliseconds * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Rotation rotation_sensor(1); + * rotation_sensor.set_data_rate(5); + * } + * \endcode */ virtual std::int32_t set_data_rate(std::uint32_t rate) const; @@ -82,11 +131,25 @@ class Rotation { * The position in terms of ticks * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.set_position(600); + * } + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t set_position(std::uint32_t position); + virtual std::int32_t set_position(std::uint32_t position) const; /** - * Reset the Rotation Sensor to a desired rotation value + * Reset the Rotation Sensor position to 0 * * This function uses the following values of errno when an error state is * reached: @@ -97,8 +160,36 @@ class Rotation { * The position in terms of ticks * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.reset_position(); + * } + * pros::delay(20); + * } + * } + * \endcode + */ + virtual std::int32_t reset_position(void) const; + + /** + * Gets all rotation sensors. + * + * \return A vector of Rotation sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector rotation_all = pros::Rotation::get_all_devices(); // All rotation sensors that are connected + * } + * \endcode */ - virtual std::int32_t reset_position(void); + static std::vector get_all_devices(); /** * Get the Rotation Sensor's current position in centidegrees @@ -110,8 +201,19 @@ class Rotation { * * \return The position value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while (true) { + * printf("Position: %d Ticks \n", rotation_sensor.get_position()); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_position(); + virtual std::int32_t get_position() const; /** * Get the Rotation Sensor's current velocity in centidegrees per second @@ -123,11 +225,21 @@ class Rotation { * * \param port * The V5 Rotation Sensor port number from 1-21 - * \return The - value or PROS_ERR_F if the operation failed, setting + * \return The velocity value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while (true) { + * printf("Velocity: %d centidegrees per second \n", rotation_sensor.get_velocity)); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_velocity(); + virtual std::int32_t get_velocity() const; /** * Get the Rotation Sensor's current position in centidegrees @@ -139,8 +251,19 @@ class Rotation { * * \return The angle value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while (true) { + * printf("Angle: %d centidegrees \n", rotation_sensor.get_angle()); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_angle(); + virtual std::int32_t get_angle() const; /** * Set the Rotation Sensor's direction reversed flag @@ -156,8 +279,22 @@ class Rotation { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.set_reversed(true); // Reverses the Rotation Sensor + * } + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t set_reversed(bool value); + virtual std::int32_t set_reversed(bool value) const; /** * Reverse the Rotation Sensor's direction. @@ -169,8 +306,22 @@ class Rotation { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * if(master.get_analog(E_CONTROLLER_DIGITAL_X) { + * rotation_sensor.reverse(); + * } + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t reverse(); + virtual std::int32_t reverse() const; /** * Get the Rotation Sensor's reversed flag @@ -182,9 +333,62 @@ class Rotation { * * \return Reversed value or PROS_ERR if the operation failed, setting * errno. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while (true) { + * printf("Reversed: %d \n", rotation_sensor.get_reversed()); + * delay(20); + * } + * } + * \endcode */ - virtual std::int32_t get_reversed(); + virtual std::int32_t get_reversed() const; + + /** + * This is the overload for the << operator for printing to streams + * + * Prints in format(this below is all in one line with no new line): + * Rotation [port: rotation._port, position: (rotation position), velocity: (rotation velocity), + * angle: (rotation angle), reversed: (reversed boolean)] + * + * \b Example + * \code + * #define ROTATION_PORT 1 + * + * void opcontrol() { + * pros::Rotation rotation_sensor(1); + * while(true) { + * std::cout << rotation_sensor << std::endl; + * pros::delay(20); + * } + * } + * \endcode + */ + friend std::ostream& operator<<(std::ostream& os, const pros::Rotation& rotation); + + ///@} }; + +namespace literals { +/** + * Constructs a Rotation sensor from a literal ending in _rot + * + * \return a pros::Rotation for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Rotation rotation = 2_rot; //Makes an Motor object on port 2 + * } + * \endcode + */ +const pros::Rotation operator"" _rot(const unsigned long long int r); +} // namespace literals +} // namespace v5 } // namespace pros #endif diff --git a/include/pros/rtos.h b/include/pros/rtos.h index c0767342..d6b9be48 100644 --- a/include/pros/rtos.h +++ b/include/pros/rtos.h @@ -1,22 +1,23 @@ /** * \file pros/rtos.h + * \ingroup c-rtos * * Contains declarations for the PROS RTOS kernel for use by typical VEX * programmers. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html to - * learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ + * + * \defgroup c-rtos RTOS Facilities C API + * \note Additional example code for this module can be found in its [Tutorial.](@ref multitasking) + */ #ifndef _PROS_RTOS_H_ #define _PROS_RTOS_H_ @@ -29,52 +30,117 @@ extern "C" { namespace pros { #endif -// The highest priority that can be assigned to a task. Beware of deadlock. +/// \ingroup c-rtos + +/// \addtogroup c-rtos +/// @{ + +/// \name Macros +/// @{ + +/** + * The highest priority that can be assigned to a task. + * + * A task with this priority will always run if it is available to. Beware of + * deadlocks when using this priority. + */ #define TASK_PRIORITY_MAX 16 -// The lowest priority that can be assigned to a task. -// This may cause severe performance problems and is generally not recommended. +/** + * The lowest priority that can be assigned to a task. + * + * This can cause severe performance problems and is generally not recommended + * that users use this priority. + */ #define TASK_PRIORITY_MIN 1 -// The default task priority, which should be used for most tasks. -// Default tasks such as autonomous() inherit this priority. +/** + * The default task priority, which should be used for most tasks unless you + * have a specific need for a higher or lower priority task. + * + * The default tasks, such as autonomous(), are run with this priority + */ #define TASK_PRIORITY_DEFAULT 8 -// The recommended stack size for a new task. This stack size is used for -// default tasks such as autonomous(). This equates to 32,768 bytes, or 128 -// times the default stack size for a task in PROS 2. +/** + * The recommended stack size for a new task. + * + * This stack size is used for the default tasks such as autonomous(). This + * size is 8,192 words, or 32,768 bytes. This should be enough for the majority + * of tasks + */ #define TASK_STACK_DEPTH_DEFAULT 0x2000 -// The minimal stack size for a task. This equates to 2048 bytes, or 8 times the -// default stack size for a task in PROS 2. +/** + * The minimal stack size for a task. + * + * This equates to 512 words, or 2,048 bytes. + */ #define TASK_STACK_DEPTH_MIN 0x200 -// The maximum number of characters allowed in a task's name. +/** + * The maximum number of characters allowed in a task's name. + */ #define TASK_NAME_MAX_LEN 32 -// The maximum timeout value that can be given to, for instance, a mutex grab. +/** + * The maximum timeout value that can be given to, for instance, a mutex grab. + */ #define TIMEOUT_MAX ((uint32_t)0xffffffffUL) +/// @} Name: Macros + +/// \name Typedefs +/// @{ + +/** + * An opaque type that pontis to a task handle. This is used for referencing a + * task. + */ typedef void* task_t; + +/** + * A pointer to a task's function. + * + * Such a function is called when a task starts, and exiting said function will + * terminate the task. + */ typedef void (*task_fn_t)(void*); +/// @} Name: Typedefs + + +/// \name Enumerations +/// @{ + +/** + * The state of a task. + */ typedef enum { - E_TASK_STATE_RUNNING = 0, - E_TASK_STATE_READY, - E_TASK_STATE_BLOCKED, - E_TASK_STATE_SUSPENDED, - E_TASK_STATE_DELETED, - E_TASK_STATE_INVALID + E_TASK_STATE_RUNNING = 0, /**< The task is actively executing. */ + E_TASK_STATE_READY, /**< The task exists and is available to run, but is not currently running. */ + E_TASK_STATE_BLOCKED, /**< The task is delayed or blocked by a mutex, semaphore, or I/O operation. */ + E_TASK_STATE_SUSPENDED, /**< The task is supended using task_suspend. */ + E_TASK_STATE_DELETED, /**< The task has been deleted using task_delete. */ + E_TASK_STATE_INVALID /**< The task handle does not point to a current or past task.*/ } task_state_e_t; +/** + * brief The action to take when a task is notified. + */ typedef enum { - E_NOTIFY_ACTION_NONE, - E_NOTIFY_ACTION_BITS, - E_NOTIFY_ACTION_INCR, - E_NOTIFY_ACTION_OWRITE, - E_NOTIFY_ACTION_NO_OWRITE + E_NOTIFY_ACTION_NONE, /**< The task’s notification value will not be touched.*/ + E_NOTIFY_ACTION_BITS, /**< The task’s notification value will be bitwise ORed with the new value.*/ + E_NOTIFY_ACTION_INCR, /**< The task’s notification value will be incremented by one, effectively using it as a notification counter.*/ + E_NOTIFY_ACTION_OWRITE, /**< The task’s notification value will be unconditionally set to the new value.*/ + E_NOTIFY_ACTION_NO_OWRITE /**< The task’s notification value will be set to the new value if the task does not already have a pending notification.*/ } notify_action_e_t; +/// @} Name: Enumerations + +/// \name Simple enum names +/// @{ + #ifdef PROS_USE_SIMPLE_NAMES #ifdef __cplusplus #define TASK_STATE_RUNNING pros::E_TASK_STATE_RUNNING @@ -103,10 +169,24 @@ typedef enum { #endif #endif +/// @} Name: Simple enum names + +/// \name Typedefs + +/** + * A [mutex.](@ref multitasking) + * + * A mutex is a synchronization object that can be used to protect a shared + * resource from being accessed by multiple tasks at the same time. A mutex can + * be claimed by a task, which will prevent other tasks from claiming it until + * that task releases it. + */ typedef void* mutex_t; +/// @} Name: Typedefs + /** - * Refers to the current task handle + * The task handle of the currently running task. */ #ifdef __cplusplus #define CURRENT_TASK ((pros::task_t)NULL) @@ -114,14 +194,31 @@ typedef void* mutex_t; #define CURRENT_TASK ((task_t)NULL) #endif +/// @} (add to group: c-rtos) + #ifdef __cplusplus namespace c { #endif +/// \ingroup c-rtos +/// \addtogroup c-rtos +/// @{ + /** * Gets the number of milliseconds since PROS initialized. * * \return The number of milliseconds since PROS initialized + * + * \b Example + * \code + * void opcontrol() { + * uint32_t now = millis(); + * while (true) { + * // Do opcontrol things + * task_delay_until(&now, 2); + * } + * } + * \endcode */ uint32_t millis(void); @@ -129,6 +226,17 @@ uint32_t millis(void); * Gets the number of microseconds since PROS initialized, * * \return The number of microseconds since PROS initialized + * + * \b Example + * \code + * void opcontrol() { + * uint64_t now = micros(); + * while (true) { + * // Do opcontrol things + * task_delay_until(&now, 2000); + * } + * } + * \endcode */ uint64_t micros(void); @@ -158,6 +266,19 @@ uint64_t micros(void); * \return A handle by which the newly created task can be referenced. If an * error occurred, NULL will be returned and errno can be checked for hints as * to why task_create failed. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode */ task_t task_create(task_fn_t function, void* const parameters, uint32_t prio, const uint16_t stack_depth, const char* const name); @@ -172,11 +293,26 @@ task_t task_create(task_fn_t function, void* const parameters, uint32_t prio, co * \param task * The handle of the task to be deleted. Passing NULL will cause the * calling task to be deleted. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * // Do other things + * task_delete(my_task); + * } + * \endcode */ void task_delete(task_t task); /** - * Delays a task for a given number of milliseconds. + * Delays the current task for a given number of milliseconds. * * This is not the best method to have a task execute code at predefined * intervals, as the delay time is measured from when the delay is requested. @@ -184,14 +320,44 @@ void task_delete(task_t task); * * \param milliseconds * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * // Do opcontrol things + * task_delay(2); + * } + * } + * \endcode */ void task_delay(const uint32_t milliseconds); +/** + * Delays the current task for a given number of milliseconds. + * + * This is not the best method to have a task execute code at predefined + * intervals, as the delay time is measured from when the delay is requested. + * To delay cyclically, use task_delay_until(). + * + * \param milliseconds + * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * // Do opcontrol things + * delay(2); + * } + * } + * \endcode + */ void delay(const uint32_t milliseconds); /** - * Delays a task until a specified time. This function can be used by periodic - * tasks to ensure a constant execution frequency. + * Delays the current task until a specified time. This function can be used + * by periodic tasks to ensure a constant execution frequency. * * The task will be woken up at the time *prev_time + delta, and *prev_time will * be updated to reflect the time at which the task will unblock. @@ -201,6 +367,17 @@ void delay(const uint32_t milliseconds); * typically be initialized to the return value of millis(). * \param delta * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * uint32_t now = millis(); + * while (true) { + * // Do opcontrol things + * task_delay_until(&now, 2); + * } + * } + * \endcode */ void task_delay_until(uint32_t* const prev_time, const uint32_t delta); @@ -211,6 +388,20 @@ void task_delay_until(uint32_t* const prev_time, const uint32_t delta); * The task to check * * \return The priority of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * printf("Task Priority: %d\n", task_get_priority(my_task)); + * } + * \endcode */ uint32_t task_get_priority(task_t task); @@ -225,6 +416,19 @@ uint32_t task_get_priority(task_t task); * The task to set * \param prio * The new priority of the task + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * // Do things + * } + * + * void opcontrol() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "Example Task"); + * task_set_priority(my_task, TASK_PRIORITY_DEFAULT + 1); + * } + * \endcode */ void task_set_priority(task_t task, uint32_t prio); @@ -235,6 +439,20 @@ void task_set_priority(task_t task, uint32_t prio); * The task to check * * \return The state of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * printf("Task's State: %d\n", task_get_state(my_task)); + * } + * \endcode */ task_state_e_t task_get_state(task_t task); @@ -243,6 +461,34 @@ task_state_e_t task_get_state(task_t task); * * \param task * The task to suspend + * + * \b Example + * \code + * mutex_t counter_mutex; + * int counter = 0; + * + * void my_task_fn(void* param) { + * while(true) { + * mutex_take(counter_mutex, TIMEOUT_MAX);// Mutexes are used for protecting shared resources + * counter++; + * mutex_give(counter_mutex); + * pros::delay(10); + * } + * } + * + * void opcontrol() { + * task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT,; + * + * while(true) { + * mutex_take(counter_mutex, TIMEOUT_MAX); + * if(counter > 100) { + * task_suspepend(task); + * } + * mutex_give(counter_mutex); + * pros::delay(10); + * } + * } + * \endcode */ void task_suspend(task_t task); @@ -251,6 +497,39 @@ void task_suspend(task_t task); * * \param task * The task to resume + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while(true) { + * // Do stuff + * delay(10); + * } + * } + * + * task_t task; + * + * void initialize() { + * task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * + * void autonomous() { + * task_resume(task); + * + * // Run autonomous , then suspend the task so it doesn't interfere run + * + * // outside of autonomous or opcontrol + * task_suspend(task); + * } + * + * void opcontrol() { + * task_resume(task); + * // Opctonrol code here + * task_suspend(task); + * } + * + * \endcode */ void task_resume(task_t task); @@ -261,6 +540,20 @@ void task_resume(task_t task); * created may take one context switch to be counted. * * \return The number of tasks that are currently being managed by the kernel. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * printf("Number of Running Tasks: %d\n", task_get_count()); + * } + * \endcode */ uint32_t task_get_count(void); @@ -271,6 +564,20 @@ uint32_t task_get_count(void); * The task to check * * \return A pointer to the name of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * printf("Task Name: %d\n", task_get_name(my_task)); + * } + * \endcode */ char* task_get_name(task_t task); @@ -283,6 +590,21 @@ char* task_get_name(task_t task); * The name to query * * \return A task handle with a matching name, or NULL if none were found. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * // Do other things + * task_delete(task_get_by_name("My Task")); + * } + * \endcode */ task_t task_get_by_name(const char* name); @@ -291,19 +613,52 @@ task_t task_get_by_name(const char* name); * wants to tell another task about itself. * * \return The currently running task handle. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * task_t this_task = task_get_current(); + * if (task_get_state(this_take) == E_TASK_STATE_RUNNING) { + * printf("This task is currently running\n"); + * } + * // ... + * } + * + * void initialize() { + * task_t my_task = task_create(my_task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode */ task_t task_get_current(); /** * Sends a simple notification to task and increments the notification counter. * - * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for - * details. - * * \param task * The task to notify * * \return Always returns true. + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * while(task_notify_take(true) == 0) { + * // Code while waiting + * } + * puts("I was unblocked!"); + * } + * + * void opcontrol() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "Notify me! Task"); + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task_notify(my_task); + * } + * } + * } + * \endcode */ uint32_t task_notify(task_t task); @@ -311,14 +666,28 @@ uint32_t task_notify(task_t task); * * Utilizes task notifications to wait until specified task is complete and deleted, * then continues to execute the program. Analogous to std::thread::join in C++. - * - * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for - * details. * * \param task - * The task to wait on. + * The handle of the task to wait on. * * \return void + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * lcd_print(1, "%s running", task_get_name(NULL)); + * task_delay(1000); + * lcd_print(2, "End of %s", task_get_name(NULL)); + * } + * + * void opcontrol() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "Example Task"); + * lcd_set_text(0, "Running task."); + * task_join(my_task); + * lcd_set_text(3, "Task completed."); + * } + * \endcode */ void task_join(task_t task); @@ -327,9 +696,6 @@ void task_join(task_t task); * retrieve the value of the notification in the target task before modifying * the notification value. * - * See https://pros.cs.purdue.edu/v5/tutorials/topical/notifications.html for - * details. - * * \param task * The task to notify * \param value @@ -345,6 +711,37 @@ void task_join(task_t task); * For NOTIFY_ACTION_NO_WRITE: return 0 if the value could be written without * needing to overwrite, 1 otherwise. * For all other NOTIFY_ACTION values: always return 0 + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while(true) { + * // Wait until we have been notified 20 times before running the code + * if(task_notify_take(false, TIMEOUT_MAX) == 20) { + * // ... Code to do stuff here ... + * + * // Reset the notification counter + * task_notify_take(true, TIMEOUT_MAX); + * } + * delay(10); + * } + * } + * + * void opcontrol() { + * task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * + * int count = 0; + * + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task_notify_ext(task, 1, NOTIFY_ACTION_INCREMENT, &count); + * } + * + * delay(20); + * } + * } + * \endcode */ uint32_t task_notify_ext(task_t task, uint32_t value, notify_action_e_t action, uint32_t* prev_value); @@ -363,6 +760,26 @@ uint32_t task_notify_ext(task_t task, uint32_t value, notify_action_e_t action, * * \return The value of the task's notification value before it is decremented * or cleared + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * task_t current_task = task_get_current(); + * while(task_notify_take(current_task, true, TIMEOUT_MAX)) { + * puts("I was unblocked!"); + * } + * } + * + * void opcontrol() { + * task_t my_task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "Notify me! Task"); + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task_notify(my_task); + * } + * } + * } + * \endcode */ uint32_t task_notify_take(bool clear_on_exit, uint32_t timeout); @@ -376,6 +793,32 @@ uint32_t task_notify_take(bool clear_on_exit, uint32_t timeout); * The task to clear * * \return False if there was not a notification waiting, true if there was + * + * \b Example + * \code + * void my_task_fn(void* param) { + * task_t task = task_get_current(); + * while(true) { + * printf("Waiting for notification...\n"); + * printf("Got a notification: %d\n", task_notify_take(task, false, TIMEOUT_MAX)); + * + * task_notify_clear(task); + * delay(10): + * } + * } + * + * void opcontrol() { + * task_t task = task_create(my_task_fn, NULL, TASK_PRIORITY_DEFAULT, + * TASK_STACK_DEPTH_DEFAULT, "My Task"); + * + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task_notify(task); + * } + * delay(10); + * } + * } + * \endcode */ bool task_notify_clear(task_t task); @@ -387,6 +830,75 @@ bool task_notify_clear(task_t task); * * \return A handle to a newly created mutex. If an error occurred, NULL will be * returned and errno can be checked for hints as to why mutex_create failed. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * mutex_t odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * mutex_take(odom_mutex, MAX_DELAY); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * mutex_give(odom_mutex); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * mutex_take(odom_mutex, MAX_DELAY); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * mutex_give(odom_mutex); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * mutex_take(odom_mutex, MAX_DELAY); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * mutex_give(odom_mutex); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = mutex_create(); + * + * task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Odometry Task"); + * task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Chassis Task"); + * } + * \endcode */ mutex_t mutex_create(void); @@ -407,6 +919,75 @@ mutex_t mutex_create(void); * \return True if the mutex was successfully taken, false otherwise. If false * is returned, then errno is set with a hint about why the the mutex * couldn't be taken. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * mutex_t odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * mutex_take(odom_mutex, MAX_DELAY); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * mutex_give(odom_mutex); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * mutex_take(odom_mutex, MAX_DELAY); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * mutex_give(odom_mutex); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * mutex_take(odom_mutex, MAX_DELAY); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * mutex_give(odom_mutex); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = mutex_create(); + * + * task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Odometry Task"); + * task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Chassis Task"); + * } + * \endcode */ bool mutex_take(mutex_t mutex, uint32_t timeout); @@ -422,6 +1003,75 @@ bool mutex_take(mutex_t mutex, uint32_t timeout); * \return True if the mutex was successfully returned, false otherwise. If * false is returned, then errno is set with a hint about why the mutex * couldn't be returned. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * mutex_t odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * mutex_take(odom_mutex, MAX_DELAY); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * mutex_give(odom_mutex); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * mutex_take(odom_mutex, MAX_DELAY); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * mutex_give(odom_mutex); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * mutex_take(odom_mutex, MAX_DELAY); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * mutex_give(odom_mutex); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = mutex_create(); + * + * task_create(odom_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Odometry Task"); + * task_create(chassis_task, NULL, TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Chassis Task"); + * } + * \endcode */ bool mutex_give(mutex_t mutex); @@ -430,9 +1080,25 @@ bool mutex_give(mutex_t mutex); * * \param mutex * Mutex to unlock. + * + * \b Example + * \code + * mutex_t mutex = mutex_create(); + * // Acquire the mutex; other tasks using this command will wait until the mutex is released + * // timeout can specify the maximum time to wait, or MAX_DELAY to wait forever + * // If the timeout expires, "false" will be returned, otherwise "true" + * mutex_take(mutex, MAX_DELAY); + * // do some work + * // Release the mutex for other tasks + * mutex_give(mutex); + * // Delete the mutex + * mutex_delete(mutex); + * \endcode */ void mutex_delete(mutex_t mutex); +/// @} Add to group: c-rtos + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/include/pros/rtos.hpp b/include/pros/rtos.hpp index 2505f1d1..f02495c2 100644 --- a/include/pros/rtos.hpp +++ b/include/pros/rtos.hpp @@ -1,21 +1,22 @@ /** * \file pros/rtos.hpp + * \ingroup cpp-rtos * * Contains declarations for the PROS RTOS kernel for use by typical VEX * programmers. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html to - * learn more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-rtos RTOS Facilities C++ API + * \note Additional example code for this module can be found in its [Tutorial.](@ref multitasking) */ #ifndef _PROS_RTOS_HPP_ @@ -32,7 +33,15 @@ #include namespace pros { +inline namespace rtos { +/** + * \ingroup cpp-rtos + */ class Task { + /** + * \addtogroup cpp-rtos + * @{ + */ public: /** * Creates a new task and add it to the list of tasks that are ready to run. @@ -57,7 +66,18 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, (void*)"PROS"); + * } + * \endcode */ Task(task_fn_t function, void* parameters = nullptr, std::uint32_t prio = TASK_PRIORITY_DEFAULT, std::uint16_t stack_depth = TASK_STACK_DEPTH_DEFAULT, const char* name = ""); @@ -79,7 +99,18 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, (void*)"PROS", "My Task"); + * } + * \endcode */ Task(task_fn_t function, void* parameters, const char* name); @@ -101,7 +132,18 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::c::task_t my_task = pros::Task::create(my_task_fn, (void*)"PROS"); + * } + * \endcode */ template static task_t create(F&& function, std::uint32_t prio = TASK_PRIORITY_DEFAULT, @@ -127,7 +169,18 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::c::task_t my_task = pros::Task::create(my_task_fn, "My Task"); + * } + * \endcode */ template static task_t create(F&& function, const char* name) { @@ -152,7 +205,19 @@ class Task { * \param name * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. - * + * + * \b Example + * \code + * + * void initialize() { + * // Create a task function using lambdas + * auto task_fn = [](void* param) { + * printf("Hello %s\n", (char*)param); + * } + * + * pros::Task my_task(task_fn, (void*)"PROS", "My Task"); + * } + * \endcode */ template explicit Task(F&& function, std::uint32_t prio = TASK_PRIORITY_DEFAULT, @@ -179,6 +244,22 @@ class Task { * A descriptive name for the task. This is mainly used to facilitate * debugging. The name may be up to 32 characters long. * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task( + * [](void* param) { + * printf("Inside the task!\n"); + * }, + * "My Task" + * ); + * } + * \endcode */ template Task(F&& function, const char* name) @@ -190,20 +271,60 @@ class Task { * \param task * A task handle from task_create() for which to create a pros::Task * object. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::c::task_t my_task = pros::Task::create(my_task_fn, "My Task"); + * + * pros::Task my_task_cpp(my_task); + * } + * \endcode */ explicit Task(task_t task); /** * Get the currently running Task + * + * @return The currently running Task. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("The name of this task is \"%s\"\n", pros::Task::current().get_name() + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, pros::TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task"); + * } + * \endcode */ static Task current(); /** - * Creates a new task and add it to the list of tasks that are ready to run. + * Creates a task object from the passed task handle. * * \param in * A task handle from task_create() for which to create a pros::Task * object. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("The name of this task is \"%s\"\n", pros::Task::current().get_name() + * } + * + * void initialize() { + * pros::c::task_t my_task = pros::Task::create(my_task_fn, "My Task"); + * + * pros::Task my_task_cpp = my_task; + * } + * \endcode */ Task& operator=(task_t in); @@ -213,6 +334,20 @@ class Task { * * Memory dynamically allocated by the task is not automatically freed, and * should be freed before the task is deleted. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * my_task.remove(); + * } + * \endcode */ void remove(); @@ -220,6 +355,20 @@ class Task { * Gets the priority of the specified task. * * \return The priority of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * printf("Task Priority: %d\n", my_task.get_priority()); + * } + * \endcode */ std::uint32_t get_priority(); @@ -232,6 +381,20 @@ class Task { * * \param prio * The new priority of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * Task.set_priority(pros::DEFAULT_PRIORITY + 1); + * } + * \endcode */ void set_priority(std::uint32_t prio); @@ -239,11 +402,53 @@ class Task { * Gets the state of the specified task. * * \return The state of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * printf("Task State: %d\n", my_task.get_state()); + * } + * \endcode */ std::uint32_t get_state(); /** * Suspends the specified task, making it ineligible to be scheduled. + * + * \b Example + * \code + * pros::Mutex counter_mutex; + * int counter = 0; + * + * void my_task_fn(void* param) { + * while(true) { + * counter_mutex.take(); // Mutexes are used for protecting shared resources + * counter++; + * counter_mutex.give(); + * pros::delay(10); + * } + * } + * + * void opcontrol() { + * pros::Task task(my_task_fn, "My Task"); + * + * while(true) { + * counter_mutex.take(); + * if(counter > 100) { + * task_suspepend(task); + * } + * counter_mutex.give(); + * pros::delay(10); + * } + * } + * \endcode */ void suspend(); @@ -252,6 +457,33 @@ class Task { * * \param task * The task to resume + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while(true) { + * // Do stuff + * pros::delay(10); + * } + * } + * + * pros::Task task(my_task_fn); + * + * void autonomous() { + * task.resume(); + * + * // Run autonomous , then suspend the task so it doesn't interfere run + * // outside of autonomous or opcontrol + * task.suspend(); + * } + * + * void opcontrol() { + * task.resume(); + * // Opctonrol code here + * task.suspend(); + * } + * + * \endcode */ void resume(); @@ -259,11 +491,38 @@ class Task { * Gets the name of the specified task. * * \return A pointer to the name of the task + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * printf("Number of Running Tasks: %d\n", my_task.get_name()); + * } + * \endcode */ const char* get_name(); /** * Convert this object to a C task_t handle + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void initialize() { + * pros::Task my_task(my_task_fn, "My Task"); + * + * pros::c::task_t my_task_c = (pros::c::task_t)my_task; + * } + * \endcode */ explicit operator task_t() { return task; @@ -277,6 +536,26 @@ class Task { * details. * * \return Always returns true. + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * while(pros::Task::current_task().notify_take(true) == 0) { + * // Code while waiting + * } + * puts("I was unblocked!"); + * } + * + * void opcontrol() { + * pros::Task my_task(my_task_fn); + * + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * my_task.notify(); + * } + * } + * } + * \endcode */ std::uint32_t notify(); @@ -288,6 +567,22 @@ class Task { * details. * * \return void + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * lcd_print(1, "%s running", pros::Task::current_task().get_name()); + * task_delay(1000); + * lcd_print(2, "End of %s", pros::Task::current_task().get_name()); + * } + * + * void opcontrol() { + * pros::Task my_task(my_task_fn); + * pros::lcd::set_text(0, "Running task."); + * my_task.join(); + * pros::lcd::lcd_set_text(3, "Task completed."); + * } + * \endcode */ void join(); @@ -312,6 +607,38 @@ class Task { * For NOTIFY_ACTION_NO_WRITE: return 0 if the value could be written without * needing to overwrite, 1 otherwise. * For all other NOTIFY_ACTION values: always return 0 + * + * \b Example + * \code + * void my_task_fn(void* param) { + * pros::Task task = pros::Task::current(); + * + * while(true) { + * // Wait until we have been notified 20 times before running the code + * if(task.notify_take(false, TIMEOUT_MAX) == 20) { + * // ... Code to do stuff here ... + * + * // Reset the notification counter + * task.notify_clear(); + * } + * delay(10); + * } + * } + * + * void opcontrol() { + * pros::Task task(my_task_fn); + * + * int count = 0; + * + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task.notify_ext(1, NOTIFY_ACTION_INCREMENT, &count); + * } + * + * delay(20); + * } + * } + * \endcode */ std::uint32_t notify_ext(std::uint32_t value, notify_action_e_t action, std::uint32_t* prev_value); @@ -330,6 +657,25 @@ class Task { * * \return The value of the task's notification value before it is decremented * or cleared + * + * \b Example + * \code + * void my_task_fn(void* ign) { + * pros::Task task = pros::task::current(); + * while(task.notify_take(true, TIMEOUT_MAX)) { + * puts("I was unblocked!"); + * } + * } + * + * void opcontrol() { + * pros::Task task(my_task_fn); + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task.notify(my_task); + * } + * } + * } + * \endcode */ static std::uint32_t notify_take(bool clear_on_exit, std::uint32_t timeout); @@ -340,11 +686,34 @@ class Task { * details. * * \return False if there was not a notification waiting, true if there was + * \b Example + * \code + * void my_task_fn(void* param) { + * pros::Task task = pros::Task::current(); + * while(true) { + * printf("Waiting for notification...\n"); + * printf("Got a notification: %d\n", task.notify_take(false, TIMEOUT_MAX)); + * + * tasK_notify(task); + * delay(10): + * } + * } + * + * void opcontrol() { + * pros::Task task(my_task_fn); + * while(true) { + * if(controller_get_digital(CONTROLLER_MASTER, DIGITAL_L1)) { + * task.notify(); + * } + * delay(10); + * } + * } + * \endcode */ bool notify_clear(); /** - * Delays a task for a given number of milliseconds. + * Delays the current task for a specified number of milliseconds. * * This is not the best method to have a task execute code at predefined * intervals, as the delay time is measured from when the delay is requested. @@ -352,11 +721,20 @@ class Task { * * \param milliseconds * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * // Do opcontrol things + * pros::Task::delay(2); + * } + * \endcode */ static void delay(const std::uint32_t milliseconds); /** - * Delays a task until a specified time. This function can be used by + * Delays the current Task until a specified time. This function can be used by * periodic tasks to ensure a constant execution frequency. * * The task will be woken up at the time *prev_time + delta, and *prev_time @@ -367,6 +745,16 @@ class Task { * typically be initialized to the return value from pros::millis(). * \param delta * The number of milliseconds to wait (1000 milliseconds per second) + * + * \b Example + * \code + * void opcontrol() { + * while (true) { + * // Do opcontrol things + * pros::Task::delay(2); + * } + * } + * \endcode */ static void delay_until(std::uint32_t* const prev_time, const std::uint32_t delta); @@ -377,6 +765,19 @@ class Task { * Tasks recently created may take one context switch to be counted. * * \return The number of tasks that are currently being managed by the kernel. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * printf("Hello %s\n", (char*)param); + * // ... + * } + * + * void opcontrol() { + * pros::Task my_task(my_task_fn); + * printf("There are %d tasks running\n", pros::Task::get_count()); + * } + * \endcode */ static std::uint32_t get_count(); @@ -398,6 +799,23 @@ struct Clock { * Effectively a wrapper around pros::millis() * * \return The current time + * + * \b Example + * \code + * void opcontrol() { + * pros::Clock::time_point start = pros::Clock::now(); + * pros::Clock::time_point end = pros::Clock::now(); + * pros::Clock::duration duration = end - start; + * printf("Duration: %d\n", duration.count()); + * + * if(duration.count() == 500) { + * // If you see this comment in the DOCS, ping @pros in VTOW. + * // If you are the first person to do so, you will receive a free PROS + * // holo! + * printf("Duration is 500 milliseconds\n"); + * } + * } + * \endcode */ static time_point now(); }; @@ -425,7 +843,76 @@ class Mutex { * * \return True if the mutex was successfully taken, false otherwise. If false * is returned, then errno is set with a hint about why the the mutex - * couldn't be taken. + * couldn't be taken + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.take(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.give(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.take(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.give(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.take(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.give(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ bool take(); @@ -445,6 +932,75 @@ class Mutex { * \return True if the mutex was successfully taken, false otherwise. If false * is returned, then errno is set with a hint about why the the mutex * couldn't be taken. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.take(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.give(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.take(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.give(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.take(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.give(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ bool take(std::uint32_t timeout); @@ -458,6 +1014,75 @@ class Mutex { * \return True if the mutex was successfully returned, false otherwise. If * false is returned, then errno is set with a hint about why the mutex * couldn't be returned. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.take(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.give(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.take(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.give(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.take(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.give(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ bool give(); @@ -475,6 +1100,75 @@ class Mutex { * * \exception std::system_error Mutex could not be locked within TIMEOUT_MAX * milliseconds. see errno for details. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.lock(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.unlock(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.lock(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.unlock(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.lock(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.unlock(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ void lock(); @@ -488,6 +1182,75 @@ class Mutex { * * \note Consider using a std::unique_lock, std::lock_guard, or * std::scoped_lock instead of interacting with the Mutex direcly. + * + * \b Example + * \code + * // Global variables for the robot's odometry, which the rest of the robot's + * // subsystems will utilize + * double odom_x = 0.0; + * double odom_y = 0.0; + * double odom_heading = 0.0; + * + * // This mutex protects the odometry data. Whenever we read or write to the + * // odometry data, we should make copies into the local variables, and read + * // all 3 values at once to avoid errors. + * pros::Mutex odom_mutex; + * + * void odom_task(void* param) { + * while(true) { + * // First we fetch the odom coordinates from the previous iteration of the + * // odometry task. These are put into local variables so that we can + * // keep the size of the critical section as small as possible. This lets + * // other tasks that need to use the odometry data run until we need to + * // update it again. + * odom_mutex.lock(); + * double x_old = odom_x; + * double y_old = odom_y; + * double heading_old = odom_heading; + * odom_mutex.unlock(); + * + * double x_new = 0.0; + * double y_new = 0.0; + * double heading_new = 0.0; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * odom_mutex.lock(); + * odom_x = x_new; + * odom_y = y_new; + * odom_heading = heading_new; + * odom_mutex.unlock(); + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * // Here we copy the current odom values into local variables so that + * // we can use them without worrying about the odometry task changing say, + * // the y value right after we've read the x. This ensures our values are + * // sound. + * odom_mutex.lock(); + * double current_x = odom_x; + * double current_y = odom_y; + * double current_heading = odom_heading; + * odom_mutex.unlock(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * \endcode. */ void unlock(); @@ -500,6 +1263,20 @@ class Mutex { * \see https://en.cppreference.com/w/cpp/named_req/Lockable * * \return True when lock was acquired succesfully, or false otherwise. + * + * pros::Mutex mutex; + * + * void my_task_fn(void* param) { + * while (true) { + * if(mutex.try_lock()) { + * printf("Mutex aquired successfully!\n"); + * // Do stuff that requires the protected resource here + * } + * else { + * printf("Mutex not aquired!\n"); + * } + * } + * } */ bool try_lock(); @@ -514,6 +1291,21 @@ class Mutex { * * \param rel_time Time to wait before the mutex becomes available. * \return True if the lock was acquired succesfully, otherwise false. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while (true) { + * if(mutex.try_lock_for(std::chrono::milliseconds(100))) { + * printf("Mutex aquired successfully!\n"); + * // Do stuff that requires the protected resource here + * } + * else { + * printf("Mutex not aquired after 100 milliseconds!\n"); + * } + * } + * } + * \endcode */ template bool try_lock_for(const std::chrono::duration& rel_time) { @@ -528,11 +1320,33 @@ class Mutex { * * \param abs_time Time point until which to wait for the mutex. * \return True if the lock was acquired succesfully, otherwise false. + * + * \b Example + * \code + * void my_task_fn(void* param) { + * while (true) { + * // Get the current time point + * auto now = std::chrono::system_clock::now(); + * + * // Calculate the time point 100 milliseconds from now + * auto abs_time = now + std::chrono::milliseconds(100); + * + * if(mutex.try_lock_until(abs_time)) { + * printf("Mutex aquired successfully!\n"); + * // Do stuff that requires the protected resource here + * } + * else { + * printf("Mutex not aquired after 100 milliseconds!\n"); + * } + * } + * } + * \endcode */ template bool try_lock_until(const std::chrono::time_point& abs_time) { return take(std::max(static_cast(0), (abs_time - Clock::now()).count())); } + ///@} }; template @@ -578,7 +1392,57 @@ class MutexVar { * constructor arguments. * * \param args - The arguments to provide to the Var constructor. + * The arguments to provide to the Var constructor. + * + * \b Example + * \code + * // We create a pose class to contain all our odometry data in a single + * // variable that can be protected by a MutexVar. Otherwise, we would have + * // three seperate variables which could not be protected in a single + * // MutexVar + * struct Pose { + * double x; + * double y; + * double heading; + * } + * + * pros::MutexVar odom_pose(0.0, 0.0, 0.0); + * + * void odom_task(void* param) { + * while(true) { + * Pose old_pose = *odom_pose.lock(); + * + * Pose new_pose{0.0, 0.0, 0.0}; + * + * // --- Calculate new pose for the robot here --- + * + * // Now that we have the new pose, we can update the global variables + * + * *odom_pose.take() = new_pose; + * + * delay(10); + * } + * } + * + * void chassis_task(void* param) { + * while(true) { + * + * Pose cur_pose = *odom_pose.take(); + * + * // ---- Move the robot using the current locations goes here ---- + * + * delay(10); + * } + * } + * + * void initialize() { + * odom_mutex = pros::Mutex(); + * + * pros::Task odom_task(odom_task, "Odometry Task"); + * pros::Task chassis_task(odom_task, "Chassis Control Task"); + * } + * + * \endcode */ template MutexVar(Args&&... args) : mutex(), var(std::forward(args)...) {} @@ -592,6 +1456,26 @@ class MutexVar { * * \return A std::optional which contains a MutexVarLock providing access to * the protected variable if locking is successful. + * + * \b Example + * \code + * pros::MutexVar odom_pose; + * + * void my_task(void* param) { + * while(true) { + * std::optional> cur_pose_opt = odom_pose.try_lock(100); + * + * if(cur_pose_opt.has_value()) { + * Pose* cur_pose = **cur_pose_opt; + * } + * else { + * printf("Could not lock the mutex var!"); + * } + * + * pros::delay(10); + * } + * } + * \endcode */ std::optional> try_lock(std::uint32_t timeout) { if (mutex.take(timeout)) { @@ -610,6 +1494,27 @@ class MutexVar { * * \return A std::optional which contains a MutexVarLock providing access to * the protected variable if locking is successful. + * + * \b Example + * \code + * pros::MutexVar odom_pose; + * + * void my_task(void* param) { + * while(true) { + * std::chrono::duration timeout(100); + * std::optional> cur_pose_opt = odom_pose.try_lock(timeout); + * + * if(cur_pose_opt.has_value()) { + * Pose* cur_pose = **cur_pose_opt; + * } + * else { + * printf("Could not lock the mutex var!"); + * } + * + * pros::delay(10); + * } + * } + * \endcode */ template std::optional> try_lock(const std::chrono::duration& rel_time) { @@ -620,6 +1525,22 @@ class MutexVar { * Lock the mutex-protected variable, waiting indefinitely. * * \return A MutexVarLock providing access to the protected variable. + * + * \b Example + * \code + * pros::MutexVar odom_pose; + * + * void my_task(void* param) { + * while(true) { + * pros::delay(10); + * + * pros::MutexVarLock cur_pose = odom_pose.lock(); + * Pose cur_pose = *cur_pose; + * + * // do stuff with cur_pose + * } + * } + * \endcode */ MutexVarLock lock() { while (!mutex.take(TIMEOUT_MAX)) @@ -653,6 +1574,7 @@ using pros::c::micros; * The number of milliseconds to wait (1000 milliseconds per second) */ using pros::c::delay; +} // namespace rtos } // namespace pros #endif // _PROS_RTOS_HPP_ diff --git a/include/pros/screen.h b/include/pros/screen.h index 5c6b538f..71c28570 100644 --- a/include/pros/screen.h +++ b/include/pros/screen.h @@ -1,5 +1,6 @@ /** * \file screen.h + * \ingroup c-screen * * Brain screen display and touch functions. * @@ -10,19 +11,22 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-screen Simplified Brain Screen C API + * */ #ifndef _PROS_SCREEN_H_ #define _PROS_SCREEN_H_ -#include -#include +#include +#include #define _GNU_SOURCE -#include +#include #undef _GNU_SOURCE #include -#include "pros/colors.h" // c color macros +#include "pros/colors.h" // c color macros #ifdef __cplusplus extern "C" { @@ -30,35 +34,56 @@ namespace pros { #endif /** - * ! Different font sizes that can be used in printing text. + * \ingroup c-screen + */ + +/** + * \addtogroup c-screen + * @{ + */ + +/** + * \enum text_format_e_t + * Different font sizes that can be used in printing text. */ typedef enum { - E_TEXT_SMALL = 0, ///< Small text font size - E_TEXT_MEDIUM, ///< Normal/Medium text font size - E_TEXT_LARGE, ///< Large text font size - E_TEXT_MEDIUM_CENTER, ///< Medium centered text - E_TEXT_LARGE_CENTER ///< Large centered text + /// Small text font size + E_TEXT_SMALL = 0, + /// Normal/Medium text font size + E_TEXT_MEDIUM, + /// Large text font size + E_TEXT_LARGE, + /// Medium centered text + E_TEXT_MEDIUM_CENTER, + /// Large centered text + E_TEXT_LARGE_CENTER } text_format_e_t; /** - * ! Enum indicating what the current touch status is for the touchscreen. + * \enum last_touch_e_t + * Enum indicating what the current touch status is for the touchscreen. */ typedef enum { - E_TOUCH_RELEASED = 0, ///< Last interaction with screen was a quick press - E_TOUCH_PRESSED, ///< Last interaction with screen was a release - E_TOUCH_HELD, ///< User is holding screen down - E_TOUCH_ERROR ///< An error occured while taking/returning the mutex + /// Last interaction with screen was a quick press + E_TOUCH_RELEASED = 0, + /// Last interaction with screen was a release + E_TOUCH_PRESSED, + /// User is holding screen down + E_TOUCH_HELD, + /// An error occured while taking/returning the mutex + E_TOUCH_ERROR } last_touch_e_t; /** - * ! Struct representing screen touch status, screen last x, screen last y, press count, release count. + * \struct screen_touch_status_s_t + * Struct representing screen touch status, screen last x, screen last y, press count, release count. */ typedef struct screen_touch_status_s { - last_touch_e_t touch_status; ///< Represents if the screen is being held, released, or pressed. - int16_t x; ///< Represents the x value of the location of the touch. - int16_t y; ///< Represents the y value of the location of the touch. - int32_t press_count; ///< Represents how many times the screen has be pressed. - int32_t release_count; ///< Represents how many times the user released after a touch on the screen. + last_touch_e_t touch_status; ///< Represents if the screen is being held, released, or pressed. + int16_t x; ///< Represents the x value of the location of the touch. + int16_t y; ///< Represents the y value of the location of the touch. + int32_t press_count; ///< Represents how many times the screen has be pressed. + int32_t release_count; ///< Represents how many times the user released after a touch on the screen. } screen_touch_status_s_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -89,24 +114,37 @@ typedef void (*touch_event_cb_fn_t)(); namespace c { #endif -/******************************************************************************/ -/** Screen Graphical Display Functions **/ -/** **/ -/** These functions allow programmers to display shapes on the v5 screen **/ -/******************************************************************************/ +/// \name Screen Graphical Display Functions +/// These functions allow programmers to display shapes on the v5 screen +///@{ /** * Set the pen color for subsequent graphics operations - * + * * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. * * \param color The pen color to set (it is recommended to use values * from the enum defined in colors.h) - * - * \return Returns 1 if the mutex was successfully returned, or PROS_ERR if + * + * \return Returns 1 if the mutex was successfully returned, or PROS_ERR if * there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_pen(COLOR_RED); + * } + * + * void opcontrol() { + * int iter = 0; + * while(1){ + * // This should print in red. + * screen_print(TEXT_MEDIUM, 1, "%d", iter++); + * } + * } + * \endcode */ uint32_t screen_set_pen(uint32_t color); @@ -116,12 +154,26 @@ uint32_t screen_set_pen(uint32_t color); * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * + * * \param color The background color to set (it is recommended to use values * from the enum defined in colors.h) - * - * \return Returns 1 if the mutex was successfully returned, or + * + * \return Returns 1 if the mutex was successfully returned, or * PROS_ERR if there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_eraser(COLOR_RED); + * } + * + * void opcontrol() { + * while(1){ + * // This should turn the screen red. + * screen_erase(); + * } + * } + * \endcode */ uint32_t screen_set_eraser(uint32_t color); @@ -131,10 +183,24 @@ uint32_t screen_set_eraser(uint32_t color); * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * - * \return The current pen color in the form of a value from the enum defined - * in colors.h, or PROS_ERR if there was an error taking or returning + * + * \return The current pen color in the form of a value from the enum defined + * in colors.h, or PROS_ERR if there was an error taking or returning * the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_pen(COLOR_RED); + * } + * + * void opcontrol() { + * while(1){ + * // Should print number equivalent to COLOR_RED defined in colors.h. + * screen_print(TEXT_MEDIUM, 1, "%d", screen_get_pen()); + * } + * } + * \endcode */ uint32_t screen_get_pen(void); @@ -145,9 +211,23 @@ uint32_t screen_get_pen(void); * reached: * EACCESS - Another resource is currently trying to access the screen mutex. * - * \return The current eraser color in the form of a value from the enum - * defined in colors.h, or PROS_ERR if there was an error taking or + * \return The current eraser color in the form of a value from the enum + * defined in colors.h, or PROS_ERR if there was an error taking or * returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_eraser(COLOR_RED); + * } + * + * void opcontrol() { + * while(1){ + * // Should print number equivalent to COLOR_RED defined in colors.h. + * screen_print(TEXT_MEDIUM, 1, "%d", screen_get_eraser()); + * } + * } + * \endcode */ uint32_t screen_get_eraser(void); @@ -157,9 +237,23 @@ uint32_t screen_get_eraser(void); * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * screen_set_eraser(COLOR_RED); + * } + * + * void opcontrol() { + * while(1){ + * // This should turn the screen red. + * screen_erase(); + * } + * } + * \endcode */ uint32_t screen_erase(void); @@ -172,9 +266,18 @@ uint32_t screen_erase(void); * * \param start_line The line from which scrolling will start * \param lines The number of lines to scroll up - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_print(TEXT_MEDIUM, 4, "Line Here"); + * // Scroll 3 lines + * screen_scroll(4, 3); + * } + * \endcode */ uint32_t screen_scroll(int16_t start_line, int16_t lines); @@ -194,14 +297,23 @@ uint32_t screen_scroll(int16_t start_line, int16_t lines); * \param x1, y1 The (x,y) coordinates of the second corner of the * rectangular region * \param lines The number of lines to scroll upwards - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_print(TEXT_MEDIUM, 1, "Line Here"); + * // Scrolls area of screen upwards slightly. including line of text + * screen_scroll_area(0,0, 400, 200, 3); + * } + * \endcode */ uint32_t screen_scroll_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t lines); /** - * Copy a screen region (designated by a rectangle) from an off-screen buffer + * Copy a screen region (designated by a rectangle) from an off-screen buffer * to the screen * * This function uses the following values of errno when an error state is @@ -215,9 +327,20 @@ uint32_t screen_scroll_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int1 * \param buf Off-screen buffer containing screen data * \param stride Off-screen buffer width in pixels, such that image size * is stride-padding - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * uint32_t* buf = malloc(sizeof(uint32_t) * 400 * 200); + * screen_print(TEXT_MEDIUM, 1, "Line Here"); + * // Copies area of the screen including text + * screen_copy_area(0, 0, 400, 200, (uint32_t*)buf, 400 + 1); + * // Equation for stride is x2 - x1 + 1 + * } + * \endcode */ uint32_t screen_copy_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t* buf, int32_t stride); @@ -229,9 +352,21 @@ uint32_t screen_copy_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32 * EACCESS - Another resource is currently trying to access the screen mutex. * * \param x, y The (x,y) coordinates of the pixel - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * int i = 0; + * void opcontrol() { + * while(i < 200){ + * screen_draw_pixel(100,i++); + * // Draws a line at x = 100 gradually down the screen, pixel by pixel + * delay(200); + * } + * } + * \endcode */ uint32_t screen_draw_pixel(int16_t x, int16_t y); @@ -243,9 +378,24 @@ uint32_t screen_draw_pixel(int16_t x, int16_t y); * EACCESS - Another resource is currently trying to access the screen mutex. * * \param x, y The (x,y) coordinates of the erased - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Color the Screen in Red + * screen_set_pen(COLOR_RED); + * screen_fill_rect(0,0,400,200); + * int i = 0; + * while(i < 200){ + * screen_erase_pixel(100,i++); + * // Erases a line at x = 100 gradually down the screen, pixel by pixel + * delay(200); + * } + * } + * \endcode */ uint32_t screen_erase_pixel(int16_t x, int16_t y); @@ -258,9 +408,18 @@ uint32_t screen_erase_pixel(int16_t x, int16_t y); * * \param x0, y0 The (x, y) coordinates of the first point of the line * \param x1, y1 The (x, y) coordinates of the second point of the line - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_set_pen(COLOR_RED); + * // Draw line down the screen at x = 100 + * screen_draw_line(100,0,100,200); + * } + * \endcode */ uint32_t screen_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -273,9 +432,20 @@ uint32_t screen_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x0, y0 The (x, y) coordinates of the first point of the line * \param x1, y1 The (x, y) coordinates of the second point of the line - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Color the Screen in Red + * screen_set_pen(COLOR_RED); + * screen_fill_rect(0,0,400,200); + * // Erase line down the screen at x = 100 + * screen_erase_line(100,0,100,200); + * } + * \endcode */ uint32_t screen_erase_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -288,9 +458,17 @@ uint32_t screen_erase_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x0, y0 The (x,y) coordinates of the first point of the rectangle * \param x1, y1 The (x,y) coordinates of the second point of the rectangle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_set_pen(COLOR_RED); + * screen_draw_rect(1,1,480,200); + * } + * \endcode */ uint32_t screen_draw_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -303,9 +481,18 @@ uint32_t screen_draw_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x0, y0 The (x,y) coordinates of the first point of the rectangle * \param x1, y1 The (x,y) coordinates of the second point of the rectangle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Draw Box Around Half the Screen in Red + * screen_set_eraser(COLOR_RED); + * screen_erase_rect(5,5,240,200); + * } + * \endcode */ uint32_t screen_erase_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -319,9 +506,18 @@ uint32_t screen_erase_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x0, y0 The (x,y) coordinates of the first point of the rectangle * \param x1, y1 The (x,y) coordinates of the second point of the rectangle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Fill Around Half the Screen in Red + * screen_set_pen(COLOR_RED); + * screen_fill_rect(5,5,240,200); + * } + * \endcode */ uint32_t screen_fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); @@ -334,9 +530,18 @@ uint32_t screen_fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1); * * \param x, y The (x,y) coordinates of the center of the circle * \param r The radius of the circle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Draw a circle with radius of 100 in red + * screen_set_pen(COLOR_RED); + * screen_draw_circle(240, 200, 100); + * } + * \endcode */ uint32_t screen_draw_circle(int16_t x, int16_t y, int16_t radius); @@ -349,9 +554,20 @@ uint32_t screen_draw_circle(int16_t x, int16_t y, int16_t radius); * * \param x, y The (x,y) coordinates of the center of the circle * \param r The radius of the circle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_set_pen(COLOR_RED); + * screen_fill_rect(5,5,240,200); + * // Erase a circle with radius of 100 in COLOR_BLUE + * screen_set_pen(COLOR_BLUE); + * screen_erase_circle(240, 200, 100); + * } + * \endcode */ uint32_t screen_erase_circle(int16_t x, int16_t y, int16_t radius); @@ -365,48 +581,86 @@ uint32_t screen_erase_circle(int16_t x, int16_t y, int16_t radius); * * \param x, y The (x,y) coordinates of the center of the circle * \param r The radius of the circle - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * screen_set_pen(COLOR_RED); + * screen_fill_rect(5,5,240,200); + * // Fill a circlular area with radius of 100 in COLOR_BLUE + * screen_set_pen(COLOR_BLUE); + * screen_fill_circle(240, 200, 100); + * } + * \endcode */ uint32_t screen_fill_circle(int16_t x, int16_t y, int16_t radius); -/******************************************************************************/ -/** Screen Text Display Functions **/ -/** **/ -/** These functions allow programmers to display text on the v5 screen **/ -/******************************************************************************/ +///@} + +/// \name Screen Text Display Functions +/// These functions allow programmers to display text on the v5 screen +///@{ /** * Print a formatted string to the screen on the specified line - * + * * Will default to a medium sized font by default if invalid txt_fmt is given. - * - * \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES NOT SUPPORT SMALL) - * \param line The line number on which to print - * \param text Format string - * \param ... Optional list of arguments for the format string - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES + * NOT SUPPORT SMALL) \param line The line number on which to print \param text Format string \param ... Optional list + * of arguments for the format string + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * + * screen_set_pen(COLOR_BLUE); + * while(1){ + * // Will print seconds started since program started on line 3 + * screen_print(TEXT_MEDIUM, 3, "Seconds Passed: %3d", i++); + * delay(1000); + * } + * } + * \endcode */ uint32_t screen_print(text_format_e_t txt_fmt, const int16_t line, const char* text, ...); /** * Print a formatted string to the screen at the specified point - * + * * Will default to a medium sized font by default if invalid txt_fmt is given. - * + * * Text formats medium_center and large_center will default to medium and large respectively. - * + * * \param txt_fmt Text format enum that determines if the text is small, medium, or large. * \param x The y coordinate of the top left corner of the string * \param y The x coordinate of the top left corner of the string * \param text Format string * \param ... Optional list of arguments for the format string - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * + * screen_set_pen(COLOR_BLUE); + * while(1){ + * // Will print seconds started since program started. + * screen_print_at(TEXT_SMALL, 3, "Seconds Passed: %3d", i++); + * delay(1000); + * } + * } + * \endcode */ uint32_t screen_print_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, ...); @@ -415,21 +669,22 @@ uint32_t screen_print_at(text_format_e_t txt_fmt, const int16_t x, const int16_t * * Same as `display_printf` except that this uses a `va_list` instead of the * ellipsis operator so this can be used by other functions. - * + * * Will default to a medium sized font by default if invalid txt_fmt is given. * Exposed mostly for writing libraries and custom functions. * * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * - * \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES NOT SUPPORT SMALL) - * \param line The line number on which to print - * \param text Format string - * \param args List of arguments for the format string - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES + * NOT SUPPORT SMALL) \param line The line number on which to print \param text Format string \param args List of + * arguments for the format string + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * while taking or returning the screen mutex. + * + * */ uint32_t screen_vprintf(text_format_e_t txt_fmt, const int16_t line, const char* text, va_list args); @@ -438,40 +693,59 @@ uint32_t screen_vprintf(text_format_e_t txt_fmt, const int16_t line, const char* * * Same as `display_printf_at` except that this uses a `va_list` instead of the * ellipsis operator so this can be used by other functions. - * + * * Will default to a medium sized font by default if invalid txt_fmt is given. - * + * * Text formats medium_center and large_center will default to medium and large respectively. * Exposed mostly for writing libraries and custom functions. * * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * + * * \param txt_fmt Text format enum that determines if the text is small, medium, or large. * \param x, y The (x,y) coordinates of the top left corner of the string * \param text Format string * \param args List of arguments for the format string - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * while taking or returning the screen mutex. + * */ uint32_t screen_vprintf_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, va_list args); -/******************************************************************************/ -/** Screen Touch Functions **/ -/** **/ -/** These functions allow programmers to access **/ -/** information about screen touches **/ -/******************************************************************************/ +///@} + +/// \name Screen Touch Functions +/// These functions allow programmers to access information about screen touches +///@{ /** * Gets the touch status of the last touch of the screen. - * - * \return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE, E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD). - * This will be released by default if no action was taken. - * If an error occured, the screen_touch_status_s_t will have its last_touch_e_t - * enum specifier set to E_TOUCH_ERR, and other values set to -1. + * + * \return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE, + * E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD). This will be released by default if no action was taken. If an + * error occured, the screen_touch_status_s_t will have its last_touch_e_t enum specifier set to E_TOUCH_ERR, and other + * values set to -1. + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * screen_touch_status_s_t status; + * while(1){ + * status = screen_touch_status(); + * + * // Will print various information about the last touch + * screen_print(TEXT_MEDIUM, 1, "Touch Status (Type): %d", status.touch_status); + * screen_print(TEXT_MEDIUM, 2, "Last X: %d", status.x); + * screen_print(TEXT_MEDIUM, 3, "Last Y: %d", status.y); + * screen_print(TEXT_MEDIUM, 4, "Press Count: %d", status.press_count); + * screen_print(TEXT_MEDIUM, 5, "Release Count: %d", status.release_count); + * delay(20); + * } + * } + * \endcode */ screen_touch_status_s_t screen_touch_status(void); @@ -481,19 +755,37 @@ screen_touch_status_s_t screen_touch_status(void); * This function uses the following values of errno when an error state is * reached: * EACCESS - Another resource is currently trying to access the screen mutex. - * + * * \param cb Function pointer to callback when event type happens * \param event_type Touch event that will trigger the callback. - * - * \return 1 if there were no errors, or PROS_ERR if an error occured + * + * \return 1 if there were no errors, or PROS_ERR if an error occured * while taking or returning the screen mutex. + * + * \b Example + * \code + * touch_event_cb_fn_t changePixel(){ + * screen_touch_status_s_t status = screen_touch_status(); + * screen_draw_pixel(status.x,status.y); + * return NULL; + * } + * + * void opcontrol() { + * screen_touch_callback(changePixel(), TOUCH_PRESSED); + * while(1) delay(20); + * } + * \endcode */ uint32_t screen_touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type); +///@} + +///@} + #ifdef __cplusplus -} //namespace c -} //namespace pros +} // namespace c +} // namespace pros } -#endif +#endif -#endif +#endif diff --git a/include/pros/screen.hpp b/include/pros/screen.hpp index d7f6c08e..c3980e1f 100644 --- a/include/pros/screen.hpp +++ b/include/pros/screen.hpp @@ -1,5 +1,6 @@ /** * \file screen.hpp + * \ingroup cpp-screen * * Brain screen display and touch functions. * @@ -10,12 +11,15 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-screen Simplified Brain Screen C++ API */ #ifndef _PROS_SCREEN_HPP_ #define _PROS_SCREEN_HPP_ #include "pros/screen.h" +#include "pros/colors.hpp" #include #include @@ -37,6 +41,15 @@ const char* convert_args(const std::string& arg) { #pragma GCC diagnostic pop +/** + * \ingroup cpp-screen + */ + +/** + * \addtogroup cpp-screen + * @{ + */ + /******************************************************************************/ /** Screen Graphical Display Functions **/ /** **/ @@ -51,12 +64,59 @@ const char* convert_args(const std::string& arg) { * EACCESS - Another resource is currently trying to access the screen mutex. * * \param color The pen color to set (it is recommended to use values - * from the enum defined in colors.h) + * from the enum defined in colors.hpp) + * + * \return Returns 1 if the mutex was successfully returned, or PROS_ERR if + * there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * pros::screen::set_pen(red); + * } + * + * void opcontrol() { + * int iter = 0; + * while(1){ + * // This should print in red. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++); + * } + * } + * + * \endcode + */ + std::uint32_t set_pen(pros::Color color); + + /** + * Set the pen color for subsequent graphics operations + * + * This function uses the following values of errno when an error state is + * reached: + * EACCESS - Another resource is currently trying to access the screen mutex. + * + * \param color The pen color to set (in hex form) * * \return Returns 1 if the mutex was successfully returned, or PROS_ERR if * there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * //set pen color to red + * pros::screen::set_pen(0x00FF0000); + * } + * + * void opcontrol() { + * int iter = 0; + * while(1){ + * // This should print in red. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++); + * } + * } + * + * \endcode */ - std::uint32_t set_pen(const std::uint32_t color); + std::uint32_t set_pen(std::uint32_t color); /** * Set the eraser color for erasing and the current background. @@ -66,12 +126,58 @@ const char* convert_args(const std::string& arg) { * EACCESS - Another resource is currently trying to access the screen mutex. * * \param color The background color to set (it is recommended to use values - * from the enum defined in colors.h) + * from the enum defined in colors.hpp) * * \return Returns 1 if the mutex was successfully returned, or PROS_ERR * if there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * //set eraser color to red + * set_eraser(red); + * } + * + * void opcontrol() { + * int iter = 0; + * while(1){ + * // This should print in red. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++); + * } + * } + * + * \endcode */ - std::uint32_t set_eraser(const std::uint32_t color); + std::uint32_t set_eraser(pros::Color color); + + /** + * Set the eraser color for erasing and the current background. + * + * This function uses the following values of errno when an error state is + * reached: + * EACCESS - Another resource is currently trying to access the screen mutex. + * + * \param color The background color to set to set (in hex form) + * + * \return Returns 1 if the mutex was successfully returned, or PROS_ERR + * if there was an error either taking or returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * //set eraser color to red + * pros::screen::set_eraser(0x00FF0000); + * } + * + * void opcontrol() { + * while(1){ + * // This should turn the screen red. + * pros::screen::erase(); + * } + * } + * \endcode + */ + std::uint32_t set_eraser(std::uint32_t color); /** * Get the current pen color. @@ -83,6 +189,20 @@ const char* convert_args(const std::string& arg) { * \return The current pen color in the form of a value from the enum * defined in colors.h, or PROS_ERR if there was an error taking or * returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * pros::screen::set_pen(red); + * } + * + * void opcontrol() { + * while(1){ + * // Should print number equivalent to red defined in colors.hpp. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", get_pen()); + * } + * } + * \endcode */ std::uint32_t get_pen(); @@ -96,6 +216,20 @@ const char* convert_args(const std::string& arg) { * \return The current eraser color in the form of a value from the enum * defined in colors.h, or PROS_ERR if there was an error taking or * returning the screen mutex. + * + * \b Example + * \code + * void initialize() { + * pros::screen::set_eraser(red); + * } + * + * void opcontrol() { + * while(1){ + * // Should print number equivalent to red defined in colors.h. + * pros::screen::print(TEXT_MEDIUM, 1, "%d", get_eraser()); + * } + * } + * \endcode */ std::uint32_t get_eraser(); @@ -108,6 +242,20 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * * \b Example + * \code + * void initialize() { + * pros::screen::set_eraser(red); + * } + * + * void opcontrol() { + * while(1){ + * // This should turn the screen red. + * pros::screen::erase(); + * } + * } + * \endcode */ std::uint32_t erase(); @@ -123,6 +271,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::print(TEXT_MEDIUM, 4, "Line Here"); + * // Scroll 3 lines + * pros::screen::scroll(4, 3); + * } + * \endcode */ std::uint32_t scroll(const std::int16_t start_line, const std::int16_t lines); @@ -145,6 +302,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::print(TEXT_MEDIUM, 1, "Line Here"); + * // Scrolls area of screen upwards slightly. including line of text + * pros::screen::scroll_area(0,0, 400, 200, 3); + * } + * \endcode */ std::uint32_t scroll_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, std::int16_t lines); @@ -166,6 +332,17 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured taking * or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * uint32_t* buf = malloc(sizeof(uint32_t) * 400 * 200); + * pros::screen::print(TEXT_MEDIUM, 1, "Line Here"); + * // Copies area of the screen including text + * pros::screen::copy_area(0, 0, 400, 200, (uint32_t*)buf, 400 + 1); + * // Equation for stride is x2 - x1 + 1 + * } + * \endcode */ std::uint32_t copy_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, uint32_t* buf, const std::int32_t stride); @@ -180,6 +357,18 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * int i = 0; + * void opcontrol() { + * while(i < 200){ + * pros::screen::draw_pixel(100,i++); + * // Draws a line at x = 100 gradually down the screen, pixel by pixel + * pros::delay(200); + * } + * } + * \endcode */ std::uint32_t draw_pixel(const std::int16_t x, const std::int16_t y); @@ -194,6 +383,21 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Color the Screen in Red + * pros::screen::set_pen(red); + * pros::screen::fill_rect(0,0,400,200); + * int i = 0; + * while(i < 200){ + * pros::screen::erase_pixel(100,i++); + * // Erases a line at x = 100 gradually down the screen, pixel by pixel + * pros::delay(200); + * } + * } + * \endcode */ std::uint32_t erase_pixel(const std::int16_t x, const std::int16_t y); @@ -209,6 +413,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::set_pen(red); + * // Draw line down the screen at x = 100 + * pros::screen::draw_line(100,0,100,200); + * } + * \endcode */ std::uint32_t draw_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -224,6 +437,17 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Color the Screen in Red + * pros::screen::set_pen(red); + * pros::screen::fill_rect(0,0,400,200); + * // Erase line down the screen at x = 100 + * pros::screen::erase_line(100,0,100,200); + * } + * \endcode */ std::uint32_t erase_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -239,6 +463,14 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::set_pen(red); + * pros::screen::draw_rect(1,1,480,200); + * } + * \endcode */ std::uint32_t draw_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -254,6 +486,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Draw Box Around Half the Screen in Red + * pros::screen::set_eraser(red); + * pros::screen::erase_rect(5,5,240,200); + * } + * \endcode */ std::uint32_t erase_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -270,6 +511,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Fill Around Half the Screen in Red + * pros::screen::set_pen(red); + * pros::screen::fill_rect(5,5,240,200); + * } + * \endcode */ std::uint32_t fill_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1); @@ -285,6 +535,15 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * // Draw a circle with radius of 100 in red + * pros::screen::set_pen(red); + * pros::screen::draw_circle(240, 200, 100); + * } + * \endcode */ std::uint32_t draw_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius); @@ -300,6 +559,17 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::set_pen(red); + * pros::screen::fill_rect(5,5,240,200); + * // Erase a circle with radius of 100 in blue + * pros::screen::set_pen(blue); + * pros::screen::erase_circle(240, 200, 100); + * } + * \endcode */ std::uint32_t erase_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius); @@ -316,6 +586,17 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * taking or returning the screen mutex. + * + * \b Example + * \code + * void opcontrol() { + * pros::screen::set_pen(red); + * pros::screen::fill_rect(5,5,240,200); + * // Fill a circlular area with radius of 100 in blue + * pros::screen::set_pen(blue); + * pros::screen::fill_circle(240, 200, 100); + * } + * \endcode */ std::uint32_t fill_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius); @@ -336,6 +617,18 @@ const char* convert_args(const std::string& arg) { * \param y The (x,y) coordinates of the top left corner of the string * \param fmt Format string * \param ... Optional list of arguments for the format string + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * pros::screen::set_pen(blue); + * while(1){ + * // Will print seconds started since program started on line 3 + * pros::screen::print(pros::TEXT_MEDIUM, 3, "Seconds Passed: %3d", i++); + * pros::delay(1000); + * } + * } */ template void print(pros::text_format_e_t txt_fmt, const std::int16_t line, const char* text, Params... args){ @@ -361,6 +654,25 @@ const char* convert_args(const std::string& arg) { * This will be released by default if no action was taken. * If an error occured, the screen_touch_status_s_t will have its * last_touch_e_t enum specifier set to E_TOUCH_ERR, and other values set to -1. + * + * \b Example + * \code + * void opcontrol() { + * int i = 0; + * pros::screen_touch_status_s_t status; + * while(1){ + * status = pros::touch_status(); + * + * // Will print various information about the last touch + * pros::screen::print(TEXT_MEDIUM, 1, "Touch Status (Type): %d", status.touch_status); + * pros::screen::print(TEXT_MEDIUM, 2, "Last X: %d", status.x); + * pros::screen::print(TEXT_MEDIUM, 3, "Last Y: %d", status.y); + * pros::screen::print(TEXT_MEDIUM, 4, "Press Count: %d", status.press_count); + * pros::screen::print(TEXT_MEDIUM, 5, "Release Count: %d", status.release_count); + * pros::delay(20); + * } + * } + * \endcode */ screen_touch_status_s_t touch_status(); @@ -376,10 +688,30 @@ const char* convert_args(const std::string& arg) { * * \return 1 if there were no errors, or PROS_ERR if an error occured * while taking or returning the screen mutex. + * + * \b Example + * \code + * touch_event_cb_fn_t changePixel(){ + * pros::screen_touch_status_s_t status = pros::screen::touch_status(); + * pros::screen::draw_pixel(status.x,status.y); + * return NULL; + * } + * + * void opcontrol() { + * pros::screen::touch_callback(changePixel(), TOUCH_PRESSED); + * while(1) { + * pros::delay(20); + * } + * } + * \endcode */ std::uint32_t touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type); -} //namespace screen -} //namespace pros +} // namespace screen + + +} // namespace pros +extern __attribute__((weak)) void lvgl_init() {} +///@} #endif //header guard diff --git a/include/pros/serial.h b/include/pros/serial.h index 357aa107..dc9ead56 100644 --- a/include/pros/serial.h +++ b/include/pros/serial.h @@ -1,19 +1,19 @@ /** * \file pros/serial.h + * \ingroup c-serial * * Contains prototypes for the V5 Generic Serial related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/serial.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-serial Generic Serial C API */ #ifndef _PROS_SERIAL_H_ @@ -28,11 +28,18 @@ namespace pros { namespace c { #endif -/******************************************************************************/ -/** Serial communication functions **/ -/** **/ -/** These functions allow programmers to communicate using UART over RS485 **/ -/******************************************************************************/ +/** + * \ingroup c-serial + */ + +/** + * \addtogroup c-serial + * @{ + */ + +/// \name Serial communication functions +/// These functions allow programmers to communicate using UART over RS485 +///@{ /** * Enables generic serial on the given port. @@ -50,6 +57,14 @@ namespace c { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * } + * \endcode */ int32_t serial_enable(uint8_t port); @@ -68,6 +83,18 @@ int32_t serial_enable(uint8_t port); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * serial_write(1, "Hello World!", 12); + * delay(100); + * } + * } + * \endcode */ int32_t serial_set_baudrate(uint8_t port, int32_t baudrate); @@ -93,6 +120,19 @@ int32_t serial_set_baudrate(uint8_t port, int32_t baudrate); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * serial_flush(1); + * serial_write(1, "Hello World!", 12); + * delay(100); + * } + * } + * \endcode */ int32_t serial_flush(uint8_t port); @@ -113,6 +153,23 @@ int32_t serial_flush(uint8_t port); * * \return The number of bytes avaliable to be read or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_read_avail(1) >= 12) { + * char buffer[12]; + * serial_read(1, buffer, 12); + * printf("%s", buffer); + * } + * delay(100); + * } + * } + * \endcode + */ int32_t serial_get_read_avail(uint8_t port); @@ -132,6 +189,20 @@ int32_t serial_get_read_avail(uint8_t port); * * \return The number of bytes free or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_write_free(1) >= 12) { + * serial_write(1, "Hello World!", 12); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_get_write_free(uint8_t port); @@ -148,6 +219,22 @@ int32_t serial_get_write_free(uint8_t port); * * \return The next byte avaliable to be read, -1 if none are available, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_peek_byte(1) == 'H') { + * char buffer[12]; + * serial_read(1, buffer, 12); + * printf("%s", buffer); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_peek_byte(uint8_t port); @@ -164,6 +251,22 @@ int32_t serial_peek_byte(uint8_t port); * * \return The next byte avaliable to be read, -1 if none are available, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_read_byte(1) == 'H') { + * char buffer[12]; + * serial_read(1, buffer, 12); + * printf("%s", buffer); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_read_byte(uint8_t port); @@ -188,6 +291,22 @@ int32_t serial_read_byte(uint8_t port); * * \return The number of bytes read or PROS_ERR if the operation failed, setting * errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_read_avail(1) >= 12) { + * char buffer[12]; + * serial_read(1, buffer, 12); + * printf("%s", buffer); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_read(uint8_t port, uint8_t* buffer, int32_t length); @@ -210,6 +329,32 @@ int32_t serial_read(uint8_t port, uint8_t* buffer, int32_t length); * * \return The number of bytes written or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_write_free(1) >= 12) { + * serial_write_byte(1, 'H'); + * serial_write_byte(1, 'e'); + * serial_write_byte(1, 'l'); + * serial_write_byte(1, 'l'); + * serial_write_byte(1, 'o'); + * serial_write_byte(1, ' '); + * serial_write_byte(1, 'W'); + * serial_write_byte(1, 'o'); + * serial_write_byte(1, 'r'); + * serial_write_byte(1, 'l'); + * serial_write_byte(1, 'd'); + * serial_write_byte(1, '!'); + * serial_write_byte(1, '\n'); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_write_byte(uint8_t port, uint8_t buffer); @@ -235,9 +380,27 @@ int32_t serial_write_byte(uint8_t port, uint8_t buffer); * * \return The number of bytes written or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code{.c} + * void opcontrol() { + * serial_enable(1); + * serial_set_baudrate(1, 9600); + * while (true) { + * if (serial_get_write_free(1) >= 12) { + * serial_write(1, "Hello World!\n", 12); + * } + * delay(100); + * } + * } + * \endcode */ int32_t serial_write(uint8_t port, uint8_t* buffer, int32_t length); +///@} + +///@} + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/include/pros/serial.hpp b/include/pros/serial.hpp index 60e82c1c..3880f61b 100644 --- a/include/pros/serial.hpp +++ b/include/pros/serial.hpp @@ -1,29 +1,39 @@ /** * \file pros/serial.hpp + * \ingroup cpp-serial * * Contains prototypes for the V5 Generic Serial related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/serial.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright (c) 2017-2021, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-serial Generic Serial C++ API */ #ifndef _PROS_SERIAL_HPP_ #define _PROS_SERIAL_HPP_ #include + +#include "pros/device.hpp" #include "pros/serial.h" namespace pros { -class Serial { +/** + * \ingroup cpp-serial + * @{ + */ +class Serial : public Device { + /** + * \addtogroup cpp-serial + * @{ + */ public: /** * Creates a Serial object for the given port and specifications. @@ -37,9 +47,30 @@ class Serial { * The V5 port number from 1-21 * \param baudrate * The baudrate to run the port at + * + * \b Example: + * \code + * pros::Serial serial(1, 9600); + * \endcode */ explicit Serial(std::uint8_t port, std::int32_t baudrate); + /** + * Creates a Serial object for the given port without a set baudrate. + * + * This function uses the following values of errno when an error state is + * reached: + * EINVAL - The given value is not within the range of V5 ports (1-21). + * EACCES - Another resource is currently trying to access the port. + * + * \param port + * The V5 port number from 1-21 + * + * \b Example: + * \code + * pros::Serial serial(1); + * \endcode + */ explicit Serial(std::uint8_t port); /******************************************************************************/ @@ -61,6 +92,12 @@ class Serial { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code + * pros::Serial serial(1); + * serial.set_baudrate(9600); + * \endcode */ virtual std::int32_t set_baudrate(std::int32_t baudrate) const; @@ -83,6 +120,12 @@ class Serial { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code + * pros::Serial serial(1); + * serial.flush(); + * \endcode */ virtual std::int32_t flush() const; @@ -100,6 +143,16 @@ class Serial { * * \return The number of bytes avaliable to be read or PROS_ERR if the operation * failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * if(serial.get_read_avail() > 0) { + * std::uint8_t byte = serial.read_byte(); + * } + * } + * \endcode */ virtual std::int32_t get_read_avail() const; @@ -116,15 +169,19 @@ class Serial { * * \return The number of bytes free or PROS_ERR if the operation failed, * setting errno. - */ - virtual std::int32_t get_write_free() const; - - /** - * Gets the port number of the serial port. * - * \return The serial port's port number. + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * if(serial.get_write_free() > 0) { + * serial.write_byte(0x01); + * pros::delay(10); + * } + * } + * \endcode */ - std::uint8_t get_port() const; + virtual std::int32_t get_write_free() const; /** * Reads the next byte avaliable in the port's input buffer without removing it. @@ -136,6 +193,16 @@ class Serial { * * \return The next byte avaliable to be read, -1 if none are available, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * if(serial.peek_byte() == 0x01) { + * serial.read_byte(); + * } + * } + * \endcode */ virtual std::int32_t peek_byte() const; @@ -149,6 +216,16 @@ class Serial { * * \return The next byte avaliable to be read, -1 if none are available, or * PROS_ERR if the operation failed, setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * if(serial.read_byte() == 0x01) { + * // Do something + * } + * } + * \endcode */ virtual std::int32_t read_byte() const; @@ -171,6 +248,15 @@ class Serial { * * \return The number of bytes read or PROS_ERR if the operation failed, setting * errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * std::uint8_t buffer[10]; + * serial.read(buffer, 10); + * } + * \endcode */ virtual std::int32_t read(std::uint8_t* buffer, std::int32_t length) const; @@ -191,6 +277,14 @@ class Serial { * * \return The number of bytes written or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * serial.write_byte(0x01); + * } + * \endcode */ virtual std::int32_t write_byte(std::uint8_t buffer) const; @@ -214,14 +308,36 @@ class Serial { * * \return The number of bytes written or PROS_ERR if the operation failed, * setting errno. + * + * \b Example: + * \code + * void opcontrol() { + * pros::Serial serial(1); + * std::uint8_t buffer[10]; + * serial.write(buffer, 10); + * } + * \endcode */ virtual std::int32_t write(std::uint8_t* buffer, std::int32_t length) const; private: - const std::uint8_t _port; + ///@} }; namespace literals { +/** + * Constructs a Serial device from a litteral ending in _ser + * + * \return a pros::Serial for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Serial serial = 2_ser; //Makes an Serial device object on port 2 + * } + * \endcode + */ const pros::Serial operator"" _ser(const unsigned long long int m); } // namespace literals } // namespace pros diff --git a/include/pros/vision.h b/include/pros/vision.h index 33918c78..dbda3fc7 100644 --- a/include/pros/vision.h +++ b/include/pros/vision.h @@ -1,39 +1,63 @@ /** * \file pros/vision.h + * \ingroup c-vision * * Contains prototypes for the VEX Vision Sensor-related functions. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup c-vision Vision Sensor C API + * \note Additional example code for this module can be found in its [Tutorial.](@ref vision) */ #ifndef _PROS_VISION_H_ #define _PROS_VISION_H_ +/** + * \ingroup c-vision + */ + +/** + * \addtogroup c-vision + * @{ + */ + +/// \name Macros +///Parameters given by VEX +///@{ + #define VISION_OBJECT_ERR_SIG 255 -// Parameters given by VEX + +/** + * The width of the Vision Sensor’s field of view. + */ #define VISION_FOV_WIDTH 316 + +/** + * The height of the Vision Sensor’s field of view. + */ #define VISION_FOV_HEIGHT 212 +///@} + #include #ifdef __cplusplus extern "C" { namespace pros { #endif + /** - * This enumeration defines the different types of objects - * that can be detected by the Vision Sensor + * \enum vision_object_type_e_t + * This enumeration defines the different types of objects that can be detected by the Vision Sensor */ typedef enum vision_object_type { E_VISION_OBJECT_NORMAL = 0, @@ -42,8 +66,8 @@ typedef enum vision_object_type { } vision_object_type_e_t; /** - * This structure contains the parameters used by the Vision Sensor - * to detect objects. + * \struct vision_signature_s_t + * This structure contains the parameters used by the Vision Sensor to detect objects. */ typedef struct __attribute__((__packed__)) vision_signature { uint8_t id; @@ -60,39 +84,45 @@ typedef struct __attribute__((__packed__)) vision_signature { } vision_signature_s_t; /** + * \typedef vision_color_code_t * Color codes are just signatures with multiple IDs and a different type. */ typedef uint16_t vision_color_code_t; /** - * This structure contains a descriptor of an object detected - * by the Vision Sensor + * \struct vision_object_s_t + * This structure contains a descriptor of an object detected by the Vision Sensor */ typedef struct __attribute__((__packed__)) vision_object { - // Object signature + /// Object signature uint16_t signature; - // Object type, e.g. normal, color code, or line detection + /// Object type, e.g. normal, color code, or line detection vision_object_type_e_t type; - // left boundary coordinate of the object + /// Left boundary coordinate of the object int16_t left_coord; - // top boundary coordinate of the object + /// Top boundary coordinate of the object int16_t top_coord; - // width of the object + /// Width of the object int16_t width; - // height of the object + /// Height of the object int16_t height; - // Angle of a color code object in 0.1 degree units (e.g. 10 -> 1 degree, 155 - // -> 15.5 degrees) + /// Angle of a color code object in 0.1 degree units (e.g. 10 -> 1 degree, 155 -> 15.5 degrees) uint16_t angle; - - // coordinates of the middle of the object (computed from the values above) + /// Coordinates of the middle of the object (computed from the values above) int16_t x_middle_coord; + /// Coordinates of the middle of the object (computed from the values above) int16_t y_middle_coord; } vision_object_s_t; +/** + * \enum vision_zero + * This enumeration defines different zero points for returned vision objects. + */ typedef enum vision_zero { - E_VISION_ZERO_TOPLEFT = 0, // (0,0) coordinate is the top left of the FOV - E_VISION_ZERO_CENTER = 1 // (0,0) coordinate is the center of the FOV + /// (0,0) coordinate is the top left of the FOV + E_VISION_ZERO_TOPLEFT = 0, + /// (0,0) coordinate is the center of the FOV + E_VISION_ZERO_CENTER = 1 } vision_zero_e_t; #ifdef PROS_USE_SIMPLE_NAMES @@ -115,6 +145,9 @@ typedef enum vision_zero { namespace c { #endif +/// \name Functions +///@{ + /** * Clears the vision sensor LED color, reseting it back to its default behavior, * displaying the most prominent object signature color. @@ -129,6 +162,14 @@ namespace c { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * void initialize() { + * vision_clear_led(VISION_PORT); + * } + * \endcode */ int32_t vision_clear_led(uint8_t port); @@ -155,6 +196,26 @@ int32_t vision_clear_led(uint8_t port); * Signature type * * \return A vision_signature_s_t that can be set using vision_set_signature + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * // values acquired from the vision utility + * vision_signature_s_t RED_SIG = + * vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0); + * vision_set_signature(VISION_PORT, EXAMPLE_SIG, &RED_SIG); + * while (true) { + * vision_signature_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG); + * // Gets the largest object of the EXAMPLE_SIG signature + * printf("sig: %d", rtn.signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ vision_signature_s_t vision_signature_from_utility(const int32_t id, const int32_t u_min, const int32_t u_max, const int32_t u_mean, const int32_t v_min, const int32_t v_max, @@ -184,6 +245,17 @@ vision_signature_s_t vision_signature_from_utility(const int32_t id, const int32 * The fifth signature id [1-7] to add to the color code * * \return A vision_color_code_t object containing the color code information. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * + * void opcontrol() { + * vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG); + * } + * \endcode */ vision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id1, const uint32_t sig_id2, const uint32_t sig_id3, const uint32_t sig_id4, const uint32_t sig_id5); @@ -206,6 +278,20 @@ vision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id * * \return The vision_object_s_t object corresponding to the given size id, or * PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void opcontrol() { + * while (true) { + * vision_object_s_t rtn = vision_get_by_size(VISION_PORT, 0); + * // Gets the largest object + * printf("sig: %d", rtn.signature); + * delay(2); + * } + * } + * \endcode */ vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id); @@ -230,6 +316,22 @@ vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id); * * \return The vision_object_s_t object corresponding to the given signature and * size_id, or PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * while (true) { + * vision_object_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG); + * // Gets the largest object of the EXAMPLE_SIG signature + * printf("sig: %d", rtn.signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ vision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id); @@ -252,13 +354,28 @@ vision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const * * \return The vision_object_s_t object corresponding to the given color code * and size_id, or PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * + * void opcontrol() { + * vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG); + * while (true) { + * vision_object_s_t rtn = vision_get_by_code(VISION_PORT, 0, code1); + * // Gets the largest object + * printf("sig: %d", rtn.signature); + * delay(2); + * } + * } + * \endcode */ vision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code); /** - * Gets the exposure parameter of the Vision Sensor. See - * https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html#exposure-setting - * for more detials. + * Gets the exposure parameter of the Vision Sensor. * * This function uses the following values of errno when an error state is * reached: @@ -270,6 +387,16 @@ vision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const * * \return The current exposure setting from [0,150], PROS_ERR if an error * occurred + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * if (vision_get_exposure(VISION_PORT) < 50) + * vision_set_exposure(VISION_PORT, 50); + * } + * \endcode */ int32_t vision_get_exposure(uint8_t port); @@ -286,6 +413,18 @@ int32_t vision_get_exposure(uint8_t port); * * \return The number of objects detected on the specified vision sensor. * Returns PROS_ERR if the port was invalid or an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void opcontrol() { + * while (true) { + * printf("Number of Objects Detected: %d\n", vision_get_object_count(VISION_PORT)); + * delay(2); + * } + * } + * \endcode */ int32_t vision_get_object_count(uint8_t port); @@ -301,6 +440,17 @@ int32_t vision_get_object_count(uint8_t port); * The V5 port number from 1-21 * * \return The current RGB white balance setting of the sensor + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define VISION_WHITE 0xff + * + * void initialize() { + * if (vision_get_white_balance(VISION_PORT) != VISION_WHITE) + * vision_set_white_balance(VISION_PORT, VISION_WHITE); + * } + * \endcode */ int32_t vision_get_white_balance(uint8_t port); @@ -311,6 +461,17 @@ int32_t vision_get_white_balance(uint8_t port); * The signature for which the contents will be printed * * \return 1 if no errors occured, PROS_ERR otherwise + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG); + * vision_print_signature(sig); + * } + * \endcode */ int32_t vision_print_signature(const vision_signature_s_t sig); @@ -339,6 +500,22 @@ int32_t vision_print_signature(const vision_signature_s_t sig); * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * while (true) { + * vision_read_by_size(VISION_PORT, 0, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints the signature of the largest object found + * delay(2); + * } + * } + * \endcode */ int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t object_count, vision_object_s_t* const object_arr); @@ -370,6 +547,23 @@ int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * while (true) { + * vision_read_by_sig(VISION_PORT, 0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ int32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id, const uint32_t object_count, vision_object_s_t* const object_arr); @@ -400,6 +594,25 @@ int32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG, 0, 0, 0); + * while (true) { + * vision_read_by_code(VISION_PORT, 0, code1, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints the signature of the largest object found + * delay(2); + * } + * } + * \endcode */ int32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code, const uint32_t object_count, vision_object_s_t* const object_arr); @@ -413,13 +626,24 @@ int32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_c * The signature id to read * * \return A vision_signature_s_t containing information about the signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG); + * vision_print_signature(sig); + * } + * \endcode */ vision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_id); /** * Stores the supplied object detection signature onto the vision sensor. * - * NOTE: This saves the signature in volatile memory, and the signature will be + * \note This saves the signature in volatile memory, and the signature will be * lost as soon as the sensor is powered down. * * \param port @@ -430,6 +654,18 @@ vision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_ * A pointer to the signature to save * * \return 1 if no errors occured, PROS_ERR otherwise + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG); + * sig.range = 10.0; + * vision_set_signature(VISION_PORT, EXAMPLE_SIG, &sig); + * } + * \endcode */ int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_signature_s_t* const signature_ptr); @@ -449,13 +685,20 @@ int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_si * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * vision_set_auto_white_balance(VISION_PORT, true); + * } + * \endcode */ int32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable); /** - * Sets the exposure parameter of the Vision Sensor. See - * https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html#exposure-setting - * for more detials. + * Sets the exposure parameter of the Vision Sensor. * * This function uses the following values of errno when an error state is * reached: @@ -469,6 +712,16 @@ int32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * if (vision_get_exposure(VISION_PORT) < 50) + * vision_set_exposure(VISION_PORT, 50); + * } + * \endcode */ int32_t vision_set_exposure(uint8_t port, const uint8_t exposure); @@ -487,6 +740,15 @@ int32_t vision_set_exposure(uint8_t port, const uint8_t exposure); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * vision_set_led(VISION_PORT, COLOR_BLANCHED_ALMOND); + * } + * \endcode */ int32_t vision_set_led(uint8_t port, const int32_t rgb); @@ -505,6 +767,16 @@ int32_t vision_set_led(uint8_t port, const int32_t rgb); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define VISION_WHITE 0xff + * + * void initialize() { + * vision_set_white_balance(VISION_PORT, VISION_WHITE); + * } + * \endcode */ int32_t vision_set_white_balance(uint8_t port, const int32_t rgb); @@ -527,6 +799,15 @@ int32_t vision_set_white_balance(uint8_t port, const int32_t rgb); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * vision_set_zero_point(VISION_PORT, E_VISION_ZERO_CENTER); + * } + * \endcode */ int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point); @@ -545,9 +826,22 @@ int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point); * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * vision_set_wifi_mode(VISION_PORT, 0); + * } + * \endcode */ int32_t vision_set_wifi_mode(uint8_t port, const uint8_t enable); +///@} + +///@} + #ifdef __cplusplus } // namespace c } // namespace pros diff --git a/include/pros/vision.hpp b/include/pros/vision.hpp index e40af9b8..ab4a61d6 100644 --- a/include/pros/vision.hpp +++ b/include/pros/vision.hpp @@ -1,31 +1,41 @@ /** * \file pros/vision.hpp + * \ingroup cpp-vision * * Contains prototypes for the VEX Vision Sensor-related functions in C++. * - * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html to learn - * more. - * * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots. + * \copyright (c) 2017-2023, Purdue University ACM SIGBots. * All rights reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * \defgroup cpp-vision Vision Sensor C++ API + * \note Additional example code for this module can be found in its [Tutorial.](@ref vision) */ #ifndef _PROS_VISION_HPP_ #define _PROS_VISION_HPP_ -#include "pros/vision.h" - #include +#include "pros/device.hpp" +#include "pros/vision.h" + namespace pros { -class Vision { +inline namespace v5 { +/** + * \ingroup cpp-vision + */ +class Vision : public Device { + /** + * \addtogroup cpp-vision + * @{ + */ public: /** * Create a Vision Sensor object on the given port. @@ -39,9 +49,18 @@ class Vision { * The V5 port number from 1-21 * \param zero_point * One of vision_zero_e_t to set the (0,0) coordinate for the FOV + * + * \b Example + * \code + * void opcontrol() { + * pros::Vision vision_sensor(1); // Creates a vision sensor on port one, with the zero point set to top left + * } + * \endcode */ Vision(std::uint8_t port, vision_zero_e_t zero_point = E_VISION_ZERO_TOPLEFT); + Vision(const Device& device) : Vision(device.get_port()){}; + /** * Clears the vision sensor LED color, reseting it back to its default * behavior, displaying the most prominent object signature color. @@ -52,6 +71,14 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * void initialize() { + * pros::Vision vision_sensor(1); + * vision_sensor.clear_led(); + * } + * \endcode */ std::int32_t clear_led(void) const; @@ -78,6 +105,27 @@ class Vision { * Signature type * * \return A vision_signature_s_t that can be set using Vision::set_signature + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * // values acquired from the vision utility + * vision_signature_s_t RED_SIG = + * vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0); + * vision_sensor.set_signature(EXAMPLE_SIG, &RED_SIG); + * while (true) { + * vision_signature_s_t rtn = vision_sensor.get_by_sig(VISION_PORT, 0, EXAMPLE_SIG); + * // Gets the largest object of the EXAMPLE_SIG signature + * printf("sig: %d", rtn.signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ static vision_signature_s_t signature_from_utility(const std::int32_t id, const std::int32_t u_min, const std::int32_t u_max, const std::int32_t u_mean, @@ -106,11 +154,37 @@ class Vision { * The fifth signature id [1-7] to add to the color code * * \return A vision_color_code_t object containing the color code information. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG); + * } + * \endcode */ vision_color_code_t create_color_code(const std::uint32_t sig_id1, const std::uint32_t sig_id2, const std::uint32_t sig_id3 = 0, const std::uint32_t sig_id4 = 0, const std::uint32_t sig_id5 = 0) const; + /** + * Gets all vision sensors. + * + * \return A vector of Vision sensor objects. + * + * \b Example + * \code + * void opcontrol() { + * std::vector vision_all = pros::Vision::get_all_devices(); // All vision sensors that are connected + * } + * \endcode + */ + static std::vector get_all_devices(); + /** * Gets the nth largest object according to size_id. * @@ -126,6 +200,21 @@ class Vision { * * \return The vision_object_s_t object corresponding to the given size id, or * PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * while (true) { + * vision_object_s_t rtn = vision_sensor.get_by_size(0); + * // Gets the largest object + * printf("sig: %d", rtn.signature); + * delay(2); + * } + * } + * \endcode */ vision_object_s_t get_by_size(const std::uint32_t size_id) const; @@ -148,6 +237,23 @@ class Vision { * * \return The vision_object_s_t object corresponding to the given signature * and size_id, or PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * while (true) { + * vision_object_s_t rtn = vision_sensor.get_by_sig(0, EXAMPLE_SIG); + * // Gets the largest object of the EXAMPLE_SIG signature + * printf("sig: %d", rtn.signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ vision_object_s_t get_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id) const; @@ -167,13 +273,29 @@ class Vision { * * \return The vision_object_s_t object corresponding to the given color code * and size_id, or PROS_ERR if an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG); + * while (true) { + * vision_object_s_t rtn = vision_sensor.get_by_code(0, code1); + * // Gets the largest object + * printf("sig: %d", rtn.signature); + * delay(2); + * } + * } + * \endcode */ vision_object_s_t get_by_code(const std::uint32_t size_id, const vision_color_code_t color_code) const; /** - * Gets the exposure parameter of the Vision Sensor. See - * https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html#exposure-setting - * for more detials. + * Gets the exposure parameter of the Vision Sensor. * * This function uses the following values of errno when an error state is * reached: @@ -181,6 +303,17 @@ class Vision { * * \return The current exposure parameter from [0,150], * PROS_ERR if an error occurred + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * if (vision_sensor.get_exposure() < 50) + * vision_sensor.set_exposure(50); + * } + * \endcode */ std::int32_t get_exposure(void) const; @@ -193,6 +326,19 @@ class Vision { * * \return The number of objects detected on the specified vision sensor. * Returns PROS_ERR if the port was invalid or an error occurred. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * while (true) { + * printf("Number of Objects Detected: %d\n", vision_sensor.get_object_count()); + * delay(2); + * } + * } + * \endcode */ std::int32_t get_object_count(void) const; @@ -207,6 +353,18 @@ class Vision { * The signature id to read * * \return A vision_signature_s_t containing information about the signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_signature_s_t sig = vision_sensor.get_signature(EXAMPLE_SIG); + * vision_sensor.print_signature(sig); + * } + * \endcode */ vision_signature_s_t get_signature(const std::uint8_t signature_id) const; @@ -218,15 +376,20 @@ class Vision { * ENODEV - The port cannot be configured as a vision sensor * * \return The current RGB white balance setting of the sensor - */ - std::int32_t get_white_balance(void) const; - - /** - * Gets the port number of the Vision Sensor. * - * \return The vision sensor's port number. + * \b Example + * \code + * #define VISION_PORT 1 + * #define VISION_WHITE 0xff + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * if (vision_sensor.get_white_balance() != VISION_WHITE) + * vision_sensor.set_white_balance(VISION_WHITE); + * } + * \endcode */ - std::uint8_t get_port(void) const; + std::int32_t get_white_balance(void) const; /** * Reads up to object_count object descriptors into object_arr. @@ -250,6 +413,23 @@ class Vision { * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * while (true) { + * vision_sensor.read_by_size(0, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints the signature of the largest object found + * delay(2); + * } + * } + * \endcode */ std::int32_t read_by_size(const std::uint32_t size_id, const std::uint32_t object_count, vision_object_s_t* const object_arr) const; @@ -280,6 +460,24 @@ class Vision { * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * while (true) { + * vision_sensor.read_by_sig(0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints "sig: 1" + * delay(2); + * } + * } + * \endcode */ std::int32_t read_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id, const std::uint32_t object_count, vision_object_s_t* const object_arr) const; @@ -308,6 +506,26 @@ class Vision { * Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects * than size_id were found. All objects in object_arr that were not found are * given VISION_OBJECT_ERR_SIG as their signature. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * #define OTHER_SIG 2 + * #define NUM_VISION_OBJECTS 4 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_object_s_t object_arr[NUM_VISION_OBJECTS]; + * vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG, 0, 0, 0); + * while (true) { + * vision_sensor.read_by_code(0, code1, NUM_VISION_OBJECTS, object_arr); + * printf("sig: %d", object_arr[0].signature); + * // Prints the signature of the largest object found + * delay(2); + * } + * } + * \endcode */ int32_t read_by_code(const std::uint32_t size_id, const vision_color_code_t color_code, const std::uint32_t object_count, vision_object_s_t* const object_arr) const; @@ -319,6 +537,18 @@ class Vision { * The signature for which the contents will be printed * * \return 1 if no errors occured, PROS_ERR otherwise + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_signature_s_t sig = visionsensor.get_signature(EXAMPLE_SIG); + * vision_print_signature(sig); + * } + * \endcode */ static std::int32_t print_signature(const vision_signature_s_t sig); @@ -334,13 +564,21 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_auto_white_balance(true); + * } + * \endcode */ std::int32_t set_auto_white_balance(const std::uint8_t enable) const; /** - * Sets the exposure parameter of the Vision Sensor. See - * https://pros.cs.purdue.edu/v5/tutorials/topical/vision.html#exposure-setting - * for more detials. + * Sets the exposure parameter of the Vision Sensor. * * This function uses the following values of errno when an error state is * reached: @@ -351,6 +589,17 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * if (vision_sensor.get_exposure() < 50) + * vision_sensor.set_exposure(50); + * } + * \endcode */ std::int32_t set_exposure(const std::uint8_t exposure) const; @@ -366,6 +615,16 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_led(COLOR_BLANCHED_ALMOND); + * } + * \endcode */ std::int32_t set_led(const std::int32_t rgb) const; @@ -386,6 +645,19 @@ class Vision { * A pointer to the signature to save * * \return 1 if no errors occured, PROS_ERR otherwise + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define EXAMPLE_SIG 1 + * + * void opcontrol() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_signature_s_t sig = vision_sensor.get_signature(EXAMPLE_SIG); + * sig.range = 10.0; + * vision_sensor.set_signature(EXAMPLE_SIG, &sig); + * } + * \endcode */ std::int32_t set_signature(const std::uint8_t signature_id, vision_signature_s_t* const signature_ptr) const; @@ -401,6 +673,17 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * #define VISION_WHITE 0xff + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_white_balance(VISION_WHITE); + * } + * \endcode */ std::int32_t set_white_balance(const std::int32_t rgb) const; @@ -420,6 +703,16 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_zero_point(E_VISION_ZERO_CENTER); + * } + * \endcode */ std::int32_t set_zero_point(vision_zero_e_t zero_point) const; @@ -435,11 +728,60 @@ class Vision { * * \return 1 if the operation was successful or PROS_ERR if the operation * failed, setting errno. + * + * \b Example + * \code + * #define VISION_PORT 1 + * + * void initialize() { + * pros::Vision vision_sensor(VISION_PORT); + * vision_sensor.set_wifi_mode(0); + * } + * \endcode */ std::int32_t set_wifi_mode(const std::uint8_t enable) const; + /** + * Gets a vision sensor that is plugged in to the brain + * + * \note The first time this function is called it returns the vision sensor at the lowest port + * If this function is called multiple times, it will cycle through all the ports. + * For example, if you have 1 vision sensor on the robot + * this function will always return a vision sensor object for that port. + * If you have 2 vision sensors, all the odd numered calls to this function will return objects + * for the lower port number, + * all the even number calls will return vision objects for the higher port number + * + * + * This functions uses the following values of errno when an error state is + * reached: + * ENODEV - No vision sensor is plugged into the brain + * + * \return A vision object corresponding to a port that a vision sensor is connected to the brain + * If no vision sensor is plugged in, it returns a vision sensor on port PROS_ERR_BYTE + * + */ + static Vision get_vision(); + private: - std::uint8_t _port; + ///@} }; +} // namespace v5 +namespace literals { +/** + * Constructs a Vision sensor from a litteral ending in _vis + * + * \return a pros::Vision for the corresponding port + * + * \b Example + * \code + * using namespace pros::literals; + * void opcontrol() { + * pros::Vision vision = 2_vis; //Makes an Vision sensor object on port 2 + * } + * \endcode + */ +const pros::Vision operator"" _vis(const unsigned long long int m); +} // namespace literals } // namespace pros #endif // _PROS_VISION_HPP_ diff --git a/include/subsystems.hpp b/include/subsystems.hpp new file mode 100644 index 00000000..404e2418 --- /dev/null +++ b/include/subsystems.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "api.h" + +// Your motors, sensors, etc. should go here. Below are examples + +// inline pros::Motor intake(1); +// inline pros::adi::DigitalIn limit_switch('A'); \ No newline at end of file diff --git a/project.pros b/project.pros index 728bdc0f..a9016daf 100644 --- a/project.pros +++ b/project.pros @@ -1,318 +1,407 @@ { - "py/object": "pros.conductor.project.Project", - "py/state": { - "project_name": "EZ-Template", + "py/object": "pros.conductor.project.Project", + "py/state": { + "project_name": "EZ-Template", + "target": "v5", + "templates": { + "kernel": { + "location": "C:\\Users\\xuzwi\\AppData\\Roaming\\PROS\\templates\\kernel@4.1.0", + "metadata": { + "cold_addr": "58720256", + "cold_output": "bin/cold.package.bin", + "hot_addr": "125829120", + "hot_output": "bin/hot.package.bin", + "origin": "pros-mainline", + "output": "bin/monolith.bin" + }, + "name": "kernel", + "py/object": "pros.conductor.templates.local_template.LocalTemplate", + "supported_kernels": null, + "system_files": [ + "include\\pros\\rtos.hpp", + "firmware\\libpros.a", + "include\\pros\\imu.hpp", + "common.mk", + "include\\pros\\rotation.hpp", + "include\\pros\\abstract_motor.hpp", + "include\\pros\\serial.h", + "include\\pros\\vision.hpp", + "include\\pros\\colors.h", + "include\\pros\\colors.hpp", + "include\\pros\\device.hpp", + "include\\pros\\misc.h", + "include\\api.h", + "include\\pros\\link.h", + "firmware\\v5-hot.ld", + "include\\pros\\distance.h", + "firmware\\v5-common.ld", + "include\\pros\\imu.h", + "include\\pros\\motor_group.hpp", + "include\\pros\\vision.h", + "include\\pros\\misc.hpp", + "include\\pros\\adi.h", + "include\\pros\\screen.h", + "include\\pros\\motors.h", + "include\\pros\\llemu.h", + "include\\pros\\adi.hpp", + "include\\pros\\device.h", + "include\\pros\\motors.hpp", + "include\\pros\\serial.hpp", + "include\\pros\\ext_adi.h", + "include\\pros\\apix.h", + "include\\pros\\rtos.h", + "include\\pros\\rotation.h", + "include\\pros\\llemu.hpp", + "firmware\\libc.a", + "firmware\\v5.ld", + "include\\pros\\gps.h", + "include\\pros\\optical.hpp", + "include\\pros\\gps.hpp", + "firmware\\libm.a", + "include\\pros\\distance.hpp", + "include\\pros\\link.hpp", + "include\\pros\\optical.h", + "include\\pros\\screen.hpp", + "include\\pros\\error.h" + ], + "target": "v5", + "user_files": [ + "src\\main.c", + "include\\main.hh", + "Makefile", + "include\\main.h", + ".gitignore", + "src\\main.cc", + "include\\main.hpp", + "src\\main.cpp" + ], + "version": "4.1.0" + }, + "liblvgl": { + "location": "C:\\Users\\xuzwi\\AppData\\Roaming\\PROS\\templates\\liblvgl@8.3.8", + "metadata": { + "origin": "kernel-beta-mainline" + }, + "name": "liblvgl", + "py/object": "pros.conductor.templates.local_template.LocalTemplate", + "supported_kernels": ">=4.0.0", + "system_files": [ + "include\\liblvgl\\extra\\others\\gridnav\\lv_gridnav.h", + "include\\liblvgl\\font\\lv_font_loader.h", + "include\\liblvgl\\misc\\lv_txt_ap.h", + "include\\liblvgl\\core\\lv_indev_scroll.h", + "include\\liblvgl\\misc\\lv_types.h", + "include\\liblvgl\\draw\\lv_img_decoder.h", + "include\\liblvgl\\extra\\libs\\freetype\\lv_freetype.h", + "include\\liblvgl\\extra\\widgets\\led\\lv_led.h", + "include\\liblvgl\\widgets\\lv_bar.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_rect.h", + "include\\liblvgl\\draw\\nxp\\vglite\\lv_draw_vglite_blend.h", + "include\\liblvgl\\extra\\libs\\png\\lv_png.h", + "include\\liblvgl\\misc\\lv_printf.h", + "include\\liblvgl\\extra\\themes\\lv_themes.h", + "include\\liblvgl\\draw\\lv_draw_transform.h", + "include\\liblvgl\\lv_conf_checker.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_priv.h", + "include\\liblvgl\\extra\\themes\\basic\\lv_theme_basic.h", + "include\\liblvgl\\extra\\widgets\\msgbox\\lv_msgbox.h", + "include\\liblvgl\\extra\\libs\\bmp\\lv_bmp.h", + "include\\liblvgl\\extra\\widgets\\span\\lv_span.h", + "include\\liblvgl\\misc\\lv_fs.h", + "include\\liblvgl\\misc\\lv_lru.h", + "include\\liblvgl\\core\\lv_obj_style.h", + "include\\liblvgl\\extra\\libs\\qrcode\\lv_qrcode.h", + "include\\liblvgl\\core\\lv_obj_class.h", + "include\\liblvgl\\lv_conf_internal.h", + "include\\liblvgl\\lv_conf.h", + "include\\liblvgl\\extra\\widgets\\lv_widgets.h", + "include\\liblvgl\\core\\lv_refr.h", + "include\\liblvgl\\extra\\widgets\\imgbtn\\lv_imgbtn.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_stack_blur.h", + "include\\liblvgl\\lvgl.h", + "include\\liblvgl\\misc\\lv_anim_timeline.h", + "include\\liblvgl\\extra\\widgets\\spinner\\lv_spinner.h", + "include\\liblvgl\\extra\\widgets\\animimg\\lv_animimg.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_texture_cache.h", + "include\\liblvgl\\extra\\libs\\fsdrv\\lv_fsdrv.h", + "include\\liblvgl\\draw\\nxp\\pxp\\lv_gpu_nxp_pxp.h", + "include\\liblvgl\\extra\\others\\fragment\\lv_fragment.h", + "include\\liblvgl\\extra\\widgets\\calendar\\lv_calendar_header_dropdown.h", + "include\\liblvgl\\draw\\lv_draw_triangle.h", + "include\\liblvgl\\lv_api_map.h", + "include\\liblvgl\\extra\\widgets\\chart\\lv_chart.h", + "include\\liblvgl\\extra\\widgets\\colorwheel\\lv_colorwheel.h", + "include\\liblvgl\\hal\\lv_hal_disp.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_img.h", + "include\\liblvgl\\extra\\widgets\\tileview\\lv_tileview.h", + "include\\liblvgl\\widgets\\lv_btnmatrix.h", + "include\\liblvgl\\core\\lv_obj_scroll.h", + "include\\liblvgl\\extra\\layouts\\grid\\lv_grid.h", + "include\\liblvgl\\misc\\lv_area.h", + "include\\liblvgl\\widgets\\lv_dropdown.h", + "include\\liblvgl\\hal\\lv_hal.h", + "include\\liblvgl\\draw\\nxp\\lv_gpu_nxp.h", + "include\\liblvgl\\extra\\others\\imgfont\\lv_imgfont.h", + "include\\liblvgl\\misc\\lv_txt.h", + "include\\liblvgl\\core\\lv_obj.h", + "include\\liblvgl\\widgets\\lv_objx_templ.h", + "include\\liblvgl\\core\\lv_group.h", + "firmware\\liblvgl.a", + "include\\liblvgl\\font\\lv_font.h", + "include\\liblvgl\\draw\\sw\\lv_draw_sw_blend.h", + "include\\liblvgl\\draw\\lv_draw_label.h", + "include\\liblvgl\\extra\\libs\\gif\\gifdec.h", + "include\\liblvgl\\lv_conf.old.h", + "include\\liblvgl\\hal\\lv_hal_tick.h", + "include\\liblvgl\\draw\\sw\\lv_draw_sw_dither.h", + "include\\liblvgl\\widgets\\lv_textarea.h", + "include\\liblvgl\\extra\\libs\\gif\\lv_gif.h", + "include\\liblvgl\\llemu.h", + "include\\liblvgl\\misc\\lv_async.h", + "include\\liblvgl\\draw\\sw\\lv_draw_sw.h", + "include\\liblvgl\\draw\\lv_draw_mask.h", + "include\\liblvgl\\widgets\\lv_img.h", + "include\\liblvgl\\extra\\widgets\\tabview\\lv_tabview.h", + "include\\liblvgl\\core\\lv_obj_style_gen.h", + "include\\liblvgl\\extra\\others\\ime\\lv_ime_pinyin.h", + "include\\liblvgl\\misc\\lv_log.h", + "include\\liblvgl\\font\\lv_symbol_def.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_utils.h", + "include\\liblvgl\\extra\\layouts\\flex\\lv_flex.h", + "include\\liblvgl\\misc\\lv_style_gen.h", + "include\\liblvgl\\extra\\libs\\sjpg\\tjpgd.h", + "include\\liblvgl\\draw\\lv_draw_rect.h", + "include\\liblvgl\\extra\\libs\\ffmpeg\\lv_ffmpeg.h", + "include\\liblvgl\\draw\\lv_draw_arc.h", + "include\\liblvgl\\misc\\lv_bidi.h", + "include\\liblvgl\\extra\\widgets\\win\\lv_win.h", + "include\\liblvgl\\draw\\lv_img_cache.h", + "include\\liblvgl\\core\\lv_obj_draw.h", + "include\\liblvgl\\extra\\others\\msg\\lv_msg.h", + "include\\liblvgl\\misc\\lv_ll.h", + "include\\liblvgl\\widgets\\lv_table.h", + "include\\liblvgl\\lv_conf_kconfig.h", + "include\\liblvgl\\draw\\lv_draw_layer.h", + "include\\liblvgl\\misc\\lv_assert.h", + "include\\liblvgl\\extra\\libs\\sjpg\\tjpgdcnf.h", + "include\\liblvgl\\widgets\\lv_checkbox.h", + "include\\liblvgl\\core\\lv_obj_tree.h", + "include\\liblvgl\\hal\\lv_hal_indev.h", + "include\\liblvgl\\widgets\\lv_label.h", + "include\\liblvgl\\misc\\lv_mem.h", + "include\\liblvgl\\widgets\\lv_btn.h", + "include\\liblvgl\\core\\lv_theme.h", + "include\\liblvgl\\font\\lv_font_fmt_txt.h", + "include\\liblvgl\\extra\\others\\snapshot\\lv_snapshot.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_layer.h", + "include\\liblvgl\\extra\\libs\\qrcode\\qrcodegen.h", + "include\\liblvgl\\draw\\sw\\lv_draw_sw_gradient.h", + "include\\liblvgl\\misc\\lv_utils.h", + "include\\liblvgl\\draw\\nxp\\pxp\\lv_draw_pxp_blend.h", + "include\\liblvgl\\misc\\lv_style.h", + "include\\liblvgl\\widgets\\lv_line.h", + "include\\liblvgl\\widgets\\lv_slider.h", + "include\\liblvgl\\extra\\widgets\\meter\\lv_meter.h", + "include\\liblvgl\\draw\\arm2d\\lv_gpu_arm2d.h", + "include\\liblvgl\\extra\\libs\\rlottie\\lv_rlottie.h", + "include\\liblvgl\\extra\\others\\lv_others.h", + "include\\liblvgl\\extra\\layouts\\lv_layouts.h", + "include\\liblvgl\\extra\\widgets\\calendar\\lv_calendar_header_arrow.h", + "include\\liblvgl\\draw\\swm341_dma2d\\lv_gpu_swm341_dma2d.h", + "include\\liblvgl\\draw\\stm32_dma2d\\lv_gpu_stm32_dma2d.h", + "include\\liblvgl\\misc\\lv_anim.h", + "include\\liblvgl\\extra\\widgets\\calendar\\lv_calendar.h", + "include\\liblvgl\\misc\\lv_templ.h", + "include\\liblvgl\\extra\\widgets\\spinbox\\lv_spinbox.h", + "include\\liblvgl\\extra\\lv_extra.h", + "include\\liblvgl\\draw\\lv_draw_img.h", + "include\\liblvgl\\draw\\lv_img_buf.h", + "include\\liblvgl\\extra\\libs\\sjpg\\lv_sjpg.h", + "include\\liblvgl\\extra\\libs\\lv_libs.h", + "include\\liblvgl\\draw\\nxp\\vglite\\lv_draw_vglite_rect.h", + "include\\liblvgl\\llemu.hpp", + "include\\liblvgl\\draw\\lv_draw.h", + "include\\liblvgl\\extra\\themes\\mono\\lv_theme_mono.h", + "include\\liblvgl\\core\\lv_event.h", + "include\\liblvgl\\widgets\\lv_canvas.h", + "include\\liblvgl\\extra\\others\\monkey\\lv_monkey.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_mask.h", + "include\\liblvgl\\draw\\nxp\\vglite\\lv_draw_vglite_arc.h", + "include\\liblvgl\\draw\\nxp\\pxp\\lv_gpu_nxp_pxp_osa.h", + "include\\liblvgl\\core\\lv_disp.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl_composite.h", + "include\\liblvgl\\widgets\\lv_switch.h", + "include\\liblvgl\\draw\\sdl\\lv_draw_sdl.h", + "include\\liblvgl\\core\\lv_indev.h", + "include\\liblvgl\\misc\\lv_timer.h", + "include\\liblvgl\\draw\\nxp\\vglite\\lv_gpu_nxp_vglite.h", + "include\\liblvgl\\extra\\widgets\\menu\\lv_menu.h", + "include\\liblvgl\\misc\\lv_math.h", + "include\\liblvgl\\misc\\lv_color.h", + "include\\liblvgl\\draw\\lv_draw_line.h", + "include\\liblvgl\\misc\\lv_gc.h", + "include\\liblvgl\\core\\lv_obj_pos.h", + "include\\liblvgl\\widgets\\lv_arc.h", + "include\\liblvgl\\extra\\themes\\default\\lv_theme_default.h", + "include\\liblvgl\\extra\\widgets\\list\\lv_list.h", + "include\\liblvgl\\widgets\\lv_roller.h", + "include\\liblvgl\\extra\\libs\\png\\lodepng.h", + "include\\liblvgl\\misc\\lv_tlsf.h", + "include\\liblvgl\\extra\\widgets\\keyboard\\lv_keyboard.h" + ], "target": "v5", - "templates": { - "kernel": { - "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\kernel@3.8.3", - "metadata": { - "cold_addr": "58720256", - "cold_output": "bin/cold.package.bin", - "hot_addr": "125829120", - "hot_output": "bin/hot.package.bin", - "origin": "pros-mainline", - "output": "bin/monolith.bin" - }, - "name": "kernel", - "py/object": "pros.conductor.templates.local_template.LocalTemplate", - "supported_kernels": null, - "system_files": [ - "include\\display\\lv_themes\\lv_theme_mono.h", - "include\\display\\lv_themes\\lv_theme_nemo.h", - "include\\display\\lv_objx\\lv_calendar.h", - "include\\display\\lv_themes\\lv_theme_zen.h", - "include\\display\\lv_objx\\lv_spinbox.h", - "include\\pros\\screen.hpp", - "include\\display\\lv_objx\\lv_ddlist.h", - "include\\display\\lv_themes\\lv_theme.h", - "include\\display\\lv_hal\\lv_hal.h", - "include\\display\\lv_draw\\lv_draw_arc.h", - "include\\display\\lv_objx\\lv_list.h", - "include\\display\\lv_themes\\lv_themes.mk", - "include\\pros\\motors.hpp", - "include\\pros\\adi.h", - "include\\display\\lv_draw\\lv_draw.h", - "include\\pros\\colors.hpp", - "include\\display\\licence.txt", - "include\\display\\lv_draw\\lv_draw_img.h", - "include\\display\\lv_fonts\\lv_fonts.mk", - "include\\display\\lv_draw\\lv_draw_rect.h", - "include\\display\\lv_core\\lv_group.h", - "include\\display\\lv_draw\\lv_draw_label.h", - "include\\pros\\llemu.h", - "include\\pros\\error.h", - "include\\display\\lv_misc\\lv_ufs.h", - "firmware\\libm.a", - "include\\display\\lv_objx\\lv_led.h", - "include\\display\\lv_objx\\lv_btn.h", - "include\\display\\lv_misc\\lv_misc.mk", - "include\\display\\lv_objx\\lv_canvas.h", - "include\\display\\lv_objx\\lv_preload.h", - "include\\pros\\misc.hpp", - "include\\display\\lv_misc\\lv_fs.h", - "include\\pros\\rotation.hpp", - "include\\pros\\colors.h", - "include\\pros\\vision.hpp", - "include\\display\\lv_objx\\lv_img.h", - "include\\display\\lv_fonts\\lv_font_builtin.h", - "include\\display\\lv_objx\\lv_lmeter.h", - "include\\display\\lv_misc\\lv_font.h", - "firmware\\v5.ld", - "include\\display\\lv_objx\\lv_tileview.h", - "include\\display\\lv_hal\\lv_hal_tick.h", - "include\\display\\lv_core\\lv_vdb.h", - "include\\display\\lv_core\\lv_indev.h", - "include\\pros\\vision.h", - "firmware\\v5-hot.ld", - "include\\display\\lv_objx\\lv_kb.h", - "include\\display\\lv_misc\\lv_symbol_def.h", - "firmware\\libc.a", - "include\\display\\lv_objx\\lv_label.h", - "include\\display\\lv_objx\\lv_tabview.h", - "firmware\\libpros.a", - "include\\display\\lv_misc\\lv_ll.h", - "include\\display\\lv_misc\\lv_log.h", - "include\\pros\\screen.h", - "include\\display\\lv_hal\\lv_hal.mk", - "include\\pros\\serial.hpp", - "include\\pros\\optical.hpp", - "include\\display\\lv_misc\\lv_txt.h", - "include\\display\\lv_misc\\lv_task.h", - "firmware\\v5-common.ld", - "include\\pros\\optical.h", - "include\\pros\\rtos.hpp", - "include\\display\\lv_conf_checker.h", - "include\\display\\lv_misc\\lv_math.h", - "include\\display\\lv_draw\\lv_draw_rbasic.h", - "include\\display\\lv_themes\\lv_theme_alien.h", - "include\\pros\\motors.h", - "include\\pros\\misc.h", - "include\\display\\lv_themes\\lv_theme_default.h", - "include\\pros\\gps.h", - "include\\display\\lv_misc\\lv_templ.h", - "include\\display\\lv_misc\\lv_circ.h", - "include\\api.h", - "include\\display\\lv_objx\\lv_ta.h", - "include\\display\\lv_draw\\lv_draw_triangle.h", - "include\\display\\lv_misc\\lv_mem.h", - "include\\display\\lv_objx\\lv_imgbtn.h", - "include\\pros\\link.h", - "include\\display\\lv_version.h", - "include\\display\\lv_conf.h", - "include\\display\\lv_objx\\lv_mbox.h", - "include\\display\\lv_misc\\lv_anim.h", - "include\\display\\lv_hal\\lv_hal_indev.h", - "include\\display\\lv_objx\\lv_btnm.h", - "include\\display\\lv_misc\\lv_color.h", - "include\\display\\lv_draw\\lv_draw_vbasic.h", - "include\\pros\\distance.hpp", - "include\\display\\lv_objx\\lv_bar.h", - "include\\display\\lv_objx\\lv_gauge.h", - "include\\display\\lv_draw\\lv_draw.mk", - "include\\display\\lvgl.h", - "include\\display\\lv_objx\\lv_slider.h", - "include\\display\\lv_objx\\lv_objx.mk", - "include\\display\\README.md", - "include\\display\\lv_core\\lv_lang.h", - "include\\display\\lv_objx\\lv_arc.h", - "include\\pros\\serial.h", - "include\\pros\\llemu.hpp", - "include\\pros\\adi.hpp", - "include\\display\\lv_objx\\lv_table.h", - "include\\display\\lv_draw\\lv_draw_line.h", - "include\\display\\lv_misc\\lv_area.h", - "include\\display\\lv_core\\lv_core.mk", - "include\\display\\lv_objx\\lv_line.h", - "include\\display\\lv_hal\\lv_hal_disp.h", - "include\\display\\lv_misc\\lv_gc.h", - "include\\pros\\rotation.h", - "include\\display\\lv_themes\\lv_theme_material.h", - "include\\display\\lv_core\\lv_style.h", - "include\\display\\lv_objx\\lv_cb.h", - "include\\display\\lv_objx\\lv_chart.h", - "common.mk", - "include\\pros\\ext_adi.h", - "include\\display\\lv_objx\\lv_objx_templ.h", - "include\\display\\lv_core\\lv_refr.h", - "include\\display\\lv_core\\lv_obj.h", - "include\\pros\\api_legacy.h", - "include\\pros\\rtos.h", - "include\\pros\\imu.h", - "include\\display\\lv_objx\\lv_win.h", - "include\\display\\lv_objx\\lv_cont.h", - "include\\display\\lv_themes\\lv_theme_templ.h", - "include\\pros\\link.hpp", - "include\\pros\\distance.h", - "include\\display\\lv_objx\\lv_roller.h", - "include\\display\\lv_objx\\lv_sw.h", - "include\\pros\\imu.hpp", - "include\\pros\\gps.hpp", - "include\\display\\lv_themes\\lv_theme_night.h", - "include\\pros\\apix.h", - "include\\display\\lv_objx\\lv_page.h" - ], - "target": "v5", - "user_files": [ - "include\\main.h", - "src\\main.c", - "include\\main.hpp", - "include\\main.hh", - "src\\main.cpp", - "src\\main.cc", - "Makefile", - ".gitignore" - ], - "version": "3.8.3" - }, - "okapilib": { - "location": "C:\\Users\\union\\AppData\\Roaming\\PROS\\templates\\okapilib@4.8.0", - "metadata": { - "origin": "pros-mainline" - }, - "name": "okapilib", - "py/object": "pros.conductor.templates.local_template.LocalTemplate", - "supported_kernels": "^3.3.1", - "system_files": [ - "include/okapi/api/odometry/odomMath.hpp", - "include/okapi/squiggles/physicalmodel/physicalmodel.hpp", - "include/okapi/api/chassis/model/threeEncoderXDriveModel.hpp", - "include/okapi/api/chassis/model/hDriveModel.hpp", - "include/okapi/api/chassis/model/readOnlyChassisModel.hpp", - "include/okapi/api/device/button/buttonBase.hpp", - "include/okapi/api/units/QAngularJerk.hpp", - "include/okapi/api/control/iterative/iterativeController.hpp", - "include/okapi/api/control/controllerInput.hpp", - "include/okapi/squiggles/math/quinticpolynomial.hpp", - "include/okapi/api/device/rotarysensor/continuousRotarySensor.hpp", - "include/okapi/api/control/async/asyncPositionController.hpp", - "include/okapi/api/filter/passthroughFilter.hpp", - "include/okapi/api/device/rotarysensor/rotarySensor.hpp", - "include/okapi/api/odometry/stateMode.hpp", - "include/okapi/impl/device/controller.hpp", - "include/okapi/api/units/QTime.hpp", - "include/okapi/api/control/util/controllerRunner.hpp", - "include/okapi/api/units/QTorque.hpp", - "include/okapi/impl/device/rotarysensor/IMU.hpp", - "include/okapi/api/control/util/pidTuner.hpp", - "include/okapi/impl/util/timeUtilFactory.hpp", - "include/okapi/api/device/motor/abstractMotor.hpp", - "include/okapi/impl/device/button/controllerButton.hpp", - "include/okapi/impl/device/rotarysensor/integratedEncoder.hpp", - "include/okapi/impl/device/rotarysensor/adiEncoder.hpp", - "include/okapi/api/filter/composableFilter.hpp", - "include/okapi/api/chassis/model/xDriveModel.hpp", - "include/okapi/squiggles/geometry/pose.hpp", - "include/okapi/api/odometry/twoEncoderOdometry.hpp", - "include/okapi/api/util/timeUtil.hpp", - "firmware/squiggles.mk", - "include/okapi/api/control/async/asyncPosPidController.hpp", - "include/okapi/impl/control/util/controllerRunnerFactory.hpp", - "include/okapi/impl/chassis/controller/chassisControllerBuilder.hpp", - "include/okapi/api/control/closedLoopController.hpp", - "include/okapi/squiggles/math/utils.hpp", - "include/okapi/api/control/async/asyncVelIntegratedController.hpp", - "include/okapi/api/units/QLength.hpp", - "include/okapi/impl/device/motor/motor.hpp", - "include/okapi/api/odometry/odometry.hpp", - "include/okapi/api/units/RQuantity.hpp", - "include/okapi/api/units/QArea.hpp", - "include/okapi/api/filter/filter.hpp", - "include/okapi/api/device/button/abstractButton.hpp", - "include/okapi/api/units/QPressure.hpp", - "include/okapi/api/control/async/asyncLinearMotionProfileController.hpp", - "include/okapi/api/control/util/flywheelSimulator.hpp", - "include/okapi/api/util/logging.hpp", - "include/okapi/api/chassis/model/threeEncoderSkidSteerModel.hpp", - "include/okapi/api/filter/emaFilter.hpp", - "include/okapi/impl/device/controllerUtil.hpp", - "include/okapi/api/util/mathUtil.hpp", - "include/okapi/api/filter/averageFilter.hpp", - "include/okapi/api/control/iterative/iterativeVelocityController.hpp", - "include/okapi/api/odometry/point.hpp", - "include/okapi/api/control/async/asyncController.hpp", - "include/okapi/impl/control/async/asyncMotionProfileControllerBuilder.hpp", - "include/okapi/api/coreProsAPI.hpp", - "include/okapi/api/units/QSpeed.hpp", - "include/okapi/impl/control/util/pidTunerFactory.hpp", - "include/okapi/api/units/QAngle.hpp", - "include/okapi/api/control/async/asyncVelocityController.hpp", - "include/okapi/api/odometry/threeEncoderOdometry.hpp", - "include/okapi/api/filter/velMath.hpp", - "include/okapi/api/control/async/asyncPosIntegratedController.hpp", - "include/okapi/squiggles/constraints.hpp", - "include/okapi/api/filter/filteredControllerInput.hpp", - "include/okapi/api/chassis/controller/chassisControllerPid.hpp", - "include/okapi/api/control/iterative/iterativePositionController.hpp", - "include/okapi/api/control/offsettableControllerInput.hpp", - "include/okapi/squiggles/squiggles.hpp", - "include/okapi/api/units/QAngularSpeed.hpp", - "include/okapi/api/control/iterative/iterativePosPidController.hpp", - "include/okapi/squiggles/physicalmodel/tankmodel.hpp", - "include/okapi/impl/util/rate.hpp", - "include/okapi/api/filter/medianFilter.hpp", - "include/okapi/impl/device/rotarysensor/potentiometer.hpp", - "include/okapi/api/control/iterative/iterativeVelPidController.hpp", - "include/okapi/squiggles/geometry/profilepoint.hpp", - "include/okapi/impl/device/button/adiButton.hpp", - "include/okapi/impl/control/async/asyncVelControllerBuilder.hpp", - "include/okapi/api/filter/demaFilter.hpp", - "include/okapi/api/units/RQuantityName.hpp", - "include/okapi/api/control/util/pathfinderUtil.hpp", - "include/okapi/api/util/abstractTimer.hpp", - "include/okapi/api.hpp", - "include/okapi/impl/control/async/asyncPosControllerBuilder.hpp", - "include/okapi/api/chassis/controller/chassisScales.hpp", - "include/okapi/api/units/QMass.hpp", - "include/okapi/impl/device/rotarysensor/adiGyro.hpp", - "include/okapi/impl/util/configurableTimeUtilFactory.hpp", - "include/okapi/api/control/util/settledUtil.hpp", - "include/okapi/impl/control/iterative/iterativeControllerFactory.hpp", - "include/okapi/impl/util/timer.hpp", - "include/okapi/api/chassis/controller/defaultOdomChassisController.hpp", - "include/okapi/impl/device/motor/motorGroup.hpp", - "include/okapi/api/control/async/asyncWrapper.hpp", - "include/okapi/squiggles/io.hpp", - "include/okapi/api/filter/ekfFilter.hpp", - "include/okapi/api/control/async/asyncMotionProfileController.hpp", - "include/okapi/squiggles/geometry/controlvector.hpp", - "include/okapi/impl/device/distanceSensor.hpp", - "include/okapi/api/control/controllerOutput.hpp", - "include/okapi/api/units/QVolume.hpp", - "include/okapi/squiggles/spline.hpp", - "include/okapi/api/units/QJerk.hpp", - "include/okapi/api/chassis/controller/chassisController.hpp", - "include/okapi/squiggles/physicalmodel/passthroughmodel.hpp", - "include/okapi/api/units/QAngularAcceleration.hpp", - "include/okapi/api/chassis/controller/chassisControllerIntegrated.hpp", - "include/okapi/impl/device/adiUltrasonic.hpp", - "include/okapi/impl/device/opticalSensor.hpp", - "include/okapi/api/units/QForce.hpp", - "include/okapi/api/util/supplier.hpp", - "include/okapi/api/chassis/controller/odomChassisController.hpp", - "include/okapi/impl/filter/velMathFactory.hpp", - "include/okapi/api/control/iterative/iterativeMotorVelocityController.hpp", - "include/okapi/api/control/async/asyncVelPidController.hpp", - "include/okapi/api/odometry/odomState.hpp", - "include/okapi/api/chassis/model/chassisModel.hpp", - "include/okapi/api/units/QFrequency.hpp", - "include/okapi/impl/device/rotarysensor/rotationSensor.hpp", - "include/okapi/api/util/abstractRate.hpp", - "include/okapi/impl/device/motor/adiMotor.hpp", - "include/okapi/api/units/QAcceleration.hpp", - "include/okapi/api/chassis/model/skidSteerModel.hpp", - "firmware/okapilib.a" - ], - "target": "v5", - "user_files": [], - "version": "4.8.0" - } + "user_files": [], + "version": "8.3.8" + }, + "okapilib": { + "location": "C:\\Users\\xuzwi\\AppData\\Roaming\\PROS\\templates\\okapilib@5.0.0", + "metadata": { + "origin": "kernel-beta-mainline" }, - "upload_options": { - "compress_bin": true, - "description": "making code ez-pz", - "remote_name": "EZ-Template", - "slot": 1 - } - } + "name": "okapilib", + "py/object": "pros.conductor.templates.local_template.LocalTemplate", + "supported_kernels": "^4.0.3", + "system_files": [ + "include/okapi/api/units/QFrequency.hpp", + "include/okapi/api/control/iterative/iterativePosPidController.hpp", + "include/okapi/impl/util/configurableTimeUtilFactory.hpp", + "include/okapi/api/filter/passthroughFilter.hpp", + "include/okapi/api/coreProsAPI.hpp", + "include/okapi/squiggles/math/quinticpolynomial.hpp", + "firmware/okapilib.a", + "include/okapi/api/util/abstractTimer.hpp", + "include/okapi/impl/control/async/asyncMotionProfileControllerBuilder.hpp", + "include/okapi/squiggles/geometry/pose.hpp", + "include/okapi/api/control/util/pathfinderUtil.hpp", + "include/okapi/squiggles/constraints.hpp", + "include/okapi/api/chassis/model/threeEncoderSkidSteerModel.hpp", + "include/okapi/api/control/iterative/iterativeMotorVelocityController.hpp", + "include/okapi/api/control/async/asyncVelIntegratedController.hpp", + "include/okapi/api/units/RQuantity.hpp", + "include/okapi/api/units/QArea.hpp", + "include/okapi/api/units/QAngularJerk.hpp", + "include/okapi/api/odometry/twoEncoderOdometry.hpp", + "include/okapi/api/chassis/model/skidSteerModel.hpp", + "include/okapi/impl/util/timeUtilFactory.hpp", + "include/okapi/impl/device/rotarysensor/rotationSensor.hpp", + "include/okapi/api/control/async/asyncController.hpp", + "include/okapi/api/chassis/model/chassisModel.hpp", + "include/okapi/api/chassis/controller/odomChassisController.hpp", + "include/okapi/api/control/iterative/iterativePositionController.hpp", + "include/okapi/api/odometry/threeEncoderOdometry.hpp", + "include/okapi/impl/device/controllerUtil.hpp", + "include/okapi/api/device/rotarysensor/rotarySensor.hpp", + "include/okapi/api/chassis/controller/chassisControllerPid.hpp", + "include/okapi/impl/device/controller.hpp", + "include/okapi/squiggles/physicalmodel/physicalmodel.hpp", + "include/okapi/api/control/iterative/iterativeVelPidController.hpp", + "include/okapi/impl/device/distanceSensor.hpp", + "include/okapi/impl/filter/velMathFactory.hpp", + "include/okapi/api/chassis/controller/chassisControllerIntegrated.hpp", + "include/okapi/squiggles/math/utils.hpp", + "include/okapi/api/util/abstractRate.hpp", + "include/okapi/api/util/supplier.hpp", + "include/okapi/api/chassis/controller/chassisController.hpp", + "include/okapi/api/odometry/stateMode.hpp", + "include/okapi/impl/util/timer.hpp", + "include/okapi/api/filter/ekfFilter.hpp", + "include/okapi/impl/chassis/controller/chassisControllerBuilder.hpp", + "include/okapi/api/units/QVolume.hpp", + "include/okapi/api/chassis/controller/chassisScales.hpp", + "firmware/squiggles.mk", + "include/okapi/impl/device/motor/motor.hpp", + "include/okapi/api/odometry/odomMath.hpp", + "include/okapi/api/chassis/model/threeEncoderXDriveModel.hpp", + "include/okapi/api/control/async/asyncMotionProfileController.hpp", + "include/okapi/api/chassis/model/hDriveModel.hpp", + "include/okapi/api/units/QJerk.hpp", + "include/okapi/impl/util/rate.hpp", + "include/okapi/api/control/offsettableControllerInput.hpp", + "include/okapi/squiggles/geometry/profilepoint.hpp", + "include/okapi/impl/device/rotarysensor/potentiometer.hpp", + "include/okapi/api/units/QAngularSpeed.hpp", + "include/okapi/squiggles/spline.hpp", + "include/okapi/api/odometry/odometry.hpp", + "include/okapi/api/util/timeUtil.hpp", + "include/okapi/squiggles/geometry/controlvector.hpp", + "include/okapi/api/control/util/flywheelSimulator.hpp", + "include/okapi/api/control/util/pidTuner.hpp", + "include/okapi/impl/device/motor/adiMotor.hpp", + "include/okapi/api/chassis/model/xDriveModel.hpp", + "include/okapi/api/units/QSpeed.hpp", + "include/okapi/api/odometry/point.hpp", + "include/okapi/api/filter/composableFilter.hpp", + "include/okapi/impl/device/adiUltrasonic.hpp", + "include/okapi/api/filter/averageFilter.hpp", + "include/okapi/api/units/QAngularAcceleration.hpp", + "include/okapi/api/device/rotarysensor/continuousRotarySensor.hpp", + "include/okapi/api/control/util/controllerRunner.hpp", + "include/okapi/api/device/button/buttonBase.hpp", + "include/okapi/squiggles/squiggles.hpp", + "include/okapi/squiggles/physicalmodel/tankmodel.hpp", + "include/okapi/api/units/QMass.hpp", + "include/okapi/api/util/mathUtil.hpp", + "include/okapi/api/control/controllerOutput.hpp", + "include/okapi/impl/control/util/pidTunerFactory.hpp", + "include/okapi/api/filter/emaFilter.hpp", + "include/okapi/impl/control/iterative/iterativeControllerFactory.hpp", + "include/okapi/api/filter/filter.hpp", + "include/okapi/api/control/controllerInput.hpp", + "include/okapi/api/units/QForce.hpp", + "include/okapi/impl/device/rotarysensor/IMU.hpp", + "include/okapi/api/control/async/asyncLinearMotionProfileController.hpp", + "include/okapi/impl/device/button/controllerButton.hpp", + "include/okapi/squiggles/io.hpp", + "include/okapi/api/chassis/controller/defaultOdomChassisController.hpp", + "include/okapi/api/control/closedLoopController.hpp", + "include/okapi/api/control/iterative/iterativeVelocityController.hpp", + "include/okapi/impl/control/util/controllerRunnerFactory.hpp", + "include/okapi/api/units/RQuantityName.hpp", + "include/okapi/api/filter/filteredControllerInput.hpp", + "include/okapi/impl/control/async/asyncVelControllerBuilder.hpp", + "include/okapi/api/units/QAcceleration.hpp", + "include/okapi/api/control/async/asyncWrapper.hpp", + "include/okapi/api/util/logging.hpp", + "include/okapi/api/units/QTime.hpp", + "include/okapi/api/control/async/asyncPositionController.hpp", + "include/okapi/impl/device/button/adiButton.hpp", + "include/okapi/api/units/QPressure.hpp", + "include/okapi/impl/device/rotarysensor/adiEncoder.hpp", + "include/okapi/impl/device/motor/motorGroup.hpp", + "include/okapi/api/units/QLength.hpp", + "include/okapi/api.hpp", + "include/okapi/api/units/QAngle.hpp", + "include/okapi/impl/control/async/asyncPosControllerBuilder.hpp", + "include/okapi/api/filter/medianFilter.hpp", + "include/okapi/api/control/async/asyncPosPidController.hpp", + "include/okapi/api/control/async/asyncVelPidController.hpp", + "include/okapi/api/control/async/asyncVelocityController.hpp", + "include/okapi/impl/device/rotarysensor/adiGyro.hpp", + "include/okapi/impl/device/rotarysensor/integratedEncoder.hpp", + "include/okapi/api/device/button/abstractButton.hpp", + "include/okapi/squiggles/physicalmodel/passthroughmodel.hpp", + "include/okapi/api/filter/demaFilter.hpp", + "include/okapi/api/device/motor/abstractMotor.hpp", + "include/okapi/impl/device/opticalSensor.hpp", + "include/okapi/api/control/async/asyncPosIntegratedController.hpp", + "include/okapi/api/filter/velMath.hpp", + "include/okapi/api/control/iterative/iterativeController.hpp", + "include/okapi/api/odometry/odomState.hpp", + "include/okapi/api/chassis/model/readOnlyChassisModel.hpp", + "include/okapi/api/control/util/settledUtil.hpp", + "include/okapi/api/units/QTorque.hpp" + ], + "target": "v5", + "user_files": [], + "version": "5.0.0" + } + }, + "upload_options": { + "compress_bin": true, + "description": "making code ez", + "remote_name": "EZ-Template", + "slot": 1 + }, + "use_early_access": false + } } \ No newline at end of file diff --git a/src/EZ-Template/PID.cpp b/src/EZ-Template/PID.cpp index 977c85a6..686e071c 100644 --- a/src/EZ-Template/PID.cpp +++ b/src/EZ-Template/PID.cpp @@ -59,18 +59,34 @@ bool PID::i_reset_get() { return reset_i_sgn; }; double PID::compute(double current) { error = target - current; - derivative = error - prev_error; + return compute_error(error, current); +} + +double PID::compute_error(double err, double current) { + error = err; + cur = current; + + return raw_compute(); +} + +double PID::raw_compute() { + // calculate derivative on measurement instead of error to avoid "derivative kick" + // https://www.isa.org/intech-home/2023/june-2023/features/fundamentals-pid-control + derivative = cur - prev_current; if (constants.ki != 0) { + // Only compute i when within a threshold of target if (fabs(error) < constants.start_i) integral += error; - if (util::sgn(error) != util::sgn(prev_error) && reset_i_sgn) + // Reset i when the sign of error flips + if (util::sgn(error) != util::sgn(prev_current) && reset_i_sgn) integral = 0; } - output = (error * constants.kp) + (integral * constants.ki) + (derivative * constants.kd); + output = (error * constants.kp) + (integral * constants.ki) - (derivative * constants.kd); + prev_current = cur; prev_error = error; return output; @@ -81,6 +97,7 @@ void PID::timers_reset() { k = 0; j = 0; l = 0; + m = 0; is_mA = false; } @@ -97,6 +114,18 @@ void PID::exit_condition_print(ez::exit_output exit_type) { std::cout << exit_to_string(exit_type) << " Exit.\n"; } +void PID::velocity_sensor_secondary_toggle_set(bool toggle) { use_second_sensor = toggle; } +bool PID::velocity_sensor_secondary_toggle_get() { return use_second_sensor; } + +void PID::velocity_sensor_secondary_set(double secondary_sensor) { second_sensor = secondary_sensor; } +double PID::velocity_sensor_secondary_get() { return second_sensor; } + +void PID::velocity_sensor_main_exit_set(double zero) { velocity_zero_main = zero; } +double PID::velocity_sensor_main_exit_get() { return velocity_zero_main; } + +void PID::velocity_sensor_secondary_exit_set(double zero) { velocity_zero_secondary = zero; } +double PID::velocity_sensor_secondary_exit_get() { return velocity_zero_secondary; } + exit_output PID::exit_condition(bool print) { // If this function is called while all exit constants are 0, print an error if (exit.small_error == 0 && exit.small_exit_time == 0 && exit.big_error == 0 && exit.big_exit_time == 0 && exit.velocity_exit_time == 0 && exit.mA_timeout == 0) { @@ -121,7 +150,7 @@ exit_output PID::exit_condition(bool print) { // If the robot is close to the target, start a timer. If the robot doesn't get closer within // a certain amount of time, exit and continue. This does not run while small_timeout is running - if (exit.big_error != 0 && exit.big_exit_time != 0) { // Check if this condition is enabled + else if (exit.big_error != 0 && exit.big_exit_time != 0) { // Check if this condition is enabled if (abs(error) < exit.big_error) { i += util::DELAY_TIME; if (i > exit.big_exit_time) { @@ -134,9 +163,9 @@ exit_output PID::exit_condition(bool print) { } } - // If the motor velocity is 0,the code will timeout and set interfered to true. + // If the motor velocity is 0, the code will timeout and set interfered to true. if (exit.velocity_exit_time != 0) { // Check if this condition is enabled - if (abs(derivative) <= 0.05) { + if (abs(derivative) <= velocity_zero_main) { k += util::DELAY_TIME; if (k > exit.velocity_exit_time) { timers_reset(); @@ -148,6 +177,25 @@ exit_output PID::exit_condition(bool print) { } } + if (!use_second_sensor) + return RUNNING; + + // If the secondary sensors velocity is 0, the code will timeout and set interfered to true. + if (exit.velocity_exit_time != 0) { // Check if this condition is enabled + if (abs(second_sensor) <= velocity_zero_secondary) { + m += util::DELAY_TIME; + if (m > exit.velocity_exit_time) { + timers_reset(); + if (print) exit_condition_print(VELOCITY_EXIT); + return VELOCITY_EXIT; + } + } else { + m = 0; + } + } + + // printf("j: %i i: %i k: %i m: %i\n", j, i, k, m); + return RUNNING; } diff --git a/src/EZ-Template/drive/drive.cpp b/src/EZ-Template/drive/drive.cpp index c24575bd..d2a6809c 100644 --- a/src/EZ-Template/drive/drive.cpp +++ b/src/EZ-Template/drive/drive.cpp @@ -28,11 +28,13 @@ Drive::Drive(std::vector left_motor_ports, std::vector right_motor_por // Set ports to a global vector for (auto i : left_motor_ports) { - pros::Motor temp(abs(i), util::reversed_active(i)); + pros::Motor temp((std::int8_t)abs(i)); + temp.set_reversed(util::reversed_active(i)); left_motors.push_back(temp); } for (auto i : right_motor_ports) { - pros::Motor temp(abs(i), util::reversed_active(i)); + pros::Motor temp((std::int8_t)abs(i)); + temp.set_reversed(util::reversed_active(i)); right_motors.push_back(temp); } @@ -59,11 +61,13 @@ Drive::Drive(std::vector left_motor_ports, std::vector right_motor_por // Set ports to a global vector for (auto i : left_motor_ports) { - pros::Motor temp(abs(i), util::reversed_active(i)); + pros::Motor temp(abs(i)); + temp.set_reversed(util::reversed_active(i)); left_motors.push_back(temp); } for (auto i : right_motor_ports) { - pros::Motor temp(abs(i), util::reversed_active(i)); + pros::Motor temp(abs(i)); + temp.set_reversed(util::reversed_active(i)); right_motors.push_back(temp); } @@ -90,11 +94,13 @@ Drive::Drive(std::vector left_motor_ports, std::vector right_motor_por // Set ports to a global vector for (auto i : left_motor_ports) { - pros::Motor temp(abs(i), util::reversed_active(i)); + pros::Motor temp(abs(i)); + temp.set_reversed(util::reversed_active(i)); left_motors.push_back(temp); } for (auto i : right_motor_ports) { - pros::Motor temp(abs(i), util::reversed_active(i)); + pros::Motor temp(abs(i)); + temp.set_reversed(util::reversed_active(i)); right_motors.push_back(temp); } @@ -123,11 +129,13 @@ Drive::Drive(std::vector left_motor_ports, std::vector right_motor_por // Set ports to a global vector for (auto i : left_motor_ports) { - pros::Motor temp(abs(i), util::reversed_active(i)); + pros::Motor temp(abs(i)); + temp.set_reversed(util::reversed_active(i)); left_motors.push_back(temp); } for (auto i : right_motor_ports) { - pros::Motor temp(abs(i), util::reversed_active(i)); + pros::Motor temp(abs(i)); + temp.set_reversed(util::reversed_active(i)); right_motors.push_back(temp); } @@ -141,11 +149,14 @@ Drive::Drive(std::vector left_motor_ports, std::vector right_motor_por } void Drive::drive_defaults_set() { + std::cout << std::fixed; + std::cout << std::setprecision(2); + // PID Constants - pid_heading_constants_set(3, 0, 20, 0); - pid_drive_constants_set(10, 0, 100, 0); - pid_turn_constants_set(3, 0, 20, 0); - pid_swing_constants_set(5, 0, 30, 0); + pid_heading_constants_set(11, 0, 20, 0); + pid_drive_constants_set(20, 0, 100, 0); + pid_turn_constants_set(3, 0.05, 20, 15); + pid_swing_constants_set(6, 0, 65); pid_turn_min_set(30); pid_swing_min_set(30); @@ -153,9 +164,13 @@ void Drive::drive_defaults_set() { slew_drive_constants_set(7_in, 80); // Exit condition constants - pid_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms); - pid_swing_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms); - pid_drive_exit_condition_set(300_ms, 1_in, 500_ms, 3_in, 750_ms, 750_ms); + pid_turn_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms); + pid_swing_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms); + pid_drive_exit_condition_set(80_ms, 1_in, 250_ms, 3_in, 500_ms, 500_ms); + + pid_turn_chain_constant_set(3_deg); + pid_swing_chain_constant_set(5_deg); + pid_drive_chain_constant_set(3_in); // Modify joystick curve on controller (defaults to disabled) opcontrol_curve_buttons_toggle(true); @@ -185,6 +200,9 @@ double Drive::drive_tick_per_inch() { } void Drive::drive_ratio_set(double ratio) { RATIO = ratio; } +double Drive::drive_ratio_get() { return RATIO; } +void Drive::drive_rpm_set(double rpm) { CARTRIDGE = rpm; } +double Drive::drive_rpm_get() { return CARTRIDGE; } void Drive::private_drive_set(int left, int right) { if (pros::millis() < 1500) return; @@ -265,7 +283,11 @@ double Drive::drive_mA_left() { return left_motors.front().get_current_draw(); } bool Drive::drive_current_left_over() { return left_motors.front().is_over_current(); } void Drive::drive_imu_reset(double new_heading) { imu.set_rotation(new_heading); } -double Drive::drive_imu_get() { return imu.get_rotation(); } +double Drive::drive_imu_get() { return imu.get_rotation() * IMU_SCALER; } +double Drive::drive_imu_accel_get() { return imu.get_accel().x + imu.get_accel().y; } + +void Drive::drive_imu_scaler_set(double scaler) { IMU_SCALER = scaler; } +double Drive::drive_imu_scaler_get() { return IMU_SCALER; } void Drive::drive_imu_display_loading(int iter) { // If the lcd is already initialized, don't run this function @@ -275,7 +297,7 @@ void Drive::drive_imu_display_loading(int iter) { int boarder = 50; // Create the boarder - pros::screen::set_pen(COLOR_WHITE); + pros::screen::set_pen(pros::c::COLOR_WHITE); for (int i = 1; i < 3; i++) { pros::screen::draw_rect(boarder + i, boarder + i, 480 - boarder - i, 240 - boarder - i); } @@ -291,7 +313,7 @@ void Drive::drive_imu_display_loading(int iter) { // Failsafe time else { static int last_x1 = boarder; - pros::screen::set_pen(COLOR_RED); + pros::screen::set_pen(pros::c::COLOR_RED); int x1 = ((iter - 2000) * ((480 - (boarder * 2)) / 1000.0)) + boarder; pros::screen::fill_rect(last_x1, boarder, x1, 240 - boarder); last_x1 = x1; @@ -301,13 +323,22 @@ void Drive::drive_imu_display_loading(int iter) { bool Drive::drive_imu_calibrate(bool run_loading_animation) { imu.reset(); int iter = 0; + bool current_status = imu.is_calibrating(); + bool last_status = current_status; + bool successful = false; while (true) { iter += util::DELAY_TIME; if (run_loading_animation) drive_imu_display_loading(iter); + if (!successful) { + last_status = current_status; + current_status = imu.is_calibrating(); + successful = !current_status && last_status ? true : false; + } + if (iter >= 2000) { - if (!(imu.get_status() & pros::c::E_IMU_STATUS_CALIBRATING)) { + if (successful) { break; } if (iter >= 3000) { diff --git a/src/EZ-Template/drive/exit_conditions.cpp b/src/EZ-Template/drive/exit_conditions.cpp index 460f8229..51747384 100644 --- a/src/EZ-Template/drive/exit_conditions.cpp +++ b/src/EZ-Template/drive/exit_conditions.cpp @@ -9,53 +9,57 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. using namespace ez; -void Drive::pid_drive_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout) { +void Drive::pid_drive_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu) { leftPID.exit_condition_set(p_small_exit_time, p_small_error, p_big_exit_time, p_big_error, p_velocity_exit_time, p_mA_timeout); rightPID.exit_condition_set(p_small_exit_time, p_small_error, p_big_exit_time, p_big_error, p_velocity_exit_time, p_mA_timeout); + leftPID.velocity_sensor_secondary_toggle_set(use_imu); + rightPID.velocity_sensor_secondary_toggle_set(use_imu); } -void Drive::pid_drive_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QLength p_small_error, okapi::QTime p_big_exit_time, okapi::QLength p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout) { +void Drive::pid_drive_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QLength p_small_error, okapi::QTime p_big_exit_time, okapi::QLength p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu) { // Convert okapi units to doubles double se = p_small_error.convert(okapi::inch); double be = p_big_error.convert(okapi::inch); - double set = p_small_exit_time.convert(okapi::millisecond); - double bet = p_big_exit_time.convert(okapi::millisecond); - double vet = p_velocity_exit_time.convert(okapi::millisecond); - double mAt = p_mA_timeout.convert(okapi::millisecond); + int set = p_small_exit_time.convert(okapi::millisecond); + int bet = p_big_exit_time.convert(okapi::millisecond); + int vet = p_velocity_exit_time.convert(okapi::millisecond); + int mAt = p_mA_timeout.convert(okapi::millisecond); - pid_drive_exit_condition_set(set, se, bet, be, vet, mAt); + pid_drive_exit_condition_set(set, se, bet, be, vet, mAt, use_imu); } -void Drive::pid_turn_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout) { +void Drive::pid_turn_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu) { turnPID.exit_condition_set(p_small_exit_time, p_small_error, p_big_exit_time, p_big_error, p_velocity_exit_time, p_mA_timeout); + turnPID.velocity_sensor_secondary_toggle_set(use_imu); } -void Drive::pid_turn_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout) { +void Drive::pid_turn_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu) { // Convert okapi units to doubles double se = p_small_error.convert(okapi::degree); double be = p_big_error.convert(okapi::degree); - double set = p_small_exit_time.convert(okapi::millisecond); - double bet = p_big_exit_time.convert(okapi::millisecond); - double vet = p_velocity_exit_time.convert(okapi::millisecond); - double mAt = p_mA_timeout.convert(okapi::millisecond); + int set = p_small_exit_time.convert(okapi::millisecond); + int bet = p_big_exit_time.convert(okapi::millisecond); + int vet = p_velocity_exit_time.convert(okapi::millisecond); + int mAt = p_mA_timeout.convert(okapi::millisecond); - pid_turn_exit_condition_set(set, se, bet, be, vet, mAt); + pid_turn_exit_condition_set(set, se, bet, be, vet, mAt, use_imu); } -void Drive::pid_swing_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout) { +void Drive::pid_swing_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu) { swingPID.exit_condition_set(p_small_exit_time, p_small_error, p_big_exit_time, p_big_error, p_velocity_exit_time, p_mA_timeout); + swingPID.velocity_sensor_secondary_toggle_set(use_imu); } -void Drive::pid_swing_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout) { +void Drive::pid_swing_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, bool use_imu) { // Convert okapi units to doubles double se = p_small_error.convert(okapi::degree); double be = p_big_error.convert(okapi::degree); - double set = p_small_exit_time.convert(okapi::millisecond); - double bet = p_big_exit_time.convert(okapi::millisecond); - double vet = p_velocity_exit_time.convert(okapi::millisecond); - double mAt = p_mA_timeout.convert(okapi::millisecond); + int set = p_small_exit_time.convert(okapi::millisecond); + int bet = p_big_exit_time.convert(okapi::millisecond); + int vet = p_velocity_exit_time.convert(okapi::millisecond); + int mAt = p_mA_timeout.convert(okapi::millisecond); - pid_swing_exit_condition_set(set, se, bet, be, vet, mAt); + pid_swing_exit_condition_set(set, se, bet, be, vet, mAt, use_imu); } // User wrapper for exit condition @@ -67,11 +71,13 @@ void Drive::pid_wait() { exit_output left_exit = RUNNING; exit_output right_exit = RUNNING; while (left_exit == RUNNING || right_exit == RUNNING) { + leftPID.velocity_sensor_secondary_set(drive_imu_accel_get()); + rightPID.velocity_sensor_secondary_set(drive_imu_accel_get()); left_exit = left_exit != RUNNING ? left_exit : leftPID.exit_condition(left_motors[0]); right_exit = right_exit != RUNNING ? right_exit : rightPID.exit_condition(right_motors[0]); pros::delay(util::DELAY_TIME); } - if (print_toggle) std::cout << " Left: " << exit_to_string(left_exit) << " Exit, error: " << leftPID.error << ". Right: " << exit_to_string(right_exit) << " Exit, error: " << rightPID.error << ".\n"; + if (print_toggle) std::cout << " Left: " << exit_to_string(left_exit) << " Exit, error: " << leftPID.error << " Right: " << exit_to_string(right_exit) << " Exit, error: " << rightPID.error << "\n"; if (left_exit == mA_EXIT || left_exit == VELOCITY_EXIT || right_exit == mA_EXIT || right_exit == VELOCITY_EXIT) { interfered = true; @@ -82,10 +88,11 @@ void Drive::pid_wait() { else if (mode == TURN) { exit_output turn_exit = RUNNING; while (turn_exit == RUNNING) { + turnPID.velocity_sensor_secondary_set(drive_imu_accel_get()); turn_exit = turn_exit != RUNNING ? turn_exit : turnPID.exit_condition({left_motors[0], right_motors[0]}); pros::delay(util::DELAY_TIME); } - if (print_toggle) std::cout << " Turn: " << exit_to_string(turn_exit) << " Exit, error: " << turnPID.error << ".\n"; + if (print_toggle) std::cout << " Turn: " << exit_to_string(turn_exit) << " Exit, error: " << turnPID.error << "\n"; if (turn_exit == mA_EXIT || turn_exit == VELOCITY_EXIT) { interfered = true; @@ -97,10 +104,11 @@ void Drive::pid_wait() { exit_output swing_exit = RUNNING; pros::Motor& sensor = current_swing == ez::LEFT_SWING ? left_motors[0] : right_motors[0]; while (swing_exit == RUNNING) { + swingPID.velocity_sensor_secondary_set(drive_imu_accel_get()); swing_exit = swing_exit != RUNNING ? swing_exit : swingPID.exit_condition(sensor); pros::delay(util::DELAY_TIME); } - if (print_toggle) std::cout << " Swing: " << exit_to_string(swing_exit) << " Exit, error: " << swingPID.error << ".\n"; + if (print_toggle) std::cout << " Swing: " << exit_to_string(swing_exit) << " Exit, error: " << swingPID.error << "\n"; if (swing_exit == mA_EXIT || swing_exit == VELOCITY_EXIT) { interfered = true; @@ -135,12 +143,16 @@ void Drive::wait_until_drive(double target) { // Before robot has reached target, use the exit conditions to avoid getting stuck in this while loop if (util::sgn(l_error) == l_sgn || util::sgn(r_error) == r_sgn) { if (left_exit == RUNNING || right_exit == RUNNING) { + leftPID.velocity_sensor_secondary_set(drive_imu_accel_get()); + rightPID.velocity_sensor_secondary_set(drive_imu_accel_get()); left_exit = left_exit != RUNNING ? left_exit : leftPID.exit_condition(left_motors[0]); right_exit = right_exit != RUNNING ? right_exit : rightPID.exit_condition(right_motors[0]); pros::delay(util::DELAY_TIME); } else { - if (print_toggle) std::cout << " Left: " << exit_to_string(left_exit) << " Wait Until Exit. Right: " << exit_to_string(right_exit) << " Wait Until Exit.\n"; - + if (print_toggle) { + std::cout << " Left: " << exit_to_string(left_exit) << " Wait Until Exit Failsafe, triggered at " << drive_sensor_left() - l_start << " instead of " << l_tar << "\n"; + std::cout << " Right: " << exit_to_string(right_exit) << " Wait Until Exit Failsafe, triggered at " << drive_sensor_right() - r_start << " instead of " << r_tar << "\n"; + } if (left_exit == mA_EXIT || left_exit == VELOCITY_EXIT || right_exit == mA_EXIT || right_exit == VELOCITY_EXIT) { interfered = true; } @@ -149,7 +161,9 @@ void Drive::wait_until_drive(double target) { } // Once we've past target, return else if (util::sgn(l_error) != l_sgn || util::sgn(r_error) != r_sgn) { - if (print_toggle) printf(" Drive Wait Until Exit. Left: %f Right: %f\n", drive_sensor_left() - l_start, drive_sensor_right() - r_start); + if (print_toggle) printf(" Drive Wait Until Exit Success. Triggered at: L,R(%.2f, %.2f) Target: L,R(%.2f, %.2f)\n", drive_sensor_left() - l_start, drive_sensor_right() - r_start, l_tar, r_tar); + leftPID.timers_reset(); + rightPID.timers_reset(); return; } @@ -182,10 +196,11 @@ void Drive::wait_until_turn_swing(double target) { // Before robot has reached target, use the exit conditions to avoid getting stuck in this while loop if (util::sgn(g_error) == g_sgn) { if (turn_exit == RUNNING) { + turnPID.velocity_sensor_secondary_set(drive_imu_accel_get()); turn_exit = turn_exit != RUNNING ? turn_exit : turnPID.exit_condition({left_motors[0], right_motors[0]}); pros::delay(util::DELAY_TIME); } else { - if (print_toggle) std::cout << " Turn: " << exit_to_string(turn_exit) << " Wait Until Exit.\n"; + if (print_toggle) std::cout << " Turn: " << exit_to_string(turn_exit) << " Wait Until Exit Failsafe, triggered at " << drive_imu_get() << " instead of " << target << "\n"; if (turn_exit == mA_EXIT || turn_exit == VELOCITY_EXIT) { interfered = true; @@ -195,7 +210,8 @@ void Drive::wait_until_turn_swing(double target) { } // Once we've past target, return else if (util::sgn(g_error) != g_sgn) { - if (print_toggle) printf(" Turn Wait Until Exit. Triggered at: %f\n", drive_imu_get()); + if (print_toggle) printf(" Turn Wait Until Exit Success, triggered at %.2f. Target: %.2f\n", drive_imu_get(), target); + turnPID.timers_reset(); return; } } @@ -205,10 +221,11 @@ void Drive::wait_until_turn_swing(double target) { // Before robot has reached target, use the exit conditions to avoid getting stuck in this while loop if (util::sgn(g_error) == g_sgn) { if (swing_exit == RUNNING) { + swingPID.velocity_sensor_secondary_set(drive_imu_accel_get()); swing_exit = swing_exit != RUNNING ? swing_exit : swingPID.exit_condition(sensor); pros::delay(util::DELAY_TIME); } else { - if (print_toggle) std::cout << " Swing: " << exit_to_string(swing_exit) << " Wait Until Exit.\n"; + if (print_toggle) std::cout << " Swing: " << exit_to_string(swing_exit) << " Wait Until Exit Failsafe, triggered at " << drive_imu_get() << " instead of " << target << "\n"; if (swing_exit == mA_EXIT || swing_exit == VELOCITY_EXIT) { interfered = true; @@ -218,7 +235,8 @@ void Drive::wait_until_turn_swing(double target) { } // Once we've past target, return else if (util::sgn(g_error) != g_sgn) { - if (print_toggle) std::cout << " Swing Wait Until Exit.\n"; + if (print_toggle) printf(" Swing Wait Until Exit Success, triggered at %.2f. Target: %.2f\n", drive_imu_get(), target); + swingPID.timers_reset(); return; } } @@ -256,4 +274,76 @@ void Drive::pid_wait_until(double target) { } else { printf("Not in a valid drive mode!\n"); } -} \ No newline at end of file +} + +// Pid wait, but quickly :) +void Drive::pid_wait_quick() { + if (!(mode == DRIVE || mode == TURN || mode == SWING)) { + printf("Not in a valid drive mode!\n"); + return; + } + + // This is the target the user set, not the modified chained target + pid_wait_until(chain_target_start); +} + +// Set drive motion chain constants +void Drive::pid_drive_chain_constant_set(double input) { + pid_drive_chain_forward_constant_set(input); + pid_drive_chain_backward_constant_set(input); +} +void Drive::pid_drive_chain_forward_constant_set(double input) { drive_forward_motion_chain_scale = fabs(input); } +void Drive::pid_drive_chain_backward_constant_set(double input) { drive_backward_motion_chain_scale = fabs(input); } +void Drive::pid_drive_chain_constant_set(okapi::QLength input) { pid_drive_chain_constant_set(input.convert(okapi::inch)); } +void Drive::pid_drive_chain_forward_constant_set(okapi::QLength input) { pid_drive_chain_forward_constant_set(input.convert(okapi::inch)); } +void Drive::pid_drive_chain_backward_constant_set(okapi::QLength input) { pid_drive_chain_backward_constant_set(input.convert(okapi::inch)); } + +// Set turn motion chain constants +void Drive::pid_turn_chain_constant_set(double input) { turn_motion_chain_scale = fabs(input); } +void Drive::pid_turn_chain_constant_set(okapi::QAngle input) { pid_turn_chain_constant_set(input.convert(okapi::degree)); } + +// Set swing motion chain constants +void Drive::pid_swing_chain_constant_set(double input) { + pid_swing_chain_forward_constant_set(input); + pid_swing_chain_backward_constant_set(input); +} +void Drive::pid_swing_chain_forward_constant_set(double input) { swing_forward_motion_chain_scale = fabs(input); } +void Drive::pid_swing_chain_backward_constant_set(double input) { swing_backward_motion_chain_scale = fabs(input); } +void Drive::pid_swing_chain_constant_set(okapi::QAngle input) { pid_swing_chain_constant_set(input.convert(okapi::degree)); } +void Drive::pid_swing_chain_forward_constant_set(okapi::QAngle input) { pid_swing_chain_forward_constant_set(input.convert(okapi::degree)); } +void Drive::pid_swing_chain_backward_constant_set(okapi::QAngle input) { pid_swing_chain_backward_constant_set(input.convert(okapi::degree)); } + +// Get motion chain constants +double Drive::pid_drive_chain_forward_constant_get() { return drive_forward_motion_chain_scale; } +double Drive::pid_drive_chain_backward_constant_get() { return drive_backward_motion_chain_scale; } +double Drive::pid_turn_chain_constant_get() { return turn_motion_chain_scale; } +double Drive::pid_swing_chain_forward_constant_get() { return swing_forward_motion_chain_scale; } +double Drive::pid_swing_chain_backward_constant_get() { return swing_backward_motion_chain_scale; } + +// Pid wait that hold momentum into the next motion +void Drive::pid_wait_quick_chain() { + // If driving, add drive_motion_chain_scale to target + if (mode == DRIVE) { + double chain_scale = motion_chain_backward ? drive_backward_motion_chain_scale : drive_forward_motion_chain_scale; + used_motion_chain_scale = chain_scale * util::sgn(chain_target_start); + leftPID.target_set(leftPID.target_get() + used_motion_chain_scale); + rightPID.target_set(rightPID.target_get() + used_motion_chain_scale); + } + // If turning, add turn_motion_chain_scale to target + else if (mode == TURN) { + used_motion_chain_scale = turn_motion_chain_scale * util::sgn(chain_target_start - chain_sensor_start); + turnPID.target_set(turnPID.target_get() + used_motion_chain_scale); + } + // If swinging, add swing_motion_chain_scale to target + else if (mode == SWING) { + double chain_scale = motion_chain_backward ? swing_backward_motion_chain_scale : swing_forward_motion_chain_scale; + used_motion_chain_scale = chain_scale * util::sgn(chain_target_start - chain_sensor_start); + swingPID.target_set(swingPID.target_get() + used_motion_chain_scale); + } else { + printf("Not in a valid drive mode!\n"); + return; + } + + // Exit at the real target + pid_wait_quick(); +} diff --git a/src/EZ-Template/drive/pid_tasks.cpp b/src/EZ-Template/drive/pid_tasks.cpp index a9ecbdee..2456051c 100644 --- a/src/EZ-Template/drive/pid_tasks.cpp +++ b/src/EZ-Template/drive/pid_tasks.cpp @@ -46,27 +46,31 @@ void Drive::drive_pid_task() { slew_left.iterate(drive_sensor_left()); slew_right.iterate(drive_sensor_right()); - // Clip leftPID and rightPID to slew (if slew is disabled, it returns max_speed) - double l_drive_out = util::clamp(leftPID.output, slew_left.output(), -slew_left.output()); - double r_drive_out = util::clamp(rightPID.output, slew_right.output(), -slew_right.output()); + // Left and Right outputs + double l_drive_out = leftPID.output; + double r_drive_out = rightPID.output; + + // Scale leftPID and rightPID to slew (if slew is disabled, it returns max_speed) + double max_slew_out = fmin(slew_left.output(), slew_right.output()); + double faster_side = fmax(fabs(l_drive_out), fabs(r_drive_out)); + if (faster_side > max_slew_out) { + l_drive_out = l_drive_out * (max_slew_out / faster_side); + r_drive_out = r_drive_out * (max_slew_out / faster_side); + } // Toggle heading - double gyro_out = heading_on ? headingPID.output : 0; + double imu_out = heading_on ? headingPID.output : 0; // Combine heading and drive - double l_out = l_drive_out + gyro_out; - double r_out = r_drive_out - gyro_out; - - // Vector scaling - double max_slew_out = fmin(slew_left.output(), slew_right.output()); - if (fabs(l_out) > max_slew_out || fabs(r_out) > max_slew_out) { - if (fabs(l_out) > fabs(r_out)) { - r_out = r_out * (max_slew_out / fabs(l_out)); - l_out = util::clamp(l_out, max_slew_out, -max_slew_out); - } else { - l_out = l_out * (max_slew_out / fabs(r_out)); - r_out = util::clamp(r_out, max_slew_out, -max_slew_out); - } + double l_out = l_drive_out + imu_out; + double r_out = r_drive_out - imu_out; + + // Vector scaling when combining drive and imo + max_slew_out = fmin(slew_left.output(), slew_right.output()); + faster_side = fmax(fabs(l_out), fabs(r_out)); + if (faster_side > max_slew_out) { + l_out = l_out * (max_slew_out / faster_side); + r_out = r_out * (max_slew_out / faster_side); } // Set motors diff --git a/src/EZ-Template/drive/pid_tuner.cpp b/src/EZ-Template/drive/pid_tuner.cpp index 77fa4f44..092518f3 100644 --- a/src/EZ-Template/drive/pid_tuner.cpp +++ b/src/EZ-Template/drive/pid_tuner.cpp @@ -6,6 +6,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. #include "EZ-Template/api.hpp" #include "EZ-Template/sdcard.hpp" +#include "pros/llemu.hpp" #include "pros/misc.h" // Is the PID Tuner enabled? diff --git a/src/EZ-Template/drive/set_pid.cpp b/src/EZ-Template/drive/set_pid.cpp index 524df281..8ed3d259 100644 --- a/src/EZ-Template/drive/set_pid.cpp +++ b/src/EZ-Template/drive/set_pid.cpp @@ -90,6 +90,10 @@ PID::Constants Drive::pid_heading_constants_get() { // Updates max speed void Drive::pid_speed_max_set(int speed) { max_speed = abs(util::clamp(speed, 127, -127)); + slew_left.speed_max_set(max_speed); + slew_right.speed_max_set(max_speed); + slew_turn.speed_max_set(max_speed); + slew_swing.speed_max_set(max_speed); } int Drive::pid_speed_max_get() { @@ -129,10 +133,16 @@ int Drive::pid_swing_min_get() { return swing_min; } // Set drive PID raw void Drive::pid_drive_set(double target, int speed, bool slew_on, bool toggle_heading) { + leftPID.timers_reset(); + rightPID.timers_reset(); + // Print targets - if (print_toggle) printf("Drive Started... Target Value: %f in", target); + if (print_toggle) printf("Drive Started... Target Value: %.2f", target); if (slew_on && print_toggle) printf(" with slew"); if (print_toggle) printf("\n"); + chain_target_start = target; + chain_sensor_start = drive_sensor_left(); + used_motion_chain_scale = 0.0; // Global setup pid_speed_max_set(speed); @@ -153,10 +163,11 @@ void Drive::pid_drive_set(double target, int speed, bool slew_on, bool toggle_he if (l_target_encoder < l_start && r_target_encoder < r_start) { pid_consts = backward_drivePID.constants_get(); slew_consts = slew_backward.constants_get(); - + motion_chain_backward = true; } else { pid_consts = forward_drivePID.constants_get(); slew_consts = slew_forward.constants_get(); + motion_chain_backward = false; } leftPID.constants_set(pid_consts.kp, pid_consts.ki, pid_consts.kd, pid_consts.start_i); rightPID.constants_set(pid_consts.kp, pid_consts.ki, pid_consts.kd, pid_consts.start_i); @@ -183,8 +194,13 @@ void Drive::pid_drive_set(okapi::QLength p_target, int speed, bool slew_on, bool // Raw Set Turn PID void Drive::pid_turn_set(double target, int speed, bool slew_on) { + turnPID.timers_reset(); + // Print targets - if (print_toggle) printf("Turn Started... Target Value: %f\n", target); + if (print_toggle) printf("Turn Started... Target Value: %.2f\n", target); + chain_sensor_start = drive_imu_get(); + chain_target_start = target; + used_motion_chain_scale = 0.0; // Set PID targets turnPID.target_set(target); @@ -192,7 +208,7 @@ void Drive::pid_turn_set(double target, int speed, bool slew_on) { pid_speed_max_set(speed); // Initialize slew - slew_turn.initialize(slew_on, max_speed, target, drive_imu_get()); + slew_turn.initialize(slew_on, max_speed, target, chain_sensor_start); // Run task drive_mode_set(TURN); @@ -220,15 +236,18 @@ void Drive::pid_turn_relative_set(double target, int speed, bool slew_on) { // Raw Set Swing PID void Drive::pid_swing_set(e_swing type, double target, int speed, int opposite_speed, bool slew_on) { - // use left/right as 1 and -1, and multiply along with sgn of error to find if fwd or rev + swingPID.timers_reset(); // Print targets - if (print_toggle) printf("Swing Started... Target Value: %f\n", target); + if (print_toggle) printf("Swing Started... Target Value: %.2f\n", target); current_swing = type; + chain_sensor_start = drive_imu_get(); + chain_target_start = target; + used_motion_chain_scale = 0.0; // Figure out if going forward or backward int side = type == ez::LEFT_SWING ? 1 : -1; - int direction = util::sgn((target - drive_imu_get()) * side); + int direction = util::sgn((target - chain_sensor_start) * side); // Set constants according to the robots direction PID::Constants pid_consts; @@ -240,12 +259,14 @@ void Drive::pid_swing_set(e_swing type, double target, int speed, int opposite_s pid_swing_consts = backward_swingPID.constants_get(); slew_consts = slew_swing_backward.constants_get(); slew_swing_using_angle = slew_swing_rev_using_angle; + motion_chain_backward = true; } else { pid_consts = forward_drivePID.constants_get(); pid_swing_consts = forward_swingPID.constants_get(); slew_consts = slew_swing_forward.constants_get(); slew_swing_using_angle = slew_swing_fwd_using_angle; + motion_chain_backward = false; } // Set targets for the side that isn't moving @@ -264,7 +285,7 @@ void Drive::pid_swing_set(e_swing type, double target, int speed, int opposite_s // Initialize slew double slew_tar = slew_swing_using_angle ? target : direction * 100; - double current = slew_swing_using_angle ? drive_imu_get() : (current_swing == LEFT_SWING ? drive_sensor_left() : drive_sensor_right()); + double current = slew_swing_using_angle ? chain_sensor_start : (current_swing == LEFT_SWING ? drive_sensor_left() : drive_sensor_right()); slew_swing.initialize(slew_on, max_speed, slew_tar, current); // Run task diff --git a/src/EZ-Template/drive/user_input.cpp b/src/EZ-Template/drive/user_input.cpp index 04ced31e..f9761aab 100644 --- a/src/EZ-Template/drive/user_input.cpp +++ b/src/EZ-Template/drive/user_input.cpp @@ -167,10 +167,14 @@ void Drive::opcontrol_curve_buttons_iterate() { button_press(&r_decrease_, master.get_digital(r_decrease_.button), ([this] { this->r_decrease(); }), ([this] { this->save_r_curve_sd(); })); } - auto sr = std::to_string(right_curve_scale); - auto sl = std::to_string(left_curve_scale); + std::ostringstream short_sl, short_sr; + short_sl << std::fixed << std::setprecision(1) << left_curve_scale; + short_sr << std::fixed << std::setprecision(1) << right_curve_scale; + + auto sr = short_sr.str(); + auto sl = short_sl.str(); if (!is_tank) - master.set_text(2, 0, sl + " " + sr); + master.set_text(2, 0, sl + " " + sr); else master.set_text(2, 0, sl); } @@ -230,11 +234,10 @@ void Drive::opcontrol_joystick_threshold_iterate(int l_stick, int r_stick) { if (abs(l_stick) > 0 || abs(r_stick) > 0) { if (practice_mode_is_on && (abs(l_stick) > 120 || abs(r_stick) > 120)) drive_set(0, 0); + else if (is_reversed == true) + drive_set(-r_stick, -l_stick); else - if(is_reversed == true) - drive_set(-r_stick, -l_stick); - else - drive_set(l_stick, r_stick); + drive_set(l_stick, r_stick); if (active_brake_kp != 0) drive_sensor_reset(); } // When joys are released, run active brake (P) on drive diff --git a/src/EZ-Template/sdcard.cpp b/src/EZ-Template/sdcard.cpp index a4140002..9edea78e 100644 --- a/src/EZ-Template/sdcard.cpp +++ b/src/EZ-Template/sdcard.cpp @@ -4,9 +4,13 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "sdcard.hpp" + #include -#include "main.h" +#include "auton_selector.hpp" +#include "pros/llemu.hpp" +#include "util.hpp" namespace ez::as { AutonSelector auton_selector{}; @@ -29,9 +33,9 @@ void auton_selector_initialize() { FILE* as_usd_file_read; // If file exists... if ((as_usd_file_read = fopen("/usd/auto.txt", "r"))) { - char l_buf[5]; - fread(l_buf, 1, 5, as_usd_file_read); - ez::as::auton_selector.auton_page_current = std::stof(l_buf); + char a_buf[10]; + fread(a_buf, 1, 10, as_usd_file_read); + ez::as::auton_selector.auton_page_current = std::stof(a_buf); fclose(as_usd_file_read); } // If file doesn't exist, create file @@ -90,10 +94,10 @@ bool enabled() { return auton_selector_running; } bool turn_off = false; // Using a button to control the lcd -pros::ADIDigitalIn* limit_switch_left = nullptr; -pros::ADIDigitalIn* limit_switch_right = nullptr; +pros::adi::DigitalIn* limit_switch_left = nullptr; +pros::adi::DigitalIn* limit_switch_right = nullptr; pros::Task limit_switch_task(ez::as::limitSwitchTask); -void limit_switch_lcd_initialize(pros::ADIDigitalIn* right_limit, pros::ADIDigitalIn* left_limit) { +void limit_switch_lcd_initialize(pros::adi::DigitalIn* right_limit, pros::adi::DigitalIn* left_limit) { if (!left_limit && !right_limit) { delete limit_switch_left; delete limit_switch_right; diff --git a/src/EZ-Template/slew.cpp b/src/EZ-Template/slew.cpp index f75debed..34a3ff87 100644 --- a/src/EZ-Template/slew.cpp +++ b/src/EZ-Template/slew.cpp @@ -20,6 +20,9 @@ void slew::constants_set(double distance, int minimum_speed) { constants.distance_to_travel = distance; } +void slew::speed_max_set(double speed) { max_speed = speed; } +double slew::speed_max_get() { return max_speed; } + bool slew::enabled() { return is_enabled; } // Is slew currently enabled? double slew::output() { return last_output; } // Returns output slew::Constants slew::constants_get() { return constants; } // Get constants diff --git a/src/EZ-Template/util.cpp b/src/EZ-Template/util.cpp index 4ef769af..bbc3e0e0 100644 --- a/src/EZ-Template/util.cpp +++ b/src/EZ-Template/util.cpp @@ -56,7 +56,7 @@ void screen_print(std::string text, int line) { std::string temp = ""; for (int i = 0; i < text.length(); i++) { - if (text[i] != '\n' && temp.length() + 1 > 32) { + if (text[i] != '\n' && temp.length() + 1 > 38) { auto last_word = get_last_word(temp); if (last_word == temp) { texts.push_back(temp); diff --git a/src/autons.cpp b/src/autons.cpp index 65715767..2ccdb230 100644 --- a/src/autons.cpp +++ b/src/autons.cpp @@ -1,12 +1,12 @@ #include "main.h" ///// -// For installation, upgrading, documentations and tutorials, check out our website! +// For installation, upgrading, documentations, and tutorials, check out our website! // https://ez-robotics.github.io/EZ-Template/ ///// // These are out of 127 -const int DRIVE_SPEED = 110; +const int DRIVE_SPEED = 110; const int TURN_SPEED = 90; const int SWING_SPEED = 90; @@ -14,19 +14,22 @@ const int SWING_SPEED = 90; // Constants /// void default_constants() { - chassis.pid_heading_constants_set(3, 0, 20); - chassis.pid_drive_constants_set(10, 0, 100); - chassis.pid_turn_constants_set(3, 0, 20); - chassis.pid_swing_constants_set(5, 0, 30); + chassis.pid_heading_constants_set(11, 0, 20); + chassis.pid_drive_constants_set(20, 0, 100); + chassis.pid_turn_constants_set(3, 0.05, 20, 15); + chassis.pid_swing_constants_set(6, 0, 65); - chassis.pid_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms); - chassis.pid_swing_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms); - chassis.pid_drive_exit_condition_set(300_ms, 1_in, 500_ms, 3_in, 750_ms, 750_ms); + chassis.pid_turn_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms); + chassis.pid_swing_exit_condition_set(80_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms); + chassis.pid_drive_exit_condition_set(80_ms, 1_in, 250_ms, 3_in, 500_ms, 500_ms); + + chassis.pid_turn_chain_constant_set(3_deg); + chassis.pid_swing_chain_constant_set(5_deg); + chassis.pid_drive_chain_constant_set(3_in); chassis.slew_drive_constants_set(7_in, 80); } - /// // Drive Example /// @@ -34,7 +37,7 @@ void drive_example() { // The first parameter is target inches // The second parameter is max speed the robot will drive at // The third parameter is a boolean (true or false) for enabling/disabling a slew at the start of drive motions - // for slew, only enable it when the drive distance is greater then the slew distance + a few inches + // for slew, only enable it when the drive distance is greater than the slew distance + a few inches chassis.pid_drive_set(24_in, DRIVE_SPEED, true); chassis.pid_wait(); @@ -50,7 +53,7 @@ void drive_example() { // Turn Example /// void turn_example() { - // The first parameter is target degrees + // The first parameter is the target in degrees // The second parameter is max speed the robot will drive at chassis.pid_turn_set(90_deg, TURN_SPEED); @@ -89,10 +92,10 @@ void drive_and_turn() { void wait_until_change_speed() { // pid_wait_until will wait until the robot gets to a desired position - // When the robot gets to 6 inches, the robot will travel the remaining distance at a max speed of 30 - chassis.pid_drive_set(24_in, DRIVE_SPEED, true); + // When the robot gets to 6 inches slowly, the robot will travel the remaining distance at full speed + chassis.pid_drive_set(24_in, 30, true); chassis.pid_wait_until(6_in); - chassis.pid_speed_max_set(30); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 30 speed + chassis.pid_speed_max_set(DRIVE_SPEED); // After driving 6 inches at 30 speed, the robot will go the remaining distance at DRIVE_SPEED chassis.pid_wait(); chassis.pid_turn_set(45_deg, TURN_SPEED); @@ -104,10 +107,10 @@ void wait_until_change_speed() { chassis.pid_turn_set(0_deg, TURN_SPEED); chassis.pid_wait(); - // When the robot gets to -6 inches, the robot will travel the remaining distance at a max speed of 30 - chassis.pid_drive_set(-24_in, DRIVE_SPEED, true); + // When the robot gets to -6 inches slowly, the robot will travel the remaining distance at full speed + chassis.pid_drive_set(-24_in, 30, true); chassis.pid_wait_until(-6_in); - chassis.pid_speed_max_set(30); // After driving 6 inches at DRIVE_SPEED, the robot will go the remaining distance at 30 speed + chassis.pid_speed_max_set(DRIVE_SPEED); // After driving 6 inches at 30 speed, the robot will go the remaining distance at DRIVE_SPEED chassis.pid_wait(); } @@ -116,8 +119,8 @@ void wait_until_change_speed() { /// void swing_example() { // The first parameter is ez::LEFT_SWING or ez::RIGHT_SWING - // The second parameter is target degrees - // The third parameter is speed of the moving side of the drive + // The second parameter is the target in degrees + // The third parameter is the speed of the moving side of the drive // The fourth parameter is the speed of the still side of the drive, this allows for wider arcs chassis.pid_swing_set(ez::LEFT_SWING, 45_deg, SWING_SPEED, 45); @@ -133,6 +136,30 @@ void swing_example() { chassis.pid_wait(); } +/// +// Motion Chaining +/// +void motion_chaining() { + // Motion chaining is where motions all try to blend together instead of individual movements. + // This works by exiting while the robot is still moving a little bit. + // To use this, replace pid_wait with pid_wait_quick_chain. + chassis.pid_drive_set(24_in, DRIVE_SPEED, true); + chassis.pid_wait(); + + chassis.pid_turn_set(45_deg, TURN_SPEED); + chassis.pid_wait_quick_chain(); + + chassis.pid_turn_set(-45_deg, TURN_SPEED); + chassis.pid_wait_quick_chain(); + + chassis.pid_turn_set(0_deg, TURN_SPEED); + chassis.pid_wait(); + + // Your final motion should still be a normal pid_wait + chassis.pid_drive_set(-24_in, DRIVE_SPEED, true); + chassis.pid_wait(); +} + /// // Auto that tests everything /// @@ -158,7 +185,7 @@ void combining_movements() { /// void tug(int attempts) { for (int i = 0; i < attempts - 1; i++) { - // Attempt to drive backwards + // Attempt to drive backward printf("i - %i", i); chassis.pid_drive_set(-12_in, 127); chassis.pid_wait(); @@ -169,15 +196,15 @@ void tug(int attempts) { chassis.pid_drive_set(-2_in, 20); pros::delay(1000); } - // If robot successfully drove back, return + // If the robot successfully drove back, return else { return; } } } -// If there is no interference, robot will drive forward and turn 90 degrees. -// If interfered, robot will drive forward and then attempt to drive backwards. +// If there is no interference, the robot will drive forward and turn 90 degrees. +// If interfered, the robot will drive forward and then attempt to drive backward. void interfered_example() { chassis.pid_drive_set(24_in, DRIVE_SPEED, true); chassis.pid_wait(); diff --git a/src/main.cpp b/src/main.cpp index 4f5d144c..162f2391 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,37 +1,19 @@ #include "main.h" ///// -// For installation, upgrading, documentations and tutorials, check out our website! +// For installation, upgrading, documentations, and tutorials, check out our website! // https://ez-robotics.github.io/EZ-Template/ ///// - // Chassis constructor -ez::Drive chassis ( - // Left Chassis Ports (negative port will reverse it!) - // the first port is used as the sensor - {-7, -6, -8, 20} - - // Right Chassis Ports (negative port will reverse it!) - // the first port is used as the sensor - ,{-12, 2, 5, 11} - - // IMU Port - ,15 - - // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!) - ,4.0 - - // Cartridge RPM - ,400 - - // External Gear Ratio (MUST BE DECIMAL) This is WHEEL GEAR / MOTOR GEAR - // eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 84/36 which is 2.333 - // eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 36/60 which is 0.6 - ,1.0 -); - +ez::Drive chassis( + // These are your drive motors, the first motor is used for sensing! + {-5, -6, -7, -8}, // Left Chassis Ports (negative port will reverse it!) + {11, 15, 16, 17}, // Right Chassis Ports (negative port will reverse it!) + 21, // IMU Port + 4.125, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!) + 420); // Wheel RPM /** * Runs initialization code. This occurs as soon as the program is started. @@ -42,28 +24,31 @@ ez::Drive chassis ( void initialize() { // Print our branding over your terminal :D ez::ez_template_print(); - - pros::delay(500); // Stop the user from doing anything while legacy ports configure + + pros::delay(500); // Stop the user from doing anything while legacy ports configure // Configure your chassis controls - chassis.opcontrol_curve_buttons_toggle(true); // Enables modifying the controller curve with buttons on the joysticks - chassis.opcontrol_drive_activebrake_set(0); // Sets the active brake kP. We recommend 2. - chassis.opcontrol_curve_default_set(0, 0); // Defaults for curve. If using tank, only the first parameter is used. (Comment this line out if you have an SD card!) - default_constants(); // Set the drive to your own constants from autons.cpp! + chassis.opcontrol_curve_buttons_toggle(true); // Enables modifying the controller curve with buttons on the joysticks + chassis.opcontrol_drive_activebrake_set(0); // Sets the active brake kP. We recommend ~2. 0 will disable. + chassis.opcontrol_curve_default_set(0, 0); // Defaults for curve. If using tank, only the first parameter is used. (Comment this line out if you have an SD card!) + + // Set the drive to your own constants from autons.cpp! + default_constants(); // These are already defaulted to these buttons, but you can change the left/right curve buttons here! - // chassis.opcontrol_curve_buttons_left_set (pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT); // If using tank, only the left side is used. - // chassis.opcontrol_curve_buttons_right_set(pros::E_CONTROLLER_DIGITAL_Y, pros::E_CONTROLLER_DIGITAL_A); + // chassis.opcontrol_curve_buttons_left_set(pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT); // If using tank, only the left side is used. + // chassis.opcontrol_curve_buttons_right_set(pros::E_CONTROLLER_DIGITAL_Y, pros::E_CONTROLLER_DIGITAL_A); // Autonomous Selector using LLEMU ez::as::auton_selector.autons_add({ - Auton("Example Drive\n\nDrive forward and come back.", drive_example), - Auton("Example Turn\n\nTurn 3 times.", turn_example), - Auton("Drive and Turn\n\nDrive forward, turn, come back. ", drive_and_turn), - Auton("Drive and Turn\n\nSlow down during drive.", wait_until_change_speed), - Auton("Swing Example\n\nSwing in an 'S' curve", swing_example), - Auton("Combine all 3 movements", combining_movements), - Auton("Interference\n\nAfter driving forward, robot performs differently if interfered or not.", interfered_example), + Auton("Example Drive\n\nDrive forward and come back.", drive_example), + Auton("Example Turn\n\nTurn 3 times.", turn_example), + Auton("Drive and Turn\n\nDrive forward, turn, come back. ", drive_and_turn), + Auton("Drive and Turn\n\nSlow down during drive.", wait_until_change_speed), + Auton("Swing Example\n\nSwing in an 'S' curve", swing_example), + Auton("Motion Chaining\n\nDrive forward, turn, and come back, but blend everything together :D", motion_chaining), + Auton("Combine all 3 movements", combining_movements), + Auton("Interference\n\nAfter driving forward, robot performs differently if interfered or not.", interfered_example), }); // Initialize chassis and auton selector @@ -72,8 +57,6 @@ void initialize() { master.rumble("."); } - - /** * Runs while the robot is in the disabled state of Field Management System or * the VEX Competition Switch, following either autonomous or opcontrol. When @@ -83,8 +66,6 @@ void disabled() { // . . . } - - /** * Runs after initialize(), and before autonomous when connected to the Field * Management System or the VEX Competition Switch. This is intended for @@ -98,8 +79,6 @@ void competition_initialize() { // . . . } - - /** * Runs the user autonomous code. This function will be started in its own task * with the default priority and stack size whenever the robot is enabled via @@ -112,16 +91,14 @@ void competition_initialize() { * from where it left off. */ void autonomous() { - chassis.pid_targets_reset(); // Resets PID targets to 0 - chassis.drive_imu_reset(); // Reset gyro position to 0 - chassis.drive_sensor_reset(); // Reset drive sensors to 0 - chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency + chassis.pid_targets_reset(); // Resets PID targets to 0 + chassis.drive_imu_reset(); // Reset gyro position to 0 + chassis.drive_sensor_reset(); // Reset drive sensors to 0 + chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency - ez::as::auton_selector.selected_auton_call(); // Calls selected auton from autonomous selector + ez::as::auton_selector.selected_auton_call(); // Calls selected auton from autonomous selector } - - /** * Runs the operator control code. This function will be started in its own task * with the default priority and stack size whenever the robot is enabled via @@ -137,37 +114,40 @@ void autonomous() { */ void opcontrol() { // This is preference to what you like to drive on - chassis.drive_brake_set(MOTOR_BRAKE_COAST); - + pros::motor_brake_mode_e_t driver_preference_brake = MOTOR_BRAKE_COAST; + + chassis.drive_brake_set(driver_preference_brake); + while (true) { - // PID Tuner // After you find values that you're happy with, you'll have to set them in auton.cpp - if (!pros::competition::is_connected()) { + if (!pros::competition::is_connected()) { // Enable / Disable PID Tuner // When enabled: // * use A and Y to increment / decrement the constants // * use the arrow keys to navigate the constants - if (master.get_digital_new_press(DIGITAL_X)) + if (master.get_digital_new_press(DIGITAL_X)) chassis.pid_tuner_toggle(); - + // Trigger the selected autonomous routine - if (master.get_digital_new_press(DIGITAL_B)) + if (master.get_digital(DIGITAL_B) && master.get_digital(DIGITAL_DOWN)) { autonomous(); + chassis.drive_brake_set(driver_preference_brake); + } - chassis.pid_tuner_iterate(); // Allow PID Tuner to iterate - } + chassis.pid_tuner_iterate(); // Allow PID Tuner to iterate + } - chassis.opcontrol_tank(); // Tank control - // chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade - // chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade - // chassis.opcontrol_arcade_flipped(ez::SPLIT); // Flipped split arcade - // chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade + // chassis.opcontrol_tank(); // Tank control + chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade + // chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade + // chassis.opcontrol_arcade_flipped(ez::SPLIT); // Flipped split arcade + // chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade // . . . // Put more user control code here! // . . . - pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME + pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME } -} +} \ No newline at end of file diff --git a/version b/version index 13d683cc..a0cd9f0c 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.0.1 \ No newline at end of file +3.1.0 \ No newline at end of file