46#include "freertos/FreeRTOS.h"
47#include "freertos/task.h"
48#include "freertos/timers.h"
49#include "freertos/semphr.h"
715struct TerminalCursorState {
716 TerminalCursorState * next;
720 bool cursorPastLastCol;
722 GlyphOptions glyphOptions;
723 uint8_t characterSetIndex;
724 uint8_t characterSet[4];
761 uint8_t characterSetIndex;
764 uint8_t characterSet[4];
766 Color foregroundColor;
767 Color backgroundColor;
773 bool cursorPastLastCol;
780 int scrollingRegionTop;
781 int scrollingRegionDown;
786 bool cursorBlinkingEnabled;
808 KeypadMode keypadMode;
814 int conformanceLevel;
821 bool allow132ColumnMode;
823 bool reverseWraparoundMode;
826 bool backarrowKeyMode;
832 bool VT52GraphicsMode;
835 int allowFabGLSequences;
842 virtual size_t write(uint8_t) = 0;
843 virtual size_t write(
const uint8_t * buffer,
size_t size);
844 size_t write(
const char *str) {
847 return write((
const uint8_t *)str, strlen(str));
849 void printf(
const char * format, ...) {
851 va_start(ap, format);
852 int size = vsnprintf(
nullptr, 0, format, ap) + 1;
855 va_start(ap, format);
857 auto l = vsnprintf(buf, size, format, ap);
858 write((uint8_t*)buf, l);
864struct Stream :
public Print{
1134 void logFmt(
const char * format, ...);
1135 void log(
const char * txt);
1148 void loadFont(FontInfo
const * font);
1193 void clear(
bool moveCursor =
true);
1201 void flush(
bool waitVSync);
1278 int read(
int timeOutMS);
1290 bool waitFor(
int value,
int timeOutMS = -1);
1328 size_t write(
const uint8_t * buffer,
size_t size);
1339 size_t write(uint8_t c);
1348 void send(uint8_t c);
1355 void send(
char const * str);
1451 bool CTSStatus() {
return m_ctsPin != GPIO_UNUSED ? gpio_get_level(m_ctsPin) == 0 :
false; }
1533 void clearMap(uint32_t * map);
1536 void freeTabStops();
1537 void freeGlyphsMap();
1539 void set132ColumnMode(
bool value);
1543 void move(
int offset);
1544 void setCursorPos(
int X,
int Y);
1545 int getAbsoluteRow(
int Y);
1547 void int_setBackgroundColor(
Color color);
1548 void int_setForegroundColor(
Color color);
1550 void syncDisplayController();
1554 void setTabStop(
int column,
bool set);
1555 void resetTabStops();
1559 void scrollDownAt(
int startingRow);
1561 void scrollUpAt(
int startingRow);
1562 void setScrollingRegion(
int top,
int down,
bool resetCursorPos =
true);
1563 void updateCanvasScrollingRegion();
1566 void saveCursorState();
1567 void restoreCursorState();
1568 void clearSavedCursorStates();
1570 void erase(
int X1,
int Y1,
int X2,
int Y2, uint8_t c,
bool maintainDoubleWidth,
bool selective);
1572 void consumeInputQueue();
1576 void consumeFabGLSeq();
1577 void consumeFabGLGraphicsSeq();
1578 void consumeCSIQUOT(
int * params,
int paramsCount);
1579 void consumeCSISPC(
int * params,
int paramsCount);
1580 uint8_t consumeParamsAndGetCode(
int * params,
int * paramsCount,
bool * questionMarkFound);
1581 void consumeDECPrivateModes(
int const * params,
int paramsCount, uint8_t c);
1583 void execSGRParameters(
int const * params,
int paramsCount);
1584 void consumeESCVT52();
1586 void execCtrlCode(uint8_t c);
1588 static void charsConsumerTask(
void * pvParameters);
1589 static void keyboardReaderTask(
void * pvParameters);
1591 static void blinkTimerFunc(TimerHandle_t xTimer);
1593 bool enableBlinkingText(
bool value);
1595 bool int_enableCursor(
bool value);
1597 static void IRAM_ATTR uart_isr(
void *arg);
1599 uint8_t getNextCode(
bool processCtrlCodes);
1601 bool setChar(uint8_t c);
1604 void insertAt(
int column,
int row,
int count);
1605 void deleteAt(
int column,
int row,
int count);
1607 bool multilineInsertChar(
int charsToMove);
1608 void multilineDeleteChar(
int charsToMove);
1610 void reverseVideo(
bool value);
1613 void refresh(
int X,
int Y);
1614 void refresh(
int X1,
int Y1,
int X2,
int Y2);
1616 void setLineDoubleWidth(
int row,
int value);
1617 int getCharWidthAt(
int row);
1618 int getColumnsAt(
int row);
1620 void useAlternateScreenBuffer(
bool value);
1625 void sendCursorKeyCode(uint8_t c);
1626 void sendKeypadCursorKeyCode(uint8_t applicationCode,
const char * numericCode);
1631 void convHandleTranslation(uint8_t c,
bool fromISR);
1632 void convSendCtrl(ConvCtrl ctrl,
bool fromISR);
1633 void convQueue(
const char * str,
bool fromISR);
1636 bool addToInputQueue(uint8_t c,
bool fromISR);
1637 bool insertToInputQueue(uint8_t c,
bool fromISR);
1639 void write(uint8_t c,
bool fromISR);
1643 void uartCheckInputQueueForFlowControl();
1645 void enableFabGLSequences(
bool value);
1647 void int_setTerminalType(
TermType value);
1648 void int_setTerminalType(TermInfo
const * value);
1650 void sound(
int waveform,
int frequency,
int duration,
int volume);
1652 uint8_t extGetByteParam();
1653 int extGetIntParam();
1654 void extGetCmdParam(
char * cmd);
1658 uint32_t makeGlyphItem(uint8_t c,
GlyphOptions * glyphOptions,
Color * newForegroundColor);
1661 static Terminal * s_activeTerminal;
1666 bool m_bitmappedDisplayController;
1670 Stream * m_logStream;
1674 GlyphsBuffer m_glyphsBuffer;
1677 uint32_t * m_alternateMap;
1680 bool m_alternateScreenBuffer;
1683 int m_alternateCursorX;
1684 int m_alternateCursorY;
1685 int m_alternateScrollingRegionTop;
1686 int m_alternateScrollingRegionDown;
1687 bool m_alternateCursorBlinkingEnabled;
1694 EmuState m_emuState;
1696 Color m_defaultForegroundColor;
1697 Color m_defaultBackgroundColor;
1700 bool m_prevCursorEnabled;
1701 bool m_prevBlinkingTextEnabled;
1704 TaskHandle_t m_charsConsumerTaskHandle;
1707 TaskHandle_t m_keyboardReaderTaskHandle;
1710 volatile bool m_cursorState;
1713 TimerHandle_t m_blinkTimer;
1716 volatile SemaphoreHandle_t m_mutex;
1718 volatile bool m_blinkingTextVisible;
1719 volatile bool m_blinkingTextEnabled;
1721 volatile int m_columns;
1722 volatile int m_rows;
1732 HardwareSerial * m_serialPort;
1738 volatile bool m_uart;
1741 volatile bool m_uartRXEnabled;
1744 volatile QueueHandle_t m_inputQueue;
1747 QueueHandle_t m_outputQueue;
1750 TerminalCursorState * m_savedCursorStateList;
1753 bool m_resetRequested;
1756 volatile bool m_sentXOFF;
1757 volatile bool m_recvXOFF;
1760 gpio_num_t m_rtsPin;
1761 gpio_num_t m_ctsPin;
1767 uint8_t m_convMatchedCount;
1768 uint8_t m_convMatchedChars[EmuTerminalMaxChars];
1769 TermInfoVideoConv
const * m_convMatchedItem;
1770 TermInfo
const * m_termInfo;
1773 volatile uint8_t m_lastWrittenChar;
1776 volatile bool m_writeDetectedFabGLSeq;
1786 bool m_coloredAttributesMaintainStyle;
1787 int m_coloredAttributesMask;
1788 Color m_coloredAttributesColor[4];
1995 void waitFor(
int value);
1996 void write(uint8_t c);
1997 void write(
char const * str);
2070 void setText(
char const * text,
bool moveCursor =
true);
2082 void setText(
char const * text,
int length,
bool moveCursor =
true);
2102 char const *
edit(
int maxLength = 0);
2109 char const *
get() {
return m_text; }
2170 void setLength(
int newLength);
2172 void write(uint8_t c);
2175 void performCursorUp();
2176 void performCursorDown();
2177 void performCursorLeft();
2178 void performCursorRight();
2179 void performCursorHome();
2180 void performCursorEnd();
2181 void performDeleteRight();
2182 void performDeleteLeft();
This file contains fabgl::Canvas definition.
Represents the base abstract class for all display controllers.
A class with a set of drawing methods.
The PS2 Keyboard controller class.
char const * edit(int maxLength=0)
Reads user input and return the inserted line.
Delegate< LineEditorSpecialChar > onSpecialChar
A delegate called whenever a special character has been pressed.
void setInsertMode(bool value)
Sets insert mode state.
void setText(char const *text, bool moveCursor=true)
Sets initial text.
LineEditor(Terminal *terminal)
Object constructor.
Delegate< int * > onChar
A delegate called whenever a character has been received.
Delegate< int * > onRead
Read character delegate.
void typeText(char const *text)
Simulates user typing.
Delegate< int > onWrite
Write character delegate.
Delegate< int * > onCarriageReturn
A delegate called whenever carriage return has been pressed.
char const * get()
Gets current content.
LineEditor is a single-line / multiple-rows editor which uses the Terminal object as input and output...
SoundGenerator handles audio output.
void connectLocally()
Permits using of terminal locally.
TermInfo const & terminalType()
Determines current terminal type.
void setRTSStatus(bool value)
Sets RTS signal status.
void pollSerialPort()
Pools the serial port for incoming data.
int getRows()
Returns the number of lines.
bool waitFor(int value, int timeOutMS=-1)
Wait for a specific code from keyboard, discarding all previous codes.
void clear(bool moveCursor=true)
Clears the screen.
Delegate< VirtualKey *, bool > onVirtualKey
Delegate called whenever a new virtual key is received from keyboard.
int available()
Gets the number of codes available in the keyboard queue.
void setLogStream(Stream &stream)
Sets the stream where to output debugging logs.
void disableSerialPortRX(bool value)
Disables/Enables serial port RX.
bool RTSStatus()
Reports current RTS signal status.
int getColumns()
Returns the number of columns.
void loadFont(FontInfo const *font)
Sets the font to use.
static int keyboardReaderTaskStackSize
Stack size of the task that reads keys from keyboard and send ANSI/VT codes to output stream in Termi...
size_t write(const uint8_t *buffer, size_t size)
Sends specified number of codes to the display.
void localInsert(uint8_t c)
Injects keys into the keyboard queue.
void localWrite(uint8_t c)
Injects keys into the keyboard queue.
Canvas * canvas()
Gets associated canvas object.
void deactivate()
Deactivates this terminal.
Keyboard * keyboard()
Gets associated keyboard object.
static int inputQueueSize
Number of characters the terminal can "write" without pause (increase if you have loss of characters ...
int availableForWrite()
Determines number of codes that the display input queue can still accept.
int peek()
Reads a code from the keyboard without advancing to the next one.
void connectSerialPort(HardwareSerial &serialPort, bool autoXONXOFF=true)
Connects a remote host using the specified serial port.
bool isActive()
Determines if this terminal is active or not.
void disconnectLocally()
Avoids using of terminal locally.
int read()
Reads codes from keyboard.
void activate(TerminalTransition transition=TerminalTransition::None)
Activates this terminal for input and output.
void enableCursor(bool value)
Enables or disables cursor.
static int inputConsumerTaskStackSize
Stack size of the task that processes Terminal input stream.
void end()
Finalizes the terminal.
Delegate< VirtualKeyItem * > onVirtualKeyItem
Delegate called whenever a new virtual key is received from keyboard, including shift states.
SoundGenerator * soundGenerator()
Gets embedded sound generator.
void send(uint8_t c)
Like localWrite() but sends also to serial port if connected.
bool CTSStatus()
Reports current CTS signal status.
bool flowControl()
Checks whether host can receive data.
void flush()
Waits for all codes sent to the display has been processed.
void setColorForAttribute(CharStyle attribute, Color color, bool maintainStyle)
Selects a color for the specified attribute.
void setTerminalType(TermType value)
Sets the terminal type to emulate.
bool XOFFStatus()
Reports whether TX is active.
void setBackgroundColor(Color color, bool setAsDefault=true)
Sets the background color.
bool begin(BaseDisplayController *displayController, int maxColumns=-1, int maxRows=-1, Keyboard *keyboard=nullptr)
Initializes the terminal.
Delegate< char const * > onUserSequence
Delegate called whenever a new user sequence has been received.
void setForegroundColor(Color color, bool setAsDefault=true)
Sets the foreground color.
void unRead(uint8_t c)
Injects keys into the keyboard queue.
void cursorRight(int count)
Moves cursor to the right.
void disableFabGLSequences()
Disables FabGL specific sequences.
void cursorLeft(int count)
Moves cursor to the left.
void multilineDeleteChar(int charsToMove)
Deletes a character moving specified amount of characters to the left.
bool isVKDown(VirtualKey vk)
Checks if a virtual key is currently down.
bool multilineInsertChar(int charsToMove)
Inserts a blank character and move specified amount of characters to the right.
int getCursorCol()
Gets current cursor column.
bool setChar(uint8_t c)
Sets a raw character at current cursor position.
void setTerminal(Terminal *terminal=nullptr)
Sets destination terminal.
Delegate< int * > onRead
Read character delegate.
int getCursorRow()
Gets current cursor row.
Delegate< int > onWrite
Write character delegate.
void getCursorPos(int *col, int *row)
Gets current cursor position.
void enableCursor(bool value)
Enables/disables cursor.
void setBackgroundColor(Color value)
Sets background color.
TerminalController(Terminal *terminal=nullptr)
Object constructor.
void clear()
Clears screen.
void setCursorPos(int col, int row)
Sets current cursor position.
void setTerminalType(TermType value)
Sets the terminal type to emulate.
void setForegroundColor(Color value)
Sets foreground color.
void setCharStyle(CharStyle style, bool enabled)
Enables or disables specified character style.
TerminalController allows direct controlling of the Terminal object without using escape sequences.
An ANSI-VT100 compatible display terminal.
GlyphOptions & Underline(bool value)
Helper method to set or reset underlined.
GlyphOptions & Italic(bool value)
Helper method to set or reset italic.
GlyphOptions & Bold(bool value)
Helper method to set or reset bold.
GlyphOptions & Blank(uint8_t value)
Helper method to set or reset foreground and background swapping.
This file contains FabGL library configuration settings, like number of supported colors,...
TerminalTransition
This enum defines terminal transition effect.
CharStyle
This enum defines a character style.
TermType
This enum defines supported terminals.
LineEditorSpecialChar
Special character specified in on values from LineEditor::onSpecialChar delegate.
Color
This enum defines named colors.
VirtualKey
Represents each possible real or derived (SHIFT + real) key.
FlowControl
This enum defines various serial port flow control methods.
This file contains fabgl::Keyboard definition.
This file contains all classes related to FabGL Sound System.
Specifies general paint options.
A struct which contains a virtual key, key state and associated scan code.
This file contains terminal emulation definitions.
Specifies various glyph painting options.