remove: 移除多余的mind目录
[LuatOS.git] / script / libs / mlx90614.lua
blobc579b2e8714d9bc86183d9514f1b7504d0e056ed
1 --[[
2 @module mlx90614
3 @summary mlx90614 红外温度
4 @version 1.0
5 @date 2023.01.12
6 @author Dozingfiretruck
7 @usage
8 -- 用法实例
9 local mlx90614 = require "mlx90614"
12 sys.taskInit(function()
13 -- 硬件i2c方式 618不支持此方式因为618发送会发送停止信号
14 i2cid = 0
15 i2c_speed = i2c.SLOW
16 print("i2c",i2c.setup(i2cid,i2c_speed))
18 -- 软件i2c 此方式通用,需要 2023.5.8之后编译的固件
19 --i2cid = i2c.createSoft(18,19)
21 mlx90614.init(i2cid)
22 while 1 do
23 print("mlx90614 ambient",mlx90614.ambient())
24 print("mlx90614 object",mlx90614.object())
25 sys.wait(1000)
26 end
27 end)
31 local mlx90614 = {}
32 local sys = require "sys"
33 local i2cid
35 local MLX90614_ADDRESS_ADR = 0x5A
37 local MLX90614_TA = 0x06
38 local MLX90614_TOBJ1 = 0x07
39 local MLX90614_TOBJ2 = 0x08
41 --[[
42 mlx90614 初始化
43 @api mlx90614.init(i2c_id)
44 @number 所在的i2c总线硬件/软件id
45 @return bool 成功返回true
46 @usage
47 mlx90614.init(0)
49 function mlx90614.init(i2c_id)
50 i2cid = i2c_id
51 sys.wait(20)--20 毫秒等待设备稳定
52 end
54 local rxbuff = zbuff.create(3)
56 --[[
57 获取 mlx90614 环境温度
58 @api mlx90614.ambient()
59 @return table mlx90614 环境温度
60 @usage
61 local mlx90614_ambient = mlx90614.ambient()
62 log.info("mlx90614_ambient", mlx90614_ambient)
64 function mlx90614.ambient()
65 local ambient
66 rxbuff:del()
67 local ret = i2c.transfer(i2cid, MLX90614_ADDRESS_ADR, MLX90614_TA, rxbuff, 3)
68 if ret then
69 ambient = rxbuff[0] | (rxbuff[1] << 8)
70 ambient = ambient*0.02 - 273.15
71 end
72 return ambient
73 end
75 --[[
76 获取 mlx90614 环境温度
77 @api mlx90614.ambient()
78 @return table mlx90614 环境温度
79 @usage
80 local mlx90614_ambient = mlx90614.ambient()
81 log.info("mlx90614_ambient", mlx90614_ambient)
83 function mlx90614.object()
84 local object
85 rxbuff:del()
86 local ret = i2c.transfer(i2cid, MLX90614_ADDRESS_ADR, MLX90614_TOBJ1, rxbuff, 3)
87 if ret then
88 object = rxbuff[0] | (rxbuff[1] << 8)
89 object = object*0.02 - 273.15
90 end
91 return object
92 end
94 return mlx90614