Lua Script: Difference between revisions
From Smart LCD
mNo edit summary |
|||
| Line 83: | Line 83: | ||
== hmt functions Summary == | == hmt functions Summary == | ||
{| | {| class="wikitable" | ||
|width="12%"| '''Category''' | |+ | ||
! width="12%" | '''Category''' | |||
! width="32%" | '''Function Name''' | |||
! width="54%" | '''Descriptions''' | |||
|- | |- | ||
| | ! rowspan="12" | | ||
VP | VP | ||
| Line 95: | Line 96: | ||
| Read VP_STR value | | Read VP_STR value | ||
|- | |- | ||
| hmt.writevpstr(addr, string) | | hmt.writevpstr(addr, string) | ||
| Write VP_STR value | | Write VP_STR value | ||
|- | |- | ||
| hmt.readvp16(addr) | | hmt.readvp16(addr) | ||
| Read VP_16 value | | Read VP_16 value | ||
|- | |- | ||
| hmt.writevp16(addr, value) | | hmt.writevp16(addr, value) | ||
| Write VP_16 value | | Write VP_16 value | ||
|- | |- | ||
| hmt.readvp32(addr) | | hmt.readvp32(addr) | ||
| Read VP_32 value | | Read VP_32 value | ||
|- | |- | ||
| hmt.readvp32f(addr) | | hmt.readvp32f(addr) | ||
| Read VP_32 value (floating point value) | | Read VP_32 value (floating point value) | ||
|- | |- | ||
| hmt.writevp32(addr, value) | | hmt.writevp32(addr, value) | ||
| Write VP_32 value | | Write VP_32 value | ||
|- | |- | ||
| hmt.readvp64(addr) | | hmt.readvp64(addr) | ||
| Read VP_64 value | | Read VP_64 value | ||
|- | |- | ||
| hmt.readvp64f(addr) | | hmt.readvp64f(addr) | ||
| Read VP_64 value (floating point value) | | Read VP_64 value (floating point value) | ||
|- | |- | ||
| hmt.writevp64(addr, value) | | hmt.writevp64(addr, value) | ||
| Write VP_64 value | | Write VP_64 value | ||
|- | |- | ||
| hmt.readvpreg(addr) | | hmt.readvpreg(addr) | ||
| Read VP_SYS value | | Read VP_SYS value | ||
|- | |- | ||
| hmt.writevpreg(addr, value) | | hmt.writevpreg(addr, value) | ||
| Write VP_SYS value | | Write VP_SYS value | ||
|- | |- | ||
| System | ! rowspan="9" | System | ||
| hmt.changepage(pageid) | | hmt.changepage(pageid) | ||
| Display a pre-stored PAGE | | Display a pre-stored PAGE | ||
|- | |- | ||
| hmt.readpage() | | hmt.readpage() | ||
| Read Page ID | | Read Page ID | ||
|- | |- | ||
| hmt.gettick() | | hmt.gettick() | ||
| Read system time | | Read system time | ||
|- | |- | ||
| hmt.delayms(time) | | hmt.delayms(time) | ||
| Delay in ms(*1) | | Delay in ms(*1) | ||
|- | |- | ||
| hmt.runcmd(table, num) | | hmt.runcmd(table, num) | ||
| | | | ||
Execute terminal command | Execute terminal command (without packet header and taill) | ||
(without packet header and taill) | |||
|- | |- | ||
| hmt.bypass(is) | | hmt.bypass(is) | ||
| | | | ||
| Line 169: | Line 152: | ||
is=1 for disable; is=0 for enable(normal) | is=1 for disable; is=0 for enable(normal) | ||
|- | |- | ||
| hmt.crc16calc(table, num) | | hmt.crc16calc(table, num) | ||
| Generate a CRC value | | Generate a CRC value | ||
|- | |- | ||
| hmt.formatdisk2() | | hmt.formatdisk2() | ||
| Format module flash second partition (*4) | | Format module flash second partition (*4) | ||
|- | |- | ||
| hmt.inituart(baudrate,parity) | | hmt.inituart(baudrate,parity) | ||
| Set baud rate and parity parameters of A and B (*4) | | Set baud rate and parity parameters of A and B (*4) | ||
|- | |- | ||
| Thread | ! rowspan="5" | Thread | ||
| hmt.createthread(function()) | | hmt.createthread(function()) | ||
| Create a thread and return a thread object (*4) | | Create a thread and return a thread object (*4) | ||
|- | |- | ||
| suspend() | | suspend() | ||
| Suspend thread (*4) | | Suspend thread (*4) | ||
|- | |- | ||
| resume() | | resume() | ||
| Resume thread (*4) | | Resume thread (*4) | ||
|- | |- | ||
| terminate() | | terminate() | ||
| Terminate thread (*4) | | Terminate thread (*4) | ||
|- | |- | ||
| getid() | | getid() | ||
| Get thread ID and handle (*4) | | Get thread ID and handle (*4) | ||
|- | |- | ||
| UART0 | ! rowspan="7" | UART0 | ||
| hmt.uartisempty() | | hmt.uartisempty() | ||
| | | | ||
| Line 208: | Line 184: | ||
1 for empty; 0 for not empty | 1 for empty; 0 for not empty | ||
|- | |- | ||
| hmt.uartclearbuf() | | hmt.uartclearbuf() | ||
| Clear UART0 buffer | | Clear UART0 buffer | ||
|- | |- | ||
| hmt.getchar() | | hmt.getchar() | ||
| Read a byte form UART0 buffer | | Read a byte form UART0 buffer | ||
|- | |- | ||
| hmt.putchar(char) | | hmt.putchar(char) | ||
| Send a byte to UART0 | | Send a byte to UART0 | ||
|- | |- | ||
| hmt.uartsendbytes(table, num) | | hmt.uartsendbytes(table, num) | ||
| Send a num of byte to UART0 | | Send a num of byte to UART0 | ||
|- | |- | ||
| hmt.uartlock() | | hmt.uartlock() | ||
| Lock UART0 before Lua sending data to UART0 (*2, *3) | | Lock UART0 before Lua sending data to UART0 (*2, *3) | ||
|- | |- | ||
| hmt.uartunlock() | | hmt.uartunlock() | ||
| Unlock UART0 after Lua sending data to UART0 (*2, *3) | | Unlock UART0 after Lua sending data to UART0 (*2, *3) | ||
|- | |- | ||
| UART1 | ! rowspan="7" | UART1 | ||
| hmt.uart1isempty() | | hmt.uart1isempty() | ||
| | | | ||
Check for UART1 buffer | Check for UART1 buffer; 1 for empty; 0 for not empty | ||
1 for empty; 0 for not empty | |||
|- | |- | ||
| hmt.uart1clearbuf() | | hmt.uart1clearbuf() | ||
| Clear UART1 buffer | | Clear UART1 buffer | ||
|- | |- | ||
| hmt.uart1getchar() | | hmt.uart1getchar() | ||
| Read a byte form UART1 buffer | | Read a byte form UART1 buffer | ||
|- | |- | ||
| hmt.uart1putchar(char) | | hmt.uart1putchar(char) | ||
| Send a byte to UART1 | | Send a byte to UART1 | ||
|- | |- | ||
| hmt.uart1sendbytes(table, num) | | hmt.uart1sendbytes(table, num) | ||
| Send a num of byte to UART1 | | Send a num of byte to UART1 | ||
|- | |- | ||
| hmt.uart1lock() | | hmt.uart1lock() | ||
| Lock UART1 before sending data to UART1 (*2, *3) | | Lock UART1 before sending data to UART1 (*2, *3) | ||
|- | |- | ||
| hmt.uart1unlock() | | hmt.uart1unlock() | ||
| Unlock UART1 after sending data to UART1 (*2, *3) | | Unlock UART1 after sending data to UART1 (*2, *3) | ||
Revision as of 14:57, 24 February 2025
Smart LCD Lua Script Support
Lua script is supported in some of the TOPWAY Smart LCD to enhance the flexibility. Engineer may refine the Smart LCD functionality with script. The provided Lua functionality support most of the features of Lua 5.3 except OS operation. (please refer to lua.net for Lua 5.3 details)It also extended with hmt library for Smart LCD variables access, function control and value return etc.
Lua Script Structure
Basic structure
-- define variable(s) Script_Variable01 = 0x00 -- main loop luamain = function(void) return 0 end
Note:
- main loop run continually
- intensive loop in the main loop may affect the Smart LCD UI operations
Advance structure with hooks
-- define variable(s) Script_Variable01 = 0x00 -- main loop luamain = function(void) return 0 end -- touch key hook tpkhook = function(page, id, state) return 0 end -- page hook pagechangehook = function(pageid) return 0 end
Note:
- main loop run continually
- intensive loop in the main loop may affect the Smart LCD UI operations
- hooks share the MCU time with the main loop.
- looping or long delay will affect the main loop
- “wait loop” is not allowed in the hooks.
Smart LCD VP variables
| Mnemonic | Name | Memory Limit | Address Range |
|---|---|---|---|
| VP_STR | String Variable | 1024(MAX)*(127+1)byte | 0x000000~0x01FF80 |
| VP_N16 | 16Bit Integer Variable | 32512(MAX)*(2)byte | 0x080000~0x08FDFE |
| VP_N32 | 32Bit Integer Variable | 16128(MAX)*(4)byte | 0x020000~0x02FEFC |
| VP_N64 | 64Bit Integer Variable | 7936(MAX)*(8)byte | 0x030000~0x03F7F8 |
| VP_SYS | System Register Variable | 256(MAX)*(1)byte | 0xFFFF00~0xFFFFFF |
Note. Please also refer to Smart LCD handbook for VP variables details
hmt functions Summary
| Category | Function Name | Descriptions |
|---|---|---|
|
VP read/write |
hmt.readvpstr(addr) | Read VP_STR value |
| hmt.writevpstr(addr, string) | Write VP_STR value | |
| hmt.readvp16(addr) | Read VP_16 value | |
| hmt.writevp16(addr, value) | Write VP_16 value | |
| hmt.readvp32(addr) | Read VP_32 value | |
| hmt.readvp32f(addr) | Read VP_32 value (floating point value) | |
| hmt.writevp32(addr, value) | Write VP_32 value | |
| hmt.readvp64(addr) | Read VP_64 value | |
| hmt.readvp64f(addr) | Read VP_64 value (floating point value) | |
| hmt.writevp64(addr, value) | Write VP_64 value | |
| hmt.readvpreg(addr) | Read VP_SYS value | |
| hmt.writevpreg(addr, value) | Write VP_SYS value | |
| System | hmt.changepage(pageid) | Display a pre-stored PAGE |
| hmt.readpage() | Read Page ID | |
| hmt.gettick() | Read system time | |
| hmt.delayms(time) | Delay in ms(*1) | |
| hmt.runcmd(table, num) |
Execute terminal command (without packet header and taill) | |
| hmt.bypass(is) |
Disable Smart LCD terminal command execution (I/O) is=1 for disable; is=0 for enable(normal) | |
| hmt.crc16calc(table, num) | Generate a CRC value | |
| hmt.formatdisk2() | Format module flash second partition (*4) | |
| hmt.inituart(baudrate,parity) | Set baud rate and parity parameters of A and B (*4) | |
| Thread | hmt.createthread(function()) | Create a thread and return a thread object (*4) |
| suspend() | Suspend thread (*4) | |
| resume() | Resume thread (*4) | |
| terminate() | Terminate thread (*4) | |
| getid() | Get thread ID and handle (*4) | |
| UART0 | hmt.uartisempty() |
Check for UART0 buffer 1 for empty; 0 for not empty |
| hmt.uartclearbuf() | Clear UART0 buffer | |
| hmt.getchar() | Read a byte form UART0 buffer | |
| hmt.putchar(char) | Send a byte to UART0 | |
| hmt.uartsendbytes(table, num) | Send a num of byte to UART0 | |
| hmt.uartlock() | Lock UART0 before Lua sending data to UART0 (*2, *3) | |
| hmt.uartunlock() | Unlock UART0 after Lua sending data to UART0 (*2, *3) | |
| UART1 | hmt.uart1isempty() |
Check for UART1 buffer; 1 for empty; 0 for not empty |
| hmt.uart1clearbuf() | Clear UART1 buffer | |
| hmt.uart1getchar() | Read a byte form UART1 buffer | |
| hmt.uart1putchar(char) | Send a byte to UART1 | |
| hmt.uart1sendbytes(table, num) | Send a num of byte to UART1 | |
| hmt.uart1lock() | Lock UART1 before sending data to UART1 (*2, *3) | |
| hmt.uart1unlock() | Unlock UART1 after sending data to UART1 (*2, *3) |
Note.
- 1. long delay may affect the Smart LCD normal operation.
- 2. It is necessary to lock the UART for Lua access, if hmt.bypass is not enabled.
- 3. Generally hmt.uartlock() and hmt.uartunlock() should be used in pair.
- 4. Selected model only