Skip to content
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3040afe
Creation of branch for FWT-58 UART Terminal
Nov 8, 2024
32a082e
everything so far
Nov 12, 2024
c36a901
nothing really changed just saving
Nov 14, 2024
c4380b5
created accessors, string representations, and
Nov 22, 2024
8e58a65
added to cmake path
Nov 28, 2024
bba9d1f
working on testing implementation for terminal
Jan 13, 2025
b9eee71
more work on making example implementation
Jan 14, 2025
3f2b8e6
saving work
Jan 14, 2025
a494476
fixing commmand running
Jan 16, 2025
ce2c918
fixing compiling errors
Jan 17, 2025
5af230c
error fixing still
Jan 20, 2025
5e0b090
no more errors, still failing to compile
Jan 23, 2025
c3db65d
fixing sample
Feb 8, 2025
4615f35
fixing sample
Feb 11, 2025
6629b97
arguments passing into cb functions properly
Feb 18, 2025
55303df
hiding code in classes from sample
Feb 21, 2025
5e2c4e1
i broke it but all functionality beyond callabck
Mar 1, 2025
d7c16a9
almost printing right again, missing final item
Mar 1, 2025
bb89320
running commands properly, not taking input well
Mar 22, 2025
d3bebcb
submenus working, input fixed, needs cleranup
Mar 22, 2025
1c21acd
header comments done, still need some comments
Mar 27, 2025
e9c339b
why is it making me put a second message?
Mar 27, 2025
9afb8ad
main file has instruction comments now
Mar 27, 2025
4299ff3
comments done
Mar 29, 2025
21f3d7e
Update terminal.cpp, include was capitalized wrong
RyanLeifer04 Mar 29, 2025
d76b916
Applied Formatting Changes During GitHub Build
Mar 29, 2025
100bac1
added terminalManager, making structural changes
Apr 12, 2025
9199f73
saving changes
Apr 19, 2025
a6bcd56
making updates to printing and terminal interface
Apr 19, 2025
b923207
beginning on terminalInterface struct
May 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@



[submodule "libs/canopen"]
path = libs/canopen
url = ../canopen-stack.git
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ target_sources(${PROJECT_NAME} PRIVATE
src/core/dev/RTCTimer.cpp
src/core/dev/storage/M24C32.cpp
src/core/dev/Thermistor.cpp
src/core/utils/log.cpp)
src/core/utils/log.cpp
src/core/utils/terminal/menu.cpp
src/core/utils/terminal/menuItem.cpp
src/core/utils/terminal/subMenu.cpp
src/core/utils/terminal/terminal.cpp)

get_directory_property(COMPDEFS COMPILE_DEFINITIONS)
if(COMPDEFS MATCHES "(.*)STM32F3xx(.*)")
Expand Down
79 changes: 79 additions & 0 deletions include/core/utils/terminal/menu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef EVT_TERM_MENU
#define EVT_TERM_MENU

// macro for max initial item count of a main menu
#include <core/utils/terminal/menuItem.hpp>

namespace core::utils {
class Menu {
public:
/**
* Basic constructor takes a list a menu items
* @param items a list of menu items
*/
Menu(MenuItem** items);

/**
* creates a string representation of a menu, with each menu item on its own line
*/
void printStr(io::UART& uart);

/**
* returns number of items in menu
*/
int getCount() {
return itemCount;
}

/**
* replaces this instance of a menu with another menu
* @param m the menu you want to replace it with
*/
void replace(Menu m);

/**
* returns list of items in menu
*/
MenuItem** getItems() {
return items;
}

/**
* adds an item to the menu
* @param item the item to add
*/
void addItem(utils::MenuItem* item);

/**
* replaces the current list of items with a new one
* @param itms the list to replace current with
*/
void newItems(utils::MenuItem** itms);

/**
* delete an item from the list
* @param index the index of the item in the list(top of list when printing is 0)
*/
void delItem(int index);

/**
* checks if this menu is equivalent to another menu
* true if every menu item is equal
* @param mnu2 the menu to compare to
*/
bool equals(Menu* mnu2);

private:
/**
* list of all items contained in the menu
*/
MenuItem** items;

@aclowmclaughlin aclowmclaughlin Apr 5, 2025

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 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.


/**
* maximum number of items allowed in any menu
*/
int itemCount = 10;
};
} // namespace core::utils

#endif
238 changes: 238 additions & 0 deletions include/core/utils/terminal/menuItem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
#ifndef EVT_TERM_MENUITEM
#define EVT_TERM_MENUITEM
#include <core/io/UART.hpp>

// macro for max initial item count of submenus

// struct used for callback functions, a uart instance to communicate over,
// 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.


namespace core::utils {
class MenuItem {
public:
/**
* constructor for menu item object
* takes a string for the option key, a string for the description text,
* a void pointer to the items callback method, and a void pointer to the items context
* @param parent pointer to parent node
* @param term pointer to terminal instance this item resides within
* @param option a string representing the items "key", the char/string used to select it
* @param text a short text description/name of an item
* @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?

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.


/**
* option acessor
*/
char* getOption() {
return option;
}

/**
* returns parent
*/
void* getParent() {
return parent;
}

/**
* text acessor
*/
char* getText() {
return text;
}

/**
* callback acessor
*/
callback_t getcb() {
return cb;
}

/**
* replace this item with another one
* @param newItem the new item
*/
void replace(MenuItem* newItem);

/**
* context acessor
*/
void* getctx() {
return ctx;
}

/**
* print string representation
* @param uart the uart instance to print over
*/
void printStr(core::io::UART& uart);

/**
* checks if 2 items are equivalent
* true if every attribute is equivalent using ==
* @param it2 a different menu item to compare to
*/
bool equals(MenuItem* it2);

private:
/**
* key value for item, this is used to select it in your commands
*/
char* option;

/**
* description/name of item
*/
char* text;

/**
* pointer to callback method for this item
*/
callback_t cb;

/**
* context for this item, void* because it is of an abstract type
*/
void* ctx;

/**
* submenu or menu this item is in
*/
void* parent;

/**
* terminal this is in
*/
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.

public:
/**
* constructor for sub-menu sub-class
* @param parent same as menuitem
* @param term same as menuitem
* @param option same as menuitem
* @param text same as menuitem
* @param cb exit behavior callback, leave null for nothing
* @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?


/**
* unique overridden printStr() method for sub-menus
*/
void printStr(io::UART& uart);

/**
* print method that displays the submenu like a menu, instead of an item
*/
void printMStr(io::UART& uart);

/**
* unique overridden equals() method for sub-menus
* true if every attribute is equivalent, checks all but items with ==
* items is checked the same way as menu equivalence
* @param sub2 the other submenu to compare to
*/
bool equals(SubMenu* sub2);

/**
* returns itemCount
*/
int getCount() {
return itemCount;
}

/**
* returns parent
*/
void* getParent() {
return parent;
}

/**
* replaces current item list with provided one
* @param itms items to replace current list with
*/
void setItems(MenuItem** itms);

/**
* returns a list of all items contained in the submenu
*/
MenuItem** getItems() {
return sitems;
}

// #
// # USE THESE TO DO ANY NEEDED SETUP/CLEANUP WHEN ENTERING/EXITING A SUB MENU:
// #

/**
* automatic callback executor for entering
* custom behavor is stored in ctx void*
* if cb is empty will do nothing
* @param uart uart instance to use for cb
* @param args arguments for cb
*/
void enter(io::UART& uart, char** args);

/**
* automatic callback executor for exiting
* custom behavor is stored in cb.
* if ctx is nullptr will do nothing
* @param uart uart instance to use for cb
* @param args arguments for cb
*/
void exit(io::UART& uart, char** args);

private:
/**
* key value for item, this is used to select it in your commands
*/
char* option;

/**
* description/name of item
*/
char* text;

/**
* 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

/**
* the total number of items that can be contained in any sub-menu
*/
int itemCount = 10;

/**
* list of all items inside of the sub-menu
*/
MenuItem** sitems;

/**
* submenu or menu this item is in
*/
void* parent;

/**
* terminal this is in
*/
void* term;
};
} // namespace core::utils

#endif
Loading