luma.led_matrix icon indicating copy to clipboard operation
luma.led_matrix copied to clipboard

Human-readable list of supported devices

Open thijstriemstra opened this issue 8 years ago • 9 comments

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.

thijstriemstra avatar Nov 03 '17 22:11 thijstriemstra

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?

rm-hull avatar Jan 02 '18 21:01 rm-hull

@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 avatar Jan 03 '18 01:01 thijstriemstra

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

  • https://github.com/rm-hull/luma.led_matrix/blob/1.2.0/doc/conf.py#L61
  • https://github.com/rm-hull/luma.led_matrix/blob/1.2.0/doc/index.rst

thijstriemstra avatar Mar 18 '19 22:03 thijstriemstra

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

thijstriemstra avatar Mar 18 '19 22:03 thijstriemstra

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?

thijstriemstra avatar Mar 18 '19 22:03 thijstriemstra

How about

__deviceNames__ = { ... }

__all__ = __deviceNames__.keys()

?

rm-hull avatar Mar 18 '19 22:03 rm-hull

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

thijstriemstra avatar Mar 18 '19 22:03 thijstriemstra

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 ?

thijstriemstra avatar Mar 18 '19 22:03 thijstriemstra

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

rm-hull avatar Mar 18 '19 22:03 rm-hull