Class: RPi::Dht::Dht22
Constant Summary
Constants inherited from Base
Base::BITS_IN_BYTE, Base::CLEAR_SIGNALS, Base::ENOUGH_TO_CAPTURE_COUNT, Base::HUMIDITY_PRECISION, Base::START_SIGNAL, Base::TEMPERATURE_PRECISION, Base::VALID_BYTE_SIZE
Instance Method Summary collapse
Methods inherited from Base
#collect_response_bits, #initialize, read, read!, #send_start_signal
Constructor Details
This class inherits a constructor from RPi::Dht::Base
Instance Method Details
#convert ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rpi/dht/dht22.rb', line 4 def convert humidity_high, humidity_low, temp_high, temp_low, _ = bytes is_negative = 0 < (temp_high & 0b10000000) temp_high &= 0b01111111 humidity = ((humidity_high << 8) + humidity_low) / HUMIDITY_PRECISION temperature = ((temp_high << 8) + temp_low) / TEMPERATURE_PRECISION temperature *= -1 if is_negative { humidity: humidity, temperature: temperature, temperature_f: fahrenheit(temperature) } end |