Class: BMxSensor
- Inherits:
-
HumitureSensor
- Object
- Receptor
- DigitalReceptor
- DigitalSensor
- TemperatureSensor
- HumitureSensor
- BMxSensor
- Defined in:
- lib/bmx_sensor.rb
Overview
BMP/BME humidity, temperature & atmospheric pressure sensor family
Instance Method Summary collapse
-
#hPa ⇒ Object
standard atmospheric pressure @ sea level = 1.01325 bar = 1013.25 mbar = 101.325 kPa.
-
#initialize(sensor_name, bus = 1) ⇒ BMxSensor
constructor
A new instance of BMxSensor.
- #pressure(mode = :hPa) ⇒ Object
- #read_data ⇒ Object
- #to_s ⇒ Object
Methods inherited from HumitureSensor
Methods inherited from TemperatureSensor
#celsius, #fahrenheit, #kelvin, #reaumur, #temperature
Methods inherited from DigitalReceptor
Methods inherited from Receptor
Constructor Details
#initialize(sensor_name, bus = 1) ⇒ BMxSensor
Returns a new instance of BMxSensor.
11 12 13 14 15 |
# File 'lib/bmx_sensor.rb', line 11 def initialize(sensor_name, bus=1) @sensor_name = sensor_name @sensor = I2C::Driver::BME280.new(device: bus) @temperature, @humidity, @pressure = read_data end |
Instance Method Details
#hPa ⇒ Object
standard atmospheric pressure @ sea level = 1.01325 bar = 1013.25 mbar = 101.325 kPa
26 27 28 |
# File 'lib/bmx_sensor.rb', line 26 def hPa @pressure end |
#pressure(mode = :hPa) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bmx_sensor.rb', line 30 def pressure(mode=:hPa) case mode when :hPa # 1 hPa = 100 Pa = 1 mbar = 1 hPa = 0.750062 mmHg [@ 0°C] hPa when :kPa # 1 kPa = 1000 Pa = 10 hPa hPa / 10.0 when :Pa # 1 Pa = 0.01 hPa = 0.001 kPa hPa * 100.0 when :mmHg # 1 mmHg = 1.3332236842105263 hPa = 133.322387415 Pa = 1.000000142466321... Torr hPa / (1013.25 / 760) # 760 mmHg = 101.3250144354 kPa when :atm # 1 atm = 101325 Pa = 101.325 kPa hPa / 1013.25 when :bar # 1 bar ≡ 100000 Pa = 1000 hPa = 0.987 atm = 750.06 mmHg = 750.06 Torr hPa / 1000.0 when :mbar # 1 mbar = 0.001 bar * 1000.0 when :Torr # 1 Torr = 1/760 atm = 101325/760 Pa = 0.999999857533699... mmHg (hPa / 1013.25) / 760 else hPa end end |
#read_data ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/bmx_sensor.rb', line 17 def read_data data = @sensor.all @temperature = data[:t] @pressure = data[:p] @humidity = data[:h] [@temperature, @humidity, @pressure] end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/bmx_sensor.rb', line 53 def to_s sprintf "%5.2f°C, %5.2f %%, %5.2f mmHg", @temperature, @humidity, pressure(:mmHg) end |