Closed dstroy0 closed 2 years ago
I pushed an example on the test branch, only the initial ListCommands is working, have to access the CommandOptions like this:
UserCommandParameters *cmd; // command pointer
CommandOptions opt; // empty options struct
memcpy_P(&opt, &(*(cmd->opt)), sizeof(opt)); // populate options struct from PROGMEM
User input is working again in the test/GetCommandFromStream example
Adding commands with the new method only costs 6 bytes of RAM for each command.
portability directives need to be added back into UserInput's constructor but this branch is almost ready to merge
I renamed CommandOptions to CommandParameters and UserCommandParameters to CommandConstructor. I wont be able to get to much today, next I wanted to implement the optional max_n_args and a constructor initialization list inside of the CommandParameters structure.
basic/GetCommandFromStream
mega2560:
Sketch uses 13486 bytes (5%) of program storage space. Maximum is 253952 bytes. Global variables use 309 bytes (3%) of dynamic memory, leaving 7883 bytes for local variables. Maximum is 8192 bytes.
Ram and program space have improved even though I am being a bit wasteful with program space because I made all string lliterals fixed width.
merged the pull-request
I'm not happy with overloading the constructor the way I am, I would rather define some structs and we can name them whatever, I was thinking for the struct maybe CommandParameters, and UserCommand for the constructor. It will make it much easier to add new options and the whole struct goes into PROGMEM instead of me fiddling around using a few bytes of ram here and there to point things into it. The nice thing is we can just use a nested struct to pass the argument array+options.