pimoroni / vl53l1x-python

Python library for the VL53L1X Laser Ranger
https://shop.pimoroni.com/products/vl53l1x-breakout
94 stars 53 forks source link

Is there a verison compatible with SMBus? #52

Closed mglowinski93 closed 2 years ago

mglowinski93 commented 2 years ago

Hi, I've noticed that this library is using SMBus2.

I've already a couple sensor connected to I2C, which are using SMBus library and moreover SMBus object is a Singleton (see below snippet).

import atexit
from smbus import SMBus

from singleton.singleton import Singleton
from .const import PATH_TO_FILE_WITH_MODEL_VERSION, RASPBERRY_PI_MODEL_1

class SMBusWrapper(metaclass=Singleton):
    def __init__(self):
        self._smbus = SMBus(define_smbus_number())
        atexit.register(self.close_smbus)

    @property
    def smbus(self):
        return self._smbus

    @smbus.setter
    def smbus(self, value):
        self._smbus = value

    def close_smbus(self):
        self._smbus.close()

Do you maybe have this library version, which is using SMBus and not SMBus2? I would like to pass an globally created SMBus object to it. I'm a little worried that if the vl53lx1object opens and closes /dev/i2c-X on its own, there will be some problems with the other sensors.

mglowinski93 commented 2 years ago

Ok, seems like smbus2 is backwards compatible and can be used instead of smbus. I can simply change import and adjust a lite VL53L1X class :)