diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d8cb7b87..964726c42 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,6 +15,15 @@ jobs: - uses: actions/checkout@v1 + - name: Install pip3 + run: sudo apt-get update && sudo apt-get install -y python3-pip + + - name: Install pros-cli + run: | + sudo apt-get install zlib1g-dev -y + pip3 install pyinstaller + pip3 install pros-cli + - name: Update Submodules run: git submodule update --init --recursive diff --git a/Makefile b/Makefile index a01ce4080..ab8d163a5 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ USE_PACKAGE:=0 # Set this to 1 to add additional rules to compile your project as a PROS library template IS_LIBRARY:=1 LIBNAME:=okapilib -VERSION:=4.8.0 +VERSION:=5.0.0 EXCLUDE_SRC_FROM_LIB=$(call rwildcard,$(SRCDIR)/test,*.*) # this line excludes opcontrol.c and similar files EXCLUDE_SRC_FROM_LIB+= $(foreach file, $(SRCDIR)/opcontrol $(SRCDIR)/initialize $(SRCDIR)/autonomous $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext))) diff --git a/Okapi_Notes.docx b/Okapi_Notes.docx new file mode 100644 index 000000000..3d22c4233 Binary files /dev/null and b/Okapi_Notes.docx differ diff --git a/common.mk b/common.mk index 778e6c705..1014a6a62 100644 --- a/common.mk +++ b/common.mk @@ -2,14 +2,27 @@ ARCHTUPLE=arm-none-eabi- DEVICE=VEX EDR V5 MFLAGS=-mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=softfp -Os -g -CPPFLAGS=-D_POSIX_THREADS -D_UNIX98_THREAD_MUTEX_ATTRIBUTES +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++17 + 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 @@ -201,7 +214,7 @@ library: $(LIBAR) .PHONY: template template: clean-template $(LIBAR) - $Dprosv5 c create-template . $(LIBNAME) $(VERSION) $(foreach file,$(TEMPLATE_FILES) $(LIBAR),--system "$(file)") --target v5 $(CREATE_TEMPLATE_FLAGS) + $Dpros c create-template . $(LIBNAME) $(VERSION) $(foreach file,$(TEMPLATE_FILES) $(LIBAR),--system "$(file)") --target v5 $(CREATE_TEMPLATE_FLAGS) endif # if project is a library source, compile the archive and link output.elf against the archive rather than source objects @@ -227,7 +240,7 @@ $(COLD_BIN): $(COLD_ELF) $(COLD_ELF): $(COLD_LIBRARIES) $(VV)mkdir -p $(dir $@) $(call test_output_2,Creating cold package with $(ARCHIVE_TEXT_LIST) ,$(LD) $(LDFLAGS) $(call wlprefix,--gc-keep-exported --whole-archive $^ -lstdc++ --no-whole-archive) $(call wlprefix,-T$(FWDIR)/v5.ld $(LNK_FLAGS) -o $@),$(OK_STRING)) - $(call test_output_2,Stripping cold package ,$(OBJCOPY) --strip-symbol=install_hot_table --strip-symbol=__libc_init_array --strip-symbol=_PROS_COMPILE_DIRECTORY --strip-symbol=_PROS_COMPILE_TIMESTAMP $@ $@, $(DONE_STRING)) + $(call test_output_2,Stripping cold package ,$(OBJCOPY) --strip-symbol=install_hot_table --strip-symbol=__libc_init_array --strip-symbol=_PROS_COMPILE_DIRECTORY --strip-symbol=_PROS_COMPILE_TIMESTAMP --strip-symbol=_PROS_COMPILE_TIMESTAMP_INT $@ $@, $(DONE_STRING)) @echo Section sizes: -$(VV)$(SIZETOOL) $(SIZEFLAGS) $@ $(SIZES_SED) $(SIZES_NUMFMT) @@ -236,7 +249,7 @@ $(HOT_BIN): $(HOT_ELF) $(COLD_BIN) $(HOT_ELF): $(COLD_ELF) $(ELF_DEPS) $(call _pros_ld_timestamp) - $(call test_output_2,Linking hot project with $(COLD_ELF) and $(ARCHIVE_TEXT_LIST) ,$(LD) $(LDFLAGS) $(call wlprefix,-nostartfiles -R $<) $(filter-out $<,$^) $(LDTIMEOBJ) $(LIBRARIES) $(call wlprefix,-T$(FWDIR)/v5-hot.ld $(LNK_FLAGS) -o $@),$(OK_STRING)) + $(call test_output_2,Linking hot project with $(COLD_ELF) and $(ARCHIVE_TEXT_LIST) ,$(LD) -nostartfiles $(LDFLAGS) $(call wlprefix,-R $<) $(filter-out $<,$^) $(LDTIMEOBJ) $(LIBRARIES) $(call wlprefix,-T$(FWDIR)/v5-hot.ld $(LNK_FLAGS) -o $@),$(OK_STRING)) @printf "%s\n" "Section sizes:" -$(VV)$(SIZETOOL) $(SIZEFLAGS) $@ $(SIZES_SED) $(SIZES_NUMFMT) @@ -272,7 +285,15 @@ $(VV)mkdir -p $(dir $(LDTIMEOBJ)) @# Pipe a line of code defining _PROS_COMPILE_TOOLSTAMP and _PROS_COMPILE_DIRECTORY into GCC, @# which allows compilation from stdin. We define _PROS_COMPILE_DIRECTORY using a command line-defined macro @# which is the pwd | tail bit, which will truncate the path to the last 23 characters -$(call test_output_2,Adding timestamp ,echo 'char const * const _PROS_COMPILE_TIMESTAMP = __DATE__ " " __TIME__; char const * const _PROS_COMPILE_DIRECTORY = "$(shell pwd | tail -c 23)";' | $(CC) -c -x c $(CFLAGS) $(EXTRA_CFLAGS) -o $(LDTIMEOBJ) -,$(OK_STRING)) +@# +@# const int _PROS_COMPILE_TIMESTAMP_INT = $(( $(date +%s) - $(date +%z) * 3600 )) +@# char const * const _PROS_COMPILE_TIEMSTAMP = __DATE__ " " __TIME__ +@# char const * const _PROS_COMPILE_DIRECTORY = "$(shell pwd | tail -c 23)"; +@# +@# The shell command $$(($$(date +%s)+($$(date +%-z)/100*3600))) fetches the current +@# unix timestamp, and then adds the UTC timezone offset to account for time zones. + +$(call test_output_2,Adding timestamp ,echo 'const int _PROS_COMPILE_TIMESTAMP_INT = $(shell echo $$(($$(date +%s)+($$(date +%-z)/100*3600)))); char const * const _PROS_COMPILE_TIMESTAMP = __DATE__ " " __TIME__; char const * const _PROS_COMPILE_DIRECTORY = "$(wildcard $(shell pwd | tail -c 23))";' | $(CC) -c -x c $(CFLAGS) $(EXTRA_CFLAGS) -o $(LDTIMEOBJ) -,$(OK_STRING)) endef # these rules are for build-compile-commands, which just print out sysroot information diff --git a/firmware/libpros.a b/firmware/libpros.a index 39803bbbf..2a6551f69 100644 Binary files a/firmware/libpros.a and b/firmware/libpros.a differ diff --git a/firmware/v5-common.ld b/firmware/v5-common.ld index f1b64f011..762a90551 100644 --- a/firmware/v5-common.ld +++ b/firmware/v5-common.ld @@ -21,21 +21,21 @@ SECTIONS *(.gnu.linkonce.t.*) *(.plt) *(.gnu_warning) - *(.gcc_execpt_table) + *(.gcc_except_table) *(.glue_7) *(.glue_7t) *(.vfp11_veneer) *(.ARM.extab) *(.gnu.linkonce.armextab.*) -} > MEMORY +} > RAM .init : { KEEP (*(.init)) -} > MEMORY +} > RAM .fini : { KEEP (*(.fini)) -} > MEMORY +} > RAM .rodata : { __rodata_start = .; @@ -43,14 +43,14 @@ SECTIONS *(.rodata.*) *(.gnu.linkonce.r.*) __rodata_end = .; -} > MEMORY +} > RAM .rodata1 : { __rodata1_start = .; *(.rodata1) *(.rodata1.*) __rodata1_end = .; -} > MEMORY +} > RAM .sdata2 : { __sdata2_start = .; @@ -58,7 +58,7 @@ SECTIONS *(.sdata2.*) *(.gnu.linkonce.s2.*) __sdata2_end = .; -} > MEMORY +} > RAM .sbss2 : { __sbss2_start = .; @@ -66,7 +66,7 @@ SECTIONS *(.sbss2.*) *(.gnu.linkonce.sb2.*) __sbss2_end = .; -} > MEMORY +} > RAM .data : { __data_start = .; @@ -77,18 +77,18 @@ SECTIONS *(.got) *(.got.plt) __data_end = .; -} > MEMORY +} > RAM .data1 : { __data1_start = .; *(.data1) *(.data1.*) __data1_end = .; -} > MEMORY +} > RAM .got : { *(.got) -} > MEMORY +} > RAM .ctors : { __CTOR_LIST__ = .; @@ -99,7 +99,7 @@ SECTIONS KEEP (*(.ctors)) __CTOR_END__ = .; ___CTORS_END___ = .; -} > MEMORY +} > RAM .dtors : { __DTOR_LIST__ = .; @@ -110,67 +110,67 @@ SECTIONS KEEP (*(.dtors)) __DTOR_END__ = .; ___DTORS_END___ = .; -} > MEMORY +} > RAM .fixup : { __fixup_start = .; *(.fixup) __fixup_end = .; -} > MEMORY +} > RAM .eh_frame : { *(.eh_frame) -} > MEMORY +} > RAM .eh_framehdr : { __eh_framehdr_start = .; *(.eh_framehdr) __eh_framehdr_end = .; -} > MEMORY +} > RAM .gcc_except_table : { *(.gcc_except_table) -} > MEMORY +} > RAM .mmu_tbl (ALIGN(16384)) : { __mmu_tbl_start = .; *(.mmu_tbl) __mmu_tbl_end = .; -} > MEMORY +} > RAM .ARM.exidx : { __exidx_start = .; *(.ARM.exidx*) *(.gnu.linkonce.armexidix.*.*) __exidx_end = .; -} > MEMORY +} > RAM .preinit_array : { __preinit_array_start = .; KEEP (*(SORT(.preinit_array.*))) KEEP (*(.preinit_array)) __preinit_array_end = .; -} > MEMORY +} > RAM .init_array : { __init_array_start = .; KEEP (*(SORT(.init_array.*))) KEEP (*(.init_array)) __init_array_end = .; -} > MEMORY +} > RAM .fini_array : { __fini_array_start = .; KEEP (*(SORT(.fini_array.*))) KEEP (*(.fini_array)) __fini_array_end = .; -} > MEMORY +} > RAM .ARM.attributes : { __ARM.attributes_start = .; *(.ARM.attributes) __ARM.attributes_end = .; -} > MEMORY +} > RAM .sdata : { __sdata_start = .; @@ -178,7 +178,7 @@ SECTIONS *(.sdata.*) *(.gnu.linkonce.s.*) __sdata_end = .; -} > MEMORY +} > RAM .sbss (NOLOAD) : { __sbss_start = .; @@ -186,7 +186,7 @@ SECTIONS *(.sbss.*) *(.gnu.linkonce.sb.*) __sbss_end = .; -} > MEMORY +} > RAM .tdata : { __tdata_start = .; @@ -194,7 +194,7 @@ SECTIONS *(.tdata.*) *(.gnu.linkonce.td.*) __tdata_end = .; -} > MEMORY +} > RAM .tbss : { __tbss_start = .; @@ -202,7 +202,7 @@ SECTIONS *(.tbss.*) *(.gnu.linkonce.tb.*) __tbss_end = .; -} > MEMORY +} > RAM .bss (NOLOAD) : { __bss_start = .; @@ -211,7 +211,7 @@ SECTIONS *(.gnu.linkonce.b.*) *(COMMON) __bss_end = .; -} > MEMORY +} > RAM _SDA_BASE_ = __sdata_start + ((__sbss_end - __sdata_start) / 2 ); diff --git a/firmware/v5-hot.ld b/firmware/v5-hot.ld index 259bab9ba..017cb3564 100644 --- a/firmware/v5-hot.ld +++ b/firmware/v5-hot.ld @@ -28,6 +28,6 @@ MEMORY HOT_MEMORY : ORIGIN = start_of_hot_mem, LENGTH = _HOT_MEM_SIZE /* Just over 8 MB */ } -REGION_ALIAS("MEMORY", HOT_MEMORY); +REGION_ALIAS("RAM", HOT_MEMORY); ENTRY(install_hot_table) diff --git a/firmware/v5.ld b/firmware/v5.ld index d6933d9d2..7cbd06f3b 100644 --- a/firmware/v5.ld +++ b/firmware/v5.ld @@ -28,6 +28,6 @@ MEMORY HOT_MEMORY : ORIGIN = start_of_hot_mem, LENGTH = _HOT_MEM_SIZE /* Just over 8 MB */ } -REGION_ALIAS("MEMORY", COLD_MEMORY); +REGION_ALIAS("RAM", COLD_MEMORY); ENTRY(vexStartup) diff --git a/include/api.h b/include/api.h index 70af8173d..fb59d7c21 100644 --- a/include/api.h +++ b/include/api.h @@ -8,7 +8,7 @@ * This file should not be modified by users, since it gets replaced whenever * a kernel upgrade occurs. * - * Copyright (c) 2017-2020, Purdue University ACM SIGBots. + * \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 @@ -39,37 +39,45 @@ #include #endif /* __cplusplus */ -#define PROS_VERSION_MAJOR 3 -#define PROS_VERSION_MINOR 3 -#define PROS_VERSION_PATCH 1 -#define PROS_VERSION_STRING "3.3.1" - -#define PROS_ERR (INT32_MAX) -#define PROS_ERR_F (INFINITY) +#define PROS_VERSION_MAJOR 4 +#define PROS_VERSION_MINOR 0 +#define PROS_VERSION_PATCH 3 +#define PROS_VERSION_STRING "4.0.3" #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" +#include "pros/gps.h" #include "pros/imu.h" +#include "pros/link.h" #include "pros/llemu.h" #include "pros/misc.h" #include "pros/motors.h" #include "pros/optical.h" -#include "pros/rtos.h" #include "pros/rotation.h" +#include "pros/rtos.h" +#include "pros/screen.h" #include "pros/vision.h" #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" #include "pros/rtos.hpp" +#include "pros/screen.hpp" #include "pros/vision.hpp" #endif diff --git a/include/display/README.md b/include/display/README.md deleted file mode 100644 index afdfdeb5c..000000000 --- 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 beaef1d26..000000000 --- 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_conf.h b/include/display/lv_conf.h deleted file mode 100644 index 0b1a1626e..000000000 --- a/include/display/lv_conf.h +++ /dev/null @@ -1,341 +0,0 @@ -/** - * @file lv_conf.h - * - */ - -#ifndef LV_CONF_H -#define LV_CONF_H - -/*---------------- - * Dynamic memory - *----------------*/ - -/* 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 \ - lv_mem_alloc/lv_mem_free*/ -#if LV_MEM_CUSTOM == 0 -#define LV_MEM_SIZE \ - (32U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ -#define LV_MEM_ATTR /*Complier prefix for big array declaration*/ -#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*/ -#define LV_MEM_CUSTOM_ALLOC kmalloc /*Wrapper to malloc*/ -#define LV_MEM_CUSTOM_FREE kfree /*Wrapper to free*/ -#endif /*LV_MEM_CUSTOM*/ -#define LV_ENABLE_GC 0 - -/*=================== - Graphical settings - *===================*/ - -/* Horizontal and vertical resolution of the library.*/ -#define LV_HOR_RES (480) -#define LV_VER_RES (240) -#define LV_DPI 126 - -/* Size of VDB (Virtual Display Buffer: the internal graphics buffer). - * Required for buffered drawing, opacity and anti-aliasing - * VDB makes the double buffering, you don't need to deal with it! - * Typical size: ~1/10 screen */ -#define LV_VDB_SIZE \ - (LV_VER_RES * \ - LV_HOR_RES) /*Size of VDB in pixel count (1/10 screen size is good for \ - first)*/ -#define LV_VDB_ADR \ - 0 /*Place VDB to a specific address (e.g. in external RAM) (0: allocate \ - automatically into RAM)*/ - -/* Use two Virtual Display buffers (VDB) parallelize rendering and flushing - * (optional) - * The flushing should use DMA to write the frame buffer in the background*/ -#define LV_VDB_DOUBLE 0 /*1: Enable the use of 2 VDBs*/ -#define LV_VDB2_ADR \ - 0 /*Place VDB2 to a specific address (e.g. in external RAM) (0: allocate \ - automatically into RAM)*/ - -/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ -#define LV_ANTIALIAS 1 /*1: Enable anti-aliasing*/ - -/*Screen refresh settings*/ -#define LV_REFR_PERIOD 40 /*Screen refresh period in milliseconds*/ -#define LV_INV_FIFO_SIZE 32 /*The average count of objects on a screen */ - -/*================= - Misc. setting - *=================*/ - -/*Input device settings*/ -#define LV_INDEV_READ_PERIOD 50 /*Input device read period in milliseconds*/ -#define LV_INDEV_POINT_MARKER \ - 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/ -#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */ -#define LV_INDEV_DRAG_THROW \ - 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */ -#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/ -#define LV_INDEV_LONG_PRESS_REP_TIME \ - 100 /*Repeated trigger period in long press [ms] */ - -/*Color settings*/ -#define LV_COLOR_DEPTH 32 /*Color depth: 1/8/16/24*/ -#define LV_COLOR_TRANSP \ - LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma \ - keying)*/ - -/*Text settings*/ -#define LV_TXT_UTF8 1 /*Enable UTF-8 coded Unicode character usage */ -#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/ -#define LV_TXT_LINE_BREAK_LONG_LEN 12 -#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 -#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 - -/*Graphics feature usage*/ -#define USE_LV_ANIMATION 1 /*1: Enable all animations*/ -#define USE_LV_SHADOW 1 /*1: Enable shadows*/ -#define USE_LV_GROUP 1 /*1: Enable object groups (for keyboards)*/ -#define USE_LV_GPU 0 /*1: Enable GPU interface*/ -#define USE_LV_REAL_DRAW \ - 1 /*1: Enable function which draw directly to the frame buffer instead of \ - VDB (required if LV_VDB_SIZE = 0)*/ -#define USE_LV_FILESYSTEM 1 /*1: Enable file system (required by images*/ -#define USE_LV_MULTI_LANG 1 - -/*Compiler attributes*/ -#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to tick increment \ - function */ -#define LV_ATTRIBUTE_TASK_HANDLER -#define LV_ATTRIBUTE_MEM_ALIGN -#define LV_COMPILER_VLA_SUPPORTED 1 -#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 - -#define USE_LV_LOG 0 -/*================ - * THEME USAGE - *================*/ -#define LV_THEME_LIVE_UPDATE 1 -#define USE_LV_THEME_TEMPL 0 /*Just for test*/ -#define USE_LV_THEME_DEFAULT 0 /*Built mainly from the built-in styles. Consumes very few RAM*/ -#define USE_LV_THEME_ALIEN 1 /*Dark futuristic theme*/ -#define USE_LV_THEME_NIGHT 1 /*Dark elegant theme*/ -#define USE_LV_THEME_MONO 1 /*Mono color theme for monochrome displays*/ -#define USE_LV_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/ -#define USE_LV_THEME_ZEN 1 /*Peaceful, mainly light theme */ - -/*================== - * FONT USAGE - *===================*/ - -/* More info about fonts: https://littlevgl.com/basics#fonts - * To enable a built-in font use 1,2,4 or 8 values - * which will determine the bit-per-pixel */ -#define LV_FONT_DEFAULT \ - &lv_font_dejavu_20 /*Always set a default font from the built-in fonts*/ - -#define USE_LV_FONT_DEJAVU_10 4 -#define USE_LV_FONT_DEJAVU_10_LATIN_SUP 4 -#define USE_LV_FONT_DEJAVU_10_CYRILLIC 4 -#define USE_LV_FONT_SYMBOL_10 4 - -#define USE_LV_FONT_DEJAVU_20 4 -#define USE_LV_FONT_DEJAVU_20_LATIN_SUP 4 -#define USE_LV_FONT_DEJAVU_20_CYRILLIC 4 -#define USE_LV_FONT_SYMBOL_20 4 - -#define USE_LV_FONT_DEJAVU_30 0 -#define USE_LV_FONT_DEJAVU_30_LATIN_SUP 0 -#define USE_LV_FONT_DEJAVU_30_CYRILLIC 0 -#define USE_LV_FONT_SYMBOL_30 0 - -#define USE_LV_FONT_DEJAVU_40 0 -#define USE_LV_FONT_DEJAVU_40_LATIN_SUP 0 -#define USE_LV_FONT_DEJAVU_40_CYRILLIC 0 -#define USE_LV_FONT_SYMBOL_40 0 - -/* PROS adds the mono variant of DejaVu sans */ -#define USE_PROS_FONT_DEJAVU_MONO_10 4 -#define USE_PROS_FONT_DEJAVU_MONO_10_LATIN_SUP 4 - -#define USE_PROS_FONT_DEJAVU_MONO_20 4 -#define USE_PROS_FONT_DEJAVU_MONO_LATIN_SUP_20 4 - -#define USE_PROS_FONT_DEJAVU_MONO_30 0 -#define USE_PROS_FONT_DEJAVU_MONO_30_LATIN_SUP 0 - -#define USE_PROS_FONT_DEJAVU_MONO_40 0 -#define USE_PROS_FONT_DEJAVU_MONO_40_LATIN_SUP 0 - -/*=================== - * LV_OBJ SETTINGS - *==================*/ -#define LV_OBJ_FREE_NUM_TYPE \ - uint32_t /*Type of free number attribute (comment out disable free number)*/ -#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/ - -/*================== - * LV OBJ X USAGE - *================*/ -/* - * Documentation of the object types: https://littlevgl.com/object-types - */ - -/***************** - * Simple object - *****************/ - -/*Label (dependencies: -*/ -#define USE_LV_LABEL 1 -#if USE_LV_LABEL != 0 -#define LV_LABEL_SCROLL_SPEED \ - 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' \ - mode*/ -#endif - -/*Image (dependencies: lv_label*/ -#define USE_LV_IMG 1 -#if USE_LV_IMG != 0 -# define LV_IMG_CF_INDEXED 1 -# define LV_IMG_CF_ALPHA 1 -#endif - -/*Line (dependencies: -*/ -#define USE_LV_LINE 1 -#define USE_LV_ARC 1 - -/******************* - * Container objects - *******************/ - -/*Container (dependencies: -*/ -#define USE_LV_CONT 1 - -/*Page (dependencies: lv_cont)*/ -#define USE_LV_PAGE 1 - -/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ -#define USE_LV_WIN 1 - -/*Tab (dependencies: lv_page, lv_btnm)*/ -#define USE_LV_TABVIEW 1 -#if USE_LV_TABVIEW != 0 -#define LV_TABVIEW_ANIM_TIME \ - 300 /*Time of slide animation [ms] (0: no animation)*/ -#endif -#define USE_LV_TILEVIEW 1 -#if USE_LV_TILEVIEW -# define LV_TILEVIEW_ANIM_TIME 300 -#endif - - -/************************* - * Data visualizer objects - *************************/ - -/*Bar (dependencies: -)*/ -#define USE_LV_BAR 1 - -/*Line meter (dependencies: *;)*/ -#define USE_LV_LMETER 1 - -/*Gauge (dependencies:bar, lmeter)*/ -#define USE_LV_GAUGE 1 - -/*Chart (dependencies: -)*/ -#define USE_LV_CHART 1 - -#define USE_LV_TABLE 1 -#if USE_LV_TABLE -# define LV_TABLE_COL_MAX 12 -#endif - -/*LED (dependencies: -)*/ -#define USE_LV_LED 1 - -/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ -#define USE_LV_MBOX 1 - -/*Text area (dependencies: lv_label, lv_page)*/ -#define USE_LV_TA 1 -#if USE_LV_TA != 0 -#define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/ -#define LV_TA_PWD_SHOW_TIME 1500 /*ms*/ -#endif - -#define USE_LV_SPINBOX 1 -#define USE_LV_CALENDAR 1 - -#define USE_PRELOAD 1 -#if USE_LV_PRELOAD != 0 -# define LV_PRELOAD_DEF_ARC_LENGTH 60 -# define LV_PRELOAD_DEF_SPIN_TIME 1000 -# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC -#endif - -#define USE_LV_CANVAS 1 -/************************* - * User input objects - *************************/ - -/*Button (dependencies: lv_cont*/ -#define USE_LV_BTN 1 -#if USE_LV_BTN != 0 -# define LV_BTN_INK_EFFECT 1 -#endif - -#define USE_LV_IMGBTN 1 -#if USE_LV_IMGBTN -# define LV_IMGBTN_TILED 0 -#endif - -/*Button matrix (dependencies: -)*/ -#define USE_LV_BTNM 1 - -/*Keyboard (dependencies: lv_btnm)*/ -#define USE_LV_KB 1 - -/*Check box (dependencies: lv_btn, lv_label)*/ -#define USE_LV_CB 1 - -/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons - * ))*/ -#define USE_LV_LIST 1 -#if USE_LV_LIST != 0 -#define LV_LIST_FOCUS_TIME \ - 100 /*Default animation time of focusing to a list element [ms] (0: no \ - animation) */ -#endif - -/*Drop down list (dependencies: lv_page, lv_label)*/ -#define USE_LV_DDLIST 1 -#if USE_LV_DDLIST != 0 -#define LV_DDLIST_ANIM_TIME \ - 200 /*Open and close default animation time [ms] (0: no animation)*/ -#endif - -/*Roller (dependencies: lv_ddlist)*/ -#define USE_LV_ROLLER 1 -#if USE_LV_ROLLER != 0 -#define LV_ROLLER_ANIM_TIME \ - 200 /*Focus animation time [ms] (0: no \ - animation)*/ -#endif - -/*Slider (dependencies: lv_bar)*/ -#define USE_LV_SLIDER 1 - -/*Switch (dependencies: lv_slider)*/ -#define USE_LV_SW 1 - -#if LV_INDEV_DRAG_THROW <= 0 -#warning "LV_INDEV_DRAG_THROW must be greater than 0" -#undef LV_INDEV_DRAG_THROW -#define LV_INDEV_DRAG_THROW 1 -#endif - -#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) -# define _CRT_SECURE_NO_WARNINGS -#endif -#include "display/lv_conf_checker.h" -#endif /*LV_CONF_H*/ diff --git a/include/display/lv_conf_checker.h b/include/display/lv_conf_checker.h deleted file mode 100644 index 3a8ead51a..000000000 --- a/include/display/lv_conf_checker.h +++ /dev/null @@ -1,664 +0,0 @@ -/** - * GENERATED FILE, DO NOT EDIT IT! - * @file lv_conf_checker.h - * Make sure all the defines of lv_conf.h have a default value -**/ - -#ifndef LV_CONF_CHECKER_H -#define LV_CONF_CHECKER_H -/*=================== - Dynamic memory - *===================*/ - -/* Memory size which will be used by the library - * to store the graphical objects and other data */ -#ifndef LV_MEM_CUSTOM -#define LV_MEM_CUSTOM 0 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/ -#endif -#if LV_MEM_CUSTOM == 0 -#ifndef LV_MEM_SIZE -# define LV_MEM_SIZE (64U * 1024U) /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ -#endif -#ifndef LV_MEM_ATTR -# define LV_MEM_ATTR /*Complier prefix for big array declaration*/ -#endif -#ifndef LV_MEM_ADR -# define LV_MEM_ADR 0 /*Set an address for memory pool instead of allocation it as an array. Can be in external SRAM too.*/ -#endif -#ifndef LV_MEM_AUTO_DEFRAG -# define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/ -#endif -#else /*LV_MEM_CUSTOM*/ -#ifndef LV_MEM_CUSTOM_INCLUDE -# define LV_MEM_CUSTOM_INCLUDE /*Header for the dynamic memory function*/ -#endif -#ifndef LV_MEM_CUSTOM_ALLOC -# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ -#endif -#ifndef LV_MEM_CUSTOM_FREE -# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ -#endif -#endif /*LV_MEM_CUSTOM*/ - -/* Garbage Collector settings - * Used if lvgl is binded to higher language and the memory is managed by that language */ -#ifndef LV_ENABLE_GC -#define LV_ENABLE_GC 0 -#endif -#if LV_ENABLE_GC != 0 -#ifndef LV_MEM_CUSTOM_REALLOC -# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/ -#endif -#ifndef LV_MEM_CUSTOM_GET_SIZE -# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/ -#endif -#ifndef LV_GC_INCLUDE -# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/ -#endif -#endif /* LV_ENABLE_GC */ - -/*=================== - Graphical settings - *===================*/ - -/* Horizontal and vertical resolution of the library.*/ -#ifndef LV_HOR_RES -#define LV_HOR_RES (480) -#endif -#ifndef LV_VER_RES -#define LV_VER_RES (320) -#endif - -/* 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)*/ -#ifndef LV_DPI -#define LV_DPI 100 -#endif - -/* Enable anti-aliasing (lines, and radiuses will be smoothed) */ -#ifndef LV_ANTIALIAS -#define LV_ANTIALIAS 1 /*1: Enable anti-aliasing*/ -#endif - -/*Screen refresh period in milliseconds*/ -#ifndef LV_REFR_PERIOD -#define LV_REFR_PERIOD 30 -#endif - -/*----------------- - * VDB settings - *----------------*/ - -/* VDB (Virtual Display Buffer) is an internal graphics buffer. - * The GUI will be drawn into this buffer first and then - * the buffer will be passed to your `disp_drv.disp_flush` function to - * copy it to your frame buffer. - * VDB is required for: buffered drawing, opacity, anti-aliasing and shadows - * Learn more: https://docs.littlevgl.com/#Drawing*/ - -/* Size of the VDB in pixels. Typical size: ~1/10 screen. Must be >= LV_HOR_RES - * Setting it to 0 will disable VDB and `disp_drv.disp_fill` and `disp_drv.disp_map` functions - * will be called to draw to the frame buffer directly*/ -#ifndef LV_VDB_SIZE -#define LV_VDB_SIZE ((LV_VER_RES * LV_HOR_RES) / 10) -#endif - - /* Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays. - * Special formats are handled with `disp_drv.vdb_wr`)*/ -#ifndef LV_VDB_PX_BPP -#define LV_VDB_PX_BPP LV_COLOR_SIZE /*LV_COLOR_SIZE comes from LV_COLOR_DEPTH below to set 8, 16 or 32 bit pixel size automatically */ -#endif - - /* Place VDB to a specific address (e.g. in external RAM) - * 0: allocate automatically into RAM - * LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/ -#ifndef LV_VDB_ADR -#define LV_VDB_ADR 0 -#endif - -/* Use two Virtual Display buffers (VDB) to parallelize rendering and flushing - * The flushing should use DMA to write the frame buffer in the background */ -#ifndef LV_VDB_DOUBLE -#define LV_VDB_DOUBLE 0 -#endif - -/* Place VDB2 to a specific address (e.g. in external RAM) - * 0: allocate automatically into RAM - * LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/ -#ifndef LV_VDB2_ADR -#define LV_VDB2_ADR 0 -#endif - -/* Using true double buffering in `disp_drv.disp_flush` you will always get the image of the whole screen. - * Your only task is to set the rendered image (`color_p` parameter) as frame buffer address or send it to your display. - * The best if you do in the blank period of you display to avoid tearing effect. - * Requires: - * - LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES - * - LV_VDB_DOUBLE = 1 - */ -#ifndef LV_VDB_TRUE_DOUBLE_BUFFERED -#define LV_VDB_TRUE_DOUBLE_BUFFERED 0 -#endif - -/*================= - Misc. setting - *=================*/ - -/*Input device settings*/ -#ifndef LV_INDEV_READ_PERIOD -#define LV_INDEV_READ_PERIOD 50 /*Input device read period in milliseconds*/ -#endif -#ifndef LV_INDEV_POINT_MARKER -#define LV_INDEV_POINT_MARKER 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/ -#endif -#ifndef LV_INDEV_DRAG_LIMIT -#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */ -#endif -#ifndef LV_INDEV_DRAG_THROW -#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%] (must be > 0). Greater value means faster slow-down */ -#endif -#ifndef LV_INDEV_LONG_PRESS_TIME -#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/ -#endif -#ifndef LV_INDEV_LONG_PRESS_REP_TIME -#define LV_INDEV_LONG_PRESS_REP_TIME 100 /*Repeated trigger period in long press [ms] */ -#endif - -/*Color settings*/ -#ifndef LV_COLOR_DEPTH -#define LV_COLOR_DEPTH 16 /*Color depth: 1/8/16/32*/ -#endif -#ifndef LV_COLOR_16_SWAP -#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/ -#endif -#ifndef LV_COLOR_SCREEN_TRANSP -#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/ -#endif -#ifndef LV_COLOR_TRANSP -#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/ -#endif - -/*Text settings*/ -#ifndef LV_TXT_UTF8 -#define LV_TXT_UTF8 1 /*Enable UTF-8 coded Unicode character usage */ -#endif -#ifndef LV_TXT_BREAK_CHARS -#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/ -#endif -#ifndef LV_TXT_LINE_BREAK_LONG_LEN -#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */ -#endif -#ifndef LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN -#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */ -#endif -#ifndef LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN -#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */ -#endif - -/*Feature usage*/ -#ifndef USE_LV_ANIMATION -#define USE_LV_ANIMATION 1 /*1: Enable all animations*/ -#endif -#ifndef USE_LV_SHADOW -#define USE_LV_SHADOW 1 /*1: Enable shadows*/ -#endif -#ifndef USE_LV_GROUP -#define USE_LV_GROUP 1 /*1: Enable object groups (for keyboards)*/ -#endif -#ifndef USE_LV_GPU -#define USE_LV_GPU 1 /*1: Enable GPU interface*/ -#endif -#ifndef USE_LV_REAL_DRAW -#define USE_LV_REAL_DRAW 1 /*1: Enable function which draw directly to the frame buffer instead of VDB (required if LV_VDB_SIZE = 0)*/ -#endif -#ifndef USE_LV_FILESYSTEM -#define USE_LV_FILESYSTEM 1 /*1: Enable file system (might be required for images*/ -#endif -#ifndef USE_LV_MULTI_LANG -#define USE_LV_MULTI_LANG 0 /* Number of languages for labels to store (0: to disable this feature)*/ -#endif - -/*Compiler settings*/ -#ifndef LV_ATTRIBUTE_TICK_INC -#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */ -#endif -#ifndef LV_ATTRIBUTE_TASK_HANDLER -#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */ -#endif -#ifndef LV_ATTRIBUTE_MEM_ALIGN -#define LV_ATTRIBUTE_MEM_ALIGN /* With size optimization (-Os) the compiler might not align data to 4 or 8 byte boundary. This alignment will be explicitly applied where needed.*/ -#endif -#ifndef LV_COMPILER_VLA_SUPPORTED -#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/ -#endif -#ifndef LV_COMPILER_NON_CONST_INIT_SUPPORTED -#define LV_COMPILER_NON_CONST_INIT_SUPPORTED 1 /* 1: Initialization with non constant values are supported */ -#endif - -/*HAL settings*/ -#ifndef LV_TICK_CUSTOM -#define LV_TICK_CUSTOM 0 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */ -#endif -#if LV_TICK_CUSTOM == 1 -#ifndef LV_TICK_CUSTOM_INCLUDE -#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/ -#endif -#ifndef LV_TICK_CUSTOM_SYS_TIME_EXPR -#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/ -#endif -#endif /*LV_TICK_CUSTOM*/ - - -/*Log settings*/ -#ifndef USE_LV_LOG -#define USE_LV_LOG 1 /*Enable/disable the log module*/ -#endif -#if USE_LV_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 caused problem - * LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail - */ -#ifndef LV_LOG_LEVEL -# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN -#endif -/* 1: Print the log with 'printf'; 0: user need to register a callback*/ - -#ifndef LV_LOG_PRINTF -# define LV_LOG_PRINTF 0 -#endif -#endif /*USE_LV_LOG*/ - -/*================ - * THEME USAGE - *================*/ -#ifndef LV_THEME_LIVE_UPDATE -#define LV_THEME_LIVE_UPDATE 1 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/ -#endif - -#ifndef USE_LV_THEME_TEMPL -#define USE_LV_THEME_TEMPL 0 /*Just for test*/ -#endif -#ifndef USE_LV_THEME_DEFAULT -#define USE_LV_THEME_DEFAULT 1 /*Built mainly from the built-in styles. Consumes very few RAM*/ -#endif -#ifndef USE_LV_THEME_ALIEN -#define USE_LV_THEME_ALIEN 1 /*Dark futuristic theme*/ -#endif -#ifndef USE_LV_THEME_NIGHT -#define USE_LV_THEME_NIGHT 1 /*Dark elegant theme*/ -#endif -#ifndef USE_LV_THEME_MONO -#define USE_LV_THEME_MONO 1 /*Mono color theme for monochrome displays*/ -#endif -#ifndef USE_LV_THEME_MATERIAL -#define USE_LV_THEME_MATERIAL 1 /*Flat theme with bold colors and light shadows*/ -#endif -#ifndef USE_LV_THEME_ZEN -#define USE_LV_THEME_ZEN 1 /*Peaceful, mainly light theme */ -#endif -#ifndef USE_LV_THEME_NEMO -#define USE_LV_THEME_NEMO 1 /*Water-like theme based on the movie "Finding Nemo"*/ -#endif - -/*================== - * FONT USAGE - *===================*/ - -/* More info about fonts: https://docs.littlevgl.com/#Fonts - * To enable a built-in font use 1,2,4 or 8 values - * which will determine the bit-per-pixel. Higher value means smoother fonts */ -#ifndef USE_LV_FONT_DEJAVU_10 -#define USE_LV_FONT_DEJAVU_10 4 -#endif -#ifndef USE_LV_FONT_DEJAVU_10_LATIN_SUP -#define USE_LV_FONT_DEJAVU_10_LATIN_SUP 4 -#endif -#ifndef USE_LV_FONT_DEJAVU_10_CYRILLIC -#define USE_LV_FONT_DEJAVU_10_CYRILLIC 4 -#endif -#ifndef USE_LV_FONT_SYMBOL_10 -#define USE_LV_FONT_SYMBOL_10 4 -#endif - -#ifndef USE_LV_FONT_DEJAVU_20 -#define USE_LV_FONT_DEJAVU_20 4 -#endif -#ifndef USE_LV_FONT_DEJAVU_20_LATIN_SUP -#define USE_LV_FONT_DEJAVU_20_LATIN_SUP 4 -#endif -#ifndef USE_LV_FONT_DEJAVU_20_CYRILLIC -#define USE_LV_FONT_DEJAVU_20_CYRILLIC 4 -#endif -#ifndef USE_LV_FONT_SYMBOL_20 -#define USE_LV_FONT_SYMBOL_20 4 -#endif - -#ifndef USE_LV_FONT_DEJAVU_30 -#define USE_LV_FONT_DEJAVU_30 4 -#endif -#ifndef USE_LV_FONT_DEJAVU_30_LATIN_SUP -#define USE_LV_FONT_DEJAVU_30_LATIN_SUP 4 -#endif -#ifndef USE_LV_FONT_DEJAVU_30_CYRILLIC -#define USE_LV_FONT_DEJAVU_30_CYRILLIC 4 -#endif -#ifndef USE_LV_FONT_SYMBOL_30 -#define USE_LV_FONT_SYMBOL_30 4 -#endif - -#ifndef USE_LV_FONT_DEJAVU_40 -#define USE_LV_FONT_DEJAVU_40 4 -#endif -#ifndef USE_LV_FONT_DEJAVU_40_LATIN_SUP -#define USE_LV_FONT_DEJAVU_40_LATIN_SUP 4 -#endif -#ifndef USE_LV_FONT_DEJAVU_40_CYRILLIC -#define USE_LV_FONT_DEJAVU_40_CYRILLIC 4 -#endif -#ifndef USE_LV_FONT_SYMBOL_40 -#define USE_LV_FONT_SYMBOL_40 4 -#endif - -#ifndef USE_LV_FONT_MONOSPACE_8 -#define USE_LV_FONT_MONOSPACE_8 1 -#endif - -/* 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) \ - */ -#ifndef LV_FONT_CUSTOM_DECLARE -#define LV_FONT_CUSTOM_DECLARE -#endif - - -#ifndef LV_FONT_DEFAULT -#define LV_FONT_DEFAULT &lv_font_dejavu_20 /*Always set a default font from the built-in fonts*/ -#endif - -/*=================== - * LV_OBJ SETTINGS - *==================*/ -#ifndef LV_OBJ_FREE_NUM_TYPE -#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/ -#endif -#ifndef LV_OBJ_FREE_PTR -#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/ -#endif -#ifndef LV_OBJ_REALIGN -#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/ -#endif - -/*================== - * LV OBJ X USAGE - *================*/ -/* - * Documentation of the object types: https://docs.littlevgl.com/#Object-types - */ - -/***************** - * Simple object - *****************/ - -/*Label (dependencies: -*/ -#ifndef USE_LV_LABEL -#define USE_LV_LABEL 1 -#endif -#if USE_LV_LABEL != 0 -#ifndef LV_LABEL_SCROLL_SPEED -# define LV_LABEL_SCROLL_SPEED 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/ -#endif -#endif - -/*Image (dependencies: lv_label*/ -#ifndef USE_LV_IMG -#define USE_LV_IMG 1 -#endif -#if USE_LV_IMG != 0 -#ifndef LV_IMG_CF_INDEXED -# define LV_IMG_CF_INDEXED 1 /*Enable indexed (palette) images*/ -#endif -#ifndef LV_IMG_CF_ALPHA -# define LV_IMG_CF_ALPHA 1 /*Enable alpha indexed images*/ -#endif -#endif - -/*Line (dependencies: -*/ -#ifndef USE_LV_LINE -#define USE_LV_LINE 1 -#endif - -/*Arc (dependencies: -)*/ -#ifndef USE_LV_ARC -#define USE_LV_ARC 1 -#endif - -/******************* - * Container objects - *******************/ - -/*Container (dependencies: -*/ -#ifndef USE_LV_CONT -#define USE_LV_CONT 1 -#endif - -/*Page (dependencies: lv_cont)*/ -#ifndef USE_LV_PAGE -#define USE_LV_PAGE 1 -#endif - -/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ -#ifndef USE_LV_WIN -#define USE_LV_WIN 1 -#endif - -/*Tab (dependencies: lv_page, lv_btnm)*/ -#ifndef USE_LV_TABVIEW -#define USE_LV_TABVIEW 1 -#endif -# if USE_LV_TABVIEW != 0 -#ifndef LV_TABVIEW_ANIM_TIME -# define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/ -#endif -#endif - -/*Tileview (dependencies: lv_page) */ -#ifndef USE_LV_TILEVIEW -#define USE_LV_TILEVIEW 1 -#endif -#if USE_LV_TILEVIEW -#ifndef LV_TILEVIEW_ANIM_TIME -# define LV_TILEVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/ -#endif -#endif - -/************************* - * Data visualizer objects - *************************/ - -/*Bar (dependencies: -)*/ -#ifndef USE_LV_BAR -#define USE_LV_BAR 1 -#endif - -/*Line meter (dependencies: *;)*/ -#ifndef USE_LV_LMETER -#define USE_LV_LMETER 1 -#endif - -/*Gauge (dependencies:lv_bar, lv_lmeter)*/ -#ifndef USE_LV_GAUGE -#define USE_LV_GAUGE 1 -#endif - -/*Chart (dependencies: -)*/ -#ifndef USE_LV_CHART -#define USE_LV_CHART 1 -#endif - -/*Table (dependencies: lv_label)*/ -#ifndef USE_LV_TABLE -#define USE_LV_TABLE 1 -#endif -#if USE_LV_TABLE -#ifndef LV_TABLE_COL_MAX -# define LV_TABLE_COL_MAX 12 -#endif -#endif - -/*LED (dependencies: -)*/ -#ifndef USE_LV_LED -#define USE_LV_LED 1 -#endif - -/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/ -#ifndef USE_LV_MBOX -#define USE_LV_MBOX 1 -#endif - -/*Text area (dependencies: lv_label, lv_page)*/ -#ifndef USE_LV_TA -#define USE_LV_TA 1 -#endif -#if USE_LV_TA != 0 -#ifndef LV_TA_CURSOR_BLINK_TIME -# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/ -#endif -#ifndef LV_TA_PWD_SHOW_TIME -# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/ -#endif -#endif - -/*Spinbox (dependencies: lv_ta)*/ -#ifndef USE_LV_SPINBOX -#define USE_LV_SPINBOX 1 -#endif - -/*Calendar (dependencies: -)*/ -#ifndef USE_LV_CALENDAR -#define USE_LV_CALENDAR 1 -#endif - -/*Preload (dependencies: lv_arc)*/ -#ifndef USE_LV_PRELOAD -#define USE_LV_PRELOAD 1 -#endif -#if USE_LV_PRELOAD != 0 -#ifndef LV_PRELOAD_DEF_ARC_LENGTH -# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/ -#endif -#ifndef LV_PRELOAD_DEF_SPIN_TIME -# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/ -#endif -#ifndef LV_PRELOAD_DEF_ANIM -# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC -#endif -#endif - -/*Canvas (dependencies: lv_img)*/ -#ifndef USE_LV_CANVAS -#define USE_LV_CANVAS 1 -#endif -/************************* - * User input objects - *************************/ - -/*Button (dependencies: lv_cont*/ -#ifndef USE_LV_BTN -#define USE_LV_BTN 1 -#endif -#if USE_LV_BTN != 0 -#ifndef LV_BTN_INK_EFFECT -# define LV_BTN_INK_EFFECT 1 /*Enable button-state animations - draw a circle on click (dependencies: USE_LV_ANIMATION)*/ -#endif -#endif - -/*Image Button (dependencies: lv_btn*/ -#ifndef USE_LV_IMGBTN -#define USE_LV_IMGBTN 1 -#endif -#if USE_LV_IMGBTN -#ifndef LV_IMGBTN_TILED -# define LV_IMGBTN_TILED 0 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/ -#endif -#endif - -/*Button matrix (dependencies: -)*/ -#ifndef USE_LV_BTNM -#define USE_LV_BTNM 1 -#endif - -/*Keyboard (dependencies: lv_btnm)*/ -#ifndef USE_LV_KB -#define USE_LV_KB 1 -#endif - -/*Check box (dependencies: lv_btn, lv_label)*/ -#ifndef USE_LV_CB -#define USE_LV_CB 1 -#endif - -/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/ -#ifndef USE_LV_LIST -#define USE_LV_LIST 1 -#endif -#if USE_LV_LIST != 0 -#ifndef LV_LIST_FOCUS_TIME -# define LV_LIST_FOCUS_TIME 100 /*Default animation time of focusing to a list element [ms] (0: no animation) */ -#endif -#endif - -/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ -#ifndef USE_LV_DDLIST -#define USE_LV_DDLIST 1 -#endif -#if USE_LV_DDLIST != 0 -#ifndef LV_DDLIST_ANIM_TIME -# define LV_DDLIST_ANIM_TIME 200 /*Open and close default animation time [ms] (0: no animation)*/ -#endif -#endif - -/*Roller (dependencies: lv_ddlist)*/ -#ifndef USE_LV_ROLLER -#define USE_LV_ROLLER 1 -#endif -#if USE_LV_ROLLER != 0 -#ifndef LV_ROLLER_ANIM_TIME -# define LV_ROLLER_ANIM_TIME 200 /*Focus animation time [ms] (0: no animation)*/ -#endif -#endif - -/*Slider (dependencies: lv_bar)*/ -#ifndef USE_LV_SLIDER -#define USE_LV_SLIDER 1 -#endif - -/*Switch (dependencies: lv_slider)*/ -#ifndef USE_LV_SW -#define USE_LV_SW 1 -#endif - -/************************* - * Non-user section - *************************/ - -#if LV_INDEV_DRAG_THROW <= 0 -#warning "LV_INDEV_DRAG_THROW must be greater than 0" -#undef LV_INDEV_DRAG_THROW -#ifndef LV_INDEV_DRAG_THROW -#define LV_INDEV_DRAG_THROW 1 -#endif -#endif - -#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/ -#ifndef _CRT_SECURE_NO_WARNINGS -# define _CRT_SECURE_NO_WARNINGS -#endif -#endif - - -#endif /*LV_CONF_CHECKER_H*/ diff --git a/include/display/lv_core/lv_core.mk b/include/display/lv_core/lv_core.mk deleted file mode 100644 index 9992e3fe7..000000000 --- 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 4fb6043b1..000000000 --- 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 b066246bf..000000000 --- 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 efbdd0a8f..000000000 --- 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 02378a513..000000000 --- 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 75b22d017..000000000 --- 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 4206ada3f..000000000 --- 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 32aac5df6..000000000 --- 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 550388362..000000000 --- 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 a384eefea..000000000 --- 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 203eabe61..000000000 --- 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 ff7795804..000000000 --- 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 8798573d3..000000000 --- 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 4269475ee..000000000 --- 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 403cb806c..000000000 --- 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 933590ca9..000000000 --- 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_triangle.h b/include/display/lv_draw/lv_draw_triangle.h deleted file mode 100644 index c3c6208da..000000000 --- a/include/display/lv_draw/lv_draw_triangle.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @file lv_draw_triangle.h - * - */ - -#ifndef LV_DRAW_TRIANGLE_H -#define LV_DRAW_TRIANGLE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_draw.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * 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 - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DRAW_TRIANGLE_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 82d4b7a1f..000000000 --- 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 5687fa1fb..000000000 --- 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 f124b5590..000000000 --- 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.h b/include/display/lv_hal/lv_hal.h deleted file mode 100644 index 5ab28f2a6..000000000 --- a/include/display/lv_hal/lv_hal.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file hal.h - * - */ - -#ifndef HAL_H -#define HAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_hal_disp.h" -#include "lv_hal_indev.h" -#include "lv_hal_tick.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/include/display/lv_hal/lv_hal.mk b/include/display/lv_hal/lv_hal.mk deleted file mode 100644 index 83f4bf175..000000000 --- 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 273f3314e..000000000 --- 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 0252dc47e..000000000 --- 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_hal/lv_hal_tick.h b/include/display/lv_hal/lv_hal_tick.h deleted file mode 100644 index c59ed0b20..000000000 --- a/include/display/lv_hal/lv_hal_tick.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - * @file lv_hal_tick.h - * Provide access to the system tick with 1 millisecond resolution - */ - -#ifndef LV_HAL_TICK_H -#define LV_HAL_TICK_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 - -/********************* - * DEFINES - *********************/ -#ifndef LV_ATTRIBUTE_TICK_INC -#define LV_ATTRIBUTE_TICK_INC -#endif - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * 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); - -/** - * Get the elapsed milliseconds since start up - * @return the elapsed milliseconds - */ -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() ) - * @return the elapsed milliseconds since 'prev_tick' - */ -uint32_t lv_tick_elaps(uint32_t prev_tick); - -/********************** - * MACROS - **********************/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_HAL_TICK_H*/ diff --git a/include/display/lv_misc/lv_anim.h b/include/display/lv_misc/lv_anim.h deleted file mode 100644 index b3b8553b1..000000000 --- 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 fc8b7dec8..000000000 --- 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 f2065f71b..000000000 --- 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 4a3e3351c..000000000 --- a/include/display/lv_misc/lv_color.h +++ /dev/null @@ -1,441 +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 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/ -#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 0b1675c59..000000000 --- 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 845b47948..000000000 --- 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 e3d0d8ac8..000000000 --- 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_ll.h b/include/display/lv_misc/lv_ll.h deleted file mode 100644 index 086ba4057..000000000 --- a/include/display/lv_misc/lv_ll.h +++ /dev/null @@ -1,145 +0,0 @@ -/** - * @file lv_ll.c - * Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module. - */ - -#ifndef LV_LL_H -#define LV_LL_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/********************* - * INCLUDES - *********************/ -#include "lv_mem.h" -#include -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/*Dummy type to make handling easier*/ -typedef uint8_t lv_ll_node_t; - -/*Description of a linked list*/ -typedef struct -{ - uint32_t n_size; - lv_ll_node_t* head; - lv_ll_node_t* tail; -} lv_ll_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Initialize linked list - * @param ll_dsc pointer to ll_dsc variable - * @param node_size the size of 1 node in bytes - */ -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); - -/** - * 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 - */ -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); - -/** - * Remove the node 'node_p' from 'll_p' linked list. - * It does not free the 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); - -/** - * 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); - -/** - * 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 - */ -void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node); - -/** - * 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); - -/** - * Return with tail node of the linked list - * @param ll_p pointer to linked list - * @return pointer to the head of 'll_p' - */ -void * lv_ll_get_tail(const lv_ll_t * ll_p); - -/** - * Return with the pointer of the next node after 'n_act' - * @param ll_p pointer to linked list - * @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); - -/** - * Return with the pointer of the previous node after 'n_act' - * @param ll_p pointer to linked list - * @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); - -/** - * Move a nodw 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); - -/********************** - * MACROS - **********************/ - -#define 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)) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/include/display/lv_misc/lv_log.h b/include/display/lv_misc/lv_log.h deleted file mode 100644 index adcb846d9..000000000 --- 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 a0229eb1b..000000000 --- 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 77429018a..000000000 --- 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 470f1230d..000000000 --- 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 6ba6241ca..000000000 --- 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 6cac3efd7..000000000 --- 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_templ.h b/include/display/lv_misc/lv_templ.h deleted file mode 100644 index a5459e8d3..000000000 --- a/include/display/lv_misc/lv_templ.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @file lv_templ.h - * - */ - -#ifndef LV_TEMPL_H -#define LV_TEMPL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/********************** - * MACROS - **********************/ - - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TEMPL_H*/ diff --git a/include/display/lv_misc/lv_txt.h b/include/display/lv_misc/lv_txt.h deleted file mode 100644 index 2e98b60e6..000000000 --- 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 d30cbe0f3..000000000 --- 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 4f82e0d81..000000000 --- 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 3938aa289..000000000 --- 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 805b5d786..000000000 --- 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 89c066a4f..000000000 --- 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 3ef4b0253..000000000 --- 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 14d6e87b3..000000000 --- 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 5c550b6ff..000000000 --- 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 92637e891..000000000 --- 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 3f4923dc6..000000000 --- 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 cd9de975e..000000000 --- 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 3f269cd06..000000000 --- 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 03eca2477..000000000 --- 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 295be8f2d..000000000 --- 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 d6ab97956..000000000 --- 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 abd176a00..000000000 --- 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 f6a18acbe..000000000 --- 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 e7be8a321..000000000 --- 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 397059a51..000000000 --- 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 dcb42bf40..000000000 --- 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 2dc0c6dcb..000000000 --- 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 d35252bce..000000000 --- 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 b8473dfb8..000000000 --- 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 d01de3584..000000000 --- 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 7e2289068..000000000 --- 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 232f5526b..000000000 --- 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 8d0d9d667..000000000 --- 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 6ec1e6677..000000000 --- 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 7f4513c84..000000000 --- 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 8e12314a8..000000000 --- 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 79ba22dc9..000000000 --- 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 73d8b17c0..000000000 --- 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 b869e7ce4..000000000 --- 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 4a64aa81f..000000000 --- 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 69aae29fc..000000000 --- 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 1f62315d3..000000000 --- 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 1348f1fc4..000000000 --- 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 d9da66467..000000000 --- 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 63039fa98..000000000 --- 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 46d43bdb5..000000000 --- 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 3e5efb8f8..000000000 --- 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 e7176636a..000000000 --- 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 ddd7cb35b..000000000 --- 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 0e4a81a54..000000000 --- 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 1e62e1e2b..000000000 --- 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 d2c93b4ed..000000000 --- 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/okapi/api/coreProsAPI.hpp b/include/okapi/api/coreProsAPI.hpp index ab1aa6949..a56533668 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 78c5b3b05..dd9cf0a51 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 000000000..1468f35f3 --- /dev/null +++ b/include/pros/abstract_motor.hpp @@ -0,0 +1,1163 @@ +/** + * \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 motor_brake + * 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 Motor_Encoder_Units + * 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 Motor_Encoder_Units +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 Motor_Gears +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 pros::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 + * + * \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 operator=(std::int32_t voltage) const = 0; + + /** + * 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 Motor_Brake, 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 Motor_Brake(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 Motor_Units 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 Motor_Units 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 Motor_Gears according to what is set for the motor, + * or pros::Motor_Gears::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 Motor_Gears according to what is set for the motor(s), + * or pros::Motor_Gears::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 Motor_Brake 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 Motor_Brake 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 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 + * + * \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 b850fc0a9..f1bbe373f 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 (c) 2017-2020, 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 { @@ -69,6 +82,15 @@ typedef enum adi_port_config_e { E_ADI_ERR = PROS_ERR } adi_port_config_e_t; +/** + * \enum adi_potentiometer_type_e_t + * Represents the potentiometer version type. + */ +typedef enum adi_potentiometer_type_e { + E_ADI_POT_EDR = 0, + E_ADI_POT_V2 +} adi_potentiometer_type_e_t; + #ifdef PROS_USE_SIMPLE_NAMES #ifdef __cplusplus #define ADI_ANALOG_IN pros::E_ADI_ANALOG_IN @@ -118,11 +140,16 @@ typedef enum adi_port_config_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. @@ -136,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); @@ -151,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); @@ -168,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); @@ -189,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. @@ -243,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: @@ -252,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); @@ -272,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); @@ -294,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); @@ -321,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); @@ -341,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); @@ -365,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); @@ -386,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); @@ -403,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); @@ -422,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); @@ -437,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); @@ -453,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; @@ -473,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); @@ -502,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); @@ -522,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); @@ -538,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; @@ -566,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); @@ -586,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); @@ -602,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; @@ -630,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); @@ -654,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); @@ -670,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); @@ -686,9 +997,383 @@ 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. + */ +typedef int32_t adi_potentiometer_t; + +/** + * Initializes a potentiometer on the given port of the original potentiometer. + * + * 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 + * EADDRINUSE - The port is not configured as a potentiometer + * + * \param port + * The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H') + * + * \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); + +/** + * Initializes a potentiometer on 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 + * EADDRINUSE - The port is not configured as a potentiometer + * + * \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 + * + * \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); + +/** + * Gets the current potentiometer angle in tenths of a degree. + * + * The original potentiometer rotates 250 degrees thus returning an angle between 0-250 degrees. + * Potentiometer V2 rotates 330 degrees thus returning an angle between 0-330 degrees. + * + * 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 + * EADDRINUSE - The port is not configured as a potentiometer + * + * \param 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); + +/** + * 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 adi_led_t; + +/** + * Initializes a led on the given port of the original led. + * + * 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 + * EINVAL - The ADI port given is not a valid port as defined below + * EADDRINUSE - The port is not configured for ADI output + * + * \param port + * The ADI port to initialize as a led (from 1-8, 'a'-'h', 'A'-'H') + * + * \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); + +/** + * @brief Clear the entire led strip of color + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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); + +/** + * @brief Set the entire led strip using the colors contained in the buffer + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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); + +/** + * @brief Set the entire led strip to one color + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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 + * @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); + +/** + * @brief Set one pixel on the led strip + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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 the input buffer + * @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); + +/** + * @brief Clear one pixel on the led strip + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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 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 305480546..2a758f247 100644 --- a/include/pros/adi.hpp +++ b/include/pros/adi.hpp @@ -1,38 +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 (c) 2017-2020, 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 "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. @@ -40,14 +57,29 @@ class ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \param adi_port * 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. @@ -55,20 +87,42 @@ class ADIPort { * 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). + * 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 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; @@ -76,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; @@ -87,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; @@ -101,6 +177,16 @@ 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; @@ -108,8 +194,13 @@ class ADIPort { std::uint8_t _smart_port; std::uint8_t _adi_port; }; +///@} -class ADIAnalogIn : private ADIPort { +class AnalogIn : protected Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as an Analog Input. @@ -117,32 +208,56 @@ class ADIAnalogIn : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \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 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). + * 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 @@ -152,29 +267,44 @@ class ADIAnalogIn : private 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: @@ -182,13 +312,25 @@ class ADIAnalogIn : private 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. @@ -204,32 +346,70 @@ class ADIAnalogIn : private 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 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)] */ - using ADIPort::get_value; + friend std::ostream& operator<<(std::ostream& os, pros::adi::AnalogIn& analog_in); }; -using ADIPotentiometer = ADIAnalogIn; -using ADILineSensor = ADIAnalogIn; -using ADILightSensor = ADIAnalogIn; -using ADIAccelerometer = ADIAnalogIn; +///@} -class ADIAnalogOut : private ADIPort { +// using ADIPotentiometer = ADIAnalogIn; +using LineSensor = AnalogIn; +using LightSensor = AnalogIn; +using Accelerometer = AnalogIn; + +class AnalogOut : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures an ADI port to act as an Analog Output. @@ -237,12 +417,22 @@ class ADIAnalogOut : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \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. @@ -250,35 +440,67 @@ class ADIAnalogOut : private ADIPort { * 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). + * 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 - * + * + * \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. - * - * This only works on ports configured as outputs, and the behavior will - * change depending on the configuration of the port. + * Sets the output for the Analog Output from 0 (0V) to 4095 (5V). * - * 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; + + /** + * 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. @@ -286,14 +508,29 @@ class ADIDigitalOut : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \param adi_port * 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. @@ -301,35 +538,79 @@ class ADIDigitalOut : private ADIPort { * 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). + * 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 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; + + /** + * 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. @@ -337,12 +618,22 @@ class ADIDigitalIn : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \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. @@ -350,13 +641,24 @@ class ADIDigitalIn : private ADIPort { * 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). + * 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 + * + * \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. @@ -375,24 +677,72 @@ 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 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. @@ -400,12 +750,25 @@ class ADIMotor : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \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. @@ -413,13 +776,27 @@ class ADIMotor : private ADIPort { * 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). + * 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 + * + * \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. @@ -430,6 +807,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; @@ -446,8 +836,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. @@ -456,12 +859,31 @@ 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; }; -class ADIEncoder : private ADIPort { +///@} + +class Encoder : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures a set of ADI ports to act as an Encoder. @@ -469,7 +891,7 @@ class ADIEncoder : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \param adi_port_top * The "top" wire from the encoder sensor with the removable cover side up @@ -477,8 +899,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. @@ -486,7 +919,7 @@ class ADIEncoder : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \param port_tuple * The tuple of the smart port number, the "top" wire from the encoder @@ -494,8 +927,20 @@ class ADIEncoder : private ADIPort { * the encoder sensor * \param reverse * 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); /** * Sets the encoder value to zero. @@ -509,6 +954,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; @@ -522,12 +979,40 @@ 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); }; -class ADIUltrasonic : private ADIPort { +///@} + +class Ultrasonic : private Port { + /** + * \addtogroup cpp-adi + * @{ + */ public: /** * Configures a set of ADI ports to act as an Ultrasonic sensor. @@ -535,7 +1020,7 @@ class ADIUltrasonic : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \param port_ping * The port connected to the orange OUTPUT cable. This should be in port @@ -543,8 +1028,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. @@ -552,15 +1052,31 @@ class ADIUltrasonic : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \param port_tuple * The tuple of the smart port number, the port connected to the orange - * OUTPUT cable (1, 3, 5, 7 or 'A', 'C', 'E', 'G'), and the port - * connected to the yellow INPUT cable (the next) highest port + * 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. @@ -575,19 +1091,40 @@ 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; }; -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. @@ -595,23 +1132,37 @@ class ADIGyro : private ADIPort { * 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). + * valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21). * * \param adi_port * 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. @@ -619,17 +1170,32 @@ class ADIGyro : private ADIPort { * 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). + * 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 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 @@ -643,6 +1209,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; @@ -655,9 +1235,684 @@ 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; }; + +///@} + +class Potentiometer : public AnalogIn { + /** + * \addtogroup cpp-adi + * @{ + */ + public: + /** + * Configures an ADI port to act as a Potentiometer. + * + * 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 adi_port + * 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 + */ + 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. + * + * 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 adi_port + * 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 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 + */ + 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. + * + * The original potentiometer rotates 250 degrees thus returning an angle between 0-250 degrees. + * Potentiometer V2 rotates 330 degrees thus returning an angle between 0-330 degrees. + * + * 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 + * 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; + + /** + * 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 a potentiometer + * + * \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 + */ + using AnalogIn::get_value; + + /** + * Calibrates the potentiometer on the specified port and returns the new + * calibration value. + * + * This method assumes that the potentiometer value is not actively changing at + * 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::adi::Potentiometer::get_value_calibrated() function. This function + * will return the difference between this value and the current sensor value + * when called. + * + * Do not use this function when the potentiometer value might be unstable (rotating the potentiometer) + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port is not configured as a potentiometer + * + * \return The average potentiometer value computed by this function + */ + using AnalogIn::calibrate; + + /** + * Gets the 12 bit calibrated value of a potentiometer port. + * + * The pros::adi::Potentiometer::calibrate() function must be run first. + * + * This function uses the following values of errno when an error state is + * reached: + * ENODEV - The port is not configured as a potentiometer + * + * \return The difference of the potentiometer value from its calibrated default from + * -4095 to 4095 + */ + 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); +}; + +///@} + +class Led : protected Port { + /** + * \addtogroup cpp-adi + * @{ + */ + public: + /** + * @brief Configures an ADI port to act as a LED. + * + * 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 adi_port + * 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 + * + */ + 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. + * + * 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 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 + */ + 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 + * recommended that you call .update(); after doing any operations with this. + * + * @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); + + /** + * @brief Clear the entire led strip of color + * + * 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 + * EINVAL - A parameter is out of bounds/incorrect + * 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(); + + /** + * @brief Force the LED strip to update with the current buffered values, this + * should be called after any changes to the buffer using the [] operator. + * + * This function uses the following values of errno when an error state is + * reached: + * EINVAL - A parameter is out of bounds/incorrect + * 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; + + /** + * @brief Set the entire led strip to one color + * + * This function uses the following values of errno when an error state is + * reached: + * EINVAL - A parameter is out of bounds/incorrect + * EADDRINUSE - The port is not configured for ADI output + * + * @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); + + /** + * @brief Set one pixel on the led strip + * + * This function uses the following values of errno when an error state is + * reached: + * EINVAL - A parameter is out of bounds/incorrect + * EADDRINUSE - The port is not configured for ADI output + * + * @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); + + /** + * @brief Clear one pixel on the led strip + * + * This function uses the following values of errno when an error state is + * reached: + * EINVAL - A parameter is out of bounds/incorrect + * EADDRINUSE - The port is not configured for ADI output + * + * @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); + + /** + * @brief Get the length of the led strip + * + * This function uses the following values of errno when an error state is + * reached: + * EINVAL - A parameter is out of bounds/incorrect + * 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(); + + 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 the match extended + * \param active_low + * If set to true, a value of false corresponds to the pneumatic's + * wire being set to high. + * + * \b Example + * \code + * #define ADI_PNEUMATICS_PORT 'a' + * + * void opcontrol() { + * pros::adi::Pneumatics pneumatics (ADI_PNEUMATICS_PORT); + * while (true) { + * // Set the pneumatic solenoid to true + * pneumatics.set_value(true); + * pros::delay(10); + * } + * } + * \endcode + */ + explicit Pneumatics(std::uint8_t adi_port, bool start_extended, bool active_low = false); + + /** + * 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 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 the match extended + * \param active_low + * If set to true, a value of false corresponds to the pneumatic's + * wire being set to high. + * + * \b Example + * \code + * #define ADI_PNEUMATICS_PORT 'a' + * #define SMART_PORT 1 + * + * void opcontrol() { + * pros::adi::Pneumatics pneumatics ({{ SMART_PORT , ADI_PNEUMATICS_PORT }}); + * while (true) { + * // Set the pneumatic solenoid to true + * pneumatics.set_value(true); + * pros::delay(10); + * } + * } + * \endcode + */ + explicit Pneumatics(ext_adi_port_pair_t port_pair, bool start_extended, bool active_low = false); + + /* + * Extends the piston, if not already extended. + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * #define ADI_PNEUMATICS_PORT 'a' + * + * void opcontrol() { + * pros::adi::Pneumatics pneumatics (ADI_PNEUMATICS_PORT); + * while (true) { + * // Extend the piston + * pneumatics.extend(); + * pros::delay(10); + * } + * } + * \endcode + */ + std::int32_t extend(); + + /* + * Retracts the piston, if not already retracted. + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + * + * \b Example + * \code + * #define ADI_PNEUMATICS_PORT 'a' + * + * void opcontrol() { + * pros::adi::Pneumatics pneumatics (ADI_PNEUMATICS_PORT); + * while (true) { + * // Retract the piston + * pneumatics.retract(); + * 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. + * + * \b Example + * \code + * #define ADI_PNEUMATICS_PORT 'a' + * + * void opcontrol() { + * pros::adi::Pneumatics pneumatics (ADI_PNEUMATICS_PORT); + * while (true) { + * // Toggle the piston + * pneumatics.toggle(); + * pros::delay(10); + * } + * } + * \endcode + */ + std::int32_t toggle(); + + /* + * Returns the current state of the piston. + * + * \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.get_state()) { + * // Do something + * } + * pros::delay(10); + * } + * } + * \endcode + */ + bool get_state() const; + +private: + bool active_low; + bool state; +}; +///@} + +} // 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 #endif // _PROS_ADI_HPP_ diff --git a/include/pros/api_legacy.h b/include/pros/api_legacy.h deleted file mode 100644 index 8768b5157..000000000 --- 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 (c) 2017-2020, 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 71146ada8..165c0541b 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 (c) 2017-2020, 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,42 +622,34 @@ 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_GENERIC = 129, - E_DEVICE_UNDEFINED = 255 -} v5_device_e_t; +/// \name Device Registration +///@{ -/* - * Registers a device in the given port +/** + * Registers a device in the given zero-indexed port * * Registers a device of the given type in the given port into the registry, if * that type of device is detected to be plugged in to that 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), or a + * ENXIO - The given value is not within the range of V5 ports (0-20), or a * a different device than specified is plugged in. * EADDRINUSE - The port is already registered to another device. * @@ -398,28 +659,91 @@ 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 port +/** + * Deregisters a devices from the given zero-indexed port * * Removes the device registed in the given port, if there is one. * * 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 (0-20). * * \param port * 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); -/******************************************************************************/ -/** Filesystem **/ -/******************************************************************************/ +/** + * Returns the type of device registered to the zero-indexed 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 (0-20). + * + * \param port + * The V5 port number from 0-20 + * + * \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 + * reached: + * ENXIO - The given value is not within the range of V5 ports (0-20). + * + * \param port + * The V5 port number from 0-20 + * + * \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); + +///@} + +/// \name Filesystem +///@{ + /** * Control settings of the serial driver. * @@ -428,10 +752,16 @@ int registry_unbind_port(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 @@ -455,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. @@ -465,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 @@ -477,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 @@ -488,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 @@ -499,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 @@ -511,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 @@ -523,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 @@ -532,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 @@ -541,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 @@ -553,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 0f5e3b93b..b70a8f997 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_ @@ -18,154 +30,175 @@ #define RGB2COLOR(R, G, B) ((R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff)) #define COLOR2R(COLOR) ((COLOR >> 16) & 0xff) -#define COLOR2G(COLOR) ((COLOR >> 8) && 0xff) +#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 new file mode 100644 index 000000000..970c2cfa9 --- /dev/null +++ b/include/pros/colors.hpp @@ -0,0 +1,190 @@ +/** + * \file pros/colors.hpp + * + * Contains enum class definitions of colors + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * Copyright (c) 2017-2022 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-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, + aqua = 0x0000FFFF, + aquamarine = 0x007FFFD4, + azure = 0x00F0FFFF, + beige = 0x00F5F5DC, + bisque = 0x00FFE4C4, + black = 0x00000000, + blanched_almond = 0x00FFEBCD, + blue = 0x000000FF, + blue_violet = 0x008A2BE2, + brown = 0x00A52A2A, + burly_wood = 0x00DEB887, + cadet_blue = 0x005F9EA0, + chartreuse = 0x007FFF00, + chocolate = 0x00D2691E, + coral = 0x00FF7F50, + cornflower_blue = 0x006495ED, + cornsilk = 0x00FFF8DC, + crimson = 0x00DC143C, + cyan = 0x0000FFFF, + dark_blue = 0x0000008B, + dark_cyan = 0x00008B8B, + dark_goldenrod = 0x00B8860B, + dark_gray = 0x00A9A9A9, + dark_grey = dark_gray, + dark_green = 0x00006400, + dark_khaki = 0x00BDB76B, + dark_magenta = 0x008B008B, + dark_olive_green = 0x00556B2F, + dark_orange = 0x00FF8C00, + dark_orchid = 0x009932CC, + dark_red = 0x008B0000, + dark_salmon = 0x00E9967A, + dark_sea_green = 0x008FBC8F, + dark_slate_gray = 0x002F4F4F, + dark_slate_grey = dark_slate_gray, + dark_turquoise = 0x0000CED1, + dark_violet = 0x009400D3, + deep_pink = 0x00FF1493, + deep_sky_blue = 0x0000BFFF, + dim_gray = 0x00696969, + dim_grey = dim_gray, + dodger_blue = 0x001E90FF, + fire_brick = 0x00B22222, + floral_white = 0x00FFFAF0, + forest_green = 0x00228B22, + fuchsia = 0x00FF00FF, + gainsboro = 0x00DCDCDC, + ghost_white = 0x00F8F8FF, + gold = 0x00FFD700, + goldenrod = 0x00DAA520, + gray = 0x00808080, + grey = gray, + green = 0x00008000, + green_yellow = 0x00ADFF2F, + honeydew = 0x00F0FFF0, + hot_pink = 0x00FF69B4, + indian_red = 0x00CD5C5C, + indigo = 0x004B0082, + ivory = 0x00FFFFF0, + khaki = 0x00F0E68C, + lavender = 0x00E6E6FA, + lavender_blush = 0x00FFF0F5, + lawn_green = 0x007CFC00, + lemon_chiffon = 0x00FFFACD, + light_blue = 0x00ADD8E6, + light_coral = 0x00F08080, + light_cyan = 0x00E0FFFF, + light_goldenrod_yellow = 0x00FAFAD2, + light_green = 0x0090EE90, + light_gray = 0x00D3D3D3, + light_grey = light_gray, + light_pink = 0x00FFB6C1, + light_salmon = 0x00FFA07A, + light_sea_green = 0x0020B2AA, + light_sky_blue = 0x0087CEFA, + light_slate_gray = 0x00778899, + light_slate_grey = light_slate_gray, + light_steel_blue = 0x00B0C4DE, + light_yellow = 0x00FFFFE0, + lime = 0x0000FF00, + lime_green = 0x0032CD32, + linen = 0x00FAF0E6, + magenta = 0x00FF00FF, + maroon = 0x00800000, + medium_aquamarine = 0x0066CDAA, + medium_blue = 0x000000CD, + medium_orchid = 0x00BA55D3, + medium_purple = 0x009370DB, + medium_sea_green = 0x003CB371, + medium_slate_blue = 0x007B68EE, + medium_spring_green = 0x0000FA9A, + medium_turquoise = 0x0048D1CC, + medium_violet_red = 0x00C71585, + midnight_blue = 0x00191970, + mint_cream = 0x00F5FFFA, + misty_rose = 0x00FFE4E1, + moccasin = 0x00FFE4B5, + navajo_white = 0x00FFDEAD, + navy = 0x00000080, + old_lace = 0x00FDF5E6, + olive = 0x00808000, + olive_drab = 0x006B8E23, + orange = 0x00FFA500, + orange_red = 0x00FF4500, + orchid = 0x00DA70D6, + pale_goldenrod = 0x00EEE8AA, + pale_green = 0x0098FB98, + pale_turquoise = 0x00AFEEEE, + pale_violet_red = 0x00DB7093, + papay_whip = 0x00FFEFD5, + peach_puff = 0x00FFDAB9, + peru = 0x00CD853F, + pink = 0x00FFC0CB, + plum = 0x00DDA0DD, + powder_blue = 0x00B0E0E6, + purple = 0x00800080, + red = 0x00FF0000, + rosy_brown = 0x00BC8F8F, + royal_blue = 0x004169E1, + saddle_brown = 0x008B4513, + salmon = 0x00FA8072, + sandy_brown = 0x00F4A460, + sea_green = 0x002E8B57, + seashell = 0x00FFF5EE, + sienna = 0x00A0522D, + silver = 0x00C0C0C0, + sky_blue = 0x0087CEEB, + slate_blue = 0x006A5ACD, + slate_gray = 0x00708090, + slate_grey = slate_gray, + snow = 0x00FFFAFA, + spring_green = 0x0000FF7F, + steel_blue = 0x004682B4, + tan = 0x00D2B48C, + teal = 0x00008080, + thistle = 0x00D8BFD8, + tomato = 0x00FF6347, + turquoise = 0x0040E0D0, + violet = 0x00EE82EE, + wheat = 0x00F5DEB3, + white = 0x00FFFFFF, + white_smoke = 0x00F5F5F5, + yellow = 0x00FFFF00, + yellow_green = 0x009ACD32, +}; +} // namespace pros + + ///@} + +#endif //_PROS_COLORS_HPP_ diff --git a/include/pros/device.h b/include/pros/device.h new file mode 100644 index 000000000..889e00859 --- /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 000000000..7fcee80ce --- /dev/null +++ b/include/pros/device.hpp @@ -0,0 +1,162 @@ +/** + * \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); + + /** + * 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; + + + 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 115cf2adb..63bcd417a 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 (c) 2017-2020, 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 b584966aa..288dff10d 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-2018, 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,6 +46,15 @@ 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); @@ -49,6 +68,19 @@ class Distance { * * \return The distance 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()); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t get(); @@ -66,6 +98,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(); @@ -83,6 +128,19 @@ class Distance { * * \return The size 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_object_size()); + * delay(20); + * } + * } + * \endcode */ virtual std::int32_t get_object_size(); @@ -96,19 +154,38 @@ 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. - * - * \return The distance sensor's port number. - */ - std::uint8_t 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): + * Distance [port: (port number), distance: (distance), confidence: (confidence), + * object size: (object size), object velocity: (object velocity)] + */ + friend std::ostream& operator<<(std::ostream& os, pros::Distance& distance); + private: - const std::uint8_t _port; + ///@} }; + +namespace literals { +const pros::Distance operator"" _dist(const unsigned long long int d); +} // namespace literals +} } // namespace pros #endif diff --git a/include/pros/error.h b/include/pros/error.h new file mode 100644 index 000000000..17dd6d3da --- /dev/null +++ b/include/pros/error.h @@ -0,0 +1,42 @@ +/** + * \file pros/error.h + * + * Contains macro definitions for return types, mostly errors + * + * 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_ERROR_H_ +#define _PROS_ERROR_H_ + +#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) + +/// @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 391617f4d..421b19381 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 (c) 2017-2020, 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,9 +1015,312 @@ 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. + */ +typedef int32_t ext_adi_potentiometer_t; + +/** + * Initializes a potentiometer on 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 + * EADDRINUSE - The port is not configured as a potentiometer + * + * \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 + * + * \return An adi_potentiometer_t object containing the given port, or PROS_ERR if the + * initialization failed. + */ +ext_adi_potentiometer_t ext_adi_potentiometer_init(uint8_t smart_port, uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type); + +/** + * Gets the current potentiometer angle in tenths of a degree. + * + * The original potentiometer rotates 250 degrees thus returning an angle between 0-250 degrees. + * Potentiometer V2 rotates 333 degrees thus returning an angle between 0-333 degrees. + * + * 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 + * EADDRINUSE - The port is not configured as a potentiometer + * + * \param potentiometer + * The adi_potentiometer_t object for which the angle will be returned + * + * \return The potentiometer angle in degrees. + */ +double ext_adi_potentiometer_get_angle(ext_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 the C++ API. + */ +typedef int32_t ext_adi_led_t; + +/** + * Initializes a led on 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * \param smart_port + * The smart port with the adi expander (1-21) + * \param adi_port + * The ADI port to initialize as a led (from 1-8, 'a'-'h', 'A'-'H') + * + * \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); + +/** + * @brief Clear the entire led strip of color + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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); + +/** + * @brief Set the entire led strip using the colors contained in the buffer + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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); + +/** + * @brief Set the entire led strip to one color + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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 + * @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); + +/** + * @brief Set one pixel on the led strip + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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 the input 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); + +/** + * @brief Clear one pixel on the led strip + * + * 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 + * EINVAL - A given value is not correct, or the buffer is null + * EADDRINUSE - The port is not configured for ADI output + * + * @param led port of type adi_led_t + * @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 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 new file mode 100644 index 000000000..9304e0f95 --- /dev/null +++ b/include/pros/gps.h @@ -0,0 +1,668 @@ +/** + * \file pros/gps.h + * \ingroup c-gps + * + * Contains prototypes for functions related to the VEX GPS. + * + * 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-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_ +#define _PROS_GPS_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +namespace pros { +#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 { + /// X Position (meters) + double x; + /// Y Position (meters) + double y; + /// Percieved Pitch based on GPS + IMU + double pitch; + /// Percieved Roll based on GPS + IMU + double roll; + /// Percieved Yaw based on GPS + IMU + double yaw; +} gps_status_s_t; + +/** + * \struct gps_raw_s + */ +struct gps_raw_s { + /// Percieved Pitch based on GPS + IMU + double x; + /// Percieved Roll based on GPS + IMU + double y; + /// Percieved 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. + * + * 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 xOffset + * Cartesian 4-Quadrant X offset from center of turning (meters) + * \param yOffset + * Cartesian 4-Quadrant Y offset from center of turning (meters) + * \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 + * 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); + +/** + * Set the GPS's offset relative to the center of turning 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 + * \param xOffset + * Cartesian 4-Quadrant X offset from center of turning (meters) + * \param yOffset + * 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); + +/** + * Gets the position and roll, yaw, and pitch of the 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 + * + * \param port + * The V5 GPS port number from 1-21 + * + * \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_status(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); + +/** + * 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); + +/** + * Get the GPS's raw gyroscope values + * + * 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. + * + * \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 + */ +gps_gyro_s_t gps_get_gyro_rate(uint8_t port); + +/** + * Get the GPS's raw accelerometer values + * + * 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 values. 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 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 + * + * \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; + * + * while (true) { + * pos = gps_get_offset(GPS_PORT, x, y); + * screen_print(TEXT_MEDIUM, 1, "X Offset: %4d, Y Offset: %4d", pos.x, pos.y); + * delay(20); + * } + * } + * \endcode + */ +gps_position_s_t gps_get_offset(uint8_t port); + +/** + * Sets the robot's location relative to the center of the field 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 + * \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 + * 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); + +/** + * Set the GPS sensor's data rate in milliseconds, only applies to IMU on 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 + * + * \param port + * The V5 GPS port number from 1-21 + * \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 + * #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); + +/** + * Get the possible RMS (Root Mean Squared) error in meters for GPS 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 + * + * \param port + * The V5 GPS port number from 1-21 + * + * \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); + +/** + * Gets the position and roll, yaw, and pitch of the 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 + * + * \param port + * The V5 GPS port number from 1-21 + * + * \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() { + * struct gps_status_s_t status; + * + * while (true) { + * status = gps_get_status(GPS_PORT); + * screen_print(TEXT_MEDIUM, 1, "x: %3f, y: %3f, pitch: %3f", status.x, status.y); + * screen_print(TEXT_MEDIUM, 2, "yaw: %3f, roll: %3f", status.pitch, status.yaw); + * screen_print(TEXT_MEDIUM, 3, "roll: %3f", status.roll); + * delay(20); + * } + * } + * \endcode + */ +gps_status_s_t gps_get_status(uint8_t port); + +/** + * Get the heading in [0,360) degree values. + * + * 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 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); + * delay(20); + * } + * } + * \endcode + */ +double gps_get_heading(uint8_t port); + +/** + * Get the heading in the max double value and min double value scale. + * + * 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 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; + * + * while (true) { + * heading = gps_get_heading_raw(GPS_PORT); + * delay(20); + * } + * } + * \endcode + */ +double gps_get_heading_raw(uint8_t port); + +/** + * Gets the GPS sensor's elapsed rotation 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 GPS + * EAGAIN - The sensor is still calibrating + * + * \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. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * double elapsed_rotation; + * + * elapsed_rotation = gps_get_rotation(GPS_PORT); + * printf("Elapsed rotation: %3f", elapsed_rotation); + * } + * \endcode + */ +double gps_get_rotation(uint8_t port); + +/** + * Set the GPS sensor's rotation value to target 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 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. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * gps_set_rotation(GPS_PORT, 60); + * printf("Elapsed rotation: %3f", gps_get_rotation(GPS_PORT)); + * } + * \endcode + */ +int32_t gps_set_rotation(uint8_t port, double target); + +/** + * Tare the GPS sensor's rotation 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 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. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void initialize() { + * gps_tare_rotation(GPS_PORT); + * printf("Elapsed rotation: %3f", gps_get_rotation(GPS_PORT)); // should be 0 + * } + * \endcode + */ +int32_t gps_tare_rotation(uint8_t port); + +/** + * Get the GPS's raw gyroscope values + * + * 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. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * struct gps_gyro_s_t gyro; + * + * while (true) { + * gyro = gps_get_gyro_rate(GPS_PORT); + * screen_print(TEXT_MEDIUM, 1, "gyroscope- x: %3f, y: %3f, z: %3f", gyro.x, gyro.y, gyro.z); + * delay(20); + * } + * } + * \endcode + */ +gps_gyro_s_t gps_get_gyro_rate(uint8_t port); + +/** + * Get the GPS's raw accelerometer values + * + * 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 values. 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() { + * struct gps_accel_s_t accel; + * + * while (true) { + * accel = gps_get_accel(GPS_PORT); + * screen_print(TEXT_MEDIUM, 1, "accleration- x: %3f, y: %3f, z: %3f", accel.x, accel.y, accel.z); + * } + * } + * \endcode + */ +gps_accel_s_t gps_get_accel(uint8_t port); + +///@} + +#ifdef __cplusplus +} +} +} +#endif + +#endif diff --git a/include/pros/gps.hpp b/include/pros/gps.hpp new file mode 100644 index 000000000..d081d619b --- /dev/null +++ b/include/pros/gps.hpp @@ -0,0 +1,649 @@ +/** + * \file pros/gps.hpp + * \ingroup cpp-gps + * + * Contains prototypes for functions related to the VEX GPS. + * + * 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-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_ +#define _PROS_GPS_HPP_ + +#include + +#include +#include + +#include "pros/gps.h" +#include "pros/device.hpp" + +namespace pros { +inline namespace v5 { +/** + * \ingroup cpp-gps + * @{ + */ +class Gps : public Device { + /** + * \addtogroup cpp-gps + * @{ + */ + + public: + + /** + * 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 + * + */ + explicit Gps(const std::uint8_t port) : Device(port, DeviceType::gps){}; + + /** + * 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); + }; + + /** + * 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); + }; + + /** + * 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); + }; + + /** + * Set the GPS's offset relative to the center of turning in meters, + * as well as its initial 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 + * + * \param xOffset + * Cartesian 4-Quadrant X offset from center of turning (meters) + * \param yOffset + * Cartesian 4-Quadrant Y offset from center of turning (meters) + * \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 + * 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; + + /** + * Set the GPS's offset relative to the center of turning 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 xOffset + * Cartesian 4-Quadrant X offset from center of turning (meters) + * \param yOffset + * 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 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 + * + * \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 pros::gps_position_s_t get_offset() const; + + /** + * Sets the robot's location relative to the center of the field 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 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 + * 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; + + /** + * Set the GPS sensor's data rate in milliseconds, only applies to IMU on 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 + * + * \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; + + /** + * Get the possible RMS (Root Mean Squared) error in meters for GPS 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 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; + + /** + * Gets the position and roll, yaw, and pitch of the 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 + * + * + * \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_status(); + * printf("X: %f, Y: %f, Heading: %f, Roll: %f, Pitch: %f, Yaw: %f\n", + * status.x, status.y, status.heading, status.roll, status.pitch, status.yaw); + * delay(20); + * } + * } + * \endcode + */ + virtual pros::gps_status_s_t get_status() const; + + /** + * 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 + * + * \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, Heading: %f\n", position.x, position.y, + * position.heading); + * delay(20); + * } + * } + * \endcode + */ + virtual pros::gps_position_s_t get_position() const; + + /** + * Get the heading in [0,360) degree values. + * + * 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 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; + + /** + * Get the heading in the max double value and min double value scale. + * + * 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 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 + * + * 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 elased heading in degrees. 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 rotation = gps.get_rotation(); + * printf("Rotation: %f\n", rotation); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual double get_rotation() const; + + /** + * Set the GPS sensor's rotation value to target 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 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. + * + * \b Example + * \code + * #define GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * double rotation = gps.set_rotation(90); + * while(true) { + * printf("Rotation: %f\n", rotation); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual std::int32_t set_rotation(double target) const; + + /** + * Tare the GPS sensor's rotation 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 GPS + * EAGAIN - The sensor is still calibrating + * + * \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.tare_rotation(); + * while(true) { + * Should be around 0 on first call since it was tared. + * printf("Rotation: %f\n", rotation); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual std::int32_t tare_rotation() const; + + /** + * Get the GPS's raw gyroscope values + * + * 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 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 GPS_PORT 1 + * + * void opcontrol() { + * Gps gps(GPS_PORT); + * while(true) { + * pros::gps_gyro_s_t gyro = gps.get_gyro_rate(); + * printf("Gyro: %f, %f, %f\n", gyro.x, gyro.y, gyro.z); + * pros::delay(20); + * } + * } + * \endcode + */ + virtual pros::gps_gyro_s_t get_gyro_rate() const; + + /** + * Get the GPS's raw accelerometer values + * + * 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 values. If the operation failed, all the + * structure's members are filled with PROS_ERR_F and errno is set. + */ + virtual pros::gps_accel_s_t get_accel() 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); + +///@} +}; // 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 0caf68430..bf724ab05 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 (c) 2017-2020, 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,15 +25,32 @@ #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 { + /** The IMU is calibrating */ E_IMU_STATUS_CALIBRATING = 0x01, - 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 + /** 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; +/** + * \struct quaternion_s_t + */ typedef struct __attribute__((__packed__)) quaternion_s { double x; double y; @@ -41,42 +58,115 @@ 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 +#define IMU_STATUS_ERROR pros::E_IMU_STATUS_ERROR +#else +#define IMU_STATUS_CALIBRATING E_IMU_STATUS_CALIBRATING +#define IMU_STATUS_ERROR E_IMU_STATUS_ERROR +#endif +#endif + #define IMU_MINIMUM_DATA_RATE 5 /** * Calibrate IMU * - * This takes approximately 2 seconds, and is a non-blocking operation. + * Calibration takes approximately 2 seconds, but this function only blocks + * until the IMU status flag is set properly to E_IMU_STATUS_CALIBRATING, + * with a minimum blocking time of 5ms. * * 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 already calibrating + * EAGAIN - The sensor is already calibrating, or time out setting the status flag. * * \param 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. + * 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); - +/** + * Calibrate IMU and Blocks while Calibrating + * + * Calibration takes approximately 2 seconds and blocks during this period, + * with a timeout for this operation being set a 3 seconds as a safety margin. + * Like the other reset function, this function also blocks until the IMU + * status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum + * blocking time of 5ms and a timeout of 1 second if it's never set. + * + * 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 already calibrating, or time out setting the status flag. + * + * \param port + * The V5 Inertial Sensor port number from 1-21 + * \return 1 if the operation was successful or PROS_ERR if the operation + * 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. * @@ -100,6 +190,11 @@ int32_t imu_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 + * + * \endcode */ int32_t imu_set_data_rate(uint8_t port, uint32_t rate); @@ -120,6 +215,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); @@ -127,7 +234,7 @@ double imu_get_rotation(uint8_t port); * Get the Inertial Sensor's heading relative to the initial direction of its * x-axis * - * This value is bounded by (-360,360). Clockwise rotations are represented with + * This value is bounded by [0,360). Clockwise rotations are represented with * positive degree values, while counterclockwise rotations are represented with * negative ones. * @@ -141,6 +248,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); @@ -158,6 +277,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); @@ -175,11 +307,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 + * Get the Inertial Sensor's raw gyroscope values * * This function uses the following values of errno when an error state is * reached: @@ -191,11 +336,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 + * Get the Inertial Sensor's raw acceleroneter values * * This function uses the following values of errno when an error state is * reached: @@ -206,11 +363,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 + * Get the Inertial Sensor's status * * This function uses the following values of errno when an error state is * reached: @@ -221,11 +390,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: @@ -237,11 +420,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: @@ -253,11 +449,24 @@ 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: @@ -269,13 +478,466 @@ imu_accel_s_t imu_get_accel(uint8_t 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); +/** + * \name Value Reset Functions + * @{ + */ + +/** + * Resets the current reading of the Inertial Sensor's heading to zero + * + * 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 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); + +/** + * Resets the current reading of the Inertial Sensor's rotation to zero + * + * 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 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); + +/** + * Resets the current reading of the Inertial Sensor's pitch to zero + * + * 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 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); + +/** + * Resets the current reading of the Inertial Sensor's roll to zero + * + * 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 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); + +/** + * Resets the current reading of the Inertial Sensor's yaw to zero + * + * 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 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); + +/** + * Reset all 3 euler values of the Inertial Sensor to 0. + * + * 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 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); + +/** + * Resets all 5 values of the Inertial Sensor to 0. + * + * 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 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); + +/** @} */ + +/** + * \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. + * + * 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 + * \param target + * 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); + +/** + * Sets the current reading of the Inertial Sensor's rotation to target 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 an Inertial Sensor + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 Inertial Sensor port number from 1-21 + * \param 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); + +/** + * Sets the current reading of the Inertial Sensor's heading to target value + * Target will default to 360 if above 360 and default to 0 if below 0. + * + * 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 + * \param 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); + +/** + * Sets the current reading of the Inertial Sensor's pitch to target value + * Will default to +/- 180 if target exceeds +/- 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 + * \param 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); + +/** + * Sets the current reading of the Inertial Sensor's roll to target value + * Will default to +/- 180 if target exceeds +/- 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 + * \param 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); + +/** + * Sets the current reading of the Inertial Sensor's yaw to target value + * Will default to +/- 180 if target exceeds +/- 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 + * \param 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); + +/** @} */ + +/** @} */ + #ifdef __cplusplus } } diff --git a/include/pros/imu.hpp b/include/pros/imu.hpp index 07159f525..cb141eccb 100644 --- a/include/pros/imu.hpp +++ b/include/pros/imu.hpp @@ -1,70 +1,168 @@ /** * \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 (c) 2017-2020, 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 "pros/imu.h" +#include "pros/device.hpp" +#include 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 { + /** The IMU is calibrating */ + calibrating = 0x01, + /** 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 + */ + explicit Imu(const std::uint8_t port) : Device(port, DeviceType::imu) {}; /** * Calibrate IMU * - * This takes approximately 2 seconds, and is a non-blocking operation. + * Calibration takes approximately 2 seconds and blocks during this period if + * the blocking param is true, with a timeout for this operation being set a 3 + * seconds as a safety margin. This function also blocks until the IMU + * status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum + * blocking time of 5ms and a timeout of 1 second if it's never set. * * 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 already calibrating + * EAGAIN - The sensor is already calibrating, or time out setting the status flag. * + * \param blocking + * 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; + /** + * Set the Inertial Sensor's refresh interval in milliseconds. + * + * The rate may be specified in increments of 5ms, and will be rounded down to + * the nearest increment. The minimum allowable refresh rate is 5ms. The default + * rate is 10ms. + * + * As values are copied into the shared memory buffer only at 10ms intervals, + * setting this value to less than 10ms does not mean that you can poll the + * sensor's values any faster. However, it will guarantee that the data is as + * recent as possible. + * + * 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 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 reset() const; - /** - * Set the Inertial Sensor's refresh interval in milliseconds. - * - * The rate may be specified in increments of 5ms, and will be rounded down to - * the nearest increment. The minimum allowable refresh rate is 5ms. The default - * rate is 10ms. - * - * As values are copied into the shared memory buffer only at 10ms intervals, - * setting this value to less than 10ms does not mean that you can poll the - * sensor's values any faster. However, it will guarantee that the data is as - * recent as possible. - * - * 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 rate The data refresh interval in milliseconds - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. - */ virtual std::int32_t set_data_rate(std::uint32_t rate) const; /** * Get the total number of degrees the Inertial Sensor has spun about the z-axis @@ -83,13 +181,29 @@ 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; /** * Get the Inertial Sensor's heading relative to the initial direction of its * x-axis * - * This value is bounded by (-360,360). Clockwise rotations are represented with + * This value is bounded by [0,360). Clockwise rotations are represented with * positive degree values, while counterclockwise rotations are represented with * negative ones. * @@ -103,6 +217,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; /** @@ -119,8 +249,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 * @@ -135,10 +282,27 @@ 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 + * 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: @@ -150,10 +314,26 @@ 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; /** - * Get the Inertial Sensor's roll angle + * 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: @@ -164,10 +344,26 @@ 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; /** - * Get the Inertial Sensor's yaw angle + * 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: @@ -178,6 +374,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; /** @@ -193,10 +405,488 @@ 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::imu_gyro_s_t get_gyro_rate() const; + /** + * Resets the current reading of the Inertial Sensor's rotation to zero + * + * 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 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; + /** + * Resets the current reading of the Inertial Sensor's heading to zero + * + * 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 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; + /** + * Resets the current reading of the Inertial Sensor's pitch to zero + * + * 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 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; + /** + * Resets the current reading of the Inertial Sensor's yaw to zero + * + * 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 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; + /** + * Resets the current reading of the Inertial Sensor's roll to zero + * + * 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 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; + /** + * Resets all 5 values of the Inertial Sensor to 0. + * + * 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 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; + /** + * Reset all 3 euler values of the Inertial Sensor to 0. + * + * 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 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; + /** + * Sets the current reading of the Inertial Sensor's heading to target value + * Target will default to 360 if above 360 and default to 0 if below 0. + * + * 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 + * \param 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() { + * 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; + /** + * Sets the current reading of the Inertial Sensor's rotation to target 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 an Inertial Sensor + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 Inertial Sensor port number from 1-21 + * \param 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() { + * 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; + /** + * Sets the current reading of the Inertial Sensor's yaw to target value + * Will default to +/- 180 if target exceeds +/- 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 + * \param target + * 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 pros::c::imu_gyro_s_t get_gyro_rate() const; + virtual std::int32_t set_yaw(const double target) const; /** - * Get the Inertial Sensor's raw acceleroneter values + * Sets the current reading of the Inertial Sensor's pitch to target 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 an Inertial Sensor + * EAGAIN - The sensor is still calibrating + * + * \param port + * The V5 Inertial Sensor port number from 1-21 + * \param 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() { + * 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; + /** + * Sets the current reading of the Inertial Sensor's roll to target value + * Will default to +/- 180 if target exceeds +/- 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 + * \param target + * 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; + /** + * 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: + * 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 + * \param target + * 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::euler_s_t target) const; + /** + * Get the Inertial Sensor's raw accelerometer values * * This function uses the following values of errno when an error state is * reached: @@ -208,8 +898,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 * @@ -223,16 +932,77 @@ class Imu { * 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; + + /** + * 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); + + ///@} }; + +namespace literals { +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 new file mode 100644 index 000000000..3e33f172c --- /dev/null +++ b/include/pros/link.h @@ -0,0 +1,421 @@ +/** + * \file pros/link.h + * \ingroup c-link + * + * Contains prototypes for functions related to the robot to robot communications. + * + * 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-link VEX Link C API + */ + +#ifndef _PROS_LINK_H_ +#define _PROS_LINK_H_ + +#include +#include + +#ifdef __cplusplus +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, ///< 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_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_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 +namespace c { +#endif + +/** + * 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. + * PROS currently only supports the use of one radio per brain. + * + * \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 + * 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 + * 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); + +/** + * Initializes a link on a radio port, with an indicated type and the ability for + * vexlink to override the controller radio. There might be a 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. + * + * \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 + * 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 + * 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. + * + * \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 + * 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 + * + * \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 + * 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. + * + * \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 + * The port of the radio for the intended link. + * + * \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. + * + * \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 + * room in the FIFO buffer (queue) to transmit the data. + * EINVAL - The data given is NULL + * + * \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 + * 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. + * + * \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 + * 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 + * 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. + * + * \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 + * room in the FIFO buffer (queue) to transmit the data. + * EINVAL - The data given is NULL + * + * \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 + * 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. + * + * \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. + * EBADMSG - Protocol error related to start byte, data size, or checksum. + * + * \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 + * 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. + * + * \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 + * The port of the radio for the intended link. + * + * \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 +} +} +} +#endif + +#endif diff --git a/include/pros/link.hpp b/include/pros/link.hpp new file mode 100644 index 000000000..40d48faae --- /dev/null +++ b/include/pros/link.hpp @@ -0,0 +1,283 @@ +/** + * \file pros/link.hpp + * \ingroup cpp-link + * + * Contains prototypes for functions related to robot to robot communications. + * + * 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-link VEX Link C++ API + */ +#ifndef _PROS_LINK_HPP_ +#define _PROS_LINK_HPP_ + +#include +#include + +#include "pros/link.h" +#include "pros/device.hpp" + +namespace pros { +/** + * \ingroup cpp-link + */ +class Link : public Device { + /** + * \addtogroup cpp-link + * ///@{ + */ + private: + + 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. + * + * \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 + * 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 + * 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 + * + * \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 + */ + explicit Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov = false); + + /** + * Checks if a radio link on a port is active or not. + * + * \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 + * + * \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 + * 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. + * + * \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. + * + * \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 + * room in the FIFO buffer (queue) to transmit the data. + * EINVAL - The data given is NULL + * + * \param data + * Buffer with data to send + * \param data_size + * Buffer with data to send + * + * \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. + * + * \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 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 + * 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. + * + * \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 + * room in the FIFO buffer (queue) to transmit the data. + * EINVAL - The data given is NULL + * + * \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 + * 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. + * + * \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. + * EBADMSG - Protocol error related to start byte, data size, or checksum. + + * \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 + * 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. + * + * \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 + +#endif diff --git a/include/pros/llemu.h b/include/pros/llemu.h index aef90d6f9..868cd7361 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 (c) 2017-2020, 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,128 +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); +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 a7eaa3729..4f75d6c79 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 (c) 2017-2020, 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,174 +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. - */ -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. + * \ingroup cpp-llemu */ -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); -} // 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 7bdb00f58..d0ad6764b 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 (c) 2017-2020, 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,169 @@ #define NUM_V5_PORTS (22) -/******************************************************************************/ -/** V5 Competition **/ -/******************************************************************************/ +/** + * \ingroup c-misc + */ + +/** + * \addtogroup c-misc + * @{ + */ + +/// \name V5 Competition +//@{ + #define COMPETITION_DISABLED (1 << 0) #define COMPETITION_AUTONOMOUS (1 << 1) #define COMPETITION_CONNECTED (1 << 2) +#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); + #ifdef __cplusplus } } } #endif + +/** + * \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 + */ #define competition_is_disabled() ((competition_get_status() & COMPETITION_DISABLED) != 0) + +/** + * \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 + */ #define competition_is_connected() ((competition_get_status() & COMPETITION_CONNECTED) != 0) + +/** + * \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 + */ #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,12 +234,10 @@ 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) { \ @@ -169,6 +274,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); @@ -191,6 +306,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); @@ -208,6 +333,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); @@ -225,6 +357,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); @@ -246,6 +385,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); @@ -275,20 +430,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). @@ -304,20 +473,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). @@ -331,6 +516,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); @@ -354,21 +554,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). @@ -376,14 +585,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: @@ -401,6 +619,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); @@ -412,6 +645,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); @@ -423,6 +663,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); @@ -434,6 +681,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); @@ -445,6 +699,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); @@ -452,12 +713,43 @@ 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); +/******************************************************************************/ +/** 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 72a689af2..8ade055ad 100644 --- a/include/pros/misc.hpp +++ b/include/pros/misc.hpp @@ -1,21 +1,22 @@ /** * \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 (c) 2017-2020, 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_ @@ -27,7 +28,15 @@ #include 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,6 +490,20 @@ 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); @@ -323,9 +516,17 @@ 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); } // 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 000000000..f6dd7ee68 --- /dev/null +++ b/include/pros/motor_group.hpp @@ -0,0 +1,2313 @@ +/** + * \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::green + * Optional parameter for the gearset for the motor. + * set to pros::v5::MotorGears::green if not specifed. + * + * \param encoder_units = pros::v5::MotorUnits::degrees + * Optional parameter for the encoder units of the motor + * set to pros::v5::MotorUnits::degrees if not specified by the user + * + * \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 + */ + explicit MotorGroup(const std::initializer_list, const pros::v5::MotorGears gearset = pros::v5::MotorGears::green, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::degrees); + /** + * 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::green + * Optional parameter for the gearset for the motor. + * set to pros::v5::MotorGears::green if not specifed. + * + * \param encoder_units = pros::v5::MotorUnits::degrees + * Optional parameter for the encoder units of the motor + * set to pros::v5::MotorUnits::degrees if not specified by the user + * + * \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 + */ + explicit MotorGroup(const std::vector& ports, const pros::v5::MotorGears gearset = pros::v5::MotorGears::green, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::degrees); + + /// \name Motor movement functions + /// These functions allow programmers to make motors move + ///@{ + + /** + * Sets the voltage for the motor group from -128 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 pros::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}, E_MOTOR_GEARSET_18); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * mg = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t operator=(std::int32_t voltage) const; + + /** + * 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 vecotr 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 vecotr 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 vecotr 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 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 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 vecotr 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 Motor_Brake 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 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::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 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::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 Motor_Gears according to what is set for the motor, + * or pros::Motor_Gears::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 Motor_Gears according to what is set for the motor, + * or pros::Motor_Gears::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 Motor_Brake 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 Motor_Brake 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 Motor_Brake 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 Motor_Brake 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 Motor_Brake 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 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::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 Motor_Brake 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 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::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 Motor_Units 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 Motor_Units 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 Motor_Units 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 Motor_Units 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 + * 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(pros::MotorGears::blue, 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 + * 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 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 + * + * * \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+=(MotorGroup&); + + /** + * Appends all the motors in the other motor group reference to this motor group + * + * Maintains the order of the other motor group + * + */ + void append(MotorGroup&); + + /** + * 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 35ef6e45a..ad6ef34a5 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 (c) 2017-2020, 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,84 @@ 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. + * + * 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 motor_move_absolute(port, 0) + * or motor_move_relative(port, 0). + * + * 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 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(int8_t port); /** * Sets the target absolute position for the motor to move to. @@ -62,16 +114,18 @@ int32_t motor_move(uint8_t port, int32_t voltage); * 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 @@ -79,8 +133,29 @@ int32_t motor_move(uint8_t port, int32_t voltage); * * \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. @@ -91,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 @@ -107,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. @@ -119,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 * + * \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. @@ -269,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 @@ -389,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 @@ -428,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 @@ -455,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. @@ -531,54 +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, // 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, // 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_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 @@ -592,9 +911,15 @@ typedef enum motor_gearset_e { #define MOTOR_ENCODER_COUNTS pros::E_MOTOR_ENCODER_COUNTS #define MOTOR_ENCODER_INVALID pros::E_MOTOR_ENCODER_INVALID #define MOTOR_GEARSET_36 pros::E_MOTOR_GEARSET_36 +#define MOTOR_GEAR_RED pros::E_MOTOR_GEAR_RED +#define MOTOR_GEAR_100 pros::E_MOTOR_GEAR_100 #define MOTOR_GEARSET_18 pros::E_MOTOR_GEARSET_18 +#define MOTOR_GEAR_GREEN pros::E_MOTOR_GEAR_GREEN +#define MOTOR_GEAR_200 pros::E_MOTOR_GEAR_200 #define MOTOR_GEARSET_06 pros::E_MOTOR_GEARSET_06 #define MOTOR_GEARSET_6 pros::E_MOTOR_GEARSET_06 +#define MOTOR_GEAR_BLUE pros::E_MOTOR_GEAR_BLUE +#define MOTOR_GEAR_600 pros::E_MOTOR_GEAR_600 #define MOTOR_GEARSET_INVALID pros::E_MOTOR_GEARSET_INVALID #else #define MOTOR_BRAKE_COAST E_MOTOR_BRAKE_COAST @@ -606,43 +931,63 @@ typedef enum motor_gearset_e { #define MOTOR_ENCODER_COUNTS E_MOTOR_ENCODER_COUNTS #define MOTOR_ENCODER_INVALID E_MOTOR_ENCODER_INVALID #define MOTOR_GEARSET_36 E_MOTOR_GEARSET_36 +#define MOTOR_GEAR_RED E_MOTOR_GEAR_RED +#define MOTOR_GEAR_100 E_MOTOR_GEAR_100 #define MOTOR_GEARSET_18 E_MOTOR_GEARSET_18 +#define MOTOR_GEAR_GREEN E_MOTOR_GEAR_GREEN +#define MOTOR_GEAR_200 E_MOTOR_GEAR_200 #define MOTOR_GEARSET_06 E_MOTOR_GEARSET_06 #define MOTOR_GEARSET_6 E_MOTOR_GEARSET_06 +#define MOTOR_GEAR_BLUE E_MOTOR_GEAR_BLUE +#define MOTOR_GEAR_600 E_MOTOR_GEAR_600 #define MOTOR_GEARSET_INVALID E_MOTOR_GEARSET_INVALID #endif #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 @@ -656,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 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 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 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 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 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 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. @@ -972,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 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 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. @@ -1081,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 adcce8add..eb8cfa8f1 100644 --- a/include/pros/motors.hpp +++ b/include/pros/motors.hpp @@ -1,69 +1,90 @@ /** * \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-2018, 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 "pros/abstract_motor.hpp" +#include "pros/device.hpp" #include "pros/motors.h" +#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). - * ENODEV - The port cannot be configured as a motor - * + * 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 gearset - * The motor's gearset - * \param reverse - * True reverses the motor, false is default - * \param encoder_units - * The motor's encoder units + * 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 + * + * \param gearset = pros::v5::MotorGears::green + * Optional parameter for the gearset for the motor. + * set to pros::v5::MotorGears::green if not specifed. + * + * \param encoder_units = pros::v5::MotorUnits::degrees + * Optional parameter for the encoder units of the motor + * set to pros::v5::MotorUnits::degrees if not specified by the user + * + * \b Example + * \code + * void opcontrol() { + * Motor first_motor(1); //Creates a motor on port 1 with green gearset and degrees as the encoder units + * Motor reversed_motor(-2); //Creates a reversed motor on port 1 with standard gearset and encoder units + * Motor blue_motor(3, pros::v5::MotorGears::blue); //Creates a motor on port 3 with blue gear set and degrees + * Motor rotations_motor(4, pros::v5::MotorGears::green, pros::v5::MotorUnits::rotations); port 4 w/ rotations + * + * } + * \endcode + * */ - explicit Motor(const std::uint8_t port, const motor_gearset_e_t gearset, const bool reverse, - const motor_encoder_units_e_t encoder_units); - - explicit Motor(const std::uint8_t port, const motor_gearset_e_t gearset, const bool reverse); - - explicit Motor(const std::uint8_t port, const motor_gearset_e_t gearset); + explicit Motor(const std::int8_t port, const pros::v5::MotorGears gearset = pros::v5::MotorGears::green, + const pros::v5::MotorUnits encoder_units = pros::v5::MotorUnits::degrees); - explicit Motor(const std::uint8_t port, const bool reverse); + + /// \name Motor movement functions + /// These functions allow programmers to make motors move + ///@{ - explicit Motor(const std::uint8_t port); - - /****************************************************************************/ - /** Motor movement functions **/ - /** **/ - /** These functions allow programmers to make motors move **/ - /****************************************************************************/ /** * Sets the voltage for the motor from -128 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 pros::Motor::move(), or motorSet from the PROS 2 API. + * analogous to use of pros::Motor::move(). * * This function uses the following values of errno when an error state is * reached: @@ -74,15 +95,27 @@ 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, E_MOTOR_GEARSET_18); + * pros::Controller master (E_CONTROLLER_MASTER); + * while (true) { + * motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t operator=(std::int32_t voltage) const; + std::int32_t operator=(std::int32_t voltage) const; /** * 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: @@ -93,8 +126,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. @@ -105,6 +150,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: @@ -117,16 +163,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. @@ -142,8 +209,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. @@ -164,8 +247,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. @@ -181,13 +274,49 @@ class Motor { * * \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. + * + * 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 + * + * \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 + */ + 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: @@ -199,74 +328,327 @@ 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; /** - * 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 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 * + * + * \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 + */ + std::vector get_target_position_all(void) const; + + /** + * 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 + */ + std::int32_t get_target_velocity(const std::uint8_t index = 0) const; + + /** + * 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 + * + * \return A vector containing 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_all()[0]; + * // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t get_target_velocity(void) const; + std::vector get_target_velocity_all(void) const; - /****************************************************************************/ - /** 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 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. + * 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 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 + */ + std::vector get_actual_velocity_all(void) 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 + */ + std::int32_t get_current_draw(const std::uint8_t index = 0) const; + + + /** + * 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 A vector conatining 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_current_draw(void) const; + std::vector get_current_draw_all(void) 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 + */ + std::int32_t get_direction(const std::uint8_t index = 0) const; + + /** + * 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: + * + * ENODEV - The port cannot be configured as a motor + * + * + * \return A vecotr 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::int32_t get_direction(void) const; + std::vector get_direction_all(void) const; /** * Gets the efficiency of the motor in percent. @@ -275,559 +657,1748 @@ 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 a vector containing 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 + * * - * \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. + * \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 */ - virtual std::int32_t is_over_current(void) const; + std::vector get_efficiency_all(void) const; /** - * Checks if the motor is stopped. + * Gets the faults experienced by the motor. + * + * 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 + * + * 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 + * * - * \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. + * \return A bitfield containing the motor's faults. * - * \return 1 if the motor is not moving, 0 if the motor is moving, 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();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 a vector of 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 * - * \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. + * \return A bitfield containing the motor's faults. * - * \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 + * \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 */ - virtual std::int32_t get_zero_position_flag(void) const; - + std::vector get_faults_all(void) const; + /** - * Gets the faults experienced by the motor. + * Gets the flags set by the motor's operation. * - * Compare this bitfield to the bitmasks in pros::motor_fault_e_t. + * 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 + * + * 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 port - * The V5 port number from 1-21 + * \return A bitfield containing the motor's flags. * - * \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::uint32_t get_faults(void) const; + std::uint32_t get_flags(const std::uint8_t index = 0) const; /** - * Gets the flags set by the motor's operation. + * Gets a vector of 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 port - * The V5 port number from 1-21 * * \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 */ - virtual std::uint32_t get_flags(void) const; + std::vector get_flags_all(void) const; /** - * Gets the raw encoder count of the motor at a given timestamp. + * Gets the absolute position of the motor in its encoder units. * + * \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 * - * \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 + * \return The motor's absolute position in its encoder units or PROS_ERR_F + * if the operation failed, setting errno. * - * \return The raw encoder count at the given timestamp or PROS_ERR if the - * operation failed. + * \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::int32_t get_raw_position(std::uint32_t* const timestamp) const; + double get_position(const std::uint8_t index = 0) const; /** - * Gets the temperature limit flag for the motor. - * + * 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 + * - * \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. + * \return A vector containing 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_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t is_over_temp(void) const; + std::vector get_position_all(void) const; /** - * Gets the absolute position of the motor in its encoder units. + * Gets the power drawn by the motor in Watts. * + * \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 power draw in Watts or PROS_ERR_F if the operation + * failed, setting errno. * - * \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 Power: " << motor.get_power(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_position(void) const; + double get_power(const std::uint8_t index = 0) const; /** - * Gets the power drawn by the motor in Watts. + * 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::vector get_power_all(void) 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 + * + * 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 motor's power draw in Watts or PROS_ERR_F if the operation - * failed, setting errno. + * + * + * \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 + */ + std::int32_t get_raw_position(std::uint32_t* const timestamp, const std::uint8_t index = 0) const; + /** + * Gets a vector of 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 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 */ - virtual double get_power(void) const; + std::vector get_raw_position_all(std::uint32_t* const timestamp) const; /** * 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 + * + * 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 + */ + double get_temperature(const std::uint8_t index = 0) 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 + * + * \return A vector contaioning 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_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - virtual double get_temperature(void) const; + std::vector get_temperature_all(void) const; /** * 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 + * + * 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_torque(void) const; + double get_torque(const std::uint8_t index = 0) const; /** - * Gets the voltage delivered to the motor in millivolts. + * Gets a vector of 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 + * + * \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 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 + * + * 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 std::int32_t get_voltage(void) const; + std::int32_t get_voltage(const std::uint8_t index = 0) const; - /****************************************************************************/ - /** Motor configuration functions **/ - /** **/ - /** These functions allow programmers to configure the behavior of motors **/ - /****************************************************************************/ + /** + * 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 + * + * + * \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::vector get_voltage_all(void) const; /** - * Sets the position for the motor in its encoder units. + * Checks if the motor is drawing over its current limit. * - * 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 + * + * 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 + */ + std::int32_t is_over_current(const std::uint8_t index = 0) const; + + /** + * 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 position - * The new reference position in its encoder units + * \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 */ - virtual std::int32_t set_zero_position(const double position) const; + std::vector is_over_current_all(void) const; /** - * Sets the "absolute" zero position of the motor to its current position. + * 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 + * + * 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. * - * \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 temperature limit?: " << motor.is_over_temp(); + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t tare_position(void) const; + std::int32_t is_over_temp(const std::uint8_t index = 0) const; + + /** + * 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 + * + * \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. + * + * \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_all(); + * 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 + ///@{ /** - * Sets one of motor_brake_mode_e_t to the motor. + * 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 + * + * 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 Motor_Brake, according to what was set for the + * motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. * - * \param mode - * The motor_brake_mode_e_t to set for the motor + * \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 + */ + MotorBrake get_brake_mode(const std::uint8_t index = 0) const; + + /** + * Gets a vector containing the brake mode that was set for the 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 + * + * \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 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 set_brake_mode(const motor_brake_mode_e_t mode) const; + std::vector get_brake_mode_all(void) const; /** - * Sets the current limit for the motor in mA. + * Gets the current limit for 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 limit in mA or PROS_ERR if the operation failed, + * setting errno. * - * \param limit - * The new current limit in mA + * \b Example + * \code + * void opcontrol() { + * pros::Motor motor (1); + * while (true) { + * std::cout << "Motor Current Limit: " << motor.get_current_limit(); + * pros::delay(2); + * } + * } + * \endcode + */ + std::int32_t get_current_limit(const std::uint8_t index = 0) const; + + /** + * Gets a vector containing the current limit for the motor in mA. * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * 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 + * + * \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 motor (1); + * while (true) { + * std::cout << "Motor Current Limit: " << motor.get_current_limit_all()[0]; + * pros::delay(2); + * } + * } + * \endcode */ - virtual std::int32_t set_current_limit(const std::int32_t limit) const; + std::vector get_current_limit_all(void) const; /** - * Sets one of motor_encoder_units_e_t for the motor encoder. + * 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 + * + * 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 Motor_Units according to what is set for the + * motor or E_MOTOR_ENCODER_INVALID if the operation failed. * - * \param units - * The new motor encoder units + * \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 + */ + MotorUnits get_encoder_units(const std::uint8_t index = 0) const; + + /** + * Gets a vector containing the encoder units that were set for the 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 + * + * \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 */ - virtual std::int32_t set_encoder_units(const motor_encoder_units_e_t units) const; + std::vector get_encoder_units_all(void) const; /** - * Sets one of motor_gearset_e_t for 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 + * + * 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 Motor_Gears according to what is set for the motor, + * or pros::Motor_Gears::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 + */ + MotorGears get_gearing(const std::uint8_t index = 0) const; + + /** + * Gets a vector containing the gearset that was set for the motor. * - * \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 * - * \return 1 if the operation was successful or PROS_ERR if the operation - * failed, setting errno. + * \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. + * + * \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; + + /** + * Gets returns a vector with all the port numbers in the motor group. + * + * \return A vector containing the signed port of the motor. (negaitve if the motor is reversed) */ - virtual std::int32_t set_gearing(const motor_gearset_e_t gearset) const; + std::vector get_port_all(void) 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. + * 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 + * + * 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 + * + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Motor Voltage Limit: " << motor.get_voltage_limit(); + * } + * \endcode + */ + std::int32_t get_voltage_limit(const std::uint8_t index = 0) const; + + /** + * Gets a vector of 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 kf - * The feedforward constant - * \param kp - * The proportional constant - * \param ki - * The integral constant - * \param kd - * The derivative constant + * \return A vector containing the motor's voltage limit in V or PROS_ERR if the operation failed, + * setting errno. * - * \return A motor_pid_s_t struct formatted properly in 4.4. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Motor Voltage Limit: " << motor.get_voltage_limit_all()[0]; + * } + * \endcode */ - static motor_pid_s_t convert_pid(double kf, double kp, double ki, double kd); + std::vector get_voltage_limit_all(void) 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. + * Gets whether the motor is reversed or not * - * \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 + * \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: + * + * 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 has been reversed and 0 if the motor was not + * reversed, or PROS_ERR if the operation failed, setting errno. * - * \return A motor_pid_s_t struct formatted properly in 4.4. + * \b Example + * \code + * void initialize() { + * pros::Motor motor (1); + * std::cout << "Is the motor reversed? " << motor.is_reversed(); + * // Prints "0" + * } + * \endcode */ - 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 is_reversed(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. + * Gets a vector containg whether the motor is reversed or not * - * Only non-zero values of the struct will change the existing motor - * constants. + * \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 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 + * + * EOVERFLOW - The index is non 0 + * + * + * \param mode + * The Motor_Brake 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. * - * \param pid - * The new motor PID constants + * \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_mode(const MotorBrake mode, const std::uint8_t index = 0) const; + /** + * 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 + * + * EOVERFLOW - The index is non 0 + * + * + * \param mode + * The Motor_Brake 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_all(pros::E_MOTOR_BRAKE_HOLD); + * std::cout << "Brake Mode: " << motor.get_brake_mode(); + * } + * \endcode */ - 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 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 + * + * \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. * - * Only non-zero values of the struct will change the existing motor - * constants. + * \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_mode_all(const MotorBrake mode) const; + /** + * 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 * - * \param pid - * The new motor PID constants + * \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 */ - virtual std::int32_t set_pos_pid_full(const motor_pid_full_s_t pid) const; - + std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const; /** - * Sets one of motor_pid_s_t for the motor. This intended to just modify the - * main PID constants. + * Sets the current limit for 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 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. * - * Only non-zero values of the struct will change the existing motor - * constants. + * \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 + */ + std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const; + /** + * 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 pid - * The new motor PID constants + * \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::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 */ - virtual std::int32_t set_vel_pid(const motor_pid_s_t pid) const; - + std::int32_t set_current_limit_all(const std::int32_t limit) const; /** - * Sets one of motor_pid_full_s_t for the motor. + * 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 + * + * \param units + * The new motor encoder units + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. * - * Only non-zero values of the struct will change the existing motor - * constants. + * \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 + */ + std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const; + /** + * 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 + * + * 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 * - * \param pid - * The new motor PID constants + * \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 + */ + std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const; + /** + * 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 + * + * 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(E_MOTOR_ENCODER_DEGREES); + * std::cout << "Encoder Units: " << motor.get_encoder_units(); + * } + * \endcode */ - virtual std::int32_t set_vel_pid_full(const motor_pid_full_s_t pid) const; - + std::int32_t set_encoder_units_all(const MotorUnits units) const; + /** - * Sets the reverse flag for the motor. + * Sets one of Motor_Units for the motor encoder. Works with the C + * enum and the C++ enum class. * - * 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 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 + */ + 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 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 + * + * 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 + */ + 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 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 + * + * 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 * - * \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::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 pros::motor_gearset_e_t 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. * * 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 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_all(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_all(const MotorGears gearset) const; + /** - * Gets the brake mode that was set 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 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. + * \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_all(E_MOTOR_GEARSET_06); + * std::cout << "Gearset: " << motor.get_gearing(); + * } + * \endcode */ - virtual motor_brake_mode_e_t get_brake_mode(void) const; + std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const; + /** - * Gets the current limit for the motor in mA. + * Sets the reverse flag for the motor. * - * The default value is 2500 mA. + * 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 + * + * EOVERFLOW - The index is non 0 + * + * \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 The motor's current limit in mA 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); + * motor.set_reversed(true); + * std::cout << "Is this motor reversed? " << motor.is_reversed(); + * } + * \endcode */ - virtual std::int32_t get_current_limit(void) const; + std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0); + /** + * Sets the reverse flag for the motor. + * + * This will invert its movements and the values returned for its position. + * + * + * \param reverse + * True reverses the motor, false is default direction + * + * \return 1 + * + * \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::int32_t set_reversed_all(const bool reverse); /** - * Gets the encoder units that were set for the motor. + * 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 One of motor_encoder_units_e_t according to what is set for the - * motor or E_MOTOR_ENCODER_INVALID if the operation failed. + * \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 motor_encoder_units_e_t get_encoder_units(void) const; - + std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const; + /** - * Gets the gearset that was set for the motor. + * Sets the voltage limit for the motor in Volts. * + * \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 limit + * The new voltage limit in Volts + * + * \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. * - * \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 autonomous() { + * pros::Motor motor (1); + * pros::Controller master (E_CONTROLLER_MASTER); + * + * 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 */ - virtual motor_gearset_e_t get_gearing(void) const; + std::int32_t set_voltage_limit_all(const std::int32_t limit) const; /** - * 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. + * 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 + * + * 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. * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. + * \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 * - * \return A motor_pid_full_s_t containing the position PID constants last set - * to the given motor */ - virtual motor_pid_full_s_t get_pos_pid(void) const; - + std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) 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. + * 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 * - * Additionally, in an error state all values of the returned struct are set - * to their negative maximum values. + * \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::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 A motor_pid_full_s_t containing the velocity PID constants last set - * to the given motor */ - virtual motor_pid_full_s_t get_vel_pid(void) const; + std::int32_t set_zero_position_all(const double position) const; /** - * Gets the operation direction of the motor as set by the user. + * 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 + * + * 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. * - * \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 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 */ - virtual std::int32_t is_reversed(void) const; - + std::int32_t tare_position(const std::uint8_t index = 0) 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. + * 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 * - * \return 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 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_all(); + * motor.move_absolute(100, 100); // Moves 100 units forward + * } + * \endcode */ - virtual std::int32_t get_voltage_limit(void) const; + std::int32_t tare_position_all(void) const; /** - * Gets the port number of the motor. - * - * \return The motor's port number. + * Gets the number of motors. + * + * \return Always returns 1 + * */ - virtual std::uint8_t get_port(void) const; + std::int8_t size(void) const; + + /** + * gets the port number of the motor + * + * \return A vector containing the signed port of the motor. (negaitve if the motor is reversed) + * + */ + std::int8_t get_port(const std::uint8_t index = 0) const; private: - const std::uint8_t _port; + std::int8_t _port; }; - namespace literals { const pros::Motor operator"" _mtr(const unsigned long long int m); 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 18bacff71..049c395b7 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 (c) 2017-2020, 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_ @@ -21,7 +21,7 @@ #include #include -#include "api.h" +#include "error.h" #define OPT_GESTURE_ERR (INT8_MAX) #define OPT_COUNT_ERR (INT16_MAX) @@ -33,9 +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, ERROR = PROS_ERR } optical_direction_e_t; +/** + * \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; @@ -43,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; @@ -50,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 * @@ -76,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); @@ -94,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); @@ -112,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); @@ -130,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); @@ -147,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); @@ -163,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); @@ -178,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); @@ -193,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); @@ -210,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); @@ -225,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); @@ -240,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); @@ -255,9 +445,25 @@ 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); +///@} + +///@} + #ifdef __cplusplus } } diff --git a/include/pros/optical.hpp b/include/pros/optical.hpp index 4b3c39da4..3f700d41c 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 (c) 2017-2020, 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/optical.h" +#include "pros/device.hpp" 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,6 +48,11 @@ 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); @@ -54,6 +69,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(); @@ -70,6 +93,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(); @@ -86,6 +117,13 @@ 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; + * } */ virtual double get_brightness(); @@ -100,8 +138,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(); @@ -115,7 +161,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); @@ -131,6 +185,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,6 +207,21 @@ class Optical { * * \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(); @@ -177,6 +255,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,6 +279,26 @@ class Optical { * * \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(); @@ -203,6 +312,25 @@ class Optical { * * \return 1 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) { + * 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); + * } + * } */ virtual std::int32_t enable_gesture(); @@ -216,19 +344,48 @@ class Optical { * * \return 1 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 */ virtual std::int32_t disable_gesture(); + /** - * Gets the port number of the Optical Sensor. - * - * \return The Optical Sensor's port number. + * 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): + * 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 { +const pros::Optical operator"" _opt(const unsigned long long int o); +} // namespace literals +} } // namespace pros #endif diff --git a/include/pros/rotation.h b/include/pros/rotation.h index 28c8e558e..1c1c73176 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 (c) 2017-2020, 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,17 @@ namespace pros { namespace c { #endif +/** + * \ingroup c-rotation + */ + +/** + * \addtogroup c-rotation + * @{ + */ + +#define ROTATION_MINIMUM_DATA_RATE 5 + /** * Reset Rotation Sensor * @@ -43,9 +54,54 @@ 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); +/** + * Set the Rotation Sensor's refresh interval in milliseconds. + * + * The rate may be specified in increments of 5ms, and will be rounded down to + * the nearest increment. The minimum allowable refresh rate is 5ms. The default + * rate is 10ms. + * + * 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 Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \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); + /** * Set the Rotation Sensor position reading to a desired rotation value * @@ -60,6 +116,21 @@ int32_t rotation_reset(uint8_t port); * 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); @@ -76,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); @@ -91,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); @@ -106,11 +204,23 @@ 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); /** - * Get the Rotation Sensor's current position in centidegrees + * Get the Rotation Sensor's current angle in centidegrees (0-36000) * * This function uses the following values of errno when an error state is * reached: @@ -119,8 +229,20 @@ int32_t rotation_get_velocity(uint8_t port); * * \param port * The V5 Rotation Sensor port number from 1-21 - * \return The angle value or PROS_ERR_F if the operation failed, setting + * \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); @@ -139,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); @@ -155,9 +293,60 @@ 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); +/** + * Initialize the Rotation Sensor with a reverse flag + * + * 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 Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \param reverse_flag + * Determines if the Rotation Sensor is reversed or not. + * + * \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); + /** * Get the Rotation Sensor's reversed flag * @@ -171,9 +360,27 @@ int32_t rotation_reverse(uint8_t port); * * \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 58595f59c..b58ad9124 100644 --- a/include/pros/rotation.hpp +++ b/include/pros/rotation.hpp @@ -1,40 +1,86 @@ /** * \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 (c) 2017-2020, 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/rotation.h" +#include "pros/device.hpp" 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 + */ + explicit Rotation(const std::uint8_t port) : Device(port, DeviceType::rotation) {}; /** - * Reset the Rotation Sensor + * 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. + * \param reverse_flag + * Determines if the Rotation Sensor is reversed or not. + * + * \b Example + * \code + * void opcontrol() { + * pros::Rotation rotation_sensor(1, true); //Creates a reversed Rotation Sensor on port 1 + * } + * \endcode + */ + explicit Rotation(const std::uint8_t port, const bool reverse_flag); + + /** + * Reset the Rotation Sensor + * * Reset the current absolute position to be the same as the * Rotation Sensor angle. - * + * * 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). @@ -42,11 +88,56 @@ 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(); /** - * Set the Rotation Sensor position reading to a desired rotation value + * Set the Rotation Sensor's refresh interval in milliseconds. + * + * The rate may be specified in increments of 5ms, and will be rounded down to + * the nearest increment. The minimum allowable refresh rate is 5ms. The default + * rate is 10ms. + * + * As values are copied into the shared memory buffer only at 10ms intervals, + * setting this value to less than 10ms does not mean that you can poll the + * sensor's values any faster. However, it will guarantee that the data is as + * recent as possible. + * + * 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 Rotation Sensor + * + * \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; + + /** + * Set the Rotation Sensor position reading to a desired rotation value * * This function uses the following values of errno when an error state is * reached: @@ -57,11 +148,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: @@ -72,11 +177,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.reset_position(); + * } + * pros::delay(20); + * } + * } + * \endcode */ - virtual std::int32_t reset_position(void); + virtual std::int32_t reset_position(void) const; /** - * Get the Rotation Sensor's current position in centidegrees + * Get the Rotation Sensor's current position in centidegrees * * This function uses the following values of errno when an error state is * reached: @@ -85,11 +204,22 @@ 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 + * Get the Rotation Sensor's current velocity in centidegrees per second * * This function uses the following values of errno when an error state is * reached: @@ -98,11 +228,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 @@ -114,8 +254,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 @@ -131,8 +282,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. @@ -144,8 +309,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 @@ -157,9 +336,49 @@ 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 { +const pros::Rotation operator"" _rot(const unsigned long long int r); +} // namespace literals +} } // namespace pros #endif diff --git a/include/pros/rtos.h b/include/pros/rtos.h index 23cfc7c22..d6b9be480 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 (c) 2017-2020, 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,17 +194,52 @@ 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); +/** + * 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); + /** * Creates a new task and add it to the list of tasks that are ready to run. * @@ -151,6 +266,19 @@ uint32_t millis(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); @@ -165,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. @@ -177,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. @@ -194,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); @@ -204,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); @@ -218,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); @@ -228,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); @@ -236,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); @@ -244,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); @@ -254,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); @@ -264,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); @@ -276,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); @@ -284,30 +613,89 @@ 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); +/** + * + * 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++. + * + * \param task + * 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); + /** * Sends a notification to a task, optionally performing some action. Will also * 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 @@ -323,6 +711,37 @@ uint32_t task_notify(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); @@ -341,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); @@ -354,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); @@ -365,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); @@ -385,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); @@ -400,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); @@ -408,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 c44f322ab..f02495c27 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 (c) 2017-2020, 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_ @@ -23,14 +24,24 @@ #include "pros/rtos.h" #undef delay +#include #include #include #include #include +#include #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. @@ -55,9 +66,20 @@ 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 = NULL, std::uint32_t prio = TASK_PRIORITY_DEFAULT, + 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 = ""); /** @@ -77,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); @@ -99,11 +132,96 @@ 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, + std::uint16_t stack_depth = TASK_STACK_DEPTH_DEFAULT, const char* name = "") { + static_assert(std::is_invocable_r_v); + return pros::c::task_create( + [](void* parameters) { + std::unique_ptr> ptr{static_cast*>(parameters)}; + (*ptr)(); + }, + new std::function(std::forward(function)), prio, stack_depth, name); + } + + /** + * Creates a new task and add it to the list of tasks that are ready to run. + * + * This function uses the following values of errno when an error state is + * reached: + * ENOMEM - The stack cannot be used as the TCB was not created. * + * \param function + * Callable object to use as entry function + * \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 - Task(F&& function, std::uint32_t prio = TASK_PRIORITY_DEFAULT, std::uint16_t stack_depth = TASK_STACK_DEPTH_DEFAULT, - const char* name = "") + static task_t create(F&& function, const char* name) { + return Task::create(std::forward(function), TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, name); + } + + /** + * Creates a new task and add it to the list of tasks that are ready to run. + * + * This function uses the following values of errno when an error state is + * reached: + * ENOMEM - The stack cannot be used as the TCB was not created. + * + * \param function + * Callable object to use as entry function + * \param prio + * The priority at which the task should run. + * TASK_PRIO_DEFAULT plus/minus 1 or 2 is typically used. + * \param stack_depth + * The number of words (i.e. 4 * stack_depth) available on the task's + * stack. TASK_STACK_DEPTH_DEFAULT is typically sufficient. + * \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, + std::uint16_t stack_depth = TASK_STACK_DEPTH_DEFAULT, const char* name = "") : Task( [](void* parameters) { std::unique_ptr> ptr{static_cast*>(parameters)}; @@ -126,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) @@ -137,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 */ - Task(task_t task); + 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); @@ -160,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(); @@ -167,8 +355,22 @@ 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(void); + std::uint32_t get_priority(); /** * Sets the priority of the specified task. @@ -179,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); @@ -186,33 +402,129 @@ 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(void); + 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(void); + void suspend(); /** * Resumes the specified task, making it eligible to be scheduled. * * \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(void); + void resume(); /** * 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(void); + 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 */ - operator task_t() { + explicit operator task_t() { return task; } @@ -224,8 +536,55 @@ 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(void); + std::uint32_t notify(); + + /** + * 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. + * + * \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(); /** * Sends a notification to a task, optionally performing some action. Will @@ -248,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); @@ -266,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); @@ -276,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(void); + 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. @@ -288,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 @@ -303,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); @@ -313,16 +765,156 @@ 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(void); + static std::uint32_t get_count(); private: - task_t task; + task_t task{}; +}; + +// STL Clock compliant clock +struct Clock { + using rep = std::uint32_t; + using period = std::milli; + using duration = std::chrono::duration; + using time_point = std::chrono::time_point; + const bool is_steady = true; + + /** + * Gets the current time. + * + * 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(); }; class Mutex { + std::shared_ptr> mutex; + public: - Mutex(void); + Mutex(); + + // disable copy and move construction and assignment per Mutex requirements + // (see https://en.cppreference.com/w/cpp/named_req/Mutex) + Mutex(const Mutex&) = delete; + Mutex(Mutex&&) = delete; + + Mutex& operator=(const Mutex&) = delete; + Mutex& operator=(Mutex&&) = delete; + + /** + * Takes and locks a mutex indefinetly. + * + * See + * https://pros.cs.purdue.edu/v5/tutorials/topical/multitasking.html#mutexes + * for details. + * + * \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(); /** * Takes and locks a mutex, waiting for up to a certain number of milliseconds @@ -340,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); @@ -353,11 +1014,539 @@ 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(void); + bool give(); - private: - std::shared_ptr> mutex; + /** + * Takes and locks a mutex, waiting for up to TIMEOUT_MAX milliseconds. + * + * Effectively equivalent to calling pros::Mutex::take with TIMEOUT_MAX as + * the parameter. + * + * Conforms to named requirment BasicLockable + * \see https://en.cppreference.com/w/cpp/named_req/BasicLockable + * + * \note Consider using a std::unique_lock, std::lock_guard, or + * std::scoped_lock instead of interacting with the Mutex directly. + * + * \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(); + + /** + * Unlocks a mutex. + * + * Equivalent to calling pros::Mutex::give. + * + * Conforms to named requirement BasicLockable + * \see https://en.cppreference.com/w/cpp/named_req/BasicLockable + * + * \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(); + + /** + * Try to lock a mutex. + * + * Returns immediately if unsucessful. + * + * Conforms to named requirement Lockable + * \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(); + + /** + * Takes and locks a mutex, waiting for a specified duration. + * + * Equivalent to calling pros::Mutex::take with a duration specified in + * milliseconds. + * + * Conforms to named requirement TimedLockable + * \see https://en.cppreference.com/w/cpp/named_req/TimedLockable + * + * \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) { + return take(std::chrono::duration_cast(rel_time).count()); + } + + /** + * Takes and locks a mutex, waiting until a specified time. + * + * Conforms to named requirement TimedLockable + * \see https://en.cppreference.com/w/cpp/named_req/TimedLockable + * + * \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 +class MutexVar; + +template +class MutexVarLock { + Mutex& mutex; + Var& var; + + friend class MutexVar; + + constexpr MutexVarLock(Mutex& mutex, Var& var) : mutex(mutex), var(var) {} + + public: + /** + * Accesses the value of the mutex-protected variable. + */ + constexpr Var& operator*() const { + return var; + } + + /** + * Accesses the value of the mutex-protected variable. + */ + constexpr Var* operator->() const { + return &var; + } + + ~MutexVarLock() { + mutex.unlock(); + } +}; + +template +class MutexVar { + Mutex mutex; + Var var; + + public: + /** + * Creates a mutex-protected variable which is initialized with the given + * constructor arguments. + * + * \param args + * 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)...) {} + + /** + * Try to lock the mutex-protected variable. + * + * \param timeout + * Time to wait before the mutex becomes available, in milliseconds. A + * timeout of 0 can be used to poll the mutex. + * + * \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)) { + return {{mutex, var}}; + } else { + return {}; + } + } + + /** + * Try to lock the mutex-protected variable. + * + * \param timeout + * Time to wait before the mutex becomes available. A timeout of 0 can + * be used to poll the mutex. + * + * \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) { + try_lock(std::chrono::duration_cast(rel_time).count()); + } + + /** + * 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)) + ; + return {mutex, var}; + } }; /** @@ -367,6 +1556,13 @@ class Mutex { */ using pros::c::millis; +/** + * Gets the number of microseconds since PROS initialized. + * + * \return The number of microseconds since PROS initialized + */ +using pros::c::micros; + /** * Delays a task for a given number of milliseconds. * @@ -375,9 +1571,10 @@ using pros::c::millis; * To delay cyclically, use task_delay_until(). * * \param milliseconds - * The number of milliseconds to wait (1000 milliseconds per second) + * The number of milliseconds to wait (1000 milliseconds per second) */ using pros::c::delay; +} // namespace rtos } // namespace pros -#endif // _PROS_RTOS_HPP_s +#endif // _PROS_RTOS_HPP_ diff --git a/include/pros/screen.h b/include/pros/screen.h new file mode 100644 index 000000000..8799058ee --- /dev/null +++ b/include/pros/screen.h @@ -0,0 +1,796 @@ +/** + * \file screen.h + * \ingroup c-screen + * + * Brain screen display and touch functions. + * + * Contains user calls to the v5 screen for touching and displaying graphics. + * + * \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-screen Simplified Brain Screen C API + * + */ + +#ifndef _PROS_SCREEN_H_ +#define _PROS_SCREEN_H_ + +#include +#include +#define _GNU_SOURCE +#include +#undef _GNU_SOURCE +#include + +#include "pros/colors.h" // c color macros + +#ifdef __cplusplus +extern "C" { +namespace pros { +#endif + +/** + * \ingroup c-screen + */ + +/** + * \addtogroup c-screen + * @{ + */ + +/** + * \enum text_format_e_t + * Different font sizes that can be used in printing text. + */ +typedef enum { + /// 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 last_touch_e_t + * Enum indicating what the current touch status is for the touchscreen. + */ +typedef enum { + /// 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 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 { + /// Represents if the screen is being held, released, or pressed. + last_touch_e_t touch_status; + /// Represents the x value of the location of the touch. + int16_t x; + /// Represents the y value of the location of the touch. + int16_t y; + /// Represents how many times the screen has be pressed. + int32_t press_count; + /// Represents how many times the user released after a touch on the screen. + int32_t release_count; +} screen_touch_status_s_t; + +#ifdef PROS_USE_SIMPLE_NAMES +#ifdef __cplusplus +#define TEXT_SMALL pros::E_TEXT_SMALL +#define TEXT_MEDIUM pros::E_TEXT_MEDIUM +#define TEXT_LARGE pros::E_TEXT_LARGE +#define TEXT_MEDIUM_CENTER pros::E_TEXT_MEDIUM_CENTER +#define TEXT_LARGE_CENTER pros::E_TEXT_LARGE_CENTER +#define TOUCH_RELEASED pros::E_TOUCH_RELEASED +#define TOUCH_PRESSED pros::E_TOUCH_PRESSED +#define TOUCH_HELD pros::E_TOUCH_HELD +#else +#define TEXT_SMALL E_TEXT_SMALL +#define TEXT_MEDIUM E_TEXT_MEDIUM +#define TEXT_LARGE E_TEXT_LARGE +#define TEXT_MEDIUM_CENTER E_TEXT_MEDIUM_CENTER +#define TEXT_LARGE_CENTER E_TEXT_LARGE_CENTER +#define TOUCH_RELEASED E_TOUCH_RELEASED +#define TOUCH_PRESSED E_TOUCH_PRESSED +#define TOUCH_HELD E_TOUCH_HELD +#endif +#endif + +typedef void (*touch_event_cb_fn_t)(); + +#ifdef __cplusplus +namespace c { +#endif + +/// \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 + * 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); + +/** + * 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 (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 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); + +/** + * Get the current pen 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 + * 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); + +/** + * Get the current eraser 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 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); + +/** + * Clear display with eraser 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 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); + +/** + * Scroll lines on the display upwards. + * + * 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 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 + * 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); + +/** + * Scroll lines within a region on the display + * + * This function behaves in the same way as `screen_scroll`, except that you + * specify a rectangular region within which to scroll lines instead of a start + * line. + * + * 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 x0, y0 The (x,y) coordinates of the first corner of the + * rectangular region + * \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 + * 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 + * to the screen + * + * 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 x0, y0 The (x,y) coordinates of the first corner of the + * rectangular region of the screen + * \param x1, y1 The (x,y) coordinates of the second corner of the + * rectangular region of the screen + * \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 + * 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); + +/** + * Draw a single pixel on the screen using the current pen 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 x, y The (x,y) coordinates of the pixel + * + * \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); + +/** + * Erase a pixel from the screen (Sets the location) + * + * 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 x, y The (x,y) coordinates of the erased + * + * \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); + +/** + * Draw a line on the screen using the current pen 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 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 + * 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); + +/** + * Erase a line on the screen using the current eraser 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 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 + * 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); + +/** + * Draw a rectangle on the screen using the current pen 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 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 + * 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); + +/** + * Erase a rectangle on the screen using the current eraser 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 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 + * 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); + +/** + * Fill a rectangular region of the screen using the current pen + * 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 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 + * 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); + +/** + * Draw a circle on the screen using the current pen 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 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 + * 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); + +/** + * Erase a circle on the screen using the current eraser 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 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 + * 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); + +/** + * Fill a circular region of the screen using the current pen + * 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 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 + * 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); + +///@} + +/// \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 + * 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 + * 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, ...); + +/** + * Print a formatted string to the screen on the specified line + * + * 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 + * 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); + +/** + * Print a formatted string to the screen at the specified coordinates + * + * 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 + * 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); + +///@} + +/// \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. + * + * \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); + +/** + * Assigns a callback function to be called when a certain touch event happens. + * + * 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 + * 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 +} +#endif + +#endif diff --git a/include/pros/screen.hpp b/include/pros/screen.hpp new file mode 100644 index 000000000..c3980e1fa --- /dev/null +++ b/include/pros/screen.hpp @@ -0,0 +1,717 @@ +/** + * \file screen.hpp + * \ingroup cpp-screen + * + * Brain screen display and touch functions. + * + * Contains user calls to the v5 screen for touching and displaying graphics. + * + * \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-screen Simplified Brain Screen C++ API + */ + +#ifndef _PROS_SCREEN_HPP_ +#define _PROS_SCREEN_HPP_ + +#include "pros/screen.h" +#include "pros/colors.hpp" +#include +#include + +namespace pros { +namespace screen { + +#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 + +/** + * \ingroup cpp-screen + */ + +/** + * \addtogroup cpp-screen + * @{ + */ + + /******************************************************************************/ + /** 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.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(std::uint32_t 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 (it is recommended to use values + * 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(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. + * + * 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 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(); + + /** + * Get the current eraser 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 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(); + + /** + * Clear display with eraser 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 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(); + + /** + * Scroll lines on the display upwards. + * + * 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 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 + * 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); + + /** + * Scroll lines within a region on the display + * + * This function behaves in the same way as `screen_scroll`, except that you + * specify a rectangular region within which to scroll lines instead of a start + * line. + * + * 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 x0, y0 The (x,y) coordinates of the first corner of the + * rectangular region + * \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 + * 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); + + /** + * 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 + * reached: + * EACCESS - Another resource is currently trying to access the screen mutex. + * + * \param x0, y0 The (x,y) coordinates of the first corner of the + * rectangular region of the screen + * \param x1, y1 The (x,y) coordinates of the second corner of the + * rectangular region of the screen + * \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 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); + + /** + * Draw a single pixel on the screen using the current pen 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 x, y The (x,y) coordinates of the pixel + * + * \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); + + /** + * Erase a pixel from the screen (Sets the location) + * + * 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 x, y The (x,y) coordinates of the erased + * + * \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); + + /** + * Draw a line on the screen using the current pen 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 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 + * 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); + + /** + * Erase a line on the screen using the current eraser 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 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 + * 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); + + /** + * Draw a rectangle on the screen using the current pen 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 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 + * 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); + + /** + * Erase a rectangle on the screen using the current eraser 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 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 + * 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); + + /** + * Fill a rectangular region of the screen using the current pen + * 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 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 + * 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); + + /** + * Draw a circle on the screen using the current pen 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 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 + * 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); + + /** + * Erase a circle on the screen using the current eraser 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 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 + * 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); + + /** + * Fill a circular region of the screen using the current pen + * 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 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 + * 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); + + /******************************************************************************/ + /** Screen Text Display Functions **/ + /** **/ + /** These functions allow programmers to display text on the v5 screen **/ + /******************************************************************************/ + + /** + * Print a formatted string to the screen, overwrite available for printing at location too. + * + * 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 x The (x,y) coordinates of the top left corner of the string + * \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){ + pros::c::screen_print(txt_fmt, line, text, convert_args(args)...); + } + + template + void print(pros::text_format_e_t txt_fmt, const std::int16_t x, const std::int16_t y, const char* text, Params... args){ + pros::c::screen_print_at(txt_fmt, x, y, text, convert_args(args)...); + } + + /******************************************************************************/ + /** 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. + * + * \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(); + + /** + * Assigns a callback function to be called when a certain touch event happens. + * + * 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 + * 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 + +extern __attribute__((weak)) void lvgl_init() {} +///@} +#endif //header guard diff --git a/include/pros/serial.h b/include/pros/serial.h index 81de139ff..dc9ead56c 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 (c) 2017-2020, 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 07378e958..a2490e236 100644 --- a/include/pros/serial.hpp +++ b/include/pros/serial.hpp @@ -1,19 +1,19 @@ /** * \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-2018, 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_ @@ -21,9 +21,18 @@ #include #include "pros/serial.h" +#include "pros/device.hpp" 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 +46,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 +91,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 +119,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 +142,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 +168,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 +192,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 +215,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 +247,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 +276,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,11 +307,20 @@ 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 { diff --git a/include/pros/vision.h b/include/pros/vision.h index a21db2d19..dbda3fc7a 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 (c) 2017-2020, 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 edcc5a3cc..b8676794a 100644 --- a/include/pros/vision.hpp +++ b/include/pros/vision.hpp @@ -1,31 +1,40 @@ /** * \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 (c) 2017-2020, 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/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,8 +48,15 @@ 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); + explicit Vision(std::uint8_t port, vision_zero_e_t zero_point = E_VISION_ZERO_TOPLEFT); /** * Clears the vision sensor LED color, reseting it back to its default @@ -52,6 +68,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 +102,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,6 +151,18 @@ 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, @@ -126,6 +183,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 +220,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 +256,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 +286,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 +309,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 +336,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 +359,21 @@ class Vision { * ENODEV - The port cannot be configured as a vision sensor * * \return The current RGB white balance setting of the sensor + * + * \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::int32_t get_white_balance(void) const; - /** - * Gets the port number of the Vision Sensor. - * - * \return The vision sensor's port number. - */ - std::uint8_t get_port(void) const; /** * Reads up to object_count object descriptors into object_arr. @@ -250,6 +397,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 +444,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 +490,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 +521,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 +548,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 +573,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 +599,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 +629,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 +657,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 +687,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 +712,22 @@ 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; - + private: - std::uint8_t _port; + ///@} }; +} // namespace v5 } // namespace pros #endif // _PROS_VISION_HPP_ diff --git a/kernel@4.0.3.zip b/kernel@4.0.3.zip new file mode 100644 index 000000000..4e160fb3b Binary files /dev/null and b/kernel@4.0.3.zip differ diff --git a/project.pros b/project.pros index 2a884ff31..c1dc02283 100644 --- a/project.pros +++ b/project.pros @@ -5,157 +5,79 @@ "target": "v5", "templates": { "kernel": { - "location": "/home/salmon/.config/pros/templates/kernel@3.3.1", + "location": "C:\\Users\\xuzwi\\AppData\\Roaming\\PROS\\templates\\kernel@4.0.3", "metadata": { "cold_addr": "58720256", "cold_output": "bin/cold.package.bin", "hot_addr": "125829120", "hot_output": "bin/hot.package.bin", - "origin": "pros-mainline", + "origin": "local", "output": "bin/monolith.bin" }, "name": "kernel", "py/object": "pros.conductor.templates.local_template.LocalTemplate", "supported_kernels": null, "system_files": [ - "include/display/lv_objx/lv_preload.h", - "include/display/lv_objx/lv_bar.h", - "include/pros/llemu.hpp", - "include/display/lv_draw/lv_draw_line.h", - "include/display/lv_objx/lv_imgbtn.h", - "include/display/lv_core/lv_style.h", - "include/display/lv_misc/lv_math.h", - "include/display/lv_misc/lv_misc.mk", - "include/display/lv_themes/lv_themes.mk", - "firmware/v5-common.ld", - "include/pros/distance.h", - "include/display/lv_core/lv_obj.h", - "include/display/lv_misc/lv_circ.h", - "include/display/lv_draw/lv_draw_triangle.h", - "include/pros/motors.hpp", - "include/pros/imu.h", - "include/display/lv_draw/lv_draw.h", - "include/display/lv_misc/lv_symbol_def.h", - "include/display/lv_themes/lv_theme_templ.h", - "include/display/lv_misc/lv_gc.h", - "include/display/lv_objx/lv_win.h", - "include/display/lv_core/lv_refr.h", - "include/display/lv_hal/lv_hal_tick.h", - "include/display/README.md", - "include/pros/misc.h", - "include/display/lv_hal/lv_hal_disp.h", - "firmware/libc.a", - "include/display/lv_misc/lv_color.h", - "include/display/lv_themes/lv_theme_night.h", - "include/display/lv_misc/lv_fs.h", - "include/display/lv_themes/lv_theme_alien.h", - "include/display/licence.txt", - "include/display/lv_misc/lv_font.h", - "include/display/lv_misc/lv_anim.h", - "common.mk", - "include/display/lvgl.h", - "include/display/lv_draw/lv_draw_vbasic.h", - "include/display/lv_core/lv_group.h", - "include/display/lv_core/lv_core.mk", - "include/display/lv_objx/lv_sw.h", - "include/display/lv_draw/lv_draw_label.h", + "include/pros/adi.hpp", + "include/pros/distance.hpp", + "include/pros/serial.hpp", + "include/pros/motors.h", + "include/pros/rotation.hpp", + "include/pros/gps.h", + "include/pros/serial.h", + "include/pros/abstract_motor.hpp", "include/pros/imu.hpp", - "include/display/lv_objx/lv_img.h", - "include/display/lv_misc/lv_txt.h", - "include/display/lv_objx/lv_line.h", - "include/pros/ext_adi.h", - "include/display/lv_draw/lv_draw_arc.h", - "include/display/lv_objx/lv_label.h", - "include/display/lv_objx/lv_kb.h", - "include/display/lv_themes/lv_theme_default.h", - "include/display/lv_misc/lv_templ.h", - "include/pros/rtos.hpp", + "include/pros/device.h", "include/pros/apix.h", - "include/display/lv_core/lv_indev.h", - "include/display/lv_objx/lv_tabview.h", - "firmware/libpros.a", - "include/display/lv_core/lv_vdb.h", - "include/display/lv_objx/lv_lmeter.h", - "include/display/lv_themes/lv_theme_nemo.h", - "firmware/libm.a", - "include/display/lv_themes/lv_theme_zen.h", - "include/pros/colors.h", - "include/display/lv_objx/lv_ta.h", - "include/display/lv_objx/lv_calendar.h", - "include/display/lv_hal/lv_hal.h", - "include/display/lv_objx/lv_canvas.h", - "include/display/lv_fonts/lv_fonts.mk", - "include/display/lv_draw/lv_draw_img.h", - "include/display/lv_misc/lv_ufs.h", "include/pros/misc.hpp", - "include/display/lv_themes/lv_theme.h", - "include/display/lv_objx/lv_cb.h", - "firmware/v5-hot.ld", - "include/display/lv_objx/lv_slider.h", - "include/pros/optical.h", - "include/display/lv_objx/lv_tileview.h", - "include/display/lv_core/lv_lang.h", - "include/pros/distance.hpp", - "include/pros/optical.hpp", - "include/display/lv_objx/lv_spinbox.h", - "include/display/lv_draw/lv_draw.mk", - "include/pros/rotation.hpp", - "include/display/lv_misc/lv_log.h", + "include/pros/motor_group.hpp", + "include/pros/screen.hpp", + "include/pros/misc.h", + "common.mk", + "include/pros/link.h", + "firmware/v5-common.ld", + "firmware/libm.a", "include/api.h", + "include/pros/motors.hpp", + "include/pros/link.hpp", + "include/pros/distance.h", + "firmware/v5-hot.ld", + "firmware/libc.a", "include/pros/llemu.h", - "include/display/lv_objx/lv_list.h", - "include/display/lv_misc/lv_ll.h", - "include/display/lv_objx/lv_roller.h", - "include/display/lv_hal/lv_hal.mk", - "include/pros/vision.h", - "include/pros/adi.h", - "include/display/lv_objx/lv_page.h", - "include/display/lv_objx/lv_cont.h", - "include/display/lv_conf.h", - "include/display/lv_conf_checker.h", - "include/display/lv_hal/lv_hal_indev.h", - "include/pros/rotation.h", - "include/pros/motors.h", - "include/display/lv_draw/lv_draw_rect.h", - "include/pros/adi.hpp", - "include/display/lv_objx/lv_gauge.h", - "include/display/lv_misc/lv_task.h", + "include/pros/error.h", + "include/pros/gps.hpp", + "include/pros/screen.h", + "include/pros/llemu.hpp", "firmware/v5.ld", + "include/pros/device.hpp", + "include/pros/rotation.h", + "include/pros/optical.h", + "include/pros/imu.h", + "include/pros/optical.hpp", + "include/pros/colors.hpp", + "firmware/libpros.a", "include/pros/vision.hpp", - "include/display/lv_objx/lv_chart.h", - "include/display/lv_objx/lv_mbox.h", + "include/pros/colors.h", + "include/pros/ext_adi.h", + "include/pros/adi.h", "include/pros/rtos.h", - "include/display/lv_fonts/lv_font_builtin.h", - "include/pros/serial.hpp", - "include/display/lv_objx/lv_led.h", - "include/display/lv_objx/lv_btn.h", - "include/display/lv_themes/lv_theme_mono.h", - "include/display/lv_objx/lv_objx.mk", - "include/display/lv_objx/lv_ddlist.h", - "include/pros/api_legacy.h", - "include/display/lv_draw/lv_draw_rbasic.h", - "include/display/lv_objx/lv_btnm.h", - "include/display/lv_themes/lv_theme_material.h", - "include/display/lv_objx/lv_table.h", - "include/display/lv_misc/lv_area.h", - "include/display/lv_objx/lv_arc.h", - "include/display/lv_objx/lv_objx_templ.h", - "include/display/lv_misc/lv_mem.h", - "include/pros/serial.h", - "include/display/lv_version.h" + "include/pros/rtos.hpp", + "include/pros/vision.h" ], "target": "v5", "user_files": [ + "include/main.hpp", + ".gitignore", + "Makefile", + "include/main.hh", "src/main.cpp", "include/main.h", - "include/main.hh", - "Makefile", - ".gitignore", - "include/main.hpp", + "src/main.cc", "src/main.c", - "src/main.cc" + "src\\main.cpp", + "include\\main.h" ], - "version": "3.3.1" + "version": "4.0.3" } }, "upload_options": {} diff --git a/src/impl/chassis/controller/chassisControllerBuilder.cpp b/src/impl/chassis/controller/chassisControllerBuilder.cpp index cca133fb7..7b6d2c093 100644 --- a/src/impl/chassis/controller/chassisControllerBuilder.cpp +++ b/src/impl/chassis/controller/chassisControllerBuilder.cpp @@ -11,6 +11,7 @@ #include "okapi/impl/util/rate.hpp" #include "okapi/impl/util/timer.hpp" #include +#include namespace okapi { ChassisControllerBuilder::ChassisControllerBuilder(const std::shared_ptr &ilogger) diff --git a/src/impl/device/motor/motor.cpp b/src/impl/device/motor/motor.cpp index 5b2f56a14..aa3a7bbb6 100644 --- a/src/impl/device/motor/motor.cpp +++ b/src/impl/device/motor/motor.cpp @@ -101,11 +101,11 @@ std::int32_t Motor::isOverTemp() { } std::int32_t Motor::isStopped() { - return pros::c::motor_is_stopped(port); + return std::abs(pros::c::motor_get_actual_velocity(port)) <= 1; } std::int32_t Motor::getZeroPositionFlag() { - return pros::c::motor_get_zero_position_flag(port); + return pros::c::motor_get_flags(port) & pros::E_MOTOR_FLAGS_ZERO_POSITION; } uint32_t Motor::getFaults() { @@ -237,42 +237,6 @@ std::int32_t Motor::setVoltageLimit(const std::int32_t ilimit) { return pros::c::motor_set_voltage_limit(port, ilimit); } -std::int32_t -Motor::setPosPID(const double ikF, const double ikP, const double ikI, const double ikD) { - return pros::c::motor_set_pos_pid(port, pros::c::motor_convert_pid(ikF, ikP, ikI, ikD)); -} - -std::int32_t Motor::setPosPIDFull(const double ikF, - const double ikP, - const double ikI, - const double ikD, - const double ifilter, - const double ilimit, - const double ithreshold, - const double iloopSpeed) { - return pros::c::motor_set_pos_pid_full( - port, - pros::c::motor_convert_pid_full(ikF, ikP, ikI, ikD, ifilter, ilimit, ithreshold, iloopSpeed)); -} - -std::int32_t -Motor::setVelPID(const double ikF, const double ikP, const double ikI, const double ikD) { - return pros::c::motor_set_vel_pid(port, pros::c::motor_convert_pid(ikF, ikP, ikI, ikD)); -} - -std::int32_t Motor::setVelPIDFull(const double ikF, - const double ikP, - const double ikI, - const double ikD, - const double ifilter, - const double ilimit, - const double ithreshold, - const double iloopSpeed) { - return pros::c::motor_set_vel_pid_full( - port, - pros::c::motor_convert_pid_full(ikF, ikP, ikI, ikD, ifilter, ilimit, ithreshold, iloopSpeed)); -} - std::shared_ptr Motor::getEncoder() { return std::make_shared(port, isReversed()); } diff --git a/src/impl/device/rotarysensor/IMU.cpp b/src/impl/device/rotarysensor/IMU.cpp index c15de3385..7a0614cfe 100644 --- a/src/impl/device/rotarysensor/IMU.cpp +++ b/src/impl/device/rotarysensor/IMU.cpp @@ -32,10 +32,10 @@ double IMU::getRemapped(const double iupperBound, const double ilowerBound) cons } double IMU::getAcceleration() const { - const pros::c::imu_accel_s_t accel = pros::c::imu_get_accel(port); + const pros::imu_accel_s_t accel = pros::c::imu_get_accel(port); switch (axis) { - case IMUAxes::x: + case IMUAxes::x: //Depending on the axes selected return double value of x,y,or z accel from pros::imu_accel_s_t struct return accel.x; case IMUAxes::y: return accel.y; @@ -101,7 +101,7 @@ double IMU::controllerGet() { } double IMU::readAngle() const { - const pros::c::euler_s_t eu = pros::c::imu_get_euler(port); + const pros::euler_s_t eu = pros::c::imu_get_euler(port); double angle = 0; switch (axis) { @@ -120,6 +120,6 @@ double IMU::readAngle() const { } bool IMU::isCalibrating() const { - return pros::c::imu_get_status(port) & pros::c::E_IMU_STATUS_CALIBRATING; + return pros::c::imu_get_status(port) & pros::E_IMU_STATUS_CALIBRATING; } } // namespace okapi