def activate(self): assert self.params['address'] assert self.params['bus'] if 'name' in self.params: self.name = self.params['name']+' %i:%s' % (self.params['bus'],hex(self.params['address'])) if not 'driver' in self.params.keys(): self.params['driver']=None self.params['n_channels']=4 if not 'channel_names' in self.config: self.config['channel_names']=['Temperature','Instantaneous reading','Running mean','Delta'] self.params['raw_units']=['degC','','',''] self.config['eng_units']=['degC','','',''] self.config['scale']=np.ones(self.params['n_channels'],) self.config['offset']=np.zeros(self.params['n_channels'],) if ('untitled' in self.name.lower()) or (self.name==''): self.name = 'MAX30105 optical sensor I2C %i:%s' % (self.params['bus'],self.params['address']) self.max30105 = MAX30105() self.max30105.setup(leds_enable=3) self.max30105.set_led_pulse_amplitude(1, 0.0) self.max30105.set_led_pulse_amplitude(2, 0.0) self.max30105.set_led_pulse_amplitude(3, 12.5) self.max30105.set_slot_mode(1, 'red') self.max30105.set_slot_mode(2, 'ir') self.max30105.set_slot_mode(3, 'green') self.max30105.set_slot_mode(4, 'off') self.hr = HeartRate(self.max30105) return
def test_get_temperature(): from max30105 import MAX30105 max30105 = MAX30105(i2c_dev=MockSMBusNoTimeout(1, default_registers={ 0x01: 0b00000010, # Die temp ready 0x09: 0b00000111 # Hard default value to avoid error })) assert max30105.get_temperature() == 0
def test_setup_timeout(): from max30105 import MAX30105 max30105 = MAX30105( i2c_dev=MockSMBus(1, default_registers={0x09: 0b00000111})) with pytest.raises(RuntimeError): max30105.setup(timeout=0.5)
def test_setup(): sys.modules['smbus'] = mock.Mock() sys.modules['RPi'] = mock.Mock() sys.modules['RPi.GPIO'] = mock.Mock() from max30105 import MAX30105 max30105 = MAX30105() del max30105
def test_get_temperature_timeout(): from max30105 import MAX30105 max30105 = MAX30105(i2c_dev=MockSMBusNoTimeout(1, default_registers={ 0x01: 0b00000000, # Die temp NOT ready 0x09: 0b00000111 # Hard default value to avoid error })) with pytest.raises(RuntimeError): max30105.get_temperature()
def setup_particle_sensor(self): self.MAX30105 = MAX30105() self.MAX30105.setup(leds_enable=3) self.MAX30105.set_led_pulse_amplitude(1, 0.0) self.MAX30105.set_led_pulse_amplitude(2, 0.0) self.MAX30105.set_led_pulse_amplitude(3, 12.5) self.MAX30105.set_slot_mode(1, "red") self.MAX30105.set_slot_mode(2, "ir") self.MAX30105.set_slot_mode(3, "green") self.MAX30105.set_slot_mode(4, "off") self.hr = HeartRate(self.MAX30105)
def test_set_slot_mode(): from max30105 import MAX30105 max30105 = MAX30105(i2c_dev=MockSMBusNoTimeout(1, default_registers={ 0x01: 0b00000010, # Die temp ready 0x09: 0b00000111 # Hard default value to avoid error })) max30105.set_slot_mode(1, 'green') max30105.set_slot_mode(1, 'red') with pytest.raises(ValueError): max30105.set_slot_mode(1, 'puce')
def test_get_status(): from max30105 import MAX30105 max30105 = MAX30105(i2c_dev=MockSMBusNoTimeout(1, default_registers={ 0x01: 0b00000010, # Die temp ready 0x09: 0b00000111 # Hard default value to avoid error })) # We don't really care about the values, # just that these don't fail due to some typo max30105.get_data_ready_status() max30105.get_die_temp_ready_status() max30105.get_fifo_almost_full_status() max30105.get_ambient_light_compensation_overflow_status() max30105.get_power_ready_status() max30105.get_proximity_triggered_threshold_status()
#!/usr/bin/env python # NOTE! This code should not be used as the basis for a real # smoke or fire detector, or in life-critical situations. It's # for fun/novelty use only, so bear that in mind while using it. import time import datetime from max30105 import MAX30105, HeartRate max30105 = MAX30105() max30105.setup(leds_enable=3) max30105.set_led_pulse_amplitude(1, 0.0) max30105.set_led_pulse_amplitude(2, 0.0) max30105.set_led_pulse_amplitude(3, 12.5) max30105.set_slot_mode(1, 'red') max30105.set_slot_mode(2, 'ir') max30105.set_slot_mode(3, 'green') max30105.set_slot_mode(4, 'off') hr = HeartRate(max30105) # Smooths wobbly data. Increase to increase smoothing. mean_size = 20 # Compares current smoothed value to smoothed value x # readings ago. Decrease this to increase detection # speed. delta_size = 10
def test_get_chip_id(): from max30105 import MAX30105 max30105 = MAX30105( i2c_dev=MockSMBusNoTimeout(1, default_registers={0x09: 0b00000111})) assert max30105.get_chip_id() == (0, 0)
def test_setup(): from max30105 import MAX30105 max30105 = MAX30105( i2c_dev=MockSMBusNoTimeout(1, default_registers={0x09: 0b00000111})) max30105.setup()