| | |
| | | #include <string.h> |
| | | |
| | | #include "sht20.h" |
| | | #include "lylib/logger.h" |
| | | |
| | | static int s_sht2x_fd = -1; |
| | | |
| | |
| | | { |
| | | close(s_sht2x_fd); |
| | | s_sht2x_fd = -1; |
| | | printf("Terminate SHT2X\n"); |
| | | log_warn("Terminate SHT2X\n"); |
| | | } |
| | | |
| | | #ifdef I2C_API_RDWR /* Use I2C userspace driver read/write API */ |
| | |
| | | |
| | | if( fd<0 ) |
| | | { |
| | | printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ ); |
| | | log_err("Invalid input arguments\n"); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | |
| | | if( (s_sht2x_fd=open("/dev/i2c-1", O_RDWR)) < 0) |
| | | { |
| | | printf("i2c device open failed: %s\n", strerror(errno)); |
| | | log_fatal("i2c device open failed: %s\n", strerror(errno)); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | |
| | | if( sht2x_softreset(s_sht2x_fd) < 0 ) |
| | | { |
| | | printf("SHT2x softreset failure\n"); |
| | | log_err("SHT2x softreset failure\n"); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | if( !temp || !rh ) |
| | | { |
| | | printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ ); |
| | | log_err("Invalid input arguments\n"); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | { |
| | | if( sht2x_init() < 0) |
| | | { |
| | | printf("SHT2x initialise failure\n"); |
| | | log_err("SHT2x initialise failure\n"); |
| | | return -2; |
| | | } |
| | | } |
| | |
| | | |
| | | if( !serialnumber || size!=8 ) |
| | | { |
| | | printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ ); |
| | | log_err("Invalid input arguments\n"); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | { |
| | | if( sht2x_init() < 0) |
| | | { |
| | | printf("SHT2x initialise failure\n"); |
| | | log_err("SHT2x initialise failure\n"); |
| | | return -2; |
| | | } |
| | | } |
| | |
| | | |
| | | if( fd<0 ) |
| | | { |
| | | printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ ); |
| | | log_err("Invalid input arguments\n"); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | |
| | | if( ioctl(fd, I2C_RDWR, &sht2x_data) < 0 ) |
| | | { |
| | | printf("%s() ioctl failure: %s\n", __func__, strerror(errno)); |
| | | log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno)); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |
| | |
| | | { |
| | | if( (s_sht2x_fd=open("/dev/i2c-1", O_RDWR)) < 0) |
| | | { |
| | | printf("i2c device open failed: %s\n", strerror(errno)); |
| | | log_err("i2c device open failed: %s\n", strerror(errno)); |
| | | return -1; |
| | | } |
| | | |
| | | if( sht2x_softreset(s_sht2x_fd) < 0 ) |
| | | { |
| | | printf("SHT2x softreset failure\n"); |
| | | log_err("SHT2x softreset failure\n"); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | if( !serialnumber || size!=8 ) |
| | | { |
| | | printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ ); |
| | | log_err("Invalid input arguments\n"); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | { |
| | | if( sht2x_init() < 0) |
| | | { |
| | | printf("SHT2x initialise failure\n"); |
| | | log_err("SHT2x initialise failure\n"); |
| | | return -2; |
| | | } |
| | | } |
| | |
| | | |
| | | if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 ) |
| | | { |
| | | printf("%s() ioctl failure: %s\n", __func__, strerror(errno)); |
| | | log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno)); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 ) |
| | | { |
| | | printf("%s() ioctl failure: %s\n", __func__, strerror(errno)); |
| | | log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno)); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | if( !temp || !rh ) |
| | | { |
| | | printf("%s line [%d] %s() get invalid input arguments\n", __FILE__, __LINE__, __func__ ); |
| | | log_err("Invalid input arguments\n"); |
| | | return -1; |
| | | } |
| | | |
| | |
| | | { |
| | | if( sht2x_init() < 0) |
| | | { |
| | | printf("SHT2x initialise failure\n"); |
| | | log_err("SHT2x initialise failure\n"); |
| | | return -2; |
| | | } |
| | | } |
| | |
| | | |
| | | if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 ) |
| | | { |
| | | printf("%s() ioctl failure: %s\n", __func__, strerror(errno)); |
| | | log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno)); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 ) |
| | | { |
| | | printf("%s() ioctl failure: %s\n", __func__, strerror(errno)); |
| | | log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno)); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 ) |
| | | { |
| | | printf("%s() ioctl failure: %s\n", __func__, strerror(errno)); |
| | | log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno)); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | if( ioctl(s_sht2x_fd, I2C_RDWR, &sht2x_data) < 0 ) |
| | | { |
| | | printf("%s() ioctl failure: %s\n", __func__, strerror(errno)); |
| | | log_err("sht2x I2C_RDWR ioctl failure: %s\n", strerror(errno)); |
| | | sht2x_term(); |
| | | return -2; |
| | | } |