Exemplo n.º 1
0
# Initialize display and touch panel

disp = ili9341(dc=32, cs=33, power=-1, backlight=-1)
touch = xpt2046()

# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

# Create a screen with a draggable image

with open('png_decoder_test.png', 'rb') as f:
    png_data = f.read()

png_img_dsc = lv.img_dsc_t({'data_size': len(png_data), 'data': png_data})

scr = lv.scr_act()

# Create an image on the left using the decoder

# lv.img.cache_set_size(2)
img1 = lv.img(scr)
img1.align(scr, lv.ALIGN.CENTER, 0, -20)
img1.set_src(png_img_dsc)
img1.set_drag(True)

img2 = lv.img(scr)
img2.set_src(lv.SYMBOL.OK + "Accept")
img2.align(img1, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
Exemplo n.º 2
0
    
# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

# Create an image from the png file
try:
    with open('../../assets/img_skew_strip.png','rb') as f:
        png_data = f.read()
except:
    print("Could not find img_skew_strip.png")
    sys.exit()
    
img_skew_strip = lv.img_dsc_t({
  'data_size': len(png_data),
  'data': png_data 
})

#
# Image styling and offset
#

style = lv.style_t()
style.init()
style.set_bg_color(lv.palette_main(lv.PALETTE.YELLOW))
style.set_bg_opa(lv.OPA.COVER)
style.set_img_recolor_opa(lv.OPA.COVER)
style.set_img_recolor(lv.color_black())

img = lv.img(lv.scr_act())
img.add_style(style, 0)
# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

anim_imgs = [None]*3
# Create an image from the png file
try:
    with open('../assets/animimg001.png','rb') as f:
        anim001_data = f.read()
except:
    print("Could not find animimg001.png")
    sys.exit()
    
anim_imgs[0] = lv.img_dsc_t({
  'data_size': len(anim001_data),
  'data': anim001_data 
})

try:
    with open('../assets/animimg002.png','rb') as f:
        anim002_data = f.read()
except:
    print("Could not find animimg002.png")
    sys.exit()
    
anim_imgs[1] = lv.img_dsc_t({
  'data_size': len(anim002_data),
  'data': anim002_data 
})

try:
Exemplo n.º 4
0
# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

# Create an image from the png file
try:
    with open('../../assets/img_hand_min.png', 'rb') as f:
        img_hand_min_data = f.read()
except:
    print("Could not find img_hand_min.png")
    sys.exit()

img_hand_min_dsc = lv.img_dsc_t({
    'data_size': len(img_hand_min_data),
    'data': img_hand_min_data
})

# Create an image from the png file
try:
    with open('../../assets/img_hand_hour.png', 'rb') as f:
        img_hand_hour_data = f.read()
except:
    print("Could not find img_hand_hour.png")
    sys.exit()

img_hand_hour_dsc = lv.img_dsc_t({
    'data_size': len(img_hand_hour_data),
    'data': img_hand_hour_data
})
Exemplo n.º 5
0
# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

# Create an image from the png file
try:
    with open('../assets/imgbtn_left.png', 'rb') as f:
        imgbtn_left_data = f.read()
except:
    print("Could not find imgbtn_left.png")
    sys.exit()

imgbtn_left_dsc = lv.img_dsc_t({
    'data_size': len(imgbtn_left_data),
    'data': imgbtn_left_data
})

try:
    with open('../assets/imgbtn_mid.png', 'rb') as f:
        imgbtn_mid_data = f.read()
except:
    print("Could not find imgbtn_mid.png")
    sys.exit()

imgbtn_mid_dsc = lv.img_dsc_t({
    'data_size': len(imgbtn_mid_data),
    'data': imgbtn_mid_data
})

try:
Exemplo n.º 6
0
import lvgl as lv
import display_driver
from imagetools import get_png_info, open_png

# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

# Create an image from the png file
try:
    with open('../../assets/img_cogwheel_argb.png', 'rb') as f:
        png_data = f.read()
except:
    print("Could not find img_cogwheel_argb.png")
    sys.exit()

img_cogwheel_argb = lv.img_dsc_t({
    'data_size': len(png_data),
    'data': png_data
})

img1 = lv.img(lv.scr_act())
img1.set_src(img_cogwheel_argb)
img1.align(lv.ALIGN.CENTER, 0, -20)
img1.set_size(200, 200)

img2 = lv.img(lv.scr_act())
img2.set_src(lv.SYMBOL.OK + "Accept")
img2.align_to(img1, lv.ALIGN.OUT_BOTTOM_MID, 0, 20)
Exemplo n.º 7
0
    def __init__(self,
                 watch,
                 screen,
                 callback=None,
                 config_file='/watchfaces/watchface_default.json',
                 size_x=240,
                 size_y=240):

        # Canvas approach
        # self._cbuff = bytearray(size_x * size_y * 4)
        # self.canvas = lv.canvas(screen)
        # self.canvas.set_buffer(self._cbuff, size_x, size_y, lv.img.CF.TRUE_COLOR)
        # self.canvas.fill_bg(styles.LV_COLOR_LIGHT_GREY, lv.OPA.COVER)
        self.name = 'Watchface Default'
        self.watch = watch
        self.screen = screen
        self.config_file = config_file
        self.containers = {}
        self.objs = {}
        self.lv_task_updater = None
        self.task_data = {}
        self.refresh_counter = 0
        try:
            with open(config_file) as wf_cfg:
                self.cfg = json.load(wf_cfg)
        except OSError:
            print('Missing or error reading watchface config:', config_file)
            exit(-1)

        # Use PNG from imagetools
        # Register new image decoder
        self.decoder = lv.img.decoder_create()
        self.decoder.info_cb = get_png_info
        self.decoder.open_cb = open_png

        self.bg_img_dsc = lv.img_dsc_t()
        self.bg_img = lv.img(screen)
        self.bg_draw_img = lv.draw_img_dsc_t()
        self.bg_draw_img.init()

        if callback is not None:
            self.bg_img.set_event_cb(callback)

        self.debug_cfg = {
            "type": "LvDebug",
            "src": "debug",
            "layout": {
                "format": "12h",
                "include_battery_percentage": "yes",
                "include_battery_voltage": "yes"
            },
            "styles": {
                "transparent": "no",
                "text": {
                    "size": 12,
                    "color": "0000ff"
                },
                "background": {
                    "color": "00fffa"
                }
            },
            "x_start": 5,
            "y_start": 5,
            "x_end": 230,
            "y_end": 230
        }
Exemplo n.º 8
0
        hand_img_data = f.read()
except:
    try:
        with open('images/img_hand_argb565.bin', 'rb') as f:
            hand_img_data = f.read()
    except:
        print("Could not find img_hand file")
        sys.exit()

# create the hands image data

img_hand_dsc = lv.img_dsc_t({
    "header": {
        "always_zero": 0,
        "w": 100,
        "h": 9,
        "cf": lv.img.CF.TRUE_COLOR_ALPHA
    },
    "data": hand_img_data,
    "data_size": len(hand_img_data),
})

# needle colors
needle_colors = [lv_colors.BLUE, lv_colors.ORANGE, lv_colors.PURPLE]

# create the gauge
gauge1 = lv.gauge(lv.scr_act(), None)
gauge1.set_needle_count(3, needle_colors)
gauge1.set_size(200, 200)
gauge1.align(None, lv.ALIGN.CENTER, 0, 0)
gauge1.set_needle_img(img_hand_dsc, 4, 4)
gauge1.set_style_local_image_recolor_opa(lv.gauge.PART.NEEDLE,
Exemplo n.º 9
0
        driver = SDL
except:
    try:
        with open('images/img_cogwheel_rgb565.bin', 'rb') as f:
            cogwheel_img_data = f.read()
            driver = ILI9341
    except:
        print("Could not find binary img_cogwheel file")

# create the cogwheel image data
if driver == SDL:
    cogwheel_img_dsc = lv.img_dsc_t({
        "header": {
            "always_zero": 0,
            "w": 100,
            "h": 100,
            "cf": lv.img.CF.TRUE_COLOR_ALPHA
        },
        "data": cogwheel_img_data,
        "data_size": len(cogwheel_img_data),
    })
else:
    cogwheel_img_dsc = lv.img_dsc_t({
        "header": {
            "always_zero": 0,
            "w": 100,
            "h": 100,
            "cf": lv.img.CF.TRUE_COLOR
        },
        "data": cogwheel_img_data,
        "data_size": len(cogwheel_img_data),
    })
Exemplo n.º 10
0
            img_data = f.read()
            driver = ILI9341
    except:
        print("Could not open image file")
        sys.exit()

scr = lv.scr_act()
img = lv.img(scr)
img.align(scr, lv.ALIGN.CENTER, 0, 0)

if driver == SDL:
    img_dsc = lv.img_dsc_t({
        "header": {
            "always_zero": 0,
            "w": 41,
            "h": 49,
            "cf": lv.img.CF.TRUE_COLOR_ALPHA
        },
        "data_size": len(img_data),
        "data": img_data,
    })
else:
    img_dsc = lv.img_dsc_t({
        "header": {
            "always_zero": 0,
            "w": 41,
            "h": 49,
            "cf": lv.img.CF.TRUE_COLOR
        },
        "data_size": len(img_data),
        "data": img_data,
    })
Exemplo n.º 11
0
freq_lis = []

############################
# define color
COLOR_SIZE = lv.color_t.SIZE
COLOR_IS_SWAPPED = hasattr(lv.color_t().ch, 'green_h')
# Register png image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png
# cache size
lv.img.cache_set_size(10)
# img load
with open('img/bird.png', 'rb') as f:
    png_data = f.read()
bird_img = lv.img_dsc_t({'data_size': len(png_data), 'data': png_data})

with open('img/pipe_bottom.png', 'rb') as f:
    png_data = f.read()
pipe_img_bottom = lv.img_dsc_t({'data_size': len(png_data), 'data': png_data})

with open('img/pipe_top.png', 'rb') as f:
    png_data = f.read()
pipe_img_top = lv.img_dsc_t({'data_size': len(png_data), 'data': png_data})

with open('img/cute_bird.png', 'rb') as f:
    png_data = f.read()
cute_bird_img_dsc = lv.img_dsc_t({
    'data_size': len(png_data),
    'data': png_data
})
Exemplo n.º 12
0
lv.log_register_print_cb(
    lambda level, path, line, msg: print('%s(%d): %s' % (path, line, msg)))

snapshot = sensor.snapshot()

# Create a screen with a draggable image

scr = lv.obj()
img = lv.img(scr)
img_data = snapshot.to_bytes()
img.align(scr, lv.ALIGN.CENTER, 0, 0)
img_dsc = lv.img_dsc_t({
    'header': {
        'always_zero': 0,
        'w': snapshot.width(),
        'h': snapshot.height(),
        'cf': lv.img.CF.TRUE_COLOR
    },
    'data_size': len(img_data),
    'data': img_data
})

img.set_src(img_dsc)
img.set_drag(True)

# Load the screen and display image

lv.scr_load(scr)


def on_timer(timer):
    lv.tick_inc(5)
Exemplo n.º 13
0
#!/opt/bin/lv_micropython -i
import lvgl as lv
import display_driver
from imagetools import get_png_info, open_png
from img_wink_png import img_wink_png_map
# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

img_wink_png = lv.img_dsc_t({
    "header": {
        "always_zero": 0,
        "w": 50,
        "h": 50,
        "cf": lv.img.CF.RAW_ALPHA
    },
    "data_size": 5158,
    "data": img_wink_png_map,
})
img1 = lv.img(lv.scr_act())
img1.set_src(img_wink_png)
img1.align(lv.ALIGN.RIGHT_MID, -250, 0)

# Create an image from the png file
try:
    with open('wink.png', 'rb') as f:
        png_data = f.read()
except:
    print("Could not find wink.png")
    sys.exit()
Exemplo n.º 14
0
with open('/flash/blue_flower_32.bin','rb') as f:
  img_data = f.read()

# Pixel format: Fix 0xFF: 8 bit, Red: 8 bit, Green: 8 bit, Blue: 8 bit

# Create a screen with a draggable image

scr = lv.obj()
img = lv.img(scr)
img.align(scr, lv.ALIGN.CENTER, 0, 0)
img_dsc = lv.img_dsc_t({
    'header':{
        'always_zero': 0,
        'w':100,
        'h':75,
        'cf':lv.img.CF.TRUE_COLOR
    },
    'data_size': len(img_data),
    'data': img_data
})

img.set_src(img_dsc)
img.set_drag(False)

# Load the screen and display image


lv.scr_load(scr)

def on_timer(timer):
	lv.tick_inc(5)
# Register PNG image decoder
decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

# Create an image from the png file
try:
    with open('../../assets/img_star.png','rb') as f:
        png_data = f.read()
except:
    print("Could not find img_star.png")
    sys.exit()
    
img_star_argb = lv.img_dsc_t({
  'data_size': len(png_data),
  'data': png_data 
})

def event_cb(e):
    code = e.get_code()
    obj = e.get_target()
    if code == lv.EVENT.DRAW_PART_BEGIN:
        dsc = lv.obj_draw_part_dsc_t.cast(e.get_param())
        # Change the draw descriptor the 2nd button
        if dsc.id == 1:
            dsc.rect_dsc.radius = 0;
            if obj.get_selected_btn() == dsc.id:
                dsc.rect_dsc.bg_color = lv.palette_darken(lv.PALETTE.GREY, 3)
            else:
                dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE)