diff --git a/README.md b/README.md index 45b4b8e..0630abf 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ LED_POWER = MAX30105_PULSEAMP_MEDIUM # MAX30105_PULSE_AMP_MEDIUM = 0x7F # 25.4mA - Presence detection of ~8 inch # MAX30105_PULSE_AMP_HIGH = 0xFF # 50.0mA - Presence detection of ~12 inch sensor.set_pulse_amplitude_red(LED_POWER) -sensor.set_pulse_amplitude_it(LED_POWER) +sensor.set_pulse_amplitude_ir(LED_POWER) sensor.set_pulse_amplitude_green(LED_POWER) # Set the LED brightness of all the active LEDs @@ -288,6 +288,17 @@ resolution of 0.0625°C, but be aware that the accuracy is ±1°C. ## Changelog +- v0.5.0 + - **Breaking:** `set_pulse_amplitude_it()` renamed to `set_pulse_amplitude_ir()` to match the + actual LED (IR, not "IT"). Callers using the old name must update to the new one. + - **Breaking:** Fixed the bit-shift direction in `fifo_bytes_to_int()` (now `>> (3 - pulse_width)` + instead of `>> pulse_width`). Raw sample magnitudes will change whenever `pulse_width` is not 0; + downstream calibration (SpO2, HR thresholds) may need to be re-tuned. + - Fixed `check()` so it drains the entire sensor FIFO per call instead of returning after the + first sample. Callers polling `check()` in a tight loop should now iterate `pop_*_from_storage()` + with `while sensor.available()` instead of `if sensor.available()` to avoid leaving samples + queued between polls. The bundled examples have been updated accordingly. + - Thanks to @sakluk for the fixes (PR #26). - v0.4.2 - Added an heartrate estimation example. - Issued a new release to update the PyPi docs. diff --git a/examples/basic_usage/main.py b/examples/basic_usage/main.py index 7e4452b..2d5cd82 100644 --- a/examples/basic_usage/main.py +++ b/examples/basic_usage/main.py @@ -93,11 +93,11 @@ def main(): while True: # The check() method has to be continuously polled, to check if # there are new readings into the sensor's FIFO queue. When new - # readings are available, this function will put them into the storage. + # readings are available, this function will put them into the storage queue. sensor.check() - # Check if the storage contains available samples - if sensor.available(): + # Drain all queued samples from the queue + while sensor.available(): # Access the storage FIFO and gather the readings (integers) red_reading = sensor.pop_red_from_storage() ir_reading = sensor.pop_ir_from_storage() diff --git a/examples/heart_rate/main.py b/examples/heart_rate/main.py index ff8cbe1..a47f50c 100644 --- a/examples/heart_rate/main.py +++ b/examples/heart_rate/main.py @@ -159,11 +159,11 @@ def main(): while True: # The check() method has to be continuously polled, to check if # there are new readings into the sensor's FIFO queue. When new - # readings are available, this function will put them into the storage. + # readings are available, this function will put them into the storage queue. sensor.check() - # Check if the storage contains available samples - if sensor.available(): + # Drain all queued samples from the queue + while sensor.available(): # Access the storage FIFO and gather the readings (integers) red_reading = sensor.pop_red_from_storage() ir_reading = sensor.pop_ir_from_storage() diff --git a/max30102/__init__.py b/max30102/__init__.py index 79fe6fb..9ed4835 100644 --- a/max30102/__init__.py +++ b/max30102/__init__.py @@ -211,7 +211,7 @@ def setup_sensor(self, led_mode=2, adc_range=16384, sample_rate=400, # Set the LED brightness to the default value of 'low' self.set_pulse_amplitude_red(led_power) - self.set_pulse_amplitude_it(led_power) + self.set_pulse_amplitude_ir(led_power) self.set_pulse_amplitude_green(led_power) self.set_pulse_amplitude_proximity(led_power) @@ -400,14 +400,14 @@ def set_active_leds_amplitude(self, amplitude): if self._active_leds > 0: self.set_pulse_amplitude_red(amplitude) if self._active_leds > 1: - self.set_pulse_amplitude_it(amplitude) + self.set_pulse_amplitude_ir(amplitude) if self._active_leds > 2: self.set_pulse_amplitude_green(amplitude) def set_pulse_amplitude_red(self, amplitude): self.i2c_set_register(MAX30105_LED1_PULSE_AMP, amplitude) - def set_pulse_amplitude_it(self, amplitude): + def set_pulse_amplitude_ir(self, amplitude): self.i2c_set_register(MAX30105_LED2_PULSE_AMP, amplitude) def set_pulse_amplitude_green(self, amplitude): @@ -580,7 +580,7 @@ def bitmask(self, reg, slotMask, thing): def fifo_bytes_to_int(self, fifo_bytes): value = unpack(">i", b'\x00' + fifo_bytes) - return (value[0] & 0x3FFFF) >> self._pulse_width + return (value[0] & 0x3FFFF) >> (3 - self._pulse_width) # Returns how many samples are available def available(self): @@ -681,7 +681,7 @@ def check(self): self.fifo_bytes_to_int(fifo_bytes[6:9]) ) - return True + return True else: return False diff --git a/package.json b/package.json index 2198371..f66de41 100644 --- a/package.json +++ b/package.json @@ -5,5 +5,5 @@ ], "deps": [ ], - "version": "0.4.2" + "version": "0.5.0" } \ No newline at end of file diff --git a/setup.py b/setup.py index 31a80ec..d795911 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="micropython-max30102", - version="0.4.2", + version="0.5.0", description="MAX30102 driver for micropython.", long_description=open("README.md").read(), long_description_content_type='text/markdown',