testqQrcode.lua 948 B

123456789101112131415161718192021222324252627282930313233
  1. --[[
  2. 模块名称:二维码生成并显示到屏幕上
  3. 模块最后修改时间:2020.3.31
  4. ]]
  5. module(...,package.seeall)
  6. --LCD分辨率的宽度和高度(单位是像素)
  7. local WIDTH, HEIGHT = 132,162
  8. --- qrencode.encode(string) 创建二维码信息
  9. -- @param string 二维码字符串
  10. -- @return width 生成的二维码信息宽度
  11. -- @return data 生成的二维码数据
  12. -- @usage local width, data = qrencode.encode("http://www.openluat.com")
  13. local width, data = qrencode.encode('http://www.openluat.com')
  14. --- disp.putqrcode(data, width, display_width, x, y) 显示二维码
  15. -- @param data 从qrencode.encode返回的二维码数据
  16. -- @param width 二维码数据的实际宽度
  17. -- @param display_width 二维码实际显示宽度,显示宽度开根号需要是整数
  18. -- @param x 二维码显示起始坐标x
  19. -- @param y 二维码显示起始坐标y
  20. --- 二维码显示函数
  21. local function appQRCode()
  22. disp.clear()
  23. local displayWidth = 100
  24. disp.putqrcode(data, width, displayWidth, (WIDTH-displayWidth)/2, (HEIGHT-displayWidth)/2)
  25. disp.update()
  26. end
  27. appQRCode()