2025-12-15 07:05:50 +01:00

184 lines
4.5 KiB
C

#define LV_USE_SDL 1
#include <stdio.h>
#include "esp_wifi.h"
#include "ihm.h"
#include "mqtt_client.h"
#include "backends.h"
#include <unistd.h>
#include "driver_backends.h"
#include "simulator_util.h"
#include "simulator_settings.h"
#include "esp_log.h"
#include "eventsManager.h"
esp_mqtt_client_handle_t client;
SemaphoreHandle_t lvgl_mux;
/* contains the name of the selected backend if user
* has specified one on the command line */
static char *selected_backend;
/* Global simulator settings, defined in lv_linux_backend.c */
extern simulator_settings_t settings;
void die(const char *msg, ...)
{
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
exit(EXIT_FAILURE);
}
/**
* @brief Print LVGL version
*/
static void print_lvgl_version(void)
{
fprintf(stdout, "%d.%d.%d-%s\n",
LVGL_VERSION_MAJOR,
LVGL_VERSION_MINOR,
LVGL_VERSION_PATCH,
LVGL_VERSION_INFO);
}
/**
* @brief Print usage information
*/
static void print_usage(void)
{
fprintf(stdout, "\nlvglsim [-V] [-B] [-b backend_name] [-W window_width] [-H window_height]\n\n");
fprintf(stdout, "-V print LVGL version\n");
fprintf(stdout, "-B list supported backends\n");
}
/**
* @brief Configure simulator
* @description process arguments recieved by the program to select
* appropriate options
* @param argc the count of arguments in argv
* @param argv The arguments
*/
static void configure_simulator(int argc, char **argv)
{
int opt = 0;
selected_backend = NULL;
driver_backends_register();
const char *env_w = getenv("LV_SIM_WINDOW_WIDTH");
const char *env_h = getenv("LV_SIM_WINDOW_HEIGHT");
/* Default values */
settings.window_width = atoi(env_w ? env_w : "1024");
settings.window_height = atoi(env_h ? env_h : "600");
/* Parse the command-line options. */
while ((opt = getopt (argc, argv, "b:fmW:H:BVh")) != -1) {
switch (opt) {
case 'h':
print_usage();
exit(EXIT_SUCCESS);
break;
case 'V':
print_lvgl_version();
exit(EXIT_SUCCESS);
break;
case 'B':
driver_backends_print_supported();
exit(EXIT_SUCCESS);
break;
case 'b':
if (driver_backends_is_supported(optarg) == 0) {
die("error no such backend: %s\n", optarg);
}
selected_backend = strdup(optarg);
break;
case 'W':
settings.window_width = atoi(optarg);
break;
case 'H':
settings.window_height = atoi(optarg);
break;
case ':':
print_usage();
die("Option -%c requires an argument.\n", optopt);
break;
case '?':
print_usage();
die("Unknown option -%c.\n", optopt);
}
}
}
static void
clock_timer_cb(lv_timer_t *t)
{
/* slowly increment the time */
int32_t minutes = lv_subject_get_int(&minuteSubj);
minutes += 1;
if (minutes > 59)
{
minutes = 0;
int32_t hour = lv_subject_get_int(&hourSubj);
hour += 1;
if (hour > 12)
{
hour = 1;
}
lv_subject_set_int(&hourSubj, hour);
}
lv_subject_set_int(&minuteSubj, minutes);
}
int app_main(int argc, char *argv[])
{
/* code */
printf("hello\n");
lvgl_mux = xSemaphoreCreateRecursiveMutex();
assert(lvgl_mux);
init_display_ihm();
/* Initialize LVGL. */
lv_init();
configure_simulator(argc, argv);
/* Initialize the configured backend */
if (driver_backends_init_backend(selected_backend) == -1) {
die("Failed to initialize display backend");
}
lv_sdl_mouse_create();
lv_sdl_keyboard_create();
lv_sdl_mousewheel_create();
lv_sdl_mousewheel_create();
size_t watermark = uxTaskGetStackHighWaterMark(NULL);
ESP_LOGI("STACK", "Remaining stack: %d bytes", watermark);
lv_subject_init_int(&hourSubj, 9);
lv_subject_init_int(&minuteSubj, 36);
lv_subject_t *grp[2] = {&hourSubj, &minuteSubj};
lv_subject_init_group(&timeGroup, grp,2);
/*lv_timer_t *clock_timer = */lv_timer_create(clock_timer_cb, 1000, NULL);
//draw_ihm();
startEvtManager();
xTaskCreate(drawIhm, "LVGL", 128 * 1024, getIHMQueueHandle(), 3, NULL);
/* Enter the run loop of the selected backend */
driver_backends_run_loop();
//drawIhm(getIHMQueueHandle());
return 0;
}