Skip to content

__get_item__ needs to support different pixel orders #41

Closed
@kevinjwalters

Description

@kevinjwalters

The get_time() function needs updating to deal with variable pixel ordering introduced in #15 #18.

    def __getitem__(self, index):
        if isinstance(index, slice):
            out = []
            for in_i in range(*index.indices(self._n)):
                out.append(
                    tuple(self._buf[in_i * 4 + (3 - i) + START_HEADER_SIZE] for i in range(3)))
            return out
        if index < 0:
            index += len(self)
        if index >= self._n or index < 0:
            raise IndexError
        offset = index * 4
        return tuple(self._buf[offset + (3 - i) + START_HEADER_SIZE]
                     for i in range(3))

I've not tested the code this is just from inspection after seeing the issue come up in adafruit/Adafruit_CircuitPython_WS2801#9. I'd imagine it'll end up similar to the neopixel implementation in https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/163bd47a8385b993309a4b9100bb5956b2066a1d/neopixel.py#L182-L195

@RedAnon and @mcscope may be interested in this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions