Skip to content

Commit

Permalink
Added the actual test screen that i forgot.
Browse files Browse the repository at this point in the history
  • Loading branch information
frnktank committed Dec 10, 2024
1 parent 9ab257d commit d7844b0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
1 change: 0 additions & 1 deletion examples/nucleo_l476rg/lvgl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ main()
lv_indev_set_read_cb(indev, my_touchpad_read);

drawTestScreen();
//drawProcessScreen();

modm::ShortPeriodicTimer tmr{20ms};

Expand Down
68 changes: 68 additions & 0 deletions examples/nucleo_l476rg/lvgl/test_screen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "test_screen.h"

static lv_obj_t* screen;
static uint16_t counter = 0;
static lv_obj_t* labelA;
static lv_obj_t* labelTouch;
static lv_obj_t* labelRawTouch;

void btn_event_cb(lv_event_t *event)
{
static uint16_t btnCounter = 0;
lv_label_set_text_fmt((lv_obj_t*) lv_event_get_user_data(event),
"Button: %d", ++btnCounter);
}

void drawTestScreen(void)
{
screen = lv_obj_create(NULL);

labelA = lv_label_create(screen);
lv_label_set_text(labelA, "Hello world!");
lv_obj_set_pos(labelA, 60, 10);
lv_obj_set_size(labelA, 120, 50);

labelTouch = lv_label_create(screen);
lv_label_set_text_fmt(labelTouch, "Pos Touch: x = %d, y = %d", 0, 0);
lv_obj_set_pos(labelTouch, 60, 30);
lv_obj_set_size(labelTouch, 120, 50);

labelRawTouch = lv_label_create(screen);
lv_label_set_text_fmt(labelRawTouch, "Raw Touch: x = %d, y = %d", 0, 0);
lv_obj_set_pos(labelRawTouch, 60, 80);
lv_obj_set_size(labelRawTouch, 120, 50);

lv_obj_t* btn = lv_button_create(screen);
lv_obj_set_pos(btn, 60, 135);
lv_obj_set_size(btn, 120, 50);

lv_obj_t* btnLabel = lv_label_create(btn);
lv_label_set_text(btnLabel, "Button");

static lv_style_t style_btn_pressed;
lv_style_init(&style_btn_pressed);
lv_style_set_bg_color(&style_btn_pressed, lv_palette_main(LV_PALETTE_ORANGE));

lv_obj_add_style(btn, &style_btn_pressed, LV_STATE_PRESSED);

lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_PRESSED, btnLabel);

lv_obj_t* labelB = lv_label_create(screen);
lv_label_set_text(labelB, "Big Font");
lv_obj_set_pos(labelB, 40, 260);
lv_obj_set_style_text_font(labelB, &lv_font_montserrat_36, LV_PART_MAIN);

// Load screen
lv_scr_load(screen);
}

void setLblText(void)
{
lv_label_set_text_fmt(labelA, "counter=%d", ++counter);
}

void setTouchText(int16_t x, int16_t y, int16_t rawX, int16_t rawY)
{
lv_label_set_text_fmt(labelTouch, "Pos Touch: x = %d, y = %d", x, y);
lv_label_set_text_fmt(labelRawTouch, "Raw Touch: x = %d, y = %d", rawX, rawY);
}
13 changes: 13 additions & 0 deletions examples/nucleo_l476rg/lvgl/test_screen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef TEST_SCREEN_H
#define TEST_SCREEN_H

#pragma once

#include <lvgl/lvgl.h>

void drawTestScreen(void);
void setLblText(void);
void setTouchText(int16_t x, int16_t y, int16_t rawX, int16_t rawY);


#endif //TEST_SCREEN_H

0 comments on commit d7844b0

Please sign in to comment.