zoukankan      html  css  js  c++  java
  • [app]温度传感器测试程序

    刚开始去读/dev/i2c-1, 但是在设置地址的时候,始终错误,返回-1, 所以最后还是用了sys接口

    /*******************************************
     * Description: Read temperature sensor from LM75
     * Author:        Aaron.gao
     * Data:        20170524
     * Histroy:
     *                1. NULL
     * ****************************************/
    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>
    #include <linux/i2c-dev.h>
    #include <stdlib.h>
    #include <fcntl.h>
    #include <termios.h>
    
    
    /* main func */
    int main(int argc, char **argv)
    {
        int ret, fd;
        char buffer[10];
        int value;
        float temp = 0.0;
    
        while(1)
        {
            /* open device */
            fd = open("/sys/bus/i2c/devices/i2c-1/1-004f/hwmon/hwmon0/temp1_input", O_RDONLY);
            if( fd < 0)
            {
                printf("fd is %d
    ", fd);
                printf("open i2c device-lm75 failed!
    ");
                exit(1);
            }
    
            ret = read(fd, buffer, 10);
            if(ret < 0)
            {
                printf("read error
    ");
            }
            value = atoi(buffer);
            memset(buffer, 0, strlen(buffer));
            temp = value / 1000.0;
            printf("environment temperature is %.2lfC
    ", temp);
            sleep(2);
            
            close(fd);
        }
        
        return 0;
    }
  • 相关阅读:
    网页字体设置你了解吗?
    CSS 定位 (Positioning)
    常用CSS缩写语法总结
    CSS 教程
    CSS Reset(CSS重置)
    边框模拟小三角形
    CSS sprites
    border:none和border:0的区别
    css display属性
    css的postion属性
  • 原文地址:https://www.cnblogs.com/aaronLinux/p/7009791.html
Copyright © 2011-2022 走看看