VisualHMI screen rotation: set_lcd_rotate and multi-direction bin

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

During the runtime, the UI can be rotated in full (0°/90°/180°/270°), applicable to both handheld devices and vertical cabinets. One set of Lua scripts adapts to all orientations, exclusive to the DX series.

1. Lua controls rotation

set_lcd_rotate(angle)  -- angle: 0~3 (0=0°,1=90°,2=180°,3=270°)

function on_init()
  local angle = get_uint16(VT_RW, 0x0001)  -- 从Flash读旋转方向
  angle = (angle < 0 or angle > 3) and 0 or angle
  set_lcd_rotate(angle)
  set_uint16(VT_LW, 0x8888, angle)
end

function on_update(slave,vtype,addr)
  if vtype == VT_LW and addr == 0x8888 then
    local val = get_uint16(VT_LW, 0x8888)
    set_uint16(VT_RW, 0x0001, val)  -- 存旋转方向
    set_lcd_rotate(val)
  end
end

VisualHMI screen rotation: set_lcd_rotate and multi-direction bin插图

2. Generates multi-orientation files

Compile landscape projects (0°/180°) twice: 0° retains the default image.bin/project.bin; 180° is renamed to image180.bin/project180.bin and placed in private. Similarly, for portrait projects (90°/270°), generate image90/image270 and place them in private. The private directory ultimately contains 8 core files, with 0° loaded by default at startup, and the corresponding bin automatically loaded during runtime when changing orientation.

VisualHMI screen rotation: set_lcd_rotate and multi-direction bin插图1

VisualHMI screen rotation: set_lcd_rotate and multi-direction bin插图2

Note on screen rotation:The Lua script logic for landscape and portrait is completely identical, with the only difference being in the compiled bin files (imageXXX.bin/projectXXX.bin). Developers only need to maintain one set of projects, compile four times according to orientation, name them appropriately, and throw them into private. Exclusive to the DX series.

Compiled from VisualHMI development documentation of Guangzhou Dacai Technology (hmi-doc.gz-dc.com) and other technical tutorials on "screen rotation", copyright belongs to Dacai Technology.

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.