Quellcode durchsuchen

add : add comments and description for DHT10

downeyboy vor 6 Jahren
Ursprung
Commit
1e7601aafd
5 geänderte Dateien mit 66 neuen und 6 gelöschten Zeilen
  1. 26 5
      DHT.cpp
  2. 27 0
      DHT.h
  3. 4 0
      README.md
  4. 1 1
      examples/DHTtester/DHTtester.ino
  5. 8 0
      keywords.txt

+ 26 - 5
DHT.cpp

@@ -38,7 +38,10 @@ void DHT::begin(void) {
 
 }
 
-
+/**Common  interface to get temp&humi value.support all DHT device.
+ * 
+ * @return 0 for calibrated failed,1 for succeed.
+ **/
 int DHT::readTempAndHumidity(float *data)
 {
     uint32_t target_val[2] = {0};
@@ -218,7 +221,9 @@ boolean DHT::read(void) {
 /*****************************************************************************/
 /*****************************************************************************/
 
-
+/**Reset sensor.
+ * @return 0 for calibrated failed,1 for succeed.
+ **/
 int DHT::DHT10Reset(void)
 {
   if(_type == DHT10)
@@ -230,6 +235,11 @@ int DHT::DHT10Reset(void)
 
 }
 
+/** Read status register.check the calibration flag - bit[3]: 1- calibrated ok ,0 - Not calibrated.
+ * 
+ * @return 0 for calibrated failed,1 for succeed. 
+ * 
+ **/
 int DHT::DHT10ReadStatus(void)
 {
 
@@ -245,12 +255,15 @@ int DHT::DHT10ReadStatus(void)
 	  	  return 0;
   }
   else{
-      return 0;
-      SERIAL.println("This function only support for DHT10");
+        SERIAL.println("This function only support for DHT10");
+        return 0;
   }
     
 }
 
+/** Init sensor,send 0x08,0x00 to register 0xe1.
+ *  @ return : 0 if success, non-zero if failed.
+ **/
 int DHT::setSystemCfg(void)
 {
 	uint8_t cfg_param[] = {0xe1,0x08,0x00};
@@ -263,6 +276,10 @@ int DHT::setSystemCfg(void)
 }
 
 
+/** Read temp & humi result buf from sensor.
+ *  total 6 bytes,the first byte for status register,other 5 bytes for temp & humidity data.
+ *  @ return : 0 if success, non-zero if failed.
+ **/
 int DHT::readTargetData(uint32_t *data)
 {
 	uint8_t statu = 0;
@@ -277,6 +294,7 @@ int DHT::readTargetData(uint32_t *data)
     }
 
     delay(75);
+    // check device busy flag, bit[7]:1 for busy, 0 for idle.
     while(statu & 0x80 == 0x80){
       SERIAL.println("Device busy!");
       delay(200);
@@ -308,7 +326,10 @@ int DHT::readTargetData(uint32_t *data)
   }
 }
 
-
+/**DHT10 Init function.
+ * Reset sensor and wait for calibration complete.
+ * @ return : 0 if success, non-zero if failed.
+ **/ 
 int DHT::DHT10Init(void)
 {
 	int ret = 0;

+ 27 - 0
DHT.h

@@ -72,6 +72,10 @@ class DHT {
   float convertCtoF(float);
   float readHumidity(void);
 
+  /**Common  interface to get temp&humi value.support all DHT device.
+   * 
+   * @return 0 for calibrated failed,1 for succeed.
+   **/
   int readTempAndHumidity(float *data);
 
 // DHT10 digital interfaces(i2c),onlu for DHT10 .
@@ -80,10 +84,33 @@ class DHT {
   int i2cWriteBytes(uint8_t *bytes,uint32_t len);
   int i2cWriteByte(uint8_t byte);
 
+
+  /**Reset sensor.
+   * @return 0 for calibrated failed,1 for succeed.
+   **/
   int DHT10Reset(void);
+
+  /** Read status register.check the calibration flag - bit[3]: 1- calibrated ok ,0 - Not calibrated.
+   * 
+   * @return 0 for calibrated failed,1 for succeed. 
+   * 
+   **/
   int DHT10ReadStatus(void);
+  /** Init sensor,send 0x08,0x00 to register 0xe1.
+   *  @ return : 0 if success, non-zero if failed.
+   **/
   int setSystemCfg(void);
+
+  /** Read temp & humi result buf from sensor.
+   *  total 6 bytes,the first byte for status register,other 5 bytes for temp & humidity data.
+   *  @ return : 0 if success, non-zero if failed.
+   **/
   int readTargetData(uint32_t *data);
+  
+  /**DHT10 Init function.
+   * Reset sensor and wait for calibration complete.
+   * @ return : 0 if success, non-zero if failed.
+   **/ 
   int DHT10Init(void);
 
 

+ 4 - 0
README.md

@@ -15,6 +15,10 @@ This temperature & humidity sensor provides a pre-calibrated digital output. A u
 
 For more information please visit [wiki DHT11](http://wiki.seeedstudio.com/Grove-TemperatureAndHumidity_Sensor/) and [wiki AM2302](http://wiki.seeedstudio.com/Grove-Temperature_and_Humidity_Sensor_Pro/)
 
+****
+
+Add support for DHT10 , The different from other DHT* device is that it uses i2c interface.  
+
 ----
 
 This demo is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check LINCESE for more information.<br>

+ 1 - 1
examples/DHTtester/DHTtester.ino

@@ -10,7 +10,7 @@
 #define DHTTYPE DHT22   // DHT 22  (AM2302)
 //#define DHTTYPE DHT21   // DHT 21 (AM2301)
 
-/*Notice: The DHT10 is different from other DHT* sensor ,it use i2c interface rather than one wire*/
+/*Notice: The DHT10 is different from other DHT* sensor ,it uses i2c interface rather than one wire*/
           /*So it doesn't require a pin.*/
 
 //#define DHTTYPE DHT10

+ 8 - 0
keywords.txt

@@ -5,6 +5,7 @@
 
 #######################################
 # Datatypes (KEYWORD1)
+DHT	KEYWORD1
 #######################################
 
 
@@ -18,6 +19,13 @@ readTemperature	KEYWORD2
 convertCtoF	KEYWORD2
 readHumidity	KEYWORD2
 
+readTempAndHumidity	KEYWORD2
+DHT10Reset	KEYWORD2
+DHT10ReadStatus	KEYWORD2
+setSystemCfg	KEYWORD2
+readTargetData	KEYWORD2
+DHT10Init	KEYWORD2
+
 #######################################
 # Constants (LITERAL1)
 #######################################