Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.

Commit a0a8e51

Browse files
authored
♻️ VDML Refactor (#64)
2 parents 2834fd9 + bfbda47 commit a0a8e51

31 files changed

Lines changed: 389 additions & 3777 deletions

docs/STRUCTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ Looking at the file structure of a project like this can feel intimidating. This
1010
- `include` contains the header files
1111
- `include/common` headers used in various parts of the project
1212
- `include/pros` headers that are distributed to user projects
13+
- `include/pros/devices` headers containing api for interacting with V5 devices
1314
- `include/rtos` headers for the scheduler (FreeRTOS)
1415
- `include/system` headers for low-level system functionality
1516
- `include/system/dev` headers for serial I/O and file management
1617
- `include/system/user_functions` a horrifying mess that should be destroyed
17-
- `include/vdml` headers for the VEX Data Management Layer (VDML), a system to ensure thread-safety when interacting with VEX devices
1818

1919
- `scripts` contains scripts used for building ZestCode and projects that use ZestCode
2020

2121
- `src` contains the source files
2222
- `src/common` sources defining symbols used throughout the project
23-
- `src/devices` implementations of VEX device abstractions. Files prefixed with `vdml_` indicate that the file makes use of the VDML
23+
- `src/devices` implementations of VEX device abstractions
2424
- `src/rtos` sources, build scripts, and misc files of FreeRTOS
2525
- `src/system` sources for low-level system functionality
2626
- `src/system/dev` sources for serial I/O and file management

include/api.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@
3939
#include <unistd.h>
4040
#endif /* __cplusplus */
4141

42-
#include "pros/colors.h"
43-
#include "pros/error.h"
4442
#include "pros/misc.h"
4543
#include "pros/rtos.h"
4644

4745
#ifdef __cplusplus
48-
#include "pros/colors.hpp"
4946
#include "pros/misc.hpp"
5047
#include "pros/rtos.hpp"
51-
#include "pros/screen.hpp"
5248
#endif
5349

5450
#endif // _PROS_API_H_

include/common/result.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ class ResultError {
4141
std::optional<RuntimeData> runtime_data;
4242
};
4343

44+
/**
45+
* @brief Unknown Error
46+
*
47+
*/
48+
class UnknownError : public ResultError {
49+
public:
50+
template<typename T>
51+
requires std::convertible_to<T, std::string>
52+
UnknownError(T&& message)
53+
: message(std::forward<T>(message)) {}
54+
55+
std::string message;
56+
};
57+
4458
/**
4559
* @brief Trait to define a "sentinel" value for types indicating an error state.
4660
* @tparam T Type to provide a sentinel value for.

include/kapi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#pragma once
2020

2121
#include "api.h"
22-
#include "pros/apix.h"
22+
#include "pros/apix.hpp"
2323
#include "rtos/FreeRTOS.h"
2424
#include "rtos/stream_buffer.h"
2525

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -559,134 +559,6 @@ void queue_reset(queue_t queue);
559559

560560
///@}
561561

562-
/// \name Device Registration
563-
///@{
564-
565-
/**
566-
* \enum v5_device_e
567-
* \brief
568-
* List of possible v5 devices
569-
*
570-
* This list contains all current V5 Devices, and mirrors V5_DeviceType from the
571-
* api.
572-
*/
573-
typedef enum v5_device_e {
574-
E_DEVICE_NONE = 0, ///< No device is plugged into the port
575-
E_DEVICE_MOTOR = 2, ///< A motor is plugged into the port
576-
E_DEVICE_ROTATION = 4, ///< A rotation sensor is plugged into the port
577-
E_DEVICE_IMU = 6, ///< An inertial sensor is plugged into the port
578-
E_DEVICE_DISTANCE = 7, ///< A distance sensor is plugged into the port
579-
E_DEVICE_RADIO = 8, ///< A radio is plugged into the port
580-
E_DEVICE_VISION = 11, ///< A vision sensor is plugged into the port
581-
E_DEVICE_ADI = 12, ///< This port is an ADI expander
582-
E_DEVICE_OPTICAL = 16, ///< An optical sensor is plugged into the port
583-
E_DEVICE_GPS = 20, ///< A GPS sensor is plugged into the port
584-
E_DEVICE_AIVISION = 29, ///< An AI Vision sensor is plugged into the port
585-
E_DEVICE_SERIAL = 129, ///< A serial device is plugged into the port
586-
E_DEVICE_GENERIC __attribute__((deprecated("use E_DEVICE_SERIAL instead"))) = E_DEVICE_SERIAL,
587-
E_DEVICE_UNDEFINED = 255 ///< The device type is not defined, or is not a valid device
588-
} v5_device_e_t;
589-
590-
/**
591-
* Registers a device in the given zero-indexed port
592-
*
593-
* Registers a device of the given type in the given port into the registry, if
594-
* that type of device is detected to be plugged in to that port.
595-
*
596-
* This function uses the following values of errno when an error state is
597-
* reached:
598-
* ENXIO - The given value is not within the range of V5 ports (0-20), or a
599-
* a different device than specified is plugged in.
600-
* EADDRINUSE - The port is already registered to another device.
601-
*
602-
* \param port
603-
* The port number to register the device
604-
* \param device
605-
* The type of device to register
606-
*
607-
* \return 1 upon success, PROS_ERR upon failure
608-
*
609-
* \b Example:
610-
* \code
611-
* void opcontrol(void) {
612-
* registry_bind_port(1, E_DEVICE_MOTOR);
613-
* }
614-
* \endcode
615-
*/
616-
int registry_bind_port(uint8_t port, v5_device_e_t device_type);
617-
618-
/**
619-
* Deregisters a devices from the given zero-indexed port
620-
*
621-
* Removes the device registed in the given port, if there is one.
622-
*
623-
* This function uses the following values of errno when an error state is
624-
* reached:
625-
* ENXIO - The given value is not within the range of V5 ports (0-20).
626-
*
627-
* \param port
628-
* The port number to deregister
629-
*
630-
* \return 1 upon success, PROS_ERR upon failure
631-
*
632-
* \b Example:
633-
* \code
634-
* void opcontrol(void) {
635-
* registry_bind_port(1, E_DEVICE_MOTOR);
636-
* registry_unbind_port(1);
637-
* }
638-
* \endcode
639-
*/
640-
int registry_unbind_port(uint8_t port);
641-
642-
/**
643-
* Returns the type of device registered to the zero-indexed port.
644-
*
645-
* This function uses the following values of errno when an error state is
646-
* reached:
647-
* ENXIO - The given value is not within the range of V5 ports (0-20).
648-
*
649-
* \param port
650-
* The V5 port number from 0-20
651-
*
652-
* \return The type of device that is registered into the port (NOT what is
653-
* plugged in)
654-
*
655-
* \b Example:
656-
* \code
657-
* void opcontrol(void) {
658-
* registry_bind_port(1, E_DEVICE_MOTOR);
659-
* printf("port 1 is registered to a motor: %d", registry_get_bound_type(1) == E_DEVICE_MOTOR);
660-
* }
661-
* \endcode
662-
*/
663-
v5_device_e_t registry_get_bound_type(uint8_t port);
664-
665-
/**
666-
* Returns the type of the device plugged into the zero-indexed port.
667-
*
668-
* This function uses the following values of errno when an error state is
669-
* reached:
670-
* ENXIO - The given value is not within the range of V5 ports (0-20).
671-
*
672-
* \param port
673-
* The V5 port number from 0-20
674-
*
675-
* \return The type of device that is plugged into the port (NOT what is
676-
* registered)
677-
*
678-
* \b Example:
679-
* \code
680-
* void opcontrol(void) {
681-
* registry_bind_port(1, E_DEVICE_MOTOR);
682-
* printf("port 1 is registered to a motor: %d", registry_get_plugged_type(1) == E_DEVICE_MOTOR);
683-
* }
684-
* \endcode
685-
*/
686-
v5_device_e_t registry_get_plugged_type(uint8_t port);
687-
688-
///@}
689-
690562
/// \name Startup options
691563
///@{
692564

0 commit comments

Comments
 (0)