1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/docs/terminal_support.txt

69 lines
3.0 KiB
Plaintext

(NOTE: view this file with a monospaced font)
Terminal support in eLua
================================================================================
NOTE: currently, this only works over serial connections (not over TCP/IP)
Besides standard stdio/stdout/stderr support (docs/console_input_output.txt),
eLua provides the "term" module to access ANSI compatible terminal emulators.
It is designed to be as flexible as possible, thus allowing a large number of
terminal emulators to be used.
To use the term module, remember to:
- build it (add BUILD_TERM in your build.h file)
- build its Lua binding ( add AUXLIB_TERM in your platform_libs.h)
See docs/elua_components.h and docs/platform_modules.txt for details.
To use it, first call the "term_init" function:
(BEGIN inc/term.h)
...........................
// Terminal output function
typedef void ( *p_term_out )( u8 );
// Terminal input function
typedef int ( *p_term_in )( int );
// Terminal translate input function
typedef int ( *p_term_translate )( u8 );
...........................
// Terminal initialization
void term_init( unsigned lines, unsigned cols, p_term_out term_out_func,
p_term_in term_in_func, p_term_translate term_translate_func );
(END inc/term.h)
The initialization function gets the physical size of the terminal emulator
window (usually 80 lines and 25 cols) and three function pointers:
- p_term_out: this function will be called to output characters to the terminal.
It receives the character to output as its single parameter.
- p_term_in: this function will be called to read a character from the terminal.
It receives a parameter that can be either TERM_INPUT_DONT_WAIT (in which case
the function returns -1 immediately if no character is available) or
TERM_INPUT_WAIT (in which case the function will wait for the character).
- p_term_translate: this function translates terminal-specific codes to "term"
codes. The "term" codes are defined in an enum from inc/term.h:
(BEGIN inc/term.h)
...........................
_D( KC_UP ),\
_D( KC_DOWN ),\
_D( KC_LEFT ),\
...........................
_D( KC_ESC ),\
_D( KC_UNKNOWN )
...........................
(END inc/term.h)
By using this function, it is possible to adapt a very large number of "term
emulators" to eLua. For example, you might want to run eLua in a "standalone
mode" that does not require a PC at all, just an external LCD display and maybe
a keyboard for data input. Your eLua board can connect to this standalone
terminal using its I/O pins, for example via SPI. By writing the three functions
described above, the effort of making eLua work with this new type of device is
minimal, as writing an "ANSI emulation" for your terminal device is not hard.
For an example, see src/main.c, where these functions are implemented for an
UART connection with a terminal emulator program running on PC.
To see what functions are exported to eLua by the "term" module reffer to the
"generic_modules.txt" file from the docs/ directory.