rm-hull / luma.led_matrix

Python module to drive LED Matrices & 7-segment displays (MAX7219) and RGB NeoPixels (WS2812 / APA102)
https://luma-led-matrix.readthedocs.io
MIT License
516 stars 159 forks source link

Human-readable list of supported devices #133

Open thijstriemstra opened 6 years ago

thijstriemstra commented 6 years ago

device.py contains:

__all__ = ["max7219", "ws2812", "neopixel", "neosegment", "apa102"]

but this cannot be used in the documentation project headline for example. Having a method that returns proper names of these devices instead would be useful.

rm-hull commented 6 years ago

I seem to think we (mis)used Python's __all__ variable so that the demos could introspect which devices were available. [https://docs.python.org/3/tutorial/modules.html#importing-from-a-package]

What do mean by proper names?

thijstriemstra commented 6 years ago

@rm-hull the names in the project description is what I'm trying to get into the documentation

 (MAX7219) and RGB NeoPixels (WS2812 / APA102) 
thijstriemstra commented 5 years ago

Specifically, I want to get rid of the hard-coded devices here:

thijstriemstra commented 5 years ago

Similar to the approach in luma.oled: https://github.com/rm-hull/luma.oled/blob/3.1.0/doc/conf.py#L69

thijstriemstra commented 5 years ago

I suggest something like __devices__ or __deviceNames..

__all__ = ["max7219", "ws2812", "neopixel", "neosegment", "apa102"]

__deviceNames__ = {
    "max7219": "MAX7219",
    "ws2812": "WS2812",
    "neopixel": "Neopixel",
    "neosegment": "Neosegment",
    "apa102": "APA102"
}

And then some method that retrieves the device name by classname etc.

Or we could add a label class var to the devices with the label name.

class max7219(device):
    """
    Serial interface to a series of 8x8 LED matrixes daisychained together with
    MAX7219 chips.
    On creation, an initialization sequence is pumped to the display to properly
    configure it. Further control commands can then be called to affect the
    brightness and other settings.
    """

    label = 'MAX7219'

Note that whatever approach has to work for all other libraries as well.

Thoughts @rm-hull?

rm-hull commented 5 years ago

How about

__deviceNames__ = { ... }

__all__ = __deviceNames__.keys()

?

thijstriemstra commented 5 years ago

That's fine with me as well. I'll make a PR.

thijstriemstra commented 5 years ago

Actually, I'd rather not mess around with __all__ and make it depend on other code. I've seen this result in strange bugs (GC) that we don't want to get into. I'd rather keep __all__ hard-coded + new __deviceNames__ with duplication, or use the device.label thing. Thoughts @rm-hull ?

rm-hull commented 5 years ago

Ok, no problem. Don’t mind which approach tbh ... maybe go with

keep __all__ hard-coded + new __deviceNames__ with duplication

to keep them located together