1 /*
2 * Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <device.h>
8 #include <drivers/display.h>
9 #include <lvgl.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <zephyr.h>
13
14 #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
15 #include <logging/log.h>
16 LOG_MODULE_REGISTER(app);
17
main(void)18 void main(void)
19 {
20 uint32_t count = 0U;
21 char count_str[11] = {0};
22 const struct device *display_dev;
23 lv_obj_t *hello_world_label;
24 lv_obj_t *count_label;
25
26 display_dev = device_get_binding(CONFIG_LVGL_DISPLAY_DEV_NAME);
27
28 if (display_dev == NULL) {
29 LOG_ERR("device not found. Aborting test.");
30 return;
31 }
32
33 if (IS_ENABLED(CONFIG_LVGL_POINTER_KSCAN)) {
34 lv_obj_t *hello_world_button;
35
36 hello_world_button = lv_btn_create(lv_scr_act(), NULL);
37 lv_obj_align(hello_world_button, NULL, LV_ALIGN_CENTER, 0, 0);
38 lv_btn_set_fit(hello_world_button, LV_FIT_TIGHT);
39 hello_world_label = lv_label_create(hello_world_button, NULL);
40 } else {
41 hello_world_label = lv_label_create(lv_scr_act(), NULL);
42 }
43
44 lv_label_set_text(hello_world_label, "Hello world!");
45 lv_obj_align(hello_world_label, NULL, LV_ALIGN_CENTER, 0, 0);
46
47 count_label = lv_label_create(lv_scr_act(), NULL);
48 lv_obj_align(count_label, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
49
50 lv_task_handler();
51 display_blanking_off(display_dev);
52
53 while (1) {
54 if ((count % 100) == 0U) {
55 sprintf(count_str, "%d", count/100U);
56 lv_label_set_text(count_label, count_str);
57 }
58 lv_task_handler();
59 k_sleep(K_MSEC(10));
60 ++count;
61 }
62 }
63