winlinvip / SimpleDHT

Simple, Stable and Fast Arduino Temp & Humidity Sensors for DHT11 and DHT22. http://learn.adafruit.com/dht
MIT License
144 stars 61 forks source link

Improved Memory usage by utilizing bytes properly #42

Closed DVSProductions closed 3 years ago

DVSProductions commented 4 years ago

In it's current state the Library uses 40 bytes to store 40 bits, which is a huge waste of memory on a restricted system. Therefore I propose a system where bytes are utilized not as booleans, but as 8bit containers. Using the bitWrite function and some math, this change will reduce the memory footprint to 5 bytes, while retaining all functionality. Furthermore this improves things like the parse function, where indices can now be used instead of pointer arithmetic. I have fixed all examples to work with this change.

winlinvip commented 3 years ago

Although the api is changed from byte[40] to byte[5], I think it's compatible, at least without crash or data corrupt.