adafruit / Adafruit_APDS9960

Arduino drivers for APDS9960 gesture sensor
Other
38 stars 45 forks source link

Fix warning unused variable in readGesture and bit shifting in read32 #24

Closed dodo5522 closed 4 years ago

dodo5522 commented 4 years ago

I got the following warnings.

/Users/takashi/Documents/Arduino/libraries/Adafruit_APDS9960-1.1.3/Adafruit_APDS9960.cpp: In member function 'uint8_t Adafruit_APDS9960::readGesture()':
/Users/takashi/Documents/Arduino/libraries/Adafruit_APDS9960-1.1.3/Adafruit_APDS9960.cpp:394:19: warning: variable 'bytesRead' set but not used [-Wunused-but-set-variable]
   uint8_t toRead, bytesRead;
                   ^~~~~~~~~
/Users/takashi/Documents/Arduino/libraries/Adafruit_APDS9960-1.1.3/Adafruit_APDS9960.cpp: In member function 'uint32_t Adafruit_APDS9960::read32(uint8_t)':
/Users/takashi/Documents/Arduino/libraries/Adafruit_APDS9960-1.1.3/Adafruit_APDS9960.cpp:643:21: warning: left shift count >= width of type [-Wshift-count-overflow]
   return (ret[0] << 24) | (ret[1] << 16) | (ret[2] << 8) | ret[3];
                     ^~
/Users/takashi/Documents/Arduino/libraries/Adafruit_APDS9960-1.1.3/Adafruit_APDS9960.cpp:643:38: warning: left shift count >= width of type [-Wshift-count-overflow]
   return (ret[0] << 24) | (ret[1] << 16) | (ret[2] << 8) | ret[3];
                                      ^~

There is comment of bytesRead is unused but produces sideffects needed for readGesture to work but it seems OK with only reading APDS9960_GFIFO_U register and bytesRead variable itself can be removed.

And I cast uint32_t before bit shifting.

dodo5522 commented 4 years ago

@ladyada Thanks!