Giter Club home page Giter Club logo

rm-hull / luma.core Goto Github PK

View Code? Open in Web Editor NEW
136.0 17.0 50.0 1.06 MB

A component library providing a Pillow-compatible drawing canvas, and other functionality to support drawing primitives and text-rendering capabilities for small displays on the Raspberry Pi and other single board computers.

Home Page: https://luma-core.readthedocs.io

License: MIT License

Python 100.00%
python lcd led oled neopixel max7219 ssd1306 raspberry-pi pcd8544 ws2812 apa102

luma.core's Introduction

luma.core | luma.docs | luma.emulator | luma.examples | luma.lcd | luma.led_matrix | luma.oled

luma.core

image

image

image

image

image

luma.core is a component library providing a Pillow-compatible drawing canvas for Python 3, and other functionality to support drawing primitives and text-rendering capabilities for small displays on the Raspberry Pi and other single board computers:

  • scrolling/panning capability,
  • terminal-style printing,
  • state management,
  • color/greyscale (where supported),
  • dithering to monochrome,
  • sprite animation,
  • flexible framebuffering (depending on device capabilities)

Documentation

API documentation can be found at https://luma-core.readthedocs.io/en/latest/

Drivers

Device drivers extend luma.core to provide the correct initialization sequences for specific physical display devices/chipsets.

There are several drivers for different classes of device available:

Emulators

There are emulators that run in real-time (with pygame) and others that can take screenshots, or assemble animated GIFs, as per the examples below. Source code for these are available in the examples directory of the luma.examples repository.

clock

invaders

crawl

License

The MIT License (MIT)

Copyright (c) 2017-2022 Richard Hull and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

luma.core's People

Contributors

7754359337 avatar alessiomorale avatar baslr avatar dhrone avatar drspangle avatar gadgetoid avatar hansliss avatar jakiee3y avatar jasongaunt avatar jonathanrjpereira avatar matemaciek avatar mlos avatar pinotree avatar relvacode avatar ric2b avatar rm-hull avatar theraspydev avatar thijstriemstra avatar vortigont avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luma.core's Issues

OSError: [Errno 5] Input/output error

Was getting this traceback when there wasn't any I2C device connected to the RPi:

$ python examples/3d_box.py -i i2c
...
3d_box.py: error: [Errno 5] Input/output error
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/home/pi/projects/pi-test/luma.core/luma/core/device.py", line 70, in cleanup
    self.hide()
  File "/home/pi/projects/pi-test/luma.core/luma/core/device.py", line 53, in hide
    self.command(self._const.DISPLAYOFF)
  File "/home/pi/projects/pi-test/luma.core/luma/core/device.py", line 32, in command
    self._serial_interface.command(*cmd)
  File "/home/pi/projects/pi-test/luma.core/luma/core/serial.py", line 63, in command
    self._bus.write_i2c_block_data(self._addr, self._cmd_mode, list(cmd))
  File "/home/pi/.virtualenvs/pi-test/lib/python3.4/site-packages/smbus2/smbus2.py", line 274, in write_i2c_block_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 5] Input/output error

I thought this OSError business was already fixed before; it should throw a devicenotfound error..

Add note to ISSUE_TEMPLATE

Mention that sub-projects specific issues should be reported in their sub-project's issue tracker, not here in core.

UTF-8 support in terminal for Python 2

When I try to draw a text containing a unicode character, I get the following error:

error from callback <function on_message at 0xb64edef0>: 'ascii' codec can't encode character u'\u015b' in position 17: ordinal not in range(128)
  File "/usr/local/lib/python2.7/dist-packages/websocket/_app.py", line 269, in _callback
    callback(self, *args)
  File "pushbullet.py", line 48, in on_message
    term.println(title)
  File "/pishare/src/luma.core/luma/core/virtual.py", line 268, in println
    self.puts(text)
  File "/pishare/src/luma.core/luma/core/virtual.py", line 282, in puts
    for method, args in ansi_color.find_directives(text, self):
  File "/pishare/src/luma.core/luma/core/ansi_color.py", line 103, in find_directives
    for directive in parse_str(text):
  File "/pishare/src/luma.core/luma/core/ansi_color.py", line 62, in parse_str
    text = str(text)

Are there any plans to support encodings other than ASCII? Or is that a limitation of the PIL library?

Add word-wrap capability to luma.core.virtual.terminal

Currently, the terminal class will check that text to be rendered using proportional fonts wont overflow over the right hand edge. If there is not enough width to display the next character, it will insert a newline. For example:

image

Add a constructor arg setting so that wrapping works at the word level, eg, the above string would render as

The quick brown fox
jumps over the lazy
dog

Running multiple I²C OLEDs

I am planning to run multiple I²C OLEDs with a Linux-based-Microcomputer which has two I²C interfaces. Now I have some Questions:

Raphael

Add 4- & 8-bit parallel interfaces

Somewhat related to rm-hull/luma.lcd#19

Use RPi.GPIO to bit-bang out 4 or 8 bus lines according to the HD44780 datasheet spec. The interface should have the same "shape" as the existing luma.core.interface.serial interfaces - i.e. implement data() and command() methods.

Also: Move luma.core.serial to luma.core.interface.serial and add this new functionality to luma.core.interface.parallel. Various breaking changes to device implementations to rename serial_interface= constructor arg to interface=. (done with #78)

screen shot 2017-03-06 at 22 12 28

(screen grab from https://cdn-shop.adafruit.com/datasheets/HD44780.pdf)

failing tests on raspberry pi

============================================= FAILURES ==============================================
_______________________________________ test_make_serial_spi ________________________________________

    def test_make_serial_spi():
        """
        :py:func:`luma.core.cmdline.make_serial.spi` returns an SPI instance.
        """
        factory = cmdline.make_serial(test_spi_opts)
        with pytest.raises(error.UnsupportedPlatform):
>           factory.spi()
E           Failed: DID NOT RAISE <class 'luma.core.error.UnsupportedPlatform'>

tests/test_cmdline.py:115: Failed
___________________________________ test_make_serial_spi_alt_gpio ___________________________________

    def test_make_serial_spi_alt_gpio():
        """
        :py:func:`luma.core.cmdline.make_serial.spi` returns an SPI instance
        when using an alternative GPIO implementation.
        """
        class opts(test_spi_opts):
            gpio = 'fake_gpio'
    
        with patch.dict('sys.modules', **{
                'fake_gpio': Mock(unsafe=True)
            }):
            factory = cmdline.make_serial(opts)
            with pytest.raises(error.DeviceNotFoundError):
>               factory.spi()
E               Failed: DID NOT RAISE <class 'luma.core.error.DeviceNotFoundError'>

tests/test_cmdline.py:131: Failed
______________________________________ test_create_device_oled ______________________________________

    def test_create_device_oled():
        """
        :py:func:`luma.core.cmdline.create_device` supports OLED displays.
        """
        display_name = 'oled1234'
        display_types = {'oled': [display_name]}
    
        class args(test_spi_opts):
            display = display_name
    
        module_mock = Mock()
        with patch.dict('sys.modules', **{
                'luma': module_mock,
                'luma.oled': module_mock,
                'luma.oled.device': module_mock
            }):
            with pytest.raises(error.UnsupportedPlatform):
>               cmdline.create_device(args, display_types=display_types)
E               Failed: DID NOT RAISE <class 'luma.core.error.UnsupportedPlatform'>

tests/test_cmdline.py:161: Failed
====================================== pytest-warning summary =======================================
WW0 in tests/test_cmdline.py:108 the following warning was recorded:
 luma/core/interface/serial.py:171: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  self._gpio.setup(pin, self._gpio.OUT)

WW0 in tests/test_cmdline.py:189 the following warning was recorded:
 luma/core/serial.py:18: DeprecationWarning: luma.core.serial is deprecated and will be removed in v1.0.0: use luma.core.interface.serial instead
  'use luma.core.interface.serial instead')

====================== 3 failed, 114 passed, 2 pytest-warnings in 9.78 seconds ======================

Support for Linux i2c

Hi,
I have an ssd1306 OLED connected to my ThinkPad via i2c and would like to use Luma to access it. However, it seems that it needs RPi.GPIO which obviously makes little sense in my case.
Is there a way to use the standard i2c kernel module instead?

Improve readme on mobile github page

When you visit the github pages for the luma libraries in a mobile browser it doesn't show any useful description in the readme, it only shows the list of links to sub-projects and the title of the library.

New scheme!

I like the new name :)

I'm wondering if splitting up the repo is the right thing to do though. I tend to like being able to grab everything with a single clone.

With a split repo, I'd suggest adding a single repo called just "luma" that would pull in everything, with a "git clone --recursive".

OSError: [Errno 121] Remote I/O error

Getting this error with the examples on rpi2:

$ python examples/3d_box.py -i i2c --display sh1106
2017-02-27 00:12:45,674 - [Errno 121] Remote I/O error
Traceback (most recent call last):
  File "/home/pi/projects/pi-test/luma.examples/examples/demo_opts.py", line 87, in <module>
    rotate=args.rotate, mode=args.mode)
  File "/home/pi/projects/pi-test/luma.oled/luma/oled/device.py", line 70, in __init__
    self._const.CHARGEPUMP,         0x14)
  File "/home/pi/projects/pi-test/luma.core/luma/core/device.py", line 39, in command
    self._serial_interface.command(*cmd)
  File "/home/pi/projects/pi-test/luma.core/luma/core/serial.py", line 63, in command
    self._bus.write_i2c_block_data(self._addr, self._cmd_mode, list(cmd))
  File "/home/pi/.virtualenvs/pi-test/lib/python3.5/site-packages/smbus2/smbus2.py", line 274, in write_i2c_block_data
    ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error

I have not hooked up any i2c sh1106 device.

Remove deprecated code in v1.0.0

Now that #2 is fixed, we should remove the deprecated bcm_DC and bcm_RST arguments from the spi class somewhere before the version 1.0.0 release.

[Question] Are "del" calls in "canvas" (render.py) actually required?

Hi! We're using luma.oled library in ZPUI, and it's a great success so far. However, the luma-provided canvas was constraining us, so we did our own implementation, based off PIL.Image and PIL.ImageDraw directly. We, of course, used your canvas implementation as a reference.

So, a question about your canvas implementation - on line 45, del is used - what's the reasoning behind it? Is the draw object not collected by GC eventually (IIRC Python can deal with cycling references quite well)?

Terminology and luma.core.virtual.viewport

Hi !
As a beginner, I'm trying to understand luma.core, and I'm learning the various concepts and terminology used for GUI.
One thing suprised me: If I read the viewport's page on Wikipedia, it's not the same concept as I understand it in caroussel.py or crawl.py.
From wikipedia:

the viewport is the visible portion of a 2D area which is larger than the visualization device

But in caroussel.py, the viewport is larger than the visualization device.

Am I wrong ?

Cyrillic upercase chars for LCD_FONT

[0x7F, 0x49, 0x49, 0x41, 0x00, 0x00, 0x00, 0x00],  # 0x81 
[0x7e, 0x11, 0x11, 0x11, 0x7e, 0x00, 0x00, 0x00],  # 0x90
[0x7F, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, 0x00],  # 0x91
[0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00, 0x00],  # 0x92
[0x7F, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00],  # 0x93
[0x80, 0x78, 0x47, 0x41, 0x7F, 0x80, 0x00, 0x00],  # 0x94
[0x7F, 0x49, 0x49, 0x41, 0x00, 0x00, 0x00, 0x00],  # 0x95
[0x63, 0x14, 0x08, 0x7F, 0x08, 0x14, 0x63, 0x00],  # 0x96
[0x22, 0x41, 0x49, 0x49, 0x36, 0x00, 0x00, 0x00],  # 0x97
[0x7F, 0x10, 0x08, 0x04, 0x7F, 0x00, 0x00, 0x00],  # 0x98
[0x7E, 0x10, 0x09, 0x04, 0x7E, 0x00, 0x00, 0x00],  # 0x99
[0x7f, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x00],  # 0x9A
[0x40, 0x3E, 0x01, 0x01, 0x7F, 0x00, 0x00, 0x00],  # 0x9B
[0x7f, 0x02, 0x0c, 0x02, 0x7f, 0x00, 0x00, 0x00],  # 0x9C
[0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00, 0x00, 0x00],  # 0x9D
[0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00, 0x00, 0x00],  # 0x9E
[0x7F, 0x01, 0x01, 0x01, 0x7F, 0x00, 0x00, 0x00],  # 0x9F
[0x7f, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00],  # 0xA0
[0x3e, 0x41, 0x41, 0x41, 0x22, 0x00, 0x00, 0x00],  # 0xA1
[0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, 0x00, 0x00],  # 0xA2
[0x47, 0x58, 0x20, 0x18, 0x07, 0x00, 0x00, 0x00],  # 0xA3
[0x0E, 0x11, 0x7F, 0x11, 0x0E, 0x00, 0x00, 0x00],  # 0xA4
[0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x00, 0x00],  # 0xA5
[0x7F, 0x40, 0x40, 0x7F, 0xC0, 0x00, 0x00, 0x00],  # 0xA6
[0x07, 0x08, 0x10, 0x10, 0x7F, 0x00, 0x00, 0x00],  # 0xA7
[0x7F, 0x40, 0x7F, 0x40, 0x7F, 0x00, 0x00, 0x00],  # 0xA8
[0x7F, 0x40, 0x7F, 0x40, 0x7F, 0xC0, 0x00, 0x00],  # 0xA9
[0x01, 0x7F, 0x48, 0x48, 0x30, 0x00, 0x00, 0x00],  # 0xAA
[0x7F, 0x48, 0x30, 0x00, 0x7F, 0x00, 0x00, 0x00],  # 0xAB
[0x00, 0x7F, 0x48, 0x48, 0x30, 0x00, 0x00, 0x00],  # 0xAC
[0x22, 0x41, 0x49, 0x49, 0x3E, 0x00, 0x00, 0x00],  # 0xAD
[0x7F, 0x08, 0x3E, 0x41, 0x41, 0x3E, 0x00, 0x00],  # 0xAE
[0x46, 0x29, 0x19, 0x09, 0x7F, 0x00, 0x00, 0x00],  # 0xAF

persistence of text on ssd1306

I'm trying to write a python script that takes a string as parameter and shows it on the display.
but if I call a simple draw.text() it shows and turn it off the display, i mean, i need to import time and call a delay to see the msg, then the text goes away after the program exits.
My question is if there is some way to let the text on display after script ends?
I was reading about the set of statements with/as, and saw that they are made in a way it guarantees the end of the methods called, i could have understood wrong, but is there another way to call the method draw.text() not using 'with' and 'as'?
If this is not the best or known solution and someone could explain another way of achieve the goal of let the text on the display after the script finishes it's execution it will be great, any help is appreciated.
the device is an orange pi zero, and it's on i2c0, default address0x3c
Thanks in advance for any help!!
Any additional info just ask i will provide asap.

Bit-banged serial interface?

Similar to #41, could be nice to have an alternative bit-banged GPIO interface for serial devices. I'm working on a project with a few screens on the same device, and being able to put a pcd8544 on gpio instead of hardware SPI would be a nice alternative to making all the hardware play nice together.

Could also be a (slow) fallback for those who can't get hardware SPI or I2C running on their oddball systems.

No worries if this seems out of scope for luma!

New Font: Spaces between characters

When creating a new font, do I need to write a column 0x00 so that there is a space between any two characters?

For example: Assume the number 3 is to be displayed in an area of 3 columns * 8 rows. Assuming it the 3 the bit pattern of the columns is 0x49, 0x49, 0x7F.

Is it necessary to add an additional 0x00 to create a space between any two characters? In such a case the bit patterns of the columns will then be 0x49, 0x49, 0x7F, 0x00.

From what I have observed, every character in the LCD_FONT has its last three columns 0x00 whereas TINY_FONT only has the last column as 0x00.

For my project, I wanted to fit 8 numbers on a single 4in1 cascaded (8*8) matrix using static text. But none of the existing fonts were capable of doing so. TINY_FONT, in my opinion, wasn't looking big enough to read easily whilst optimizing the display area. So I'm currently trying to create a font that is similar to a 7 segment font wherein each character only consumes a fixed area of 3 columns & 7 rows. The 4th column will act as a space between the two characters.
My reference font style is: 7 Segment Font
The 7SEG_FONT only supports Capital Letters(0x41 - 0x5A inclusive) & Numbers(0x30 - 0x39 inclusive). I haven't calculated the bit patterns for any other special characters since I feel that the purpose of this font is only for a few static display alpha-numeric applications.

[feature request] support for Sharp memory LCD

Hi !
Following my question for menu management #112 I'd like to know if it's possible to support the Sharp memory LCD. These low power LCDs are a good solution when you want something readable under direct sunlight, without the e-ink drawback (slow refresh rate).
I plan to use this lcd on my bike for collection photos for OpenStreetMap contributions (you can see more here).

Sharp Memory LCD doc:
datasheet
programming Memory LCD
Some code on github:
https://github.com/MakerDyne/Memory-LCD-for-Raspberry-Pi

Deprecate legacy code

luma.core v1.0.0 was released but the legacy package still exists. Let's add a deprecation warning and/or note to the module(s) that it'll be removed eventually.

Format cmdline display options

It's currently printed twice (and becoming a long list). I also suggest to use pygame or different emulator as the default option.

  --display {ssd1306,ssd1322,ssd1325,ssd1331,sh1106,pcd8544,st7735,max7219,neopixel,capture,gifanim,pygame}, -d {ssd1306,ssd1322,ssd1325,ssd1331,sh1106,pcd8544,st7735,max7219,neopixel,capture,gifanim,pygame}
                        Display type, supports real devices or emulators
                        (default: ssd1306)

add argparser utils from luma.examples

Being able to reuse the demo_opts, argparser code, in luma.examples would be beneficial for sub-projects. You would be able to use the parser code to create a command-line script that handles all compatible luma libraries.

I'm not sure if it belongs in core or a new luma.commandline-something llibrary. Thoughts?

disable pytest-warnings plugin

Getting this warning lately:

/home/pi/projects/pi-test/luma.oled/.tox/py35/lib/python3.5/site-packages/pytest_warnings/__init__.py:44:
UserWarning: pytest-warnings plugin was introduced in core pytest on 3.1, please uninstall pytest-warnings
  warnings.warn('pytest-warnings plugin was introduced in core pytest on 3.1, please '

support CHIP_IO (Next Thing C.H.I.P.)

Type of Raspberry Pi

Next Thing C.H.I.P.

Linux Kernel version

Linux compy386 4.4.13-ntc-mlc #1 SMP Tue Dec 6 21:38:00 UTC 2016 armv7l GNU/Linux

Expected behaviour

Would love to see support for CHIP_IO, the C.H.I.P. version of RPi.GPIO :) I bet it would be just a few lines in lib.py and serial.py. (I will try this out myself but I am pretty noob.)

Actual behaviour

Traceback (most recent call last):
  File "st7735.py", line 14, in <module>
    serial = spi(port=0, device=0, bcm_DC=23, bcm_RST=24)
  File "/usr/local/lib/python2.7/dist-packages/luma/core/serial.py", line 163, in __init__
    self._gpio = gpio or self.__rpi_gpio__()
  File "/usr/local/lib/python2.7/dist-packages/luma/core/lib.py", line 23, in __rpi_gpio__
    import RPi.GPIO
ImportError: No module named RPi.GPIO

Core docs

Currently the same instructions to enable spi/i2c are duplicated across the various luma sub-projects. I think common docs like how to enable spi should be in the core docs, and device specific installation instructions belong in the specific sub-project docs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.