Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
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
135 changes: 135 additions & 0 deletions include/core/utils/terminal/menu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#ifndef EVT_TERM_MENU
#define EVT_TERM_MENU

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

namespace core::utils {


class Menu : public MenuItem{
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(Menu* parent, void* term, char* option, char* text, callback_t cb, void* ctx, MenuItem** items);

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

/**
* context for this item, void* because it is of an abstract type
*/
void* ctx;
/**
* 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
* if nullptr the current node is the head
*/
Menu* parent;

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

#endif
116 changes: 116 additions & 0 deletions include/core/utils/terminal/menuItem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#ifndef EVT_TERM_MENUITEM
#define EVT_TERM_MENUITEM
#include <core/io/UART.hpp>
#include <core/utils/terminal/terminal.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*)

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;
};
} // namespace core::utils

#endif
21 changes: 21 additions & 0 deletions include/core/utils/terminal/terminal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef EVT_TERM_STRUCTS
#define EVT_TERM_STRUCTS
#include <core/utils/terminal/terminalManager.hpp>

struct TerminalInterface
{
//fill with list full of pointers to terminalManager functions to circumvent
void** funclist;

FunctionRunner(void** funclist): funclist(funclist) {}

void runAll()
{

}
};

using callback_t = void (*)(core::io::UART&, char** inputList, void*);


#endif
101 changes: 101 additions & 0 deletions include/core/utils/terminal/terminalManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#ifndef EVT_TERMINAL
#define EVT_TERMINAL

#include <core/io/UART.hpp>
#include <core/io/pin.hpp>
#include <core/utils/terminal/menu.hpp>
#include <core/utils/terminal/menuItem.hpp>
#include <core/utils/terminal/terminal.hpp>
#include <cstring>

namespace core::utils {

class TerminalManager {
public:
/**
* constructor for terminal object
* takes a uart object and sets up the command line terminal
* @param uart an instance of a UART object
* @param menu head node of terminal structure
*/
Terminal(io::UART& uart, Menu* menu);

/**
* returns uart instance used
*/
io::UART& getUART() {
return uart;
}

/**
* returns main menu
*/
Menu* getMenu() {
return menu;
}

/**
* enters the given submenu
* @param uart the uart instance to use
* @param args the arguments provided, used for enter callback, first index is still option string
* @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);
/**
* sets current menu/submenu to provided value
* @param sub the submenu to replace the current one with
*/
void setMenu(SubMenu* sub);

/**
* checks if the terminal is still on the main menu
* OK FOR NOW< MAYBE MAKE IT DETECT WHEN HEAD INSTED OF USING A FLAG
*/
bool isMain() {
return m;
}

/**
* Sends a provided message over UART
* also replaces menu with provided menu
* used to reset menu to desired state and notify user
* @param message a string message to send via UART
* @param menu the menu to replace the current menu with
*/
void update(char* message, utils::Menu menu);

/**
* proccesses incoming UART messages
* @param holder list to store tokenized strings in, should be full of "/0" to start
*/
bool recieve(char** holder);

/**
* processes chosen menu item and runs its callback(if exit, exits into higher menu)
* @param tag the user input key for the item
*/
void process(char* tag, char** args);

// TERMINAL specific print function
void printTerm();

private:
// menu instance
Menu* menu;

// current submenu, if there is one, nullptr otherwise
Menu* current;

// true if currently in main menu
bool m;

// uart instance this terminal is using
core::io::UART& uart;

// char buffer for UART entry
char buffer[99];
};
} // namespace core::utils

#endif
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ add_subdirectory(rtos)
add_subdirectory(thermistor)
add_subdirectory(timer)
add_subdirectory(spi)
add_subdirectory(terminal)
Loading
Loading