2023-03-26 19:34:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file main
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <emscripten.h>
|
|
|
|
#include "lvgl/lvgl.h"
|
|
|
|
#include "lvgl/demos/lv_demos.h"
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/*On OSX SDL needs different handling*/
|
|
|
|
#if defined(__APPLE__) && defined(TARGET_OS_MAC)
|
|
|
|
# if __APPLE__ && TARGET_OS_MAC
|
|
|
|
#define SDL_APPLE
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
static void hal_init(void);
|
|
|
|
static int tick_thread(void * data);
|
|
|
|
static void memory_monitor(lv_timer_t * param);
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2024-04-10 15:17:44 +08:00
|
|
|
static lv_display_t * disp1;
|
2023-03-26 19:34:43 +08:00
|
|
|
|
|
|
|
int monitor_hor_res, monitor_ver_res;
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
void do_loop(void *arg);
|
|
|
|
|
|
|
|
/* Allows disabling CHOSEN_DEMO */
|
|
|
|
static void lv_example_noop(void) {
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
|
|
|
|
monitor_hor_res = 800;
|
|
|
|
monitor_ver_res = 480;
|
|
|
|
printf("Starting with screen resolution of %dx%d px\n", monitor_hor_res, monitor_ver_res);
|
|
|
|
|
|
|
|
/*Initialize LittlevGL*/
|
|
|
|
lv_init();
|
|
|
|
|
|
|
|
/*Initialize the HAL (display, input devices, tick) for LittlevGL*/
|
|
|
|
hal_init();
|
|
|
|
|
|
|
|
lv_demo_widgets();
|
|
|
|
|
|
|
|
emscripten_set_main_loop_arg(do_loop, NULL, -1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_loop(void *arg)
|
|
|
|
{
|
2024-04-10 15:17:44 +08:00
|
|
|
/* Periodically call the lv_timer handler.
|
2023-03-26 19:34:43 +08:00
|
|
|
* It could be done in a timer interrupt or an OS task too.*/
|
2024-04-10 15:17:44 +08:00
|
|
|
lv_timer_handler();
|
2023-03-26 19:34:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library
|
|
|
|
*/
|
|
|
|
static void hal_init(void)
|
|
|
|
{
|
2024-04-10 15:17:44 +08:00
|
|
|
lv_display_t * disp = lv_sdl_window_create(monitor_hor_res, monitor_ver_res);
|
2023-03-26 19:34:43 +08:00
|
|
|
|
|
|
|
lv_group_t * g = lv_group_create();
|
|
|
|
lv_group_set_default(g);
|
|
|
|
|
|
|
|
lv_sdl_mouse_create();
|
2023-07-15 05:22:44 +08:00
|
|
|
lv_indev_t * mousewheel = lv_sdl_mousewheel_create();
|
|
|
|
lv_indev_set_group(mousewheel, lv_group_get_default());
|
2023-11-15 21:08:03 +08:00
|
|
|
|
2023-07-15 05:22:44 +08:00
|
|
|
lv_indev_t * keyboard = lv_sdl_keyboard_create();
|
|
|
|
lv_indev_set_group(keyboard, lv_group_get_default());
|
|
|
|
}
|