rm-hull / luma.examples

Companion repo for running examples against the luma.oled, luma.lcd, luma.led_matrix and luma.emulator display drivers.
MIT License
370 stars 144 forks source link

show better error message for sevensegment demo #76

Closed thijstriemstra closed 6 years ago

thijstriemstra commented 6 years ago

when using unsupported devices.

fixes #71

thijstriemstra commented 6 years ago

ps. i haven't tested this on python 2.7; 3.4 only.. (rpi2 jessie)

rm-hull commented 6 years ago

I think it he emulators have a seven seg transform that should be accommodated as well

thijstriemstra commented 6 years ago

@rm-hull in that case this isn't a good fix. Ideally we should be able to query a luma library for their sevensegment devices. Thoughts?

rm-hull commented 6 years ago

Maybe do a hasattr check on the device to see if it has the segment_mapper defined? Or simply do a try/catch for the specific attribute error?

thijstriemstra commented 6 years ago

Not that it's terribly important but this PR doesn't have any effect on OSX either;

$ python examples/sevensegment_demo.py 
usage: sevensegment_demo.py [-h] [--config CONFIG] [--display] [--width WIDTH]
                            [--height HEIGHT] [--rotate] [--interface]
                            [--i2c-port I2C_PORT] [--i2c-address I2C_ADDRESS]
                            [--spi-port SPI_PORT] [--spi-device SPI_DEVICE]
                            [--spi-bus-speed SPI_BUS_SPEED] [--gpio GPIO]
                            [--gpio-data-command GPIO_DATA_COMMAND]
                            [--gpio-reset GPIO_RESET]
                            [--gpio-backlight GPIO_BACKLIGHT]
                            [--block-orientation] [--mode] [--framebuffer]
                            [--bgr] [--h-offset H_OFFSET]
                            [--v-offset V_OFFSET] [--backlight-active]
                            [--transform] [--scale SCALE]
                            [--duration DURATION] [--loop LOOP]
                            [--max-frames MAX_FRAMES]
sevensegment_demo.py: error: I2C device not found: /dev/i2c-1

what it does show is that the settings can be printed earlier to clarify what params are used, e.g.

$ python examples/sevensegment_demo.py
Version: luma.oled 2.3.1 (luma.core 1.2.1)
Display: ssd1306
Interface: i2c
Dimensions: 128 x 64
------------------------------------------------------------
usage: sevensegment_demo.py [-h] [--config CONFIG] [--display] [--width WIDTH]
                            [--height HEIGHT] [--rotate] [--interface]
                            [--i2c-port I2C_PORT] [--i2c-address I2C_ADDRESS]
                            [--spi-port SPI_PORT] [--spi-device SPI_DEVICE]
                            [--spi-bus-speed SPI_BUS_SPEED] [--gpio GPIO]
                            [--gpio-data-command GPIO_DATA_COMMAND]
                            [--gpio-reset GPIO_RESET]
                            [--gpio-backlight GPIO_BACKLIGHT]
                            [--block-orientation] [--mode] [--framebuffer]
                            [--bgr] [--h-offset H_OFFSET]
                            [--v-offset V_OFFSET] [--backlight-active]
                            [--transform] [--scale SCALE]
                            [--duration DURATION] [--loop LOOP]
                            [--max-frames MAX_FRAMES]
sevensegment_demo.py: error: I2C device not found: /dev/i2c-1
rm-hull commented 6 years ago

For OSX, I just checked, and the seven segment demo command args are:

$ python examples/sevensegment_demo.py -d pygame  --transform=seven_segment --width=8 --height=8

That continues to work with 937eb9c that I just pushed

thijstriemstra commented 6 years ago

Looks like that didn't help either, e.g.:

$ python examples/sevensegment_demo.py -d ssd1306
Version: luma.oled 2.3.1 (luma.core 1.2.1)
Display: ssd1306
Interface: i2c
Dimensions: 128 x 64
------------------------------------------------------------
usage: sevensegment_demo.py [-h] [--config CONFIG] [--display] [--width WIDTH]
                            [--height HEIGHT] [--rotate] [--interface]
                            [--i2c-port I2C_PORT] [--i2c-address I2C_ADDRESS]
                            [--spi-port SPI_PORT] [--spi-device SPI_DEVICE]
                            [--spi-bus-speed SPI_BUS_SPEED] [--gpio GPIO]
                            [--gpio-data-command GPIO_DATA_COMMAND]
                            [--gpio-reset GPIO_RESET]
                            [--gpio-backlight GPIO_BACKLIGHT]
                            [--block-orientation] [--mode] [--framebuffer]
                            [--bgr] [--h-offset H_OFFSET]
                            [--v-offset V_OFFSET] [--backlight-active]
sevensegment_demo.py: error: I2C device not found on address: 0x3C
rm-hull commented 6 years ago

Presumably that fails earlier in the init, because OSX doesnt have the i2c device ?

p.s. it would be useful if the version printed something like:

Version: luma.oled 2.3.1 (luma.core 1.2.1) on ${platform.platform} with Python X.Y.Z