Эх сурвалжийг харах

fix: fix some compilation errors

Lesords 1 жил өмнө
parent
commit
253d6009b4
3 өөрчлөгдсөн 11 нэмэгдсэн , 10 устгасан
  1. 6 10
      DHT.cpp
  2. 1 0
      DHT.h
  3. 4 0
      examples/DHTtester/DHTtester.ino

+ 6 - 10
DHT.cpp

@@ -20,13 +20,13 @@ DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
 }
 
 DHT::DHT(uint8_t type) {
-    if (_type != DHT10){
-        DEBUG_PRINT("Error : No pins are defined\n");
-    }
     _pin = 0;
     _type = type;
     _count = COUNT;
     firstreading = true;
+    if (_type != DHT10){
+        DEBUG_PRINT("Error : No pins are defined\n");
+    }
 }
 
 void DHT::begin(void) {
@@ -425,14 +425,14 @@ int DHT::i2cReadByte(uint8_t& byte) {
 int DHT::i2cReadBytes(uint8_t* bytes, uint32_t len) {
     int cnt = 0;
     Wire.requestFrom(DEFAULT_IIC_ADDR, len);
-    while (len != Wire.available()) {
+    while (len != (uint32_t) Wire.available()) {
         cnt++;
         if (cnt >= 10) {
             return -1;
         }
         delay(1);
     }
-    for (int i = 0; i < len; i++) {
+    for (uint32_t i = 0; i < len; i++) {
         bytes[i] = Wire.read();
     }
     return 0;
@@ -441,7 +441,7 @@ int DHT::i2cReadBytes(uint8_t* bytes, uint32_t len) {
 
 int DHT::i2cWriteBytes(uint8_t* bytes, uint32_t len) {
     Wire.beginTransmission(DEFAULT_IIC_ADDR);
-    for (int i = 0; i < len; i++) {
+    for (uint32_t i = 0; i < len; i++) {
         Wire.write(bytes[i]);
     }
     return Wire.endTransmission();
@@ -452,7 +452,3 @@ int DHT::i2cWriteByte(uint8_t byte) {
     Wire.write(byte);
     return Wire.endTransmission();
 }
-
-
-
-

+ 1 - 0
DHT.h

@@ -33,6 +33,7 @@
 
 //RP2040
 #if defined(ARDUINO_ARCH_RP2040)
+    #undef COUNT
     #define COUNT 10
 #endif
 /*  DHT library

+ 4 - 0
examples/DHTtester/DHTtester.ino

@@ -26,10 +26,14 @@ DHT dht(DHTPIN, DHTTYPE);   //   DHT11 DHT21 DHT22
     #define debug  Serial
 
 #elif defined(ARDUINO_ARCH_SAMD) ||  defined(ARDUINO_ARCH_SAM)
+#ifdef SerialUSB
     #define debug  SerialUSB
 #else
     #define debug  Serial
 #endif
+#else
+    #define debug  Serial
+#endif
 
 void setup() {