Example #1
0
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.  

import os
import ugfx
import glut

white = ugfx.color(255, 255, 255)
black = ugfx.color(0, 0, 0)

use_glut = 'DISPLAY' in os.environ

if use_glut:
    screen = glut.screen()
else:
    screen = ugfx.screen("/dev/fb0")

c, d = black, white
x, w = 0, 400
while w >= 100:
    screen.box(x, x, x+w, x+w, c)
    x += 2
    w -= 4
    c, d = d, c

screen.invert(100, 100, 200, 200)

import font
font.draw(screen, (0, 0), "Hello!", 80, False)

print 'type', str(type(screen))
Example #2
0
    ifont = ImageFont.truetype(fontpath, size)
    size = ifont.getsize(c)
    image = Image.new('RGBA', size)
    draw = ImageDraw.Draw(image)
    draw.text((0, 0), c, font=ifont)

    if crop:
        bg = Image.new(image.mode, image.size, image.getpixel((0, 0)))
        diff = ImageChops.difference(image, bg)
        bbox = diff.getbbox()
        if bbox:
            image = image.crop(bbox)

    if bpp:
        data = list(image.getdata())
        for i in range(len(data)):
            d = 255 / (1 << bpp)
            v = int(
                round(data[i][0] / (255 / (1 << bpp))) * (255 /
                                                          ((1 << bpp) - 1)))
            data[i] = (v, v, v, v)
        image.putdata(data)

    return ugfx.surface(image.size[0], image.size[1], bypp, image.tobytes())


if __name__ == '__main__':
    print('ugfx test program')
    screen = ugfx.screen('/dev/fb0'.encode('utf-8'))
    draw(screen, (0, 100), "1234567890", 28, False)
Example #3
0
    def __init__(self, hat):
        self.hat = hat

        if hat:
            self.config = hat.config['lcd']
        elif micropython:
            from config_esp32 import read_config
            self.config = read_config()
        else:
            self.config = {}

        default = {
            'contrast': 60,
            'invert': False,
            'backlight': 20,
            'flip': False,
            'language': 'en',
            'bigstep': 10,
            'smallstep': 1
        }

        for name in default:
            if not name in self.config:
                self.config[name] = default[name]

        # set the driver to the one from hat eeprom
        driver = 'default'
        if self.hat and 'hat' in self.hat.config:
            driver = self.hat.config['hat']['lcd']['driver']
            self.host = self.hat.client.config['host']
        else:
            self.host = False

        for pdriver in [
                'nokia5110', 'jlx12864', 'glut', 'framebuffer', 'tft', 'none'
        ]:
            if pdriver in sys.argv:
                print('overriding driver', driver, ' to command line', pdriver)
                sys.argv.remove(pdriver)
                driver = pdriver
                break

        self.battery_voltage = 0
        use_tft = True if micropython else False

        if not use_tft:
            use_glut = 'DISPLAY' in os.environ
        self.use_glut = False
        self.surface = None

        if driver == 'none':
            page = None
        elif driver == 'tft' or (driver == 'default' and use_tft):
            screen = ugfx.surface(136, 240, 1)
            self.surface = screen
        elif driver == 'nokia5110' or (driver == 'default' and not use_glut):
            screen = ugfx.spiscreen(0)
        elif driver == 'jlx12864':
            screen = ugfx.spiscreen(1)
        elif driver == 'glut' or (driver == 'default' and use_glut):
            self.use_glut = True
            print('using glut')
            import glut
            # emulate which screen resolution?
            #screen = glut.screen((240, 320))
            screen = glut.screen((136, 240))
            #screen = glut.screen((48, 84))
            #screen = glut.screen((96, 168))

            from OpenGL.GLUT import glutKeyboardFunc, glutKeyboardUpFunc
            from OpenGL.GLUT import glutSpecialFunc, glutSpecialUpFunc

            glutKeyboardFunc(self.glutkeydown)
            glutKeyboardUpFunc(self.glutkeyup)
            glutSpecialFunc(self.glutspecialdown)
            glutSpecialUpFunc(self.glutspecialup)
            self.glutkeytime = False
            #        glutIgnoreKeyRepeat(True)
        elif driver == 'framebuffer':
            print('using framebuffer')
            screen = ugfx.screen("/dev/fb0")
            if screen.width > 480:
                print('warning huge width')
                #screen.width = 480
                #screen.height= min(screen.height, 640)

        if screen:
            self.bw = 1 if screen.width < 120 else False
            self.mag = 1

            if not self.surface:
                w, h = screen.width, screen.height
                self.surface = ugfx.surface(w, h, screen.bypp, None)

                # magnify to fill screen
                self.mag = min(screen.width / self.surface.width,
                               screen.height / self.surface.height)
                if self.mag != 1:
                    print('magnifying lcd surface to fit screen')
                    self.magsurface = ugfx.surface(screen)

                self.invsurface = ugfx.surface(self.surface)
        else:
            self.surface = None

        self.lastframetime = 0
        self.screen = screen

        set_language(self.config['language'])
        self.client = False
        self.connect()

        self.menu = False
        self.page = connecting(self)
        self.need_refresh = True

        self.keypad = []
        for i in range(NUM_KEYS):
            self.keypad.append(Key())

        self.blink = black, white  # two cursor states
        self.data_update = False
Example #4
0
    def __init__(self, config):
        if config:
            self.config = config['lcd']
        else:
            self.config = {}
        self.pipe = False
        self.poller = False
        self.voltage = False

        default = {
            'contrast': 60,
            'invert': False,
            'backlight': 20,
            'hue': 214,
            'flip': False,
            'language': 'en',
            'bigstep': 10,
            'smallstep': 1,
            'buzzer': 2
        }

        for name in default:
            if not name in self.config:
                self.config[name] = default[name]

        global driver
        # set the driver to the one read from hat eeprom, or specified in hat.conf
        if config and 'hat' in config:
            if driver == 'default':
                driver = config['hat']['lcd']['driver']
            self.host = config['host']
        else:
            self.host = False

        self.battery_voltage = 0
        use_tft = True if micropython else False
        self.keypress = False

        use_glut = not use_tft and 'DISPLAY' in os.environ
        self.surface = None

        self.use_glut = False
        print('lcd driver', driver, use_tft, use_glut)
        if driver == 'none':
            page = None
            screen = None
            self.bw = None
        elif driver == 'tft' or (driver == 'default' and use_tft):
            import gc
            if gc.mem_free() > 1e6:  # larger ttgo display
                screen = ugfx.surface(240, 320, 1)
            else:
                screen = ugfx.surface(136, 240, 1)
            self.surface = screen
        elif driver == 'nokia5110' or (driver == 'default' and not use_glut):
            screen = ugfx.spiscreen(0)
        elif driver == 'jlx12864':
            screen = ugfx.spiscreen(1)
        elif driver == 'glut' or (driver == 'default' and use_glut):
            self.use_glut = True
            print('using glut')
            import glut
            # emulate which screen resolution?
            #screen = glut.screen((240, 320))
            screen = glut.screen((136, 240))
            #screen = glut.screen((48, 84))
            #screen = glut.screen((96, 168))

            from OpenGL.GLUT import glutKeyboardFunc, glutKeyboardUpFunc
            from OpenGL.GLUT import glutSpecialFunc, glutSpecialUpFunc

            glutKeyboardFunc(self.glutkeydown)
            glutKeyboardUpFunc(self.glutkeyup)
            glutSpecialFunc(self.glutspecialdown)
            glutSpecialUpFunc(self.glutspecialup)
            self.glutkeytime = False
            #        glutIgnoreKeyRepeat(True)
        elif driver == 'framebuffer':
            print('using framebuffer')
            screen = ugfx.screen("/dev/fb0")
            if screen.width > 480:
                print('warning huge width')
                #screen.width = 480
                #screen.height= min(screen.height, 640)

        if screen:
            self.bw = 1 if screen.width < 120 else False
            self.mag = 1

            if not self.surface:
                w, h = screen.width, screen.height
                self.surface = ugfx.surface(w, h, screen.bypp, None)

                # magnify to fill screen
                self.mag = min(screen.width / self.surface.width,
                               screen.height / self.surface.height)
                if self.mag != 1:
                    print('magnifying lcd surface to fit screen')
                    self.magsurface = ugfx.surface(screen)

                self.invsurface = ugfx.surface(self.surface)
        else:
            self.surface = None

        self.screen = screen

        set_language(self.config['language'])
        self.client = False
        self.connect()

        self.menu = False
        self.page = connecting(self)
        self.need_refresh = True

        self.keypad = []
        for i in range(NUM_KEYS):
            self.keypad.append(Key())

        self.blink = black, white  # two cursor states
        self.data_update = False