Lua Script: Difference between revisions

From Smart LCD
Line 85: Line 85:
{| class="wikitable"
{| class="wikitable"
|+
|+
! width="12%" | '''Category'''
| '''Category'''
! width="32%" | '''Function Name'''
| '''Function Name'''
! width="54%" | '''Descriptions'''
| '''Descriptions'''
|-
|-
! rowspan="12" |VP
! rowspan="12" |VP

Revision as of 15:07, 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