1 -- LuaTools需要PROJECT和VERSION这两个信息
2 PROJECT
= "thermal_imaging"
5 log.info("main", PROJECT
, VERSION
)
7 -- 引入必要的库文件(lua编写), 内部库不需要require
8 local sys
= require
"sys"
11 -- LCD接法示例, 以Air105开发板的HSPI为例
18 DC (PE08) --开发板上的U3_RX
20 BL (PE09) --开发板上的U3_TX
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
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
)
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
)
45 sys
.taskInit(function()
49 if mlx90640
.init(0,i2c
.FAST
,mlx90640
.FPS4HZ
) then
50 log.info("mlx90640", "init ok")
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
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
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
77 log.info("mlx90640", "init fail")
83 -- 用户代码已结束---------------------------------------------
86 -- sys.run()之后后面不要加任何语句!!!!!