mfitzp / max30100

A Python library for the MAX30100 HR/Oximetry sensor.
45 stars 26 forks source link

Bug in setting the pulse width #4

Open nonnullish opened 1 year ago

nonnullish commented 1 year ago

When setting the pulse width, the value is passed as follows: https://github.com/mfitzp/max30100/blob/242c781a02c2571287687ae134487021d828e39c/max30100.py#L135

This value is in microseconds (1600 by default), instead of the corresponding LED_PW register value.

I believe it is supposed to be set like with the LED current: https://github.com/mfitzp/max30100/blob/242c781a02c2571287687ae134487021d828e39c/max30100.py#L124

which would make the whole function set_spo_config something more like:

def set_spo_config(self, sample_rate=100, pulse_width=1600):
    reg = self.i2c.read_byte_data(I2C_ADDRESS, SPO2_CONFIG)
    reg = reg & 0xFC  # Set LED pulsewidth to 00
    pulse_width_value = _get_valid(PULSE_WIDTH, pulse_width)
    self.i2c.write_byte_data(I2C_ADDRESS, SPO2_CONFIG, reg | pulse_width_value)