Skip to content

__get_item__ needs to support different pixel orders #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kevinjwalters opened this issue Nov 7, 2019 · 1 comment · Fixed by #48
Closed

__get_item__ needs to support different pixel orders #41

kevinjwalters opened this issue Nov 7, 2019 · 1 comment · Fixed by #48

Comments

@kevinjwalters
Copy link

kevinjwalters commented Nov 7, 2019

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.

@kevinjwalters
Copy link
Author

#42 looks like it changes this area of the code too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants