Skip to content

♻️ Refactor VDML#40

Closed
Exortions wants to merge 18 commits intomainfrom
refactor/vdml
Closed

♻️ Refactor VDML#40
Exortions wants to merge 18 commits intomainfrom
refactor/vdml

Conversation

@Exortions
Copy link
Copy Markdown

@Exortions Exortions commented Feb 27, 2025

Overview

Refactor the Current C VDML implementation, in favor of a much cleaner C++ implementation.

Motivation

Needed to create the hardware API for ZestCode, as the VDML ensures safe access of ports on a device between threads.

References (optional)

Closes #22
Blocked on #20

Implementation Details (optional)

Currently unknown

Test Plan:

@SizzinSeal should be able to hardware test the new VDML with the current device implementation from PROS.

@Exortions Exortions added the in progress this issue is currently being worked on label Feb 27, 2025
@Exortions Exortions changed the title ♻️refactor VDML ♻️ Refactor VDML Feb 27, 2025
@liam-teale liam-teale removed the in progress this issue is currently being worked on label Feb 28, 2025
@Exortions Exortions self-assigned this Feb 28, 2025
using namespace zest::vdml;

// initialize the device mutex array
std::array<std::mutex, 32> device_mutexes;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be constinit

Suggested change
std::array<std::mutex, 32> device_mutexes;
constinit std::array<std::mutex, 32> device_mutexes;

std::mutex& smart_port_mutex(int8_t port) {
port = abs(port); // prevent negative port

return device_mutexes[port];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return device_mutexes[port];
return device_mutexes.at(port);

In the future this should have error logging in the event of an out-of-range port.


void initialize_vdml() {
// initialize the device (port) mutexes
for (int i = 0; i < MAX_DEVICE_PORTS; i++)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop isn't needed with constinit (and the create_mutex function can be discarded as well)

return device_mutexes[port];
}

bool is_valid_port(uint8_t port) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this function is so simple, it should be moved to the header and made an inline function.


namespace zest {
namespace vdml {
enum class DeviceType {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enum should have a comment explaining that these values are based on VEXos (since they seem rather arbitrary right now)

@liam-teale liam-teale closed this Mar 19, 2025
@liam-teale liam-teale deleted the refactor/vdml branch March 19, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

♻ VDML Refactor

3 participants