diff --git a/examples/advanced/m5_env.rb b/examples/advanced/m5_env.rb index 3e754d6..af5514b 100644 --- a/examples/advanced/m5_env.rb +++ b/examples/advanced/m5_env.rb @@ -16,8 +16,12 @@ qmp.pressure_samples = 16 qmp.iir_coefficient = 2 +# Buggy on ESP32-S3 in forced mode. Data registers return zeroes on all but first read. +# Can't recreate on ESP32 V1, AVR or SAMD21. Put it in contiuous mode just in case. +qmp.continuous_mode + # Get the shared #print_tph_reading method to print readings neatly. -require_relative 'neat_tph_readings' +require_relative '../sensor/neat_tph_readings' # How many degrees C the two temperature values can differ by before a warning. TOLERANCE = 0.50 diff --git a/examples/sensor/qmp6988.rb b/examples/sensor/qmp6988.rb index dcc63bb..b7e224c 100644 --- a/examples/sensor/qmp6988.rb +++ b/examples/sensor/qmp6988.rb @@ -28,9 +28,13 @@ sensor.pressure_samples = 16 sensor.iir_coefficient = 2 +# # Change mode (default: forced_mode) +# +# Buggy on ESP32S3 in forced mode. Data registers return zeroes on all but first read. +# Can't recreate on ESP32 V1, AVR or SAMD21. Put it in contiuous mode just in case. +sensor.continuous_mode # sensor.forced_mode -# sensor.continuous_mode # # Set standby time (between measurements) for continuous mode only: diff --git a/lib/denko/sensor/qmp6988.rb b/lib/denko/sensor/qmp6988.rb index 779d558..89c7ef3 100644 --- a/lib/denko/sensor/qmp6988.rb +++ b/lib/denko/sensor/qmp6988.rb @@ -103,12 +103,6 @@ def reset sleep UPDATE_TIME end - def get_config_registers - i2c_read(IIR_REGISTER, 5) - sleep 0.001 while !@registers - @registers - end - def iir_coefficient=(coeff) raise ArgumentError, "invalid IIR coefficient: #{coeff}" unless IIR_COEFFICIENTS.keys.include? coeff i2c_write [IIR_REGISTER, IIR_COEFFICIENTS[coeff]] @@ -160,7 +154,7 @@ def forced_mode end def continuous_mode - @ctrl_meas_register = (@ctrl_meas_register & 0b11111100) | NORMAL_MDOE + @ctrl_meas_register = (@ctrl_meas_register & 0b11111100) | NORMAL_MODE i2c_write [CTRL_MEAS_REGISTER, @ctrl_meas_register] @forced_mode = false sleep UPDATE_TIME @@ -233,6 +227,13 @@ def update_state(reading) end end + def get_config_registers + @registers = {} + i2c_read(IIR_REGISTER, CONFIG_LENGTH) + sleep 0.001 while @registers.empty? + @registers + end + def process_config(bytes) @registers = { f1: bytes[0], f2: bytes[1], f3: bytes[2], f4: bytes[3], f5: bytes[4] } end