Skip to content

Commit

Permalink
Terminal bugfix (bigtreetech#2756)
Browse files Browse the repository at this point in the history
  • Loading branch information
kisslorand authored Apr 11, 2023
1 parent f860ae1 commit 6c82451
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
5 changes: 0 additions & 5 deletions TFT/src/User/API/SerialConnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ void Serial_Forward(SERIAL_PORT_INDEX portIndex, const char * msg)
Serial_Put(SERIAL_DEBUG_PORT, msg);
#endif

uint16_t msgLen = MENU_IS(menuTerminal ? strlen(msg) : 0); // retrieve message lenght if Terminal menu is currently displayed
uint8_t portCount = SERIAL_PORT_COUNT; // by default, select all the serial ports

if (portIndex == ALL_PORTS) // if ALL_PORTS, forward the message to all the enabled serial ports
Expand All @@ -132,12 +131,8 @@ void Serial_Forward(SERIAL_PORT_INDEX portIndex, const char * msg)
&& serialPort[portIndex].port != SERIAL_DEBUG_PORT // do not forward data to serial debug port
#endif
)
{
Serial_Put(serialPort[portIndex].port, msg); // pass on the message to the port

if (msgLen != 0) // if Terminal menu is currently displayed
terminalCache(msg, msgLen, portIndex, SRC_TERMINAL_GCODE);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions TFT/src/User/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,13 @@
*/
#define TERMINAL_KEYBOARD_LAYOUT 0 // Default: 0

/**
* Suppress/allow terminal cache during keyboard view
* - uncomment to disable terminal cache during keyboard view
* - comment it to enable terminal cache during keyboard view
*/
#define TERMINAL_KEYBOARD_VIEW_SUPPRESS_ACK // Default: uncommented (cache suppressed)

/**
* Progress Bar Color (Printing menu)
* The color of the progress bar during print.
Expand Down
33 changes: 18 additions & 15 deletions TFT/src/User/Menu/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ typedef struct
uint8_t lastSrc;
} TERMINAL_DATA;

typedef enum
{
KEYBOARD_VIEW = 0,
TERMINAL_WINDOW,
} TERMINAL_VIEW;

typedef enum
{
GKEY_PREV = 0,
Expand Down Expand Up @@ -316,7 +310,12 @@ const uint16_t fontSrcColor[3][3] = {
KEYBOARD_DATA * keyboardData;
TERMINAL_DATA * terminalData;
char * terminalBuf;
TERMINAL_VIEW curView = KEYBOARD_VIEW;

enum
{
KEYBOARD_VIEW = 0,
TERMINAL_VIEW,
} curView = KEYBOARD_VIEW;

bool numpad =
#if defined(KB_TYPE_QWERTY)
Expand Down Expand Up @@ -588,11 +587,12 @@ static inline void menuKeyboardView(void)
saveGcodeIndex = (saveGcodeIndex + 1) % MAX_GCODE_COUNT; // move to next save index in the gcode history table
}

handleCmd(strcat(gcodeBuf, "\n"));
strcpy(&gcodeBuf[nowIndex], "\n");
handleCmd(gcodeBuf);
}

keyboardData->gcodeIndex = saveGcodeIndex; // save and update gcode index
curView = TERMINAL_WINDOW;
curView = TERMINAL_VIEW;
break;

case GKEY_ABC_123:
Expand Down Expand Up @@ -666,6 +666,12 @@ static inline void saveGcodeTerminalCache(const char * str, uint16_t strLen)

void terminalCache(const char * stream, uint16_t streamLen, SERIAL_PORT_INDEX portIndex, TERMINAL_SRC src)
{

#ifdef TERMINAL_KEYBOARD_VIEW_SUPPRESS_ACK
if (curView == KEYBOARD_VIEW)
return;
#endif

char * srcId[SRC_TERMINAL_COUNT] = {"\5", "\6"};

// copy string source identifier
Expand Down Expand Up @@ -821,7 +827,7 @@ static inline void terminalDrawMenu(void)
terminalDrawPageNumber();
}

void menuTerminalWindow(void)
void menuTerminalView(void)
{
#define CURSOR_START_X (terminalAreaRect[0].x0 + CURSOR_H_OFFSET)

Expand All @@ -837,7 +843,7 @@ void menuTerminalWindow(void)

terminalDrawMenu();

while (curView == TERMINAL_WINDOW)
while (curView == TERMINAL_VIEW)
{
if (MENU_IS_NOT(menuTerminal))
break;
Expand Down Expand Up @@ -1025,9 +1031,6 @@ void menuTerminal(void)

while (MENU_IS(menuTerminal))
{
if (curView == KEYBOARD_VIEW)
menuKeyboardView();
else if (curView == TERMINAL_WINDOW)
menuTerminalWindow();
(curView == KEYBOARD_VIEW) ? menuKeyboardView() : menuTerminalView();
}
}

0 comments on commit 6c82451

Please sign in to comment.