fix: 解决netdrv-ch390h在780epm下死机的问题
[LuatOS.git] / script / turnkey / thermal_imaging / main.lua
blob22719bc413d5e4c16cc4beb3c705c8766780d1cc
1 -- LuaTools需要PROJECT和VERSION这两个信息
2 PROJECT = "thermal_imaging"
3 VERSION = "1.0.0"
5 log.info("main", PROJECT, VERSION)
7 -- 引入必要的库文件(lua编写), 内部库不需要require
8 local sys = require "sys"
10 --[[
11 -- LCD接法示例, 以Air105开发板的HSPI为例
12 LCD管脚 Air105管脚
13 GND GND
14 VCC 3.3V
15 SCL (PC15/HSPI_SCK)
16 SDA (PC13/HSPI_MOSI)
17 RES (PC12/HSPI_MISO)
18 DC (PE08) --开发板上的U3_RX
19 CS (PC14/HSPI_CS)
20 BL (PE09) --开发板上的U3_TX
23 提示:
24 1. 只使用SPI的时钟线(SCK)和数据输出线(MOSI), 其他均为GPIO脚
25 2. 数据输入(MISO)和片选(CS), 虽然是SPI, 但已复用为GPIO, 并非固定,是可以自由修改成其他脚
28 local rtos_bsp = rtos.bsp():lower()
29 if rtos_bsp=="air101" or rtos_bsp=="air103" then
30 mcu.setClk(240)
31 spi_lcd = spi.deviceSetup(0,pin.PB04,0,0,8,20*1000*1000,spi.MSB,1,0)
32 lcd.init("st7735",{port = "device",pin_dc = pin.PB01, pin_pwr = pin.PB00, pin_rst = pin.PB03,direction = 3,w = 160,h = 128,xoffset = 1,yoffset = 2},spi_lcd)
33 elseif rtos_bsp=="air105" then
34 spi_lcd = spi.deviceSetup(5,pin.PC14,0,0,8,48*1000*1000,spi.MSB,1,0)
35 lcd.init("st7735",{port = "device",pin_dc = pin.PE08 ,pin_rst = pin.PC12,pin_pwr = pin.PE09,direction = 3,w = 160,h = 128,xoffset = 1,yoffset = 2},spi_lcd)
36 lcd.setupBuff()
37 lcd.autoFlush(false)
38 elseif rtos_bsp=="esp32c3" then
39 spi_lcd = spi.deviceSetup(2, 7, 0, 0, 8, 40000000, spi.MSB, 1, 0)
40 lcd.init("st7735",{port = "device",pin_dc = 6, pin_pwr = 11,pin_rst = 10,direction = 3,w = 160,h = 128,xoffset = 1,yoffset = 2},spi_lcd)
41 end
43 lcd.clear(0x0000)
45 sys.taskInit(function()
46 local skew_x = 16
47 local skew_y = 16
48 local fold = 4
49 if mlx90640.init(0,i2c.FAST,mlx90640.FPS4HZ) then
50 log.info("mlx90640", "init ok")
51 sys.wait(500) -- 稍等片刻
52 while 1 do
53 local temp_max = {temp = 0,x = 0,y = 0}
54 mlx90640.feed() -- 取一帧数据
55 local temp,index = mlx90640.max_temp()
56 mlx90640.draw2lcd(skew_x, skew_y, fold)
57 temp_max.temp = math.floor(temp)
58 temp_max.x = (index%32)*fold+skew_x
59 temp_max.y = (math.floor (index/32))*fold+skew_y
60 if temp_max.x-fold<skew_x then
61 temp_max.x = skew_x+fold
62 elseif temp_max.x+fold>32*fold+skew_x then
63 temp_max.x = 32*fold+skew_x-fold
64 end
65 if temp_max.y-fold<skew_y then
66 temp_max.y = skew_y+fold
67 elseif temp_max.y+fold>24*fold+skew_y then
68 temp_max.y = 24*fold+skew_y-fold
69 end
70 lcd.drawCircle(temp_max.x,temp_max.y,fold/2,0x001F)
72 lcd.drawStr(temp_max.x,temp_max.y,temp_max.temp)
73 if rtos_bsp=="air105" then lcd.flush() end
74 sys.wait(100)
75 end
76 else
77 log.info("mlx90640", "init fail")
78 end
79 end)
83 -- 用户代码已结束---------------------------------------------
84 -- 结尾总是这一句
85 sys.run()
86 -- sys.run()之后后面不要加任何语句!!!!!