gx21m15.c 892 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /******************************************************************************
  2. 版权所有: 文件名称: gx21m15.c
  3. 文件版本: 01.01
  4. 创建作者: sunxi
  5. 创建日期: 2022-05-12
  6. 功能说明: 温度传感器驱动
  7. 其它说明:
  8. 修改记录:
  9. */
  10. #include "bspconfig.h"
  11. #include "bsp.h"
  12. #define TEMP_FILE_NAME "/sys/devices/platform/soc/a011b000.i2c/i2c-0/0-0048/hwmon/hwmon0/temp1_input"
  13. /******************************************************************************
  14. 函数名称: gx21m15_get_temp
  15. 函数版本: 01.01
  16. 创建作者: sunxi
  17. 创建日期: 2022-05-12
  18. 函数说明: 获取温度.
  19. 参数说明: 无
  20. 返回值: 返回温度值.
  21. 修改记录:
  22. */
  23. float gx21m15_get_temp(void)
  24. {
  25. float ftemp = 0.0;
  26. int temp;
  27. char read_buf[8] = {0x00};
  28. int fd = open(TEMP_FILE_NAME, O_RDONLY);
  29. if(fd >= 0)
  30. {
  31. if(read(fd, read_buf, 8) > 0)
  32. {
  33. temp = atoi(read_buf);
  34. ftemp = ((float)temp/1000.0);
  35. }
  36. close(fd);
  37. }
  38. return ftemp;
  39. }