Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for lists in config.yaml #342

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nils
Copy link
Contributor

@nils nils commented Mar 19, 2022

DRAFT
This is just a FYI PR in case anyone is interested in what I'm doing.
No expectations from my side attached to it at the moment (no expectation to have it merged, reviewed, ...)

Initial work on allowing YAML lists to instantiate multiple objects of the same type (see #341 for a use case).

There are many things that need to be improved or that are missing at this point. (also see @MitchBradley's comments on #341)

Currently it allows me to do what I had in mind (but not much more, I assume):

[ ... ]
besc:
  - pwm_hz: 50
    output_pin: gpio.12
    enable_pin: gpio.13:low
    direction_pin: NO_PIN
    disable_with_s0: false
    s0_with_disable: true
    spinup_ms: 0
    spindown_ms: 0
    tool_num: 0
    speed_map: 0=0.000% 255=100.000%
    min_pulse_us: 500
    max_pulse_us: 2500

  - pwm_hz: 50
    output_pin: gpio.33
    enable_pin: gpio.27:low
    direction_pin: NO_PIN
    disable_with_s0: false
    s0_with_disable: true
    spinup_ms: 0
    spindown_ms: 0
    tool_num: 100
    speed_map: 0=0.000% 255=100.000%
    min_pulse_us: 500
    max_pulse_us: 2500

Next steps:

  • Think about how to implement enterSectionList on the other HandlerBase subclasses.
    • i.e. addressing scheme proposal (RuntimeSetting?), e.g. $besc/0/pwm_hz
  • potential future extension: reference other items from another branch of the tree (to e.g. define motors globally, only reference them from kinematics)

while (_parser.token_.is_list_) {
_parser.token_.is_list_ = false;
entryIndent = _parser.token_.indent_;
_parser.token_.indent_ += 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks a bit fishy. I could introduce another member on Token as well, but it would basically do the same, I assume.

@@ -8,6 +8,22 @@
#include "HandlerBase.h"

namespace Configuration {
template <typename BaseType>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to make BuilderBase a non-inner class to be able to forward declare it in HandlerBase.h

if (IsListItem()) {
token_.is_list_ = true;
Inc();
// skip expected whitespace. TODO: validate that it's indeed a whitespace
Copy link
Contributor Author

@nils nils Mar 19, 2022

Choose a reason for hiding this comment

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

Reason: It could also be a plain scalar (e.g. -42)
But did this YAML parser support that before? I guess not, it always relied on "key: value" pairs.

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.

1 participant