|
| 1 | + |
| 2 | +/** |
| 3 | + * @file main |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +/********************* |
| 8 | + * INCLUDES |
| 9 | + *********************/ |
| 10 | +#include <stdlib.h> |
| 11 | +#include <unistd.h> |
| 12 | +#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/ |
| 13 | +#include <SDL2/SDL.h> |
| 14 | +#include <emscripten.h> |
| 15 | +#include "lvgl/lvgl.h" |
| 16 | +#include "lvgl/demos/lv_demos.h" |
| 17 | +#include "lvgl/examples/lv_examples.h" |
| 18 | + |
| 19 | +/********************* |
| 20 | + * DEFINES |
| 21 | + *********************/ |
| 22 | + |
| 23 | +/*On OSX SDL needs different handling*/ |
| 24 | +#if defined(__APPLE__) && defined(TARGET_OS_MAC) |
| 25 | +# if __APPLE__ && TARGET_OS_MAC |
| 26 | +#define SDL_APPLE |
| 27 | +# endif |
| 28 | +#endif |
| 29 | + |
| 30 | +/********************** |
| 31 | + * TYPEDEFS |
| 32 | + **********************/ |
| 33 | + |
| 34 | +/********************** |
| 35 | + * STATIC PROTOTYPES |
| 36 | + **********************/ |
| 37 | +static void hal_init(void); |
| 38 | +static int tick_thread(void * data); |
| 39 | +static void memory_monitor(lv_timer_t * param); |
| 40 | + |
| 41 | +/********************** |
| 42 | + * STATIC VARIABLES |
| 43 | + **********************/ |
| 44 | +static lv_display_t * disp1; |
| 45 | + |
| 46 | +int monitor_hor_res, monitor_ver_res; |
| 47 | + |
| 48 | +/********************** |
| 49 | + * MACROS |
| 50 | + **********************/ |
| 51 | + |
| 52 | +/********************** |
| 53 | + * GLOBAL FUNCTIONS |
| 54 | + **********************/ |
| 55 | +void do_loop(void *arg); |
| 56 | + |
| 57 | +/* Allows disabling CHOSEN_DEMO */ |
| 58 | +static void lv_example_noop(void) { |
| 59 | +} |
| 60 | + |
| 61 | +int main(int argc, char ** argv) |
| 62 | +{ |
| 63 | + |
| 64 | + monitor_hor_res = 800; |
| 65 | + monitor_ver_res = 480; |
| 66 | + printf("Starting with screen resolution of %dx%d px\n", monitor_hor_res, monitor_ver_res); |
| 67 | + |
| 68 | + /*Initialize LittlevGL*/ |
| 69 | + lv_init(); |
| 70 | + |
| 71 | + /*Initialize the HAL (display, input devices, tick) for LittlevGL*/ |
| 72 | + hal_init(); |
| 73 | + |
| 74 | + lv_demo_widgets(); |
| 75 | + |
| 76 | + emscripten_set_main_loop_arg(do_loop, NULL, -1, true); |
| 77 | +} |
| 78 | + |
| 79 | +void do_loop(void *arg) |
| 80 | +{ |
| 81 | + /* Periodically call the lv_timer handler. |
| 82 | + * It could be done in a timer interrupt or an OS task too.*/ |
| 83 | + lv_timer_handler(); |
| 84 | +} |
| 85 | + |
| 86 | +/********************** |
| 87 | + * STATIC FUNCTIONS |
| 88 | + **********************/ |
| 89 | + |
| 90 | + |
| 91 | +/** |
| 92 | + * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library |
| 93 | + */ |
| 94 | +static void hal_init(void) |
| 95 | +{ |
| 96 | + lv_display_t * disp = lv_sdl_window_create(monitor_hor_res, monitor_ver_res); |
| 97 | + |
| 98 | + lv_group_t * g = lv_group_create(); |
| 99 | + lv_group_set_default(g); |
| 100 | + |
| 101 | + lv_sdl_mouse_create(); |
| 102 | + lv_indev_t * mousewheel = lv_sdl_mousewheel_create(); |
| 103 | + lv_indev_set_group(mousewheel, lv_group_get_default()); |
| 104 | + |
| 105 | + lv_indev_t * keyboard = lv_sdl_keyboard_create(); |
| 106 | + lv_indev_set_group(keyboard, lv_group_get_default()); |
| 107 | +} |
0 commit comments