pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

PebbleOS

  • Overview
  • Start here
    • Getting started guide
    • Playground
  • Development
    • The pbl CLI
    • Build system
    • Samples
      • Kernel
      • Subsystems
      • Drivers
      • Third-party
      • Rust
      • Benchmarks
    • Emulator and simulator
    • Testing
    • Debugging
    • Conventions
  • System
    • Architecture overview
    • Kernel
    • Subsystems
    • Drivers
    • Services
    • Libraries
    • Third-party
    • Application SDK
  • Hardware
    • Boards
    • Programmers
  • Community
    • Contribution Guidelines
  • Reference
    • Reference
    • Kconfig options

LVGL: Hello world

This sample starts LVGL on the display with pbl_lvgl_init(), puts a label and a spinner on the active screen and renders them for 5 seconds. Its loop is the whole of what LVGL needs to run: lv_timer_handler() renders what changed and returns how long it can wait until it is called again.

Watch the screen, on a watch or in the emulator’s window.

Run:

pbl samples samples/third_party/lvgl/hello_world

Boards:

every board

Sources

src/main.c
#include <stdio.h>

#include <pbl/kernel/delay.h>
#include <pbl/kernel/time.h>

#include <pbl_lvgl.h>

#define SHOW_MS 5000

int main(void) {
  lv_obj_t *label;
  lv_obj_t *spinner;
  uint64_t end;
  int ret;

  ret = pbl_lvgl_init();
  if (ret != 0) {
    fprintf(stderr, "lvgl: init failed (%d)\n", ret);
    return ret;
  }

  label = lv_label_create(lv_screen_active());
  lv_label_set_text(label, "Hello World!\n" CONFIG_BOARD);
  lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
  lv_obj_align(label, LV_ALIGN_CENTER, 0, -40);

  /* An animation, so that there is something to render on every pass. */
  spinner = lv_spinner_create(lv_screen_active());
  lv_obj_set_size(spinner, 60, 60);
  lv_obj_align(spinner, LV_ALIGN_CENTER, 0, 30);

  printf("lvgl: %d.%d.%d, showing for %d s\n", lv_version_major(), lv_version_minor(),
         lv_version_patch(), SHOW_MS / 1000);

  /* LVGL does its work in lv_timer_handler(), which says when it is next due. */
  end = pbl_uptime_ms() + SHOW_MS;
  while (pbl_uptime_ms() < end) {
    pbl_sleep_ms(lv_timer_handler());
  }

  printf("Sample done\n");

  return 0;
}

Output

lvgl: \d+\.\d+\.\d+, showing for 5 s
Sample done

Generated from PebbleOS 4bbc630fa. This page is maintained in the pebbleos repository: docs/samples/third_party/lvgl/hello_world.md.

Overview

  • Sources
  • Output