Skip to content

FWT-58 Oh no, Its Terminal!#117

Open
RyanLeifer04 wants to merge 30 commits intomainfrom
FWT-58-UART-Terminal-Ryan-Leifer
Open

FWT-58 Oh no, Its Terminal!#117
RyanLeifer04 wants to merge 30 commits intomainfrom
FWT-58-UART-Terminal-Ryan-Leifer

Conversation

@RyanLeifer04
Copy link
Copy Markdown

generic UART terminal to load and execute functions

@aclowmclaughlin aclowmclaughlin self-requested a review April 5, 2025 16:36
* @param cb a void pointer to this items callback method
* @param ctx a void pointer to any context information for this menu(if none provided, is NULL)
*/
MenuItem(void* parent, void* term, char* option, char* text, callback_t cb, void* ctx);
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.

Is there a reason these are void* instead of MenuItem pointers? Isn't it always the case that the parent to a MenuItem will be another MenuItem?

* @param cb a void pointer to this items callback method
* @param ctx a void pointer to any context information for this menu(if none provided, is NULL)
*/
MenuItem(void* parent, void* term, char* option, char* text, callback_t cb, void* ctx);
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.

If many of these are going to be passed a null value commonly, they could be given default values. Default values only work for objects at the end of the initialization list, so perhaps they should be re-ordered so that things that are almost never null are at the front of the list.

void* term;
};

class SubMenu : public MenuItem {
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.

I don't particularly like that these are in the same hpp but have different cpps. Is there any reason for them to be in the same hpp? if there isn't, please move them to separate hpps.

Comment on lines +16 to +19
* takes a uart object and sets up the command line terminal
* @param uart an instance of a UART object
* @param baud 9600 or 115200
*/
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.

incorrect doc comment

* @param term void pointer to the terminal this is being done inside of(optional to leave as nullptr, just here to
* be used with callbacks)
*/
void enterSub(io::UART& uart, char** args, void* term);
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.

Is there a reason to pass in another uart instance? won't it always be the same one?

callback_t cb2 = it2->getcb();
void* ctx2 = it2->getctx();
// if any corresponding arent equal, return false
if (option != option2 || text != text2 || cb != cb2 || ctx != ctx2) {
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.

bear in mind that this will literally compare memory addresses, not contents. If that is intended, that's alright, but otherwise this will not work the way you think it does. Additionally, do we necessarily need an equals() method? Is there any point at which we are using it?

* @param ctx enterence behavior callback void*(leave null for nothing)
* @param items list of items in submenu
*/
SubMenu(void* parent, void* term, char* option, char* text, callback_t cb, void* ctx, MenuItem** items);
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.

I'm struggling to understand what make a subMenu different from a MenuItem. If they aren't significantly different we should consider if we need to care about the distinction between them.

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.

additionally, if a submenu is also a menu, maybe it should inherit from menu as well?

/**
* pointer to callback method for this item
*/
callback_t cb;
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.

rename this to callback

/**
* context for this item, void* because it is of an abstract type
*/
void* ctx;
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.

rename this to context

// a list of input strings(your input from the terminal), and a void*
// mostly a placeholder to ease handling void* to a function, when you fill with a function make sure the parameters are
// (UART,char**,void*)
using callback_t = void (*)(core::io::UART&, char** inputList, void*);
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.

Big fan of this, we should possibly consider requiring this instead of typedefs in our code, because this is far more readable. However, it should probably be in the namespace.

/**
* list of all items contained in the menu
*/
MenuItem** items;
Copy link
Copy Markdown
Contributor

@aclowmclaughlin aclowmclaughlin Apr 5, 2025

Choose a reason for hiding this comment

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

I'm confused about what we're doing here tbh. Since we are capping the size of the list to such a small number, we could just create the array statically, inside this class, instead of having the user pass the array into the object. This will both protect access and also clean up the main code.
We may want to look into using templates to set the size of the menu, but I'm not married to that.
Also see my notes on having this be a linked list instead. I think for our use case it makes far more sense.

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.

2 participants