/********************************************************************************* * Copyright: (C) 2018 LingYun IoT System Studio * All rights reserved. * * Filename: sht20.c * Description: This file is temperature and relative humidity sensor SHT20 code * * Version: 1.0.0(2018/10/14) * Author: Guo Wenxue * ChangeLog: 1, Release initial version on "2018/10/14 12:13:26" * ********************************************************************************/ #ifndef __SHT20_H #define __SHT20_H #include #include #define SOFTRESET 0xFE #define TRIGGER_TEMPERATURE_NO_HOLD 0xF3 #define TRIGGER_HUMIDITY_NO_HOLD 0xF5 //#define I2C_API_IOCTL /* Use I2C userspace driver ioctl API */ #define I2C_API_RDWR /* Use I2C userspace driver read/write API */ void sht2x_term(void); int sht2x_init(void); int sht2x_get_serialnumber(uint8_t *serialnumber, int size); int sht2x_get_temp_humidity(float *temp, float *rh); static inline void msleep(unsigned long ms) { struct timespec cSleep; unsigned long ulTmp; cSleep.tv_sec = ms / 1000; if (cSleep.tv_sec == 0) { ulTmp = ms * 10000; cSleep.tv_nsec = ulTmp * 100; } else { cSleep.tv_nsec = 0; } nanosleep(&cSleep, 0); } static inline void dump_buf(const char *prompt, uint8_t *buf, int size) { int i; if( !buf ) { return ; } if( prompt ) { printf("%s ", prompt); } for(i=0; i