dstroy0 / InputHandler

Arduino input handler
https://dstroy0.github.io/InputHandler/
GNU General Public License v3.0
1 stars 0 forks source link

UserCommandParameters Constructor overhaul #14

Closed dstroy0 closed 2 years ago

dstroy0 commented 2 years ago

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.

dstroy0 commented 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
dstroy0 commented 2 years ago

User input is working again in the test/GetCommandFromStream example

dstroy0 commented 2 years ago

Adding commands with the new method only costs 6 bytes of RAM for each command.

dstroy0 commented 2 years ago

portability directives need to be added back into UserInput's constructor but this branch is almost ready to merge

dstroy0 commented 2 years ago

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.

dstroy0 commented 2 years ago

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.

dstroy0 commented 2 years ago

merged the pull-request