0% found this document useful (0 votes)
1 views

code ecran jaune

The document is a C++ code for an embedded system using LVGL library to create a graphical user interface on a TFT display with touchscreen support. It defines multiple screens including a main screen and three additional screens for 'Cartonier', 'Onduleuse', and 'Parametre', with event handlers for button interactions. The setup function initializes the touchscreen and display, while the loop function handles tasks and timing for the GUI updates.

Uploaded by

cyrilbelorge
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

code ecran jaune

The document is a C++ code for an embedded system using LVGL library to create a graphical user interface on a TFT display with touchscreen support. It defines multiple screens including a main screen and three additional screens for 'Cartonier', 'Onduleuse', and 'Parametre', with event handlers for button interactions. The setup function initializes the touchscreen and display, while the loop function handles tasks and timing for the GUI updates.

Uploaded by

cyrilbelorge
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <lvgl.

h>
#include <TFT_eSPI.h>
#include <XPT2046_Touchscreen.h>

#define SCREEN_WIDTH 240


#define SCREEN_HEIGHT 320

#define XPT2046_IRQ 36 // T_IRQ


#define XPT2046_MOSI 32 // T_DIN
#define XPT2046_MISO 39 // T_OUT
#define XPT2046_CLK 25 // T_CLK
#define XPT2046_CS 33 // T_CS

SPIClass touchscreenSPI = SPIClass(VSPI);


XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ);

#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))


uint32_t draw_buf[DRAW_BUF_SIZE / 4];

// Déclaration des écrans


lv_obj_t * main_screen;
lv_obj_t * cartonier_screen;
lv_obj_t * onduleuse_screen;
lv_obj_t * parametre_screen;

void log_print(lv_log_level_t level, const char * buf) {


LV_UNUSED(level);
Serial.println(buf);
Serial.flush();
}

void touchscreen_read(lv_indev_t * indev, lv_indev_data_t * data) {


if (touchscreen.tirqTouched() && touchscreen.touched()) {
TS_Point p = touchscreen.getPoint();

int x = map(p.x, 200, 3700, 0, SCREEN_WIDTH);


int y = map(p.y, 240, 3800, 0, SCREEN_HEIGHT);

x = SCREEN_WIDTH - x;
y = SCREEN_HEIGHT - y;

data->state = LV_INDEV_STATE_PRESSED;
data->point.x = x;
data->point.y = y;

Serial.print("X = "); Serial.print(x);


Serial.print(" | Y = "); Serial.print(y);
Serial.println();
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}

// Gestionnaire d'événements pour le bouton "Retour"


static void event_handler_back(lv_event_t * e) {
lv_disp_load_scr(main_screen); // Revenir à l'écran principal
}

// Gestionnaire d'événements pour le bouton "Cartonier"


static void event_handler_btn1(lv_event_t * e) {
lv_disp_load_scr(cartonier_screen); // Afficher l'écran Cartonier
}

// Gestionnaire d'événements pour le bouton "Onduleuse"


static void event_handler_btn2(lv_event_t * e) {
lv_disp_load_scr(onduleuse_screen); // Afficher l'écran Onduleuse
}

// Gestionnaire d'événements pour le bouton "Parametre"


static void event_handler_btn3(lv_event_t * e) {
lv_disp_load_scr(parametre_screen); // Afficher l'écran Parametre
}

// Créer l'écran principal


void lv_create_main_gui(void) {
main_screen = lv_scr_act();

// Appliquer un style futuriste aux boutons


static lv_style_t style_btn;
lv_style_init(&style_btn);
lv_style_set_radius(&style_btn, 10);
lv_style_set_bg_color(&style_btn, lv_palette_main(LV_PALETTE_BLUE));
lv_style_set_bg_grad_color(&style_btn, lv_palette_darken(LV_PALETTE_BLUE, 3));
lv_style_set_bg_grad_dir(&style_btn, LV_GRAD_DIR_VER);
lv_style_set_border_width(&style_btn, 2);
lv_style_set_border_color(&style_btn, lv_palette_main(LV_PALETTE_CYAN));
lv_style_set_shadow_width(&style_btn, 10);
lv_style_set_shadow_color(&style_btn, lv_palette_main(LV_PALETTE_CYAN));
lv_style_set_text_font(&style_btn, &lv_font_montserrat_22);

// Arrière-plan futuriste
lv_obj_set_style_bg_color(main_screen, lv_palette_lighten(LV_PALETTE_BLUE_GREY,
2), 0);
lv_obj_set_style_bg_grad_color(main_screen, lv_palette_main(LV_PALETTE_GREY),
0);
lv_obj_set_style_bg_grad_dir(main_screen, LV_GRAD_DIR_VER, 0);

// Titre principal
lv_obj_t * text_label = lv_label_create(main_screen);
lv_label_set_text(text_label, "Bonjour, le monde !");
lv_obj_align(text_label, LV_ALIGN_CENTER, 0, -90);

// Bouton Cartonier
lv_obj_t * btn1 = lv_btn_create(main_screen);
lv_obj_add_style(btn1, &style_btn, 0);
lv_obj_set_size(btn1, 180, 60);
lv_obj_add_event_cb(btn1, event_handler_btn1, LV_EVENT_CLICKED, NULL);
lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -50);

lv_obj_t * btn_icon1 = lv_label_create(btn1);


lv_label_set_text(btn_icon1, LV_SYMBOL_RIGHT "");
lv_obj_set_style_text_font(btn_icon1, &lv_font_montserrat_24, LV_PART_MAIN);
lv_obj_align(btn_icon1, LV_ALIGN_LEFT_MID, 5, 0);

lv_obj_t * btn_label1 = lv_label_create(btn1);


lv_label_set_text(btn_label1, "Cartonier");
lv_obj_set_style_text_font(btn_label1, &lv_font_montserrat_20, LV_PART_MAIN);
lv_obj_align(btn_label1, LV_ALIGN_LEFT_MID, 50, 0);
// Bouton Onduleuse
lv_obj_t * btn2 = lv_btn_create(main_screen);
lv_obj_add_style(btn2, &style_btn, 0);
lv_obj_set_size(btn2, 180, 60);
lv_obj_add_event_cb(btn2, event_handler_btn2, LV_EVENT_CLICKED, NULL);
lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 10);

lv_obj_t * btn_icon2 = lv_label_create(btn2);


lv_label_set_text(btn_icon2, LV_SYMBOL_RIGHT "");
lv_obj_set_style_text_font(btn_icon2, &lv_font_montserrat_24, LV_PART_MAIN);
lv_obj_align(btn_icon2, LV_ALIGN_LEFT_MID, 5, 0);

lv_obj_t * btn_label2 = lv_label_create(btn2);


lv_label_set_text(btn_label2, "Onduleuse");
lv_obj_set_style_text_font(btn_label2, &lv_font_montserrat_20, LV_PART_MAIN);
lv_obj_align(btn_label2, LV_ALIGN_LEFT_MID, 50, 0);

// Bouton Parametre
lv_obj_t * btn3 = lv_btn_create(main_screen);
lv_obj_add_style(btn3, &style_btn, 0);
lv_obj_set_size(btn3, 180, 60);
lv_obj_add_event_cb(btn3, event_handler_btn3, LV_EVENT_CLICKED, NULL);
lv_obj_align(btn3, LV_ALIGN_CENTER, 0, 70);

lv_obj_t * btn_icon3 = lv_label_create(btn3);


lv_label_set_text(btn_icon3, LV_SYMBOL_SETTINGS "");
lv_obj_set_style_text_font(btn_icon3, &lv_font_montserrat_24, LV_PART_MAIN);
lv_obj_align(btn_icon3, LV_ALIGN_LEFT_MID, 5, 0);

lv_obj_t * btn_label3 = lv_label_create(btn3);


lv_label_set_text(btn_label3, "Parametre");
lv_obj_set_style_text_font(btn_label3, &lv_font_montserrat_20, LV_PART_MAIN);
lv_obj_align(btn_label3, LV_ALIGN_LEFT_MID, 50, 0);
}

// Créer l'écran Cartonier


void lv_create_cartonier_gui(void) {
cartonier_screen = lv_obj_create(NULL);

// Titre
lv_obj_t * title = lv_label_create(cartonier_screen);
lv_label_set_text(title, "Cartonier");
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 10);

// Bouton Retour
lv_obj_t * btn_back = lv_btn_create(cartonier_screen);
lv_obj_set_size(btn_back, 100, 40);
lv_obj_add_event_cb(btn_back, event_handler_back, LV_EVENT_CLICKED, NULL);
lv_obj_align(btn_back, LV_ALIGN_BOTTOM_MID, 0, -10);

lv_obj_t * btn_label = lv_label_create(btn_back);


lv_label_set_text(btn_label, "Retour");
lv_obj_center(btn_label);
}

// Créer l'écran Onduleuse


void lv_create_onduleuse_gui(void) {
onduleuse_screen = lv_obj_create(NULL);
// Titre
lv_obj_t * title = lv_label_create(onduleuse_screen);
lv_label_set_text(title, "Onduleuse");
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 10);

// Bouton Retour
lv_obj_t * btn_back = lv_btn_create(onduleuse_screen);
lv_obj_set_size(btn_back, 100, 40);
lv_obj_add_event_cb(btn_back, event_handler_back, LV_EVENT_CLICKED, NULL);
lv_obj_align(btn_back, LV_ALIGN_BOTTOM_MID, 0, -10);

lv_obj_t * btn_label = lv_label_create(btn_back);


lv_label_set_text(btn_label, "Retour");
lv_obj_center(btn_label);
}

// Créer l'écran Parametre


void lv_create_parametre_gui(void) {
parametre_screen = lv_obj_create(NULL);

// Titre
lv_obj_t * title = lv_label_create(parametre_screen);
lv_label_set_text(title, "Parametre");
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 10);

// Bouton Retour
lv_obj_t * btn_back = lv_btn_create(parametre_screen);
lv_obj_set_size(btn_back, 100, 40);
lv_obj_add_event_cb(btn_back, event_handler_back, LV_EVENT_CLICKED, NULL);
lv_obj_align(btn_back, LV_ALIGN_BOTTOM_MID, 0, -10);

lv_obj_t * btn_label = lv_label_create(btn_back);


lv_label_set_text(btn_label, "Retour");
lv_obj_center(btn_label);
}

void setup() {
Serial.begin(115200);
lv_init();
lv_log_register_print_cb(log_print);

touchscreenSPI.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);


touchscreen.begin(touchscreenSPI);
touchscreen.setRotation(2);

lv_display_t * disp;
disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf,
sizeof(draw_buf));
lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_0);

lv_indev_t * indev = lv_indev_create();


lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev, touchscreen_read);

lv_create_main_gui();
lv_create_cartonier_gui();
lv_create_onduleuse_gui();
lv_create_parametre_gui();
}

void loop() {
lv_task_handler();
lv_tick_inc(5);
delay(5);
}

You might also like