| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- /******************************************************************************
- 版权所有: 文件名称: gx21m15.c
- 文件版本: 01.01
- 创建作者: sunxi
- 创建日期: 2022-05-12
- 功能说明: 温度传感器驱动
- 其它说明:
- 修改记录:
- */
- #include "bspconfig.h"
- #include "bsp.h"
- #define TEMP_FILE_NAME "/sys/devices/platform/soc/a011b000.i2c/i2c-0/0-0048/hwmon/hwmon0/temp1_input"
- /******************************************************************************
- 函数名称: gx21m15_get_temp
- 函数版本: 01.01
- 创建作者: sunxi
- 创建日期: 2022-05-12
- 函数说明: 获取温度.
- 参数说明: 无
-
- 返回值: 返回温度值.
- 修改记录:
- */
- float gx21m15_get_temp(void)
- {
- float ftemp = 0.0;
- int temp;
- char read_buf[8] = {0x00};
- int fd = open(TEMP_FILE_NAME, O_RDONLY);
- if(fd >= 0)
- {
- if(read(fd, read_buf, 8) > 0)
- {
- temp = atoi(read_buf);
- ftemp = ((float)temp/1000.0);
- }
- close(fd);
- }
- return ftemp;
- }
|