Skip to content

Commit 1e27ccd

Browse files
authored
Merge pull request #26 from sakluk/main
1 renamed set_pulse_amplitude_it() to set_pulse_amplitude_ir() 2 changed bit shift direction in fifo_bytes_to_int() to return (value[0] & 0x3FFFF) >> (3 - self._pulse_width) 3 changed in check() the intendation to left for return True to let the function handle all samples in buffer
2 parents 2b9a810 + 5c0c6b8 commit 1e27ccd

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ LED_POWER = MAX30105_PULSEAMP_MEDIUM
178178
# MAX30105_PULSE_AMP_MEDIUM = 0x7F # 25.4mA - Presence detection of ~8 inch
179179
# MAX30105_PULSE_AMP_HIGH = 0xFF # 50.0mA - Presence detection of ~12 inch
180180
sensor.set_pulse_amplitude_red(LED_POWER)
181-
sensor.set_pulse_amplitude_it(LED_POWER)
181+
sensor.set_pulse_amplitude_ir(LED_POWER)
182182
sensor.set_pulse_amplitude_green(LED_POWER)
183183

184184
# Set the LED brightness of all the active LEDs

‎examples/heart_rate/README.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ The `HeartRateMonitor` class is designed to calculate heart rate from the raw se
4040

4141
## Example Usage
4242

43-
python
44-
Copy code
45-
hr_monitor = HeartRateMonitor(sample_rate=100, window_size=150, smoothing_window=10)
43+
For a complete example, see `./main.py`.
4644

4745
```python
46+
# Initialize the heart rate monitor
47+
hr_monitor = HeartRateMonitor(
48+
# Select a sample rate that matches the sensor's acquisition rate
49+
sample_rate=actual_acquisition_rate,
50+
# Select a significant window size to calculate the heart rate (2-5 seconds)
51+
window_size=int(actual_acquisition_rate * 3),
52+
)
53+
4854
# Add samples in a loop (replace the sample polling with actual sensor data retrieval)
4955
for _ in range(1000): # Example loop
5056
sample = ... # Poll the MAX30102/5 sensor to get a new sample

‎max30102/__init__.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def setup_sensor(self, led_mode=2, adc_range=16384, sample_rate=400,
211211

212212
# Set the LED brightness to the default value of 'low'
213213
self.set_pulse_amplitude_red(led_power)
214-
self.set_pulse_amplitude_it(led_power)
214+
self.set_pulse_amplitude_ir(led_power)
215215
self.set_pulse_amplitude_green(led_power)
216216
self.set_pulse_amplitude_proximity(led_power)
217217

@@ -400,14 +400,14 @@ def set_active_leds_amplitude(self, amplitude):
400400
if self._active_leds > 0:
401401
self.set_pulse_amplitude_red(amplitude)
402402
if self._active_leds > 1:
403-
self.set_pulse_amplitude_it(amplitude)
403+
self.set_pulse_amplitude_ir(amplitude)
404404
if self._active_leds > 2:
405405
self.set_pulse_amplitude_green(amplitude)
406406

407407
def set_pulse_amplitude_red(self, amplitude):
408408
self.i2c_set_register(MAX30105_LED1_PULSE_AMP, amplitude)
409409

410-
def set_pulse_amplitude_it(self, amplitude):
410+
def set_pulse_amplitude_ir(self, amplitude):
411411
self.i2c_set_register(MAX30105_LED2_PULSE_AMP, amplitude)
412412

413413
def set_pulse_amplitude_green(self, amplitude):
@@ -580,7 +580,8 @@ def bitmask(self, reg, slotMask, thing):
580580

581581
def fifo_bytes_to_int(self, fifo_bytes):
582582
value = unpack(">i", b'\x00' + fifo_bytes)
583-
return (value[0] & 0x3FFFF) >> self._pulse_width
583+
# return (value[0] & 0x3FFFF) >> self._pulse_width # original (bug: shifts wrong direction)
584+
return (value[0] & 0x3FFFF) >> (3 - self._pulse_width)
584585

585586
# Returns how many samples are available
586587
def available(self):
@@ -681,7 +682,7 @@ def check(self):
681682
self.fifo_bytes_to_int(fifo_bytes[6:9])
682683
)
683684

684-
return True
685+
return True
685686

686687
else:
687688
return False

0 commit comments

Comments
 (0)