Abstract-Horizon / vl53l5cx_python

Python transliteration of VL53L5CX ultra lite driver from C to Python. Current implementation is tested on Raspberry Pi with SMBus2 for i2c communication.
Apache License 2.0
6 stars 6 forks source link

More Pythonic (and faster) swap buffer #3

Open Gadgetoid opened 2 years ago

Gadgetoid commented 2 years ago

The buffer swap:

https://github.com/Abstract-Horizon/vl53l5cx_python/blob/b6bed0ad85061b97eac31a55743e649e13b7a2f1/vl53l5cx/vl53l5cx.py#L319-L338

Can be more readable and faster using:

    @staticmethod
    def swap_buffer(buffer: List[int], size: int) -> None:
        for i in range(0, min(size, len(buffer)), 4):
            buffer[i:i+4] = reversed(buffer[i:i+4])

I don't mind raising a PR for this and some other bits and bobs (i2c_msg is never set if you pass in an i2c object).

Gadgetoid commented 2 years ago

Raised as a draft along with some other bits for your consideration in #4